Skip to content

Commit a01e2e9

Browse files
authored
[ALICE3] Use TEnv for config (#13088)
Configurations are in the type of the ini files with TEnv ``` bpipe0.r: 0.48 bpipe0.z: 250 bpipe0.x0: 0.001592 bpipe0.xrho: 0 bpipe0.resRPhi: 0.0 bpipe0.resZ: 0.0 bpipe0.eff: 0.0 bpipe0.type: 0 ```
1 parent 8e6bb6f commit a01e2e9

File tree

2 files changed

+72
-18
lines changed

2 files changed

+72
-18
lines changed

ALICE3/Core/FastTracker.cxx

Lines changed: 42 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,11 @@
1717
#include "TMatrixD.h"
1818
#include "TMatrixDSymEigen.h"
1919
#include "TRandom.h"
20+
#include <TEnv.h>
21+
#include <THashList.h>
22+
#include <TObject.h>
2023

24+
#include <fstream>
2125
#include <string>
2226
#include <vector>
2327

@@ -260,27 +264,47 @@ void FastTracker::AddGenericDetector(std::string filename, o2::ccdb::BasicCCDBMa
260264
return;
261265
}
262266

263-
std::ifstream infile(filename);
264-
if (!infile.is_open()) {
265-
LOG(fatal) << "Could not open detector configuration file: " << filename;
266-
return;
267-
}
268-
269-
std::string line;
270-
while (std::getline(infile, line)) {
271-
if (line.empty() || line[0] == '#')
272-
continue; // skip comments and empty lines
273-
std::istringstream iss(line);
274-
std::string name;
275-
float r, z, x0, xrho, resRPhi, resZ, eff;
276-
int type;
277-
if (!(iss >> name >> r >> z >> x0 >> xrho >> resRPhi >> resZ >> eff >> type)) {
278-
LOG(error) << "Malformed line in detector config: " << line;
267+
TEnv env(filename.c_str());
268+
THashList* table = env.GetTable();
269+
std::vector<std::string> layers;
270+
for (int i = 0; i < table->GetEntries(); ++i) {
271+
const std::string key = table->At(i)->GetName();
272+
// key should contain exactly one dot
273+
if (key.find('.') == std::string::npos || key.find('.') != key.rfind('.')) {
274+
LOG(fatal) << "Key " << key << " does not contain exactly one dot";
279275
continue;
280276
}
281-
AddLayer(name.c_str(), r, z, x0, xrho, resRPhi, resZ, eff, type);
277+
const std::string firstPart = key.substr(0, key.find('.'));
278+
if (std::find(layers.begin(), layers.end(), firstPart) == layers.end()) {
279+
layers.push_back(firstPart);
280+
}
281+
}
282+
// env.Print();
283+
// Layers
284+
for (const auto& layer : layers) {
285+
LOG(info) << " Reading layer " << layer;
286+
287+
auto getKey = [&layer, &env](const std::string& name) {
288+
std::string key = layer + "." + name;
289+
if (!env.Defined(key.c_str())) {
290+
LOG(warning) << "Key " << key << " not defined in configuration file, getting the default value";
291+
}
292+
LOG(info) << " Getting key " << key;
293+
return key;
294+
};
295+
const float r = env.GetValue(getKey("r").c_str(), -1.0f);
296+
LOG(info) << " Layer " << layer << " has radius " << r;
297+
const float z = env.GetValue(getKey("z").c_str(), -1.0f);
298+
const float x0 = env.GetValue(getKey("x0").c_str(), 0.0f);
299+
const float xrho = env.GetValue(getKey("xrho").c_str(), 0.0f);
300+
const float resRPhi = env.GetValue(getKey("resRPhi").c_str(), 0.0f);
301+
const float resZ = env.GetValue(getKey("resZ").c_str(), 0.0f);
302+
const float eff = env.GetValue(getKey("eff").c_str(), 0.0f);
303+
const int type = env.GetValue(getKey("type").c_str(), 0);
304+
305+
// 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);
306+
AddLayer(layer.c_str(), r, z, x0, xrho, resRPhi, resZ, eff, type);
282307
}
283-
infile.close();
284308
}
285309

286310
float FastTracker::Dist(float z, float r)

ALICE3/macros/testFastTracker.cxx

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
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+
/// \file testFastTracker.C
13+
/// \author Nicolò Jacazio nicolo.jacazio@cern.ch
14+
/// \brief Test the FastTracker functionality
15+
16+
#include "ALICE3/Core/FastTracker.h"
17+
18+
#include "CCDB/BasicCCDBManager.h"
19+
#include "DataFormatsParameters/GRPLHCIFData.h"
20+
21+
void testFastTracker(std::string geometryFile = "a3geo.ini")
22+
{
23+
24+
// auto& ccdb = o2::ccdb::BasicCCDBManager::instance();
25+
// ccdb.setURL("http://alice-ccdb.cern.ch");
26+
o2::fastsim::FastTracker fastTracker;
27+
fastTracker.AddGenericDetector(geometryFile);
28+
// fastTracker.AddGenericDetector(geometryFile, &ccdb);
29+
fastTracker.Print();
30+
}

0 commit comments

Comments
 (0)