14#ifndef COMMON_SIMCONFIG_INCLUDE_SIMCONFIG_CONFIGURABLEPARAM_H_
15#define COMMON_SIMCONFIG_INCLUDE_SIMCONFIG_CONFIGURABLEPARAM_H_
20#include <unordered_map>
21#include <boost/property_tree/ptree_fwd.hpp>
91 std::vector<std::pair<std::string, int>>
vvalues;
120 void add(
const std::string&
key,
const TDataMember* dm);
124 return entries.count(
key) > 0;
131 auto iter = entries.find(
key);
132 return iter != entries.end() ? &iter->second :
nullptr;
136 std::unordered_map<std::string, EnumLegalValues> entries;
157 static std::array<std::string, 3> names = {
"CODE",
"CCDB",
"RT"};
158 return names[(
int)p];
165 virtual void printKeyValues(
bool showprov =
true,
bool useLogger =
false,
bool withPadding =
false,
bool showHash =
false)
const = 0;
186 static void writeJSON(std::string
const&
filename, std::string
const& keyOnly =
"");
188 static void writeINI(std::string
const&
filename, std::string
const& keyOnly =
"");
191 static void write(std::string
const&
filename, std::string
const& keyOnly =
"");
194 template <
typename T>
197 return [](
auto*
tree,
const std::string&
key) -> T {
198 if (!sIsFullyInitialized) {
201 return tree->template get<T>(
key);
205 template <
typename T>
206 static void setValue(std::string
const& mainkey, std::string
const& subkey, T
x)
208 if (!sIsFullyInitialized) {
211 return [&subkey, &
x, &mainkey](
auto*
tree) ->
void {
214 auto key = mainkey +
"." + subkey;
215 if (
tree->template get_optional<std::string>(
key).is_initialized()) {
222 }
catch (std::exception
const& e) {
223 std::cerr <<
"Error in setValue (T) " << e.what() <<
"\n";
230 if (!sIsFullyInitialized) {
231 std::cerr <<
"setProvenance was called on non-initialized ConfigurableParam\n";
235 auto key = mainkey +
"." + subkey;
240 }
catch (std::exception
const& e) {
241 std::cerr <<
"Error in setProvenance (T) " << e.what() <<
"\n";
247 static void setValue(std::string
const&
key, std::string
const& valuestring);
248 static void setEnumValue(
const std::string&,
const std::string&);
249 static void setArrayValue(
const std::string&,
const std::string&);
252 static void setValues(std::vector<std::pair<std::string, std::string>>
const& keyValues);
271 static void updateFromFile(std::string
const&, std::string
const& paramsList =
"",
bool unchangedOnly =
false);
292 virtual void output(std::ostream& out)
const = 0;
316 static std::vector<ConfigurableParam*>* sRegisteredParamClasses;
318 static boost::property_tree::ptree* sPtree;
319 static bool sIsFullyInitialized;
320 static bool sRegisterMode;
327#define O2ParamDef(classname, key) \
329 classname(TRootIOCtor*) {} \
330 classname(classname const&) = delete; \
333 static constexpr char const* const sKey = key; \
334 static classname sInstance; \
335 classname() = default; \
336 template <typename T> \
337 friend class o2::conf::ConfigurableParamHelper; \
338 template <typename T, typename P> \
339 friend class o2::conf::ConfigurableParamPromoter;
342#define O2ParamImpl(classname) classname classname::sInstance;
friend std::ostream & operator<<(std::ostream &out, const ConfigurableParam &me)
virtual ~ConfigurableParam()=default
virtual void printKeyValues(bool showprov=true, bool useLogger=false, bool withPadding=false, bool showHash=false) const =0
static EParamUpdateStatus updateThroughStorageMapWithConversion(std::string const &, std::string const &)
virtual void serializeTo(TFile *) const =0
virtual std::string getName() const =0
static void setEnumValue(const std::string &, const std::string &)
static void writeINI(std::string const &filename, std::string const &keyOnly="")
static void setValues(std::vector< std::pair< std::string, std::string > > const &keyValues)
static bool configFileExists(std::string const &filepath)
virtual void putKeyValues(boost::property_tree::ptree *)=0
static std::map< std::string, std::pair< std::type_info const &, void * > > * sKeyToStorageMap
static void printAllRegisteredParamNames()
static void setProvenance(std::string const &mainkey, std::string const &subkey, EParamProvenance p)
void setRegisterMode(bool b)
bool isInitialized() const
static void updateFromFile(std::string const &, std::string const ¶msList="", bool unchangedOnly=false)
static void write(std::string const &filename, std::string const &keyOnly="")
static T getValueAs(std::string key)
virtual size_t getHash() const =0
virtual void initFrom(TFile *)=0
virtual EParamProvenance getMemberProvenance(const std::string &key) const =0
static void setArrayValue(const std::string &, const std::string &)
static void initPropertyTree()
static void setValue(std::string const &mainkey, std::string const &subkey, T x)
static std::string sOutputDir
static std::map< std::string, ConfigurableParam::EParamProvenance > * sValueProvenanceMap
static EParamProvenance getProvenance(const std::string &key)
static const std::string & getOutputDir()
static void printAllKeyValuePairs(bool useLogger=false)
static void toCCDB(std::string filename)
static void writeJSON(std::string const &filename, std::string const &keyOnly="")
static void setOutputDir(const std::string &d)
static std::string toString(EParamProvenance p)
static EParamUpdateStatus updateThroughStorageMap(std::string, std::string, std::type_info const &, void *)
static EnumRegistry * sEnumRegistry
virtual void output(std::ostream &out) const =0
virtual void syncCCDBandRegistry(void *obj)=0
static void fromCCDB(std::string filename)
static void updateFromString(std::string const &)
void add(const std::string &key, const TDataMember *dm)
std::string toString() const
bool contains(const std::string &key) const
const EnumLegalValues * operator[](const std::string &key) const
GLboolean GLboolean GLboolean b
GLsizei const GLfloat * value
a couple of static helper functions to create timestamp values for CCDB queries or override obsolete ...
bool isLegal(int value) const
bool isLegal(const std::string &value) const
std::vector< std::pair< std::string, int > > vvalues
int getIntValue(const std::string &value) const
std::string toString() const
std::unique_ptr< TTree > tree((TTree *) flIn.Get(std::string(o2::base::NameConf::CTFTREENAME).c_str()))