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
12
#include <
CommonUtils/ConfigurableParam.h
>
13
#include <
CommonUtils/ConfigurableParamHelper.h
>
14
#include <
SimConfig/SimConfig.h
>
15
#include <iostream>
16
#include <TInterpreter.h>
17
18
class
BazParam
:
public
o2::conf::ConfigurableParamHelper
<BazParam>
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
};
29
O2ParamImpl
(
BazParam
);
30
31
int
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
42
o2::conf::ConfigurableParam::printAllKeyValuePairs
();
43
44
// writes a configuration file
45
o2::conf::ConfigurableParam::writeINI
(
"initialconf.ini"
);
46
47
// override some keys from command line
48
o2::conf::ConfigurableParam::updateFromString
(conf.getKeyValueString());
49
50
// query using C++ object + API
51
auto
d1 =
BazParam::Instance
().
getGasDensity
();
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
66
o2::conf::ConfigurableParam::writeINI
(
"newconf.ini"
);
67
}
ConfigurableParamHelper.h
ConfigurableParam.h
O2ParamDef
#define O2ParamDef(classname, key)
Definition
ConfigurableParam.h:324
O2ParamImpl
#define O2ParamImpl(classname)
Definition
ConfigurableParam.h:339
SimConfig.h
BazParam
Definition
TestConfigurableParam.cxx:19
BazParam::getGasDensity
double getGasDensity() const
Definition
TestConfigurableParam.cxx:21
o2::conf::ConfigurableParamHelper
Definition
ConfigurableParamHelper.h:78
o2::conf::ConfigurableParamHelper< BazParam >::Instance
static const BazParam & Instance()
Definition
ConfigurableParamHelper.h:81
o2::conf::ConfigurableParam::writeINI
static void writeINI(std::string const &filename, std::string const &keyOnly="")
Definition
ConfigurableParam.cxx:171
o2::conf::ConfigurableParam::printAllKeyValuePairs
static void printAllKeyValuePairs(bool useLogger=false)
Definition
ConfigurableParam.cxx:255
o2::conf::ConfigurableParam::updateFromString
static void updateFromString(std::string const &)
Definition
ConfigurableParam.cxx:433
o2::conf::SimConfig::Instance
static SimConfig & Instance()
Definition
SimConfig.h:111
x
GLint GLenum GLint x
Definition
glcorearb.h:403
main
#define main
Definition
test_OverrideLabels.cxx:13
Common
SimConfig
test
TestConfigurableParam.cxx
Generated on Tue Feb 25 2025 23:16:08 for Project by
1.9.8