Skip to content

Commit 84f53f4

Browse files
authored
Merge pull request #24 from sy-c/master
support for o2 configuration
2 parents ba470c5 + 35a8418 commit 84f53f4

File tree

2 files changed

+37
-2
lines changed

2 files changed

+37
-2
lines changed

doc/README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,12 @@ It takes as command-line argument the name of the configuration file to be used:
127127

128128
readout.exe file://path/to/my/readout.cfg
129129

130+
It may also be started by providing a URI for the O2 Configuration backend
131+
(with as optional extra parameter the entry point in the configuration tree, by default empty, i.e. top of the tree)
132+
133+
readout.exe ini://path/to/my/readout.ini
134+
readout.exe consul://localhost:8500 /readout
135+
130136

131137

132138
# Contact

src/mainReadout.cxx

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,12 @@
1313
#include <Common/Fifo.h>
1414
#include <Common/Thread.h>
1515

16+
#define WITH_CONFIG
17+
#ifdef WITH_CONFIG
18+
#include <Configuration/ConfigurationFactory.h>
19+
#endif
20+
21+
1622
#include <atomic>
1723
#include <chrono>
1824
#include <memory>
@@ -75,11 +81,15 @@ int main(int argc, char* argv[])
7581
{
7682
ConfigFile cfg;
7783
const char* cfgFileURI="";
84+
const char* cfgFileEntryPoint=""; // where in the config tree to look for
7885
if (argc<2) {
7986
printf("Please provide path to configuration file\n");
8087
return -1;
8188
}
8289
cfgFileURI=argv[1];
90+
if (argc>2) {
91+
cfgFileEntryPoint=argv[2];
92+
}
8393

8494
// configure signal handlers for clean exit
8595
struct sigaction signalSettings;
@@ -105,9 +115,28 @@ int main(int argc, char* argv[])
105115
theLog.log("NUMA : no");
106116
#endif
107117
// load configuration file
108-
theLog.log("Reading configuration from %s",cfgFileURI);
118+
theLog.log("Reading configuration from %s %s",cfgFileURI,cfgFileEntryPoint);
109119
try {
110-
cfg.load(cfgFileURI);
120+
// check URI prefix
121+
if (!strncmp(cfgFileURI,"file:",5)) {
122+
// let's use the 'Common' config file library
123+
cfg.load(cfgFileURI);
124+
} else {
125+
// otherwise use the Configuration module, if available
126+
#ifdef WITH_CONFIG
127+
try {
128+
std::unique_ptr<o2::configuration::ConfigurationInterface> conf = o2::configuration::ConfigurationFactory::getConfiguration(cfgFileURI);
129+
boost::property_tree::ptree t=conf->getRecursive(cfgFileEntryPoint);
130+
cfg.load(t);
131+
//cfg.print();
132+
}
133+
catch (std::exception &e) {
134+
throw std::string(e.what());
135+
}
136+
# else
137+
throw std::string("This type of URI is not supported");
138+
#endif
139+
}
111140
}
112141
catch (std::string err) {
113142
theLog.log("Error : %s",err.c_str());

0 commit comments

Comments
 (0)