Skip to content

Commit 0c58c62

Browse files
committed
[roc-config] Use AliceO2 configuration library
1 parent 9773074 commit 0c58c62

File tree

7 files changed

+111
-146
lines changed

7 files changed

+111
-146
lines changed

CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ find_package(Boost 1.56
8181

8282
find_package(Git QUIET)
8383
find_package(Common REQUIRED)
84+
find_package(Configuration REQUIRED)
8485
find_package(InfoLogger REQUIRED)
8586
find_package(PDA)
8687

@@ -155,6 +156,7 @@ target_link_libraries(ReadoutCard
155156
PUBLIC
156157
AliceO2::InfoLogger
157158
AliceO2::Common
159+
AliceO2::Configuration
158160
$<$<BOOL:${Python2_FOUND}>:Boost::python27>
159161
$<$<BOOL:${Python2_FOUND}>:Python2::Python>
160162
$<$<BOOL:${Python3_FOUND}>:Boost::python${Python3_VERSION_MAJOR}${Python3_VERSION_MINOR}>

cmake/ReadoutCardConfig.cmake.in

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ get_filename_component(ReadoutCard_CMAKE_DIR "${CMAKE_CURRENT_LIST_FILE}" PATH)
44
include(CMakeFindDependencyMacro)
55

66
set(Common_CMAKE_DIR @Common_DIR@)
7+
set(Configuration_CMAKE_DIR @Configuration_DIR@)
78
set(InfoLogger_CMAKE_DIR @InfoLogger_ROOT@)
89

910
if(NOT APPLE)
@@ -19,6 +20,7 @@ if(NOT APPLE)
1920
endif()
2021

2122
find_dependency(Common CONFIG HINTS ${Common_CMAKE_DIR})
23+
find_dependency(Configuration CONFIG HINTS ${Configuration_CMAKE_DIR})
2224
find_dependency(InfoLogger CONFIG HINTS ${InfoLogger_CMAKE_DIR})
2325

2426
# find package must be used as Common already looks for boost and set Boost_FOUND

include/ReadoutCard/CardConfigurator.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class CardConfigurator
3030
CardConfigurator(Parameters& parameters, bool forceConfigure = false);
3131

3232
private:
33-
void parseConfigFile(std::string pathToConfigFile, Parameters& parameters);
33+
void parseConfigUri(std::string configUri, Parameters& parameters);
3434
};
3535

3636
} // namespace roc

src/CardConfigurator.cxx

Lines changed: 88 additions & 131 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
/// \author Kostas Alexopoulos ([email protected])
55

66
#include "Common/Configuration.h"
7+
#include "Configuration/ConfigurationFactory.h"
78
#include "Cru/CruBar.h"
89
#include "ReadoutCard/CardConfigurator.h"
910
#include "ReadoutCard/ChannelFactory.h"
@@ -13,13 +14,13 @@ namespace AliceO2
1314
namespace roc
1415
{
1516

16-
CardConfigurator::CardConfigurator(Parameters::CardIdType cardId, std::string pathToConfigFile, bool forceConfigure)
17+
CardConfigurator::CardConfigurator(Parameters::CardIdType cardId, std::string configUri, bool forceConfigure)
1718
{
1819
auto parameters = Parameters::makeParameters(cardId, 2); //have to make parameters for this case, bar2
1920
try {
20-
parseConfigFile(pathToConfigFile, parameters);
21-
} catch (std::string e) {
22-
throw std::runtime_error(e);
21+
parseConfigUri(configUri, parameters);
22+
} catch (...) {
23+
throw;
2324
}
2425

2526
auto bar2 = ChannelFactory().getBar(parameters);
@@ -48,10 +49,9 @@ CardConfigurator::CardConfigurator(Parameters& parameters, bool forceConfigure)
4849
}
4950
}
5051

51-
/// pathToConfigFile: Has to start with "file:"
52-
void CardConfigurator::parseConfigFile(std::string pathToConfigFile, Parameters& parameters)
52+
/// configUri has to start with "ini://", "json://" or "consul://"
53+
void CardConfigurator::parseConfigUri(std::string configUri, Parameters& parameters)
5354
{
54-
ConfigFile configFile;
5555
std::set<uint32_t> linkMask;
5656
std::map<uint32_t, GbtMux::type> gbtMuxMap;
5757

@@ -66,158 +66,115 @@ void CardConfigurator::parseConfigFile(std::string pathToConfigFile, Parameters&
6666
GbtMode::type gbtMode = GbtMode::type::Gbt;
6767
DownstreamData::type downstreamData = DownstreamData::type::Ctp;
6868

69-
//Open the file
69+
bool enabled = false;
70+
std::string gbtMux = "ttc";
71+
72+
std::unique_ptr<o2::configuration::ConfigurationInterface> conf;
7073
try {
71-
if (!strncmp(pathToConfigFile.c_str(), "file:", 5)) {
72-
configFile.load(pathToConfigFile);
73-
//configFile.print(); //for debugging
74-
} else {
75-
throw std::runtime_error("Configuration or path invalid");
76-
}
77-
} catch (std::string e) {
78-
throw std::runtime_error(e);
74+
conf = o2::configuration::ConfigurationFactory::getConfiguration(configUri);
75+
} catch (std::exception& e) {
76+
std::cout << boost::diagnostic_information(e) << std::endl;
77+
throw;
7978
}
8079

81-
//* Global *//
82-
for (auto globalGroup : ConfigFileBrowser(&configFile, "cru")) { //Is there another way to do this?
83-
std::string parsedString;
84-
try {
85-
parsedString = configFile.getValue<std::string>(globalGroup + ".clock");
86-
clock = Clock::fromString(parsedString);
87-
} catch (...) {
88-
throw std::runtime_error("Invalid or missing clock property");
89-
}
80+
auto tree = conf->getRecursive("");
81+
std::string group = "";
82+
try {
83+
for (auto it : tree) {
84+
group = it.first;
9085

91-
try {
92-
parsedString = configFile.getValue<std::string>(globalGroup + ".datapathmode");
93-
datapathMode = DatapathMode::fromString(parsedString);
94-
} catch (...) {
95-
throw std::runtime_error("Invalid or missing datapath mode property");
96-
}
86+
if (group == "cru") { // Configure the CRU globally
9787

98-
try {
99-
parsedString = configFile.getValue<std::string>(globalGroup + ".gbtmode");
100-
gbtMode = GbtMode::fromString(parsedString);
101-
} catch (...) {
102-
throw("Invalid or missing gbtmode property");
103-
}
88+
std::string parsedString;
89+
conf->setPrefix(group);
10490

105-
try {
106-
parsedString = configFile.getValue<std::string>(globalGroup + ".downstreamdata");
107-
downstreamData = DownstreamData::fromString(parsedString);
108-
} catch (...) {
109-
throw("Invalid or missing downstreamdata property");
110-
}
91+
parsedString = conf->get<std::string>("clock");
92+
clock = Clock::fromString(parsedString);
11193

112-
try {
113-
loopback = configFile.getValue<bool>(globalGroup + ".loopback");
114-
} catch (...) {
115-
throw("Invalid or missing loopback property");
116-
}
94+
parsedString = conf->get<std::string>("datapathmode");
95+
datapathMode = DatapathMode::fromString(parsedString);
11796

118-
try {
119-
ponUpstream = configFile.getValue<bool>(globalGroup + ".ponupstream");
120-
} catch (...) {
121-
throw("Invalid or missing ponupstream property");
122-
}
97+
parsedString = conf->get<std::string>("gbtmode");
98+
gbtMode = GbtMode::fromString(parsedString);
12399

124-
try {
125-
dynamicOffset = configFile.getValue<bool>(globalGroup + ".dynamicoffset");
126-
} catch (...) {
127-
throw("Invalid or missing dynamicoffset property");
128-
}
100+
parsedString = conf->get<std::string>("downstreamdata");
101+
downstreamData = DownstreamData::fromString(parsedString);
129102

130-
try {
131-
parsedString = configFile.getValue<std::string>(globalGroup + ".onuaddress");
132-
onuAddress = Hex::fromString(parsedString);
133-
} catch (...) {
134-
throw("Invalid or missing onuAddress property");
135-
}
103+
loopback = conf->get<bool>("loopback");
104+
ponUpstream = conf->get<bool>("ponupstream");
105+
dynamicOffset = conf->get<bool>("dynamicoffset");
136106

137-
try {
138-
parsedString = configFile.getValue<std::string>(globalGroup + ".cruid");
139-
cruId = Hex::fromString(parsedString);
140-
} catch (...) {
141-
throw("Invalid or missing cruId property");
142-
}
107+
parsedString = conf->get<std::string>("onuaddress");
108+
onuAddress = Hex::fromString(parsedString);
143109

144-
try {
145-
allowRejection = configFile.getValue<bool>(globalGroup + ".allowrejection");
146-
} catch (...) {
147-
throw("Invalid or missing allowrejection property");
148-
}
149-
}
110+
parsedString = conf->get<std::string>("cruid");
111+
cruId = Hex::fromString(parsedString);
112+
113+
allowRejection = conf->get<bool>("allowrejection");
114+
115+
conf->setPrefix("");
116+
117+
parameters.setClock(clock);
118+
parameters.setDatapathMode(datapathMode);
119+
parameters.setGbtMode(gbtMode);
120+
parameters.setDownstreamData(downstreamData);
121+
parameters.setLinkLoopbackEnabled(loopback);
122+
parameters.setPonUpstreamEnabled(ponUpstream);
123+
parameters.setDynamicOffsetEnabled(dynamicOffset);
124+
parameters.setOnuAddress(onuAddress);
125+
parameters.setCruId(cruId);
126+
parameters.setAllowRejection(allowRejection);
127+
128+
} else if (group == "links") { // Configure all links with default values
129+
130+
conf->setPrefix(group);
131+
enabled = conf->get<bool>("enabled");
150132

151-
parameters.setClock(clock);
152-
parameters.setDatapathMode(datapathMode);
153-
parameters.setGbtMode(gbtMode);
154-
parameters.setDownstreamData(downstreamData);
155-
parameters.setLinkLoopbackEnabled(loopback);
156-
parameters.setPonUpstreamEnabled(ponUpstream);
157-
parameters.setDynamicOffsetEnabled(dynamicOffset);
158-
parameters.setOnuAddress(onuAddress);
159-
parameters.setCruId(cruId);
160-
parameters.setAllowRejection(allowRejection);
161-
162-
//* Per link *//
163-
for (auto configGroup : ConfigFileBrowser(&configFile, "link")) {
164-
165-
bool enabled = false;
166-
std::string gbtMux;
167-
168-
/* configure for all links */
169-
if (configGroup == "links") {
170-
try {
171-
enabled = configFile.getValue<bool>(configGroup + ".enabled");
172133
if (enabled) {
173134
for (int i = 0; i < 24; i++) {
174135
linkMask.insert((uint32_t)i);
175136
}
176137
}
177-
} catch (...) {
178-
throw("Invalid or missing enabled property for all links");
179-
}
180138

181-
try {
182-
gbtMux = configFile.getValue<std::string>(configGroup + ".gbtmux");
139+
gbtMux = conf->get<std::string>("gbtmux");
183140
for (int i = 0; i < 24; i++) {
184141
gbtMuxMap.insert(std::make_pair((uint32_t)i, GbtMux::fromString(gbtMux)));
185142
}
186-
} catch (...) {
187-
throw("Invalid or missing gbt mux property for all links");
188-
}
189-
continue;
190-
}
191143

192-
/* configure for individual links */
193-
std::string linkIndexString = configGroup.substr(configGroup.find("k") + 1);
194-
uint32_t linkIndex = std::stoul(linkIndexString, NULL, 10);
144+
conf->setPrefix("");
195145

196-
try {
197-
enabled = configFile.getValue<bool>(configGroup + ".enabled");
198-
if (enabled) {
199-
linkMask.insert(linkIndex);
200-
} else {
201-
linkMask.erase(linkIndex);
202-
}
203-
} catch (...) {
204-
throw("Invalid or missing enabled property for link: " + linkIndexString);
205-
}
146+
} else if (!group.find("link")) { // Configure individual links
147+
148+
std::string linkIndexString = group.substr(group.find("k") + 1);
149+
uint32_t linkIndex = std::stoul(linkIndexString, NULL, 10);
150+
151+
conf->setPrefix(group);
206152

207-
try {
208-
gbtMux = configFile.getValue<std::string>(configGroup + ".gbtmux");
209-
if (gbtMuxMap.find(linkIndex) != gbtMuxMap.end()) {
210-
gbtMuxMap[linkIndex] = GbtMux::fromString(gbtMux);
211-
} else {
212-
gbtMuxMap.insert(std::make_pair(linkIndex, GbtMux::fromString(gbtMux)));
153+
enabled = conf->get<bool>("enabled");
154+
if (enabled) {
155+
linkMask.insert(linkIndex);
156+
} else {
157+
linkMask.erase(linkIndex);
158+
}
159+
160+
gbtMux = conf->get<std::string>("gbtmux");
161+
if (gbtMuxMap.find(linkIndex) != gbtMuxMap.end()) {
162+
gbtMuxMap[linkIndex] = GbtMux::fromString(gbtMux);
163+
} else {
164+
gbtMuxMap.insert(std::make_pair(linkIndex, GbtMux::fromString(gbtMux)));
165+
}
166+
167+
conf->setPrefix("");
213168
}
214-
} catch (...) {
215-
throw("Invalid or missing gbt mux set for link: " + linkIndexString);
216169
}
217-
}
218170

219-
parameters.setLinkMask(linkMask);
220-
parameters.setGbtMuxMap(gbtMuxMap);
171+
parameters.setLinkMask(linkMask);
172+
parameters.setGbtMuxMap(gbtMuxMap);
173+
174+
} catch (...) {
175+
BOOST_THROW_EXCEPTION(ParseException() << ErrorInfo::ConfigParse(group));
176+
}
221177
}
178+
222179
} // namespace roc
223180
} // namespace AliceO2

src/CommandLineUtilities/ProgramConfig.cxx

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,9 @@ class ProgramConfig : public Program
6464
options.add_options()("links",
6565
po::value<std::string>(&mOptions.links)->default_value("0"),
6666
"Links to enable");
67-
options.add_options()("config-file",
68-
po::value<std::string>(&mOptions.configFile)->default_value(""),
69-
"Configuration file [file:*.cfg]");
67+
options.add_options()("config-uri",
68+
po::value<std::string>(&mOptions.configUri)->default_value(""),
69+
"Configuration URI ('ini://[path]', 'json://[path]' or 'consul://[host][:port][/path]'");
7070
options.add_options()("loopback",
7171
po::bool_switch(&mOptions.linkLoopbackEnabled),
7272
"Flag to enable link loopback for DDG");
@@ -98,8 +98,8 @@ class ProgramConfig : public Program
9898
if (mOptions.configAll) {
9999
std::cout << "Running RoC Configuration for all cards" << std::endl;
100100
std::vector<CardDescriptor> cardsFound;
101-
if (mOptions.configFile == "") {
102-
std::cout << "A configuration file is necessary with the startup-config flag set" << std::endl;
101+
if (mOptions.configUri == "") {
102+
std::cout << "A configuration URI is necessary with the startup-config flag set" << std::endl;
103103
return;
104104
}
105105

@@ -110,7 +110,7 @@ class ProgramConfig : public Program
110110
if (!mOptions.bypassFirmwareCheck) {
111111
try {
112112
FirmwareChecker().checkFirmwareCompatibility(params);
113-
CardConfigurator(card.pciAddress, mOptions.configFile, mOptions.forceConfig);
113+
CardConfigurator(card.pciAddress, mOptions.configUri, mOptions.forceConfig);
114114
} catch (const Exception& e) {
115115
std::cout << boost::diagnostic_information(e) << std::endl;
116116
}
@@ -130,7 +130,7 @@ class ProgramConfig : public Program
130130
}
131131
}
132132

133-
if (mOptions.configFile == "") {
133+
if (mOptions.configUri == "") {
134134
std::cout << "Configuring with command line arguments" << std::endl;
135135
auto params = Parameters::makeParameters(cardId, 2);
136136
params.setLinkMask(Parameters::linkMaskFromString(mOptions.links));
@@ -151,23 +151,20 @@ class ProgramConfig : public Program
151151
} catch (const Exception& e) {
152152
std::cout << boost::diagnostic_information(e) << std::endl;
153153
}
154-
} else if (!strncmp(mOptions.configFile.c_str(), "file:", 5)) {
154+
} else {
155155
std::cout << "Configuring with config file" << std::endl;
156156
try {
157-
CardConfigurator(cardId, mOptions.configFile, mOptions.forceConfig);
157+
CardConfigurator(cardId, mOptions.configUri, mOptions.forceConfig);
158158
} catch (std::runtime_error e) {
159-
std::cout << "Something went badly reading the configuration file..." << e.what() << std::endl;
159+
std::cout << "Error parsing the configuration..." << boost::diagnostic_information(e) << std::endl;
160160
}
161-
} else {
162-
std::cout << "Configuration file path should start with 'file:'" << std::endl;
163161
}
164-
165162
return;
166163
}
167164

168165
struct OptionsStruct {
169166
std::string clock = "local";
170-
std::string configFile = "";
167+
std::string configUri = "";
171168
std::string datapathMode = "packet";
172169
std::string downstreamData = "Ctp";
173170
std::string gbtMode = "gbt";

src/ExceptionInternal.cxx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,4 +149,9 @@ std::string to_string(const ErrorInfo::CardId& e)
149149
return toStringHelper("ReadoutCard PCI address", message);
150150
}
151151

152+
std::string to_string(const ErrorInfo::ConfigParse& e)
153+
{
154+
return b::str(b::format("Invalid or missing property for group [%s]") % e.value());
155+
}
156+
152157
} // namespace boost

0 commit comments

Comments
 (0)