Skip to content

Commit 091f9d1

Browse files
committed
Drop need to include ptree in ConfigurableParam.h
1 parent 8fe191e commit 091f9d1

15 files changed

Lines changed: 66 additions & 48 deletions

File tree

Common/SimConfig/test/testSimCutParam.cxx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include <boost/test/unit_test.hpp>
1616
#include "SimConfig/SimParams.h"
1717
#include "CommonUtils/ConfigurableParam.h"
18+
#include <boost/property_tree/ptree.hpp>
1819

1920
using namespace o2::conf;
2021

Common/Utils/include/CommonUtils/ConfigurableParam.h

Lines changed: 21 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
#include <cassert>
1919
#include <map>
2020
#include <unordered_map>
21-
#include <boost/property_tree/ptree.hpp>
21+
#include <boost/property_tree/ptree_fwd.hpp>
2222
#include <typeinfo>
2323
#include <iostream>
2424

@@ -181,9 +181,6 @@ class ConfigurableParam
181181
static void setInputDir(const std::string& d) { sInputDir = d; }
182182
static void setOutputDir(const std::string& d) { sOutputDir = d; }
183183

184-
static boost::property_tree::ptree readINI(std::string const& filepath);
185-
static boost::property_tree::ptree readJSON(std::string const& filepath);
186-
static boost::property_tree::ptree readConfigFile(std::string const& filepath);
187184
static bool configFileExists(std::string const& filepath);
188185

189186
// writes a human readable JSON file of all parameters
@@ -195,10 +192,12 @@ class ConfigurableParam
195192
template <typename T>
196193
static T getValueAs(std::string key)
197194
{
198-
if (!sIsFullyInitialized) {
199-
initialize();
200-
}
201-
return sPtree->get<T>(key);
195+
return [](auto* tree, const std::string& key) -> T {
196+
if (!sIsFullyInitialized) {
197+
initialize();
198+
}
199+
return tree->template get<T>(key);
200+
}(sPtree, key);
202201
}
203202

204203
template <typename T>
@@ -207,19 +206,21 @@ class ConfigurableParam
207206
if (!sIsFullyInitialized) {
208207
initialize();
209208
}
210-
assert(sPtree);
211-
try {
212-
auto key = mainkey + "." + subkey;
213-
if (sPtree->get_optional<std::string>(key).is_initialized()) {
214-
sPtree->put(key, x);
215-
auto changed = updateThroughStorageMap(mainkey, subkey, typeid(T), (void*)&x);
216-
if (changed != EParamUpdateStatus::Failed) {
217-
sValueProvenanceMap->find(key)->second = kRT; // set to runtime
209+
return [&subkey, &x, &mainkey](auto* tree) -> void {
210+
assert(tree);
211+
try {
212+
auto key = mainkey + "." + subkey;
213+
if (tree->template get_optional<std::string>(key).is_initialized()) {
214+
tree->put(key, x);
215+
auto changed = updateThroughStorageMap(mainkey, subkey, typeid(T), (void*)&x);
216+
if (changed != EParamUpdateStatus::Failed) {
217+
sValueProvenanceMap->find(key)->second = kRT; // set to runtime
218+
}
218219
}
220+
} catch (std::exception const& e) {
221+
std::cerr << "Error in setValue (T) " << e.what() << "\n";
219222
}
220-
} catch (std::exception const& e) {
221-
std::cerr << "Error in setValue (T) " << e.what() << "\n";
222-
}
223+
}(sPtree);
223224
}
224225

225226
static void setProvenance(std::string const& mainkey, std::string const& subkey, EParamProvenance p)
@@ -241,25 +242,7 @@ class ConfigurableParam
241242

242243
// specialized for std::string
243244
// which means that the type will be converted internally
244-
static void setValue(std::string const& key, std::string const& valuestring)
245-
{
246-
if (!sIsFullyInitialized) {
247-
initialize();
248-
}
249-
assert(sPtree);
250-
try {
251-
if (sPtree->get_optional<std::string>(key).is_initialized()) {
252-
sPtree->put(key, valuestring);
253-
auto changed = updateThroughStorageMapWithConversion(key, valuestring);
254-
if (changed != EParamUpdateStatus::Failed) {
255-
sValueProvenanceMap->find(key)->second = kRT; // set to runtime
256-
}
257-
}
258-
} catch (std::exception const& e) {
259-
std::cerr << "Error in setValue (string) " << e.what() << "\n";
260-
}
261-
}
262-
245+
static void setValue(std::string const& key, std::string const& valuestring);
263246
static void setEnumValue(const std::string&, const std::string&);
264247
static void setArrayValue(const std::string&, const std::string&);
265248

Common/Utils/src/ConfigurableParam.cxx

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@ namespace o2
4343
{
4444
namespace conf
4545
{
46+
boost::property_tree::ptree readINI(std::string const& filepath);
47+
boost::property_tree::ptree readJSON(std::string const& filepath);
48+
boost::property_tree::ptree readConfigFile(std::string const& filepath);
49+
4650
std::vector<ConfigurableParam*>* ConfigurableParam::sRegisteredParamClasses = nullptr;
4751
boost::property_tree::ptree* ConfigurableParam::sPtree = nullptr;
4852
std::map<std::string, std::pair<std::type_info const&, void*>>* ConfigurableParam::sKeyToStorageMap = nullptr;
@@ -199,9 +203,9 @@ bool ConfigurableParam::configFileExists(std::string const& filepath)
199203

200204
// ------------------------------------------------------------------
201205

202-
boost::property_tree::ptree ConfigurableParam::readConfigFile(std::string const& filepath)
206+
boost::property_tree::ptree readConfigFile(std::string const& inputDir, std::string const& filepath)
203207
{
204-
auto inpfilename = o2::utils::Str::concat_string(sInputDir, filepath);
208+
auto inpfilename = o2::utils::Str::concat_string(inputDir, filepath);
205209
if (!std::filesystem::exists(inpfilename)) {
206210
LOG(fatal) << inpfilename << " : config file does not exist!";
207211
}
@@ -219,9 +223,28 @@ boost::property_tree::ptree ConfigurableParam::readConfigFile(std::string const&
219223
return pt;
220224
}
221225

226+
void ConfigurableParam::setValue(std::string const& key, std::string const& valuestring)
227+
{
228+
if (!sIsFullyInitialized) {
229+
initialize();
230+
}
231+
assert(sPtree);
232+
try {
233+
if (sPtree->get_optional<std::string>(key).is_initialized()) {
234+
sPtree->put(key, valuestring);
235+
auto changed = updateThroughStorageMapWithConversion(key, valuestring);
236+
if (changed != EParamUpdateStatus::Failed) {
237+
sValueProvenanceMap->find(key)->second = kRT; // set to runtime
238+
}
239+
}
240+
} catch (std::exception const& e) {
241+
std::cerr << "Error in setValue (string) " << e.what() << "\n";
242+
}
243+
}
244+
222245
// ------------------------------------------------------------------
223246

224-
boost::property_tree::ptree ConfigurableParam::readINI(std::string const& filepath)
247+
boost::property_tree::ptree readINI(std::string const& filepath)
225248
{
226249
boost::property_tree::ptree pt;
227250
try {
@@ -237,7 +260,7 @@ boost::property_tree::ptree ConfigurableParam::readINI(std::string const& filepa
237260

238261
// ------------------------------------------------------------------
239262

240-
boost::property_tree::ptree ConfigurableParam::readJSON(std::string const& filepath)
263+
boost::property_tree::ptree readJSON(std::string const& filepath)
241264
{
242265
boost::property_tree::ptree pt;
243266

@@ -258,7 +281,7 @@ void ConfigurableParam::writeJSON(std::string const& filename, std::string const
258281
LOG(info) << "ignoring writing of json file " << filename;
259282
return;
260283
}
261-
initPropertyTree(); // update the boost tree before writing
284+
initPropertyTree(); // update the boost tree before writing
262285
auto outfilename = o2::utils::Str::concat_string(sOutputDir, filename);
263286
if (!keyOnly.empty()) { // write ini for selected key only
264287
try {
@@ -409,7 +432,7 @@ void ConfigurableParam::updateFromFile(std::string const& configFile, std::strin
409432
return;
410433
}
411434

412-
boost::property_tree::ptree pt = readConfigFile(cfgfile);
435+
boost::property_tree::ptree pt = readConfigFile(ConfigurableParam::sInputDir, cfgfile);
413436

414437
std::vector<std::pair<std::string, std::string>> keyValPairs;
415438
auto request = o2::utils::Str::tokenize(paramsList, ',', true);

Detectors/MUON/MCH/Raw/test/testClosureCoDec.cxx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#define BOOST_TEST_DYN_LINK
1717

1818
#include <boost/test/unit_test.hpp>
19+
#include <boost/property_tree/ptree.hpp>
1920
#include "DetectorsRaw/HBFUtils.h"
2021
#include "DetectorsRaw/RawFileWriter.h"
2122
#include "Framework/Logger.h"

Detectors/MUON/MCH/Simulation/test/testDigitizer.cxx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
#include "TGeoManager.h"
3232
#include "boost/format.hpp"
3333
#include <boost/test/data/test_case.hpp>
34+
#include <boost/property_tree/ptree.hpp>
3435
#include <algorithm>
3536
#include <unordered_map>
3637

Detectors/MUON/MCH/Triggering/test/testEventFinder.cxx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include <vector>
2828

2929
#include <boost/test/unit_test.hpp>
30+
#include <boost/property_tree/ptree.hpp>
3031

3132
#include "CommonUtils/ConfigurableParam.h"
3233
#include "SimulationDataFormat/MCCompLabel.h"

Detectors/TPC/base/test/testTPCParameters.cxx

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@
2323
#include "TPCBase/ParameterGas.h"
2424
#include <CommonUtils/ConfigurableParam.h>
2525
#include <CommonUtils/ConfigurableParamHelper.h>
26-
namespace o2
27-
{
28-
namespace tpc
26+
#include <boost/property_tree/ptree.hpp>
27+
28+
namespace o2::tpc
2929
{
3030

3131
constexpr float NominalTimeBin = 8 * o2::constants::lhc::LHCBunchSpacingNS * 1e-3;
@@ -367,5 +367,4 @@ BOOST_AUTO_TEST_CASE(ParameterGEM_test2)
367367
BOOST_CHECK_CLOSE(o2::conf::ConfigurableParam::getValueAs<float>("TPCGEMParam.KappaStack"), 32, 1e-12);
368368
BOOST_CHECK_CLOSE(o2::conf::ConfigurableParam::getValueAs<float>("TPCGEMParam.EfficiencyStack"), 33, 1e-3);
369369
}
370-
} // namespace tpc
371370
} // namespace o2

Detectors/TPC/calibration/include/TPCCalibration/IDCAverageGroup.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include "TPCCalibration/IDCAverageGroupBase.h"
2121
#include "TPCBase/Sector.h"
2222
#include "TPCBase/CalDet.h"
23+
#include <boost/property_tree/ptree.hpp>
2324
#include <vector>
2425
#include "Rtypes.h"
2526

Detectors/TPC/calibration/include/TPCCalibration/IDCFactorization.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include "TPCCalibration/IDCContainer.h"
2525
#include "TPCCalibration/IDCGroupHelperSector.h"
2626
#include "DataFormatsTPC/Defs.h"
27+
#include <boost/property_tree/ptree.hpp>
2728

2829
namespace o2::tpc
2930
{

Detectors/TPC/calibration/include/TPCCalibration/SACFactorization.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include "Rtypes.h"
2222
#include "TPCCalibration/IDCContainer.h"
2323
#include "DataFormatsTPC/Defs.h"
24+
#include <boost/property_tree/ptree.hpp>
2425

2526
namespace o2::tpc
2627
{

0 commit comments

Comments
 (0)