99// granted to it by virtue of its status as an Intergovernmental Organization
1010// or submit itself to any jurisdiction.
1111
12- // first version 8/2018, Sandro Wenzel
12+ // first version 8/2018, Sandro Wenzel
1313
1414#ifndef COMMON_SIMCONFIG_INCLUDE_SIMCONFIG_CONFIGURABLEPARAM_H_
1515#define COMMON_SIMCONFIG_INCLUDE_SIMCONFIG_CONFIGURABLEPARAM_H_
1616
1717#include < vector>
1818#include < map>
1919#include < unordered_map>
20- #include < boost/property_tree/ptree .hpp>
20+ #include < boost/property_tree/ptree_fwd .hpp>
2121#include < typeinfo>
2222#include < iostream>
2323
2424class TFile ;
2525class TRootIOCtor ;
2626class TDataMember ;
2727
28- namespace o2
29- {
30- namespace conf
28+ namespace o2 ::conf
3129{
3230// Base class for a configurable parameter.
3331//
@@ -88,7 +86,7 @@ namespace conf
8886struct EnumLegalValues {
8987 std::vector<std::pair<std::string, int >> vvalues;
9088
91- bool isLegal (const std::string& value) const
89+ [[nodiscard]] bool isLegal (const std::string& value) const
9290 {
9391 for (auto & v : vvalues) {
9492 if (v.first == value) {
@@ -98,7 +96,7 @@ struct EnumLegalValues {
9896 return false ;
9997 }
10098
101- bool isLegal (int value) const
99+ [[nodiscard]] bool isLegal (int value) const
102100 {
103101 for (auto & v : vvalues) {
104102 if (v.second == value) {
@@ -108,21 +106,21 @@ struct EnumLegalValues {
108106 return false ;
109107 }
110108
111- std::string toString () const ;
112- int getIntValue (const std::string& value) const ;
109+ [[nodiscard]] std::string toString () const ;
110+ [[nodiscard]] int getIntValue (const std::string& value) const ;
113111};
114112
115113class EnumRegistry
116114{
117115 public:
118116 void add (const std::string& key, const TDataMember* dm);
119117
120- bool contains (const std::string& key) const
118+ [[nodiscard]] bool contains (const std::string& key) const
121119 {
122120 return entries.count (key) > 0 ;
123121 }
124122
125- std::string toString () const ;
123+ [[nodiscard]] std::string toString () const ;
126124
127125 const EnumLegalValues* operator [](const std::string& key) const
128126 {
@@ -157,17 +155,17 @@ class ConfigurableParam
157155 }
158156
159157 // get the name of the configurable Parameter
160- virtual std::string getName () const = 0;
158+ [[nodiscard]] virtual std::string getName () const = 0;
161159
162160 // print the current keys and values to screen (optionally with provenance information)
163161 virtual void printKeyValues (bool showprov = true , bool useLogger = false ) const = 0;
164162
165163 // get a single size_t hash_value of this parameter (can be used as a checksum to see
166164 // if object changed or different)
167- virtual size_t getHash () const = 0;
165+ [[nodiscard]] virtual size_t getHash () const = 0;
168166
169167 // return the provenance of the member key
170- virtual EParamProvenance getMemberProvenance (const std::string& key) const = 0;
168+ [[nodiscard]] virtual EParamProvenance getMemberProvenance (const std::string& key) const = 0;
171169
172170 static EParamProvenance getProvenance (const std::string& key);
173171
@@ -180,9 +178,6 @@ class ConfigurableParam
180178 static void setInputDir (const std::string& d) { sInputDir = d; }
181179 static void setOutputDir (const std::string& d) { sOutputDir = d; }
182180
183- static boost::property_tree::ptree readINI (std::string const & filepath);
184- static boost::property_tree::ptree readJSON (std::string const & filepath);
185- static boost::property_tree::ptree readConfigFile (std::string const & filepath);
186181 static bool configFileExists (std::string const & filepath);
187182
188183 // writes a human readable JSON file of all parameters
@@ -194,10 +189,12 @@ class ConfigurableParam
194189 template <typename T>
195190 static T getValueAs (std::string key)
196191 {
197- if (!sIsFullyInitialized ) {
198- initialize ();
199- }
200- return sPtree ->get <T>(key);
192+ return [](auto * tree, const std::string& key) -> T {
193+ if (!sIsFullyInitialized ) {
194+ initialize ();
195+ }
196+ return tree->template get <T>(key);
197+ }(sPtree , key);
201198 }
202199
203200 template <typename T>
@@ -206,42 +203,26 @@ class ConfigurableParam
206203 if (!sIsFullyInitialized ) {
207204 initialize ();
208205 }
209- assert (sPtree );
210- try {
211- auto key = mainkey + " ." + subkey;
212- if (sPtree ->get_optional <std::string>(key).is_initialized ()) {
213- sPtree ->put (key, x);
214- auto changed = updateThroughStorageMap (mainkey, subkey, typeid (T), (void *)&x);
215- if (changed != EParamUpdateStatus::Failed) {
216- sValueProvenanceMap ->find (key)->second = kRT ; // set to runtime
206+ return [&subkey, &x, &mainkey](auto * tree) -> void {
207+ assert (tree);
208+ try {
209+ auto key = mainkey + " ." + subkey;
210+ if (tree->template get_optional <std::string>(key).is_initialized ()) {
211+ tree->put (key, x);
212+ auto changed = updateThroughStorageMap (mainkey, subkey, typeid (T), (void *)&x);
213+ if (changed != EParamUpdateStatus::Failed) {
214+ sValueProvenanceMap ->find (key)->second = kRT ; // set to runtime
215+ }
217216 }
217+ } catch (std::exception const & e) {
218+ std::cerr << " Error in setValue (T) " << e.what () << " \n " ;
218219 }
219- } catch (std::exception const & e) {
220- std::cerr << " Error in setValue (T) " << e.what () << " \n " ;
221- }
220+ }(sPtree );
222221 }
223222
224223 // specialized for std::string
225224 // which means that the type will be converted internally
226- static void 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-
225+ static void setValue (std::string const & key, std::string const & valuestring);
245226 static void setEnumValue (const std::string&, const std::string&);
246227 static void setArrayValue (const std::string&, const std::string&);
247228
@@ -306,7 +287,7 @@ class ConfigurableParam
306287 static std::string sOutputDir ;
307288
308289 void setRegisterMode (bool b) { sRegisterMode = b; }
309- bool isInitialized () const { return sIsFullyInitialized ; }
290+ [[nodiscard]] bool isInitialized () const { return sIsFullyInitialized ; }
310291
311292 // friend class o2::ccdb::CcdbApi;
312293 private:
@@ -318,8 +299,7 @@ class ConfigurableParam
318299 static bool sRegisterMode ; // ! (flag to enable/disable autoregistering of child classes)
319300};
320301
321- } // end namespace conf
322- } // end namespace o2
302+ } // namespace o2::conf
323303
324304// a helper macro for boilerplate code in parameter classes
325305#define O2ParamDef (classname, key ) \
0 commit comments