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
1314namespace 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
0 commit comments