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)
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 template <
typename T>
194 return [](
auto*
tree,
const std::string&
key) -> T {
195 if (!sIsFullyInitialized) {
198 return tree->template get<T>(
key);
202 template <
typename T>
203 static void setValue(std::string
const& mainkey, std::string
const& subkey, T
x)
205 if (!sIsFullyInitialized) {
208 return [&subkey, &
x, &mainkey](
auto*
tree) ->
void {
211 auto key = mainkey +
"." + subkey;
212 if (
tree->template get_optional<std::string>(
key).is_initialized()) {
219 }
catch (std::exception
const& e) {
220 std::cerr <<
"Error in setValue (T) " << e.what() <<
"\n";
227 if (!sIsFullyInitialized) {
228 std::cerr <<
"setProvenance was called on non-initialized ConfigurableParam\n";
232 auto key = mainkey +
"." + subkey;
237 }
catch (std::exception
const& e) {
238 std::cerr <<
"Error in setProvenance (T) " << e.what() <<
"\n";
244 static void setValue(std::string
const&
key, std::string
const& valuestring);
245 static void setEnumValue(
const std::string&,
const std::string&);
246 static void setArrayValue(
const std::string&,
const std::string&);
249 static void setValues(std::vector<std::pair<std::string, std::string>>
const& keyValues);
268 static void updateFromFile(std::string
const&, std::string
const& paramsList =
"",
bool unchangedOnly =
false);
289 virtual void output(std::ostream& out)
const = 0;
313 static std::vector<ConfigurableParam*>* sRegisteredParamClasses;
315 static boost::property_tree::ptree* sPtree;
316 static bool sIsFullyInitialized;
317 static bool sRegisterMode;
324#define O2ParamDef(classname, key) \
326 classname(TRootIOCtor*) {} \
327 classname(classname const&) = delete; \
330 static constexpr char const* const sKey = key; \
331 static classname sInstance; \
332 classname() = default; \
333 template <typename T> \
334 friend class o2::conf::ConfigurableParamHelper; \
335 template <typename T, typename P> \
336 friend class o2::conf::ConfigurableParamPromoter;
339#define O2ParamImpl(classname) classname classname::sInstance;
friend std::ostream & operator<<(std::ostream &out, const ConfigurableParam &me)
virtual ~ConfigurableParam()=default
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 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
virtual void printKeyValues(bool showprov=true, bool useLogger=false) 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()))