Project
Loading...
Searching...
No Matches
TestConfigurableParam.cxx
Go to the documentation of this file.
1// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
2// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
3// All rights not expressly granted are reserved.
4//
5// This software is distributed under the terms of the GNU General Public
6// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
7//
8// In applying this license CERN does not waive the privileges and immunities
9// granted to it by virtue of its status as an Intergovernmental Organization
10// or submit itself to any jurisdiction.
11
14#include <SimConfig/SimConfig.h>
15#include <iostream>
16#include <TInterpreter.h>
17
19{
20 public:
21 double getGasDensity() const { return mGasDensity; }
22
23 private:
24 double mGasDensity = 2.0;
25 std::array<int, 3> mPos = {1, 2, 3};
26
27 O2ParamDef(BazParam, "Baz");
28};
30
31int main(int argc, char* argv[])
32{
33 // generate dictionary for BazParam (done here since this is just
34 // a tmp test class)
35 gInterpreter->GenerateDictionary("BazParam");
36 gInterpreter->GenerateTClass("BazParam", false);
37
38 auto& conf = o2::conf::SimConfig::Instance();
39 conf.resetFromArguments(argc, argv);
40
41 // prints all parameters from any ConfigurableParam
43
44 // writes a configuration file
46
47 // override some keys from command line
48 o2::conf::ConfigurableParam::updateFromString(conf.getKeyValueString());
49
50 // query using C++ object + API
52
53 // query from global parameter registry AND by string name
54 auto d2 = o2::conf::ConfigurableParam::getValueAs<double>("Baz.mGasDensity");
55 assert(d1 == d2);
56
57 // update
58 double x = 102;
59 o2::conf::ConfigurableParam::setValue<double>("Baz", "mGasDensity", x);
60
61 // check that update correctly synced
62 auto d3 = o2::conf::ConfigurableParam::getValueAs<double>("Baz.mGasDensity");
63 assert(d3 == BazParam::Instance().getGasDensity());
64 assert(x == BazParam::Instance().getGasDensity());
65
67}
#define O2ParamDef(classname, key)
#define O2ParamImpl(classname)
double getGasDensity() const
static void writeINI(std::string const &filename, std::string const &keyOnly="")
static void printAllKeyValuePairs(bool useLogger=false)
static void updateFromString(std::string const &)
static SimConfig & Instance()
Definition SimConfig.h:111
GLint GLenum GLint x
Definition glcorearb.h:403
#define main