@@ -236,6 +236,42 @@ void FastTracker::AddTPC(float phiResMean, float zResMean)
236236 }
237237}
238238
239+ std::map<std::string, std::map<std::string, std::string>> FastTracker::parseTEnvConfiguration (std::string filename)
240+ {
241+ std::map<std::string, std::map<std::string, std::string>> configMap;
242+
243+ TEnv env (filename.c_str ());
244+ THashList* table = env.GetTable ();
245+ std::vector<std::string> layers;
246+ for (int i = 0 ; i < table->GetEntries (); ++i) {
247+ const std::string key = table->At (i)->GetName ();
248+ // key should contain exactly one dot
249+ if (key.find (' .' ) == std::string::npos || key.find (' .' ) != key.rfind (' .' )) {
250+ LOG (fatal) << " Key " << key << " does not contain exactly one dot" ;
251+ continue ;
252+ }
253+ const std::string firstPart = key.substr (0 , key.find (' .' ));
254+ if (std::find (layers.begin (), layers.end (), firstPart) == layers.end ()) {
255+ layers.push_back (firstPart);
256+ }
257+ }
258+ env.Print ();
259+
260+ // Layers
261+ for (const auto & layer : layers) {
262+ LOG (info) << " Reading layer " << layer;
263+ for (int i = 0 ; i < table->GetEntries (); ++i) {
264+ const std::string key = table->At (i)->GetName ();
265+ if (key.find (layer + " ." ) == 0 ) {
266+ const std::string paramName = key.substr (key.find (' .' ) + 1 );
267+ const std::string value = env.GetValue (key.c_str (), " " );
268+ configMap[layer][paramName] = value;
269+ }
270+ }
271+ }
272+ return configMap;
273+ }
274+
239275void FastTracker::AddGenericDetector (std::string filename, o2::ccdb::BasicCCDBManager* ccdbManager)
240276{
241277 LOG (info) << " Adding generic detector from file " << filename;
@@ -263,54 +299,27 @@ void FastTracker::AddGenericDetector(std::string filename, o2::ccdb::BasicCCDBMa
263299 return ;
264300 }
265301
266- TEnv env (filename.c_str ());
267- THashList* table = env.GetTable ();
268- std::vector<std::string> layers;
269- for (int i = 0 ; i < table->GetEntries (); ++i) {
270- const std::string key = table->At (i)->GetName ();
271- // key should contain exactly one dot
272- if (key.find (' .' ) == std::string::npos || key.find (' .' ) != key.rfind (' .' )) {
273- LOG (fatal) << " Key " << key << " does not contain exactly one dot" ;
274- continue ;
275- }
276- const std::string firstPart = key.substr (0 , key.find (' .' ));
277- if (std::find (layers.begin (), layers.end (), firstPart) == layers.end ()) {
278- layers.push_back (firstPart);
279- }
280- }
281- // env.Print();
302+ std::map<std::string, std::map<std::string, std::string>> configMap = parseTEnvConfiguration (filename);
282303 // Layers
283- for (const auto & layer : layers) {
284- LOG (info) << " Reading layer " << layer;
285-
286- auto getKey = [&layer, &env](const std::string& name, const bool required = true ) {
287- std::string key = layer + " ." + name;
288- if (!env.Defined (key.c_str ())) {
289- if (required) {
290- LOG (fatal) << " Key " << key << " not defined in configuration file" ;
291- }
292- LOG (debug) << " Key " << key << " not defined in configuration file, getting the default value" ;
293- }
294- LOG (debug) << " Getting key " << key << " from configuration file" ;
295- return key;
296- };
297- const float r = env.GetValue (getKey (" r" ).c_str (), -1 .0f );
298- LOG (info) << " Layer " << layer << " has radius " << r;
299- const float z = env.GetValue (getKey (" z" ).c_str (), -1 .0f );
300- const float x0 = env.GetValue (getKey (" x0" ).c_str (), 0 .0f );
301- const float xrho = env.GetValue (getKey (" xrho" ).c_str (), 0 .0f );
302- const float resRPhi = env.GetValue (getKey (" resRPhi" ).c_str (), 0 .0f );
303- const float resZ = env.GetValue (getKey (" resZ" ).c_str (), 0 .0f );
304- const float eff = env.GetValue (getKey (" eff" ).c_str (), 0 .0f );
305- const int type = env.GetValue (getKey (" type" ).c_str (), 0 );
306- const char * deadPhiRegions = env.GetValue (getKey (" deadPhiRegions" , false ).c_str (), " " );
304+ for (const auto & layer : configMap) {
305+ LOG (info) << " Reading layer " << layer.first ;
306+ const float r = std::stof (layer.second .at (" r" ));
307+ LOG (info) << " Layer " << layer.first << " has radius " << r;
308+ const float z = std::stof (layer.second .at (" z" ));
309+ const float x0 = std::stof (layer.second .at (" x0" ));
310+ const float xrho = std::stof (layer.second .at (" xrho" ));
311+ const float resRPhi = std::stof (layer.second .at (" resRPhi" ));
312+ const float resZ = std::stof (layer.second .at (" resZ" ));
313+ const float eff = std::stof (layer.second .at (" eff" ));
314+ const int type = std::stoi (layer.second .at (" type" ));
315+ const std::string deadPhiRegions = layer.second .at (" deadPhiRegions" );
307316
308317 // void AddLayer(TString name, float r, float z, float x0, float xrho, float resRPhi = 0.0f, float resZ = 0.0f, float eff = 0.0f, int type = 0);
309- LOG (info) << " Adding layer " << layer << " r=" << r << " z=" << z << " x0=" << x0 << " xrho=" << xrho << " resRPhi=" << resRPhi << " resZ=" << resZ << " eff=" << eff << " type=" << type << " deadPhiRegions=" << deadPhiRegions;
318+ LOG (info) << " Adding layer " << layer. first << " r=" << r << " z=" << z << " x0=" << x0 << " xrho=" << xrho << " resRPhi=" << resRPhi << " resZ=" << resZ << " eff=" << eff << " type=" << type << " deadPhiRegions=" << deadPhiRegions;
310319
311- DetLayer* addedLayer = AddLayer (layer.c_str (), r, z, x0, xrho, resRPhi, resZ, eff, type);
312- if (strlen ( deadPhiRegions) > 0 ) { // Taking it as ccdb path or local file
313- // Check if it begins with ccdb:
320+ DetLayer* addedLayer = AddLayer (layer.first . c_str (), r, z, x0, xrho, resRPhi, resZ, eff, type);
321+ if (! deadPhiRegions. empty () ) { // Taking it as ccdb path or local file
322+ // Check if it begins with ccdb:
314323 if (std::string (deadPhiRegions).rfind (" ccdb:" , 0 ) == 0 ) {
315324 std::string ccdbPath = std::string (deadPhiRegions).substr (5 ); // remove "ccdb:" prefix
316325 if (ccdbManager == nullptr ) {
@@ -321,7 +330,7 @@ void FastTracker::AddGenericDetector(std::string filename, o2::ccdb::BasicCCDBMa
321330 addedLayer->setDeadPhiRegions (g);
322331 } else {
323332 // Taking it as local file
324- TFile infile (deadPhiRegions, " READ" );
333+ TFile infile (deadPhiRegions. c_str () , " READ" );
325334 if (!infile.IsOpen ()) {
326335 LOG (fatal) << " Cannot open dead phi regions file " << deadPhiRegions;
327336 return ;
@@ -331,7 +340,7 @@ void FastTracker::AddGenericDetector(std::string filename, o2::ccdb::BasicCCDBMa
331340 addedLayer->setDeadPhiRegions (g);
332341 }
333342 } else {
334- LOG (debug) << " No dead phi regions for layer " << layer;
343+ LOG (debug) << " No dead phi regions for layer " << layer. first ;
335344 }
336345 }
337346}
0 commit comments