|
17 | 17 | #include "TMatrixD.h" |
18 | 18 | #include "TMatrixDSymEigen.h" |
19 | 19 | #include "TRandom.h" |
| 20 | +#include <TEnv.h> |
| 21 | +#include <THashList.h> |
| 22 | +#include <TObject.h> |
20 | 23 |
|
| 24 | +#include <fstream> |
| 25 | +#include <map> |
21 | 26 | #include <string> |
22 | 27 | #include <vector> |
23 | 28 |
|
@@ -180,7 +185,7 @@ void FastTracker::AddSiliconALICE3(float scaleX0VD, std::vector<float> pixelReso |
180 | 185 | AddLayer("B03", 7., 250, x0OT, xrhoOT, resRPhiOT, resZOT, eff, 1); |
181 | 186 | AddLayer("B04", 9., 250, x0OT, xrhoOT, resRPhiOT, resZOT, eff, 1); |
182 | 187 | AddLayer("B05", 12., 250, x0OT, xrhoOT, resRPhiOT, resZOT, eff, 1); |
183 | | - AddLayer("iTOF", 19, 250, x0iTOF, xrhoiTOF, resRPhiOT, resZOT, eff, 0); |
| 188 | + AddLayer("iTOF", 19, 250, x0iTOF, xrhoiTOF, resRPhiOT, resZOT, 0.0f, 0); |
184 | 189 | AddLayer("B06", 20., 250, x0OT, xrhoOT, resRPhiOT, resZOT, eff, 1); |
185 | 190 | AddLayer("B07", 30., 250, x0OT, xrhoOT, resRPhiOT, resZOT, eff, 1); |
186 | 191 | AddLayer("B08", 45., 250, x0OT, xrhoOT, resRPhiOT, resZOT, eff, 1); |
@@ -260,27 +265,47 @@ void FastTracker::AddGenericDetector(std::string filename, o2::ccdb::BasicCCDBMa |
260 | 265 | return; |
261 | 266 | } |
262 | 267 |
|
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; |
| 268 | + TEnv env(filename.c_str()); |
| 269 | + THashList* table = env.GetTable(); |
| 270 | + std::vector<std::string> layers; |
| 271 | + for (int i = 0; i < table->GetEntries(); ++i) { |
| 272 | + const std::string key = table->At(i)->GetName(); |
| 273 | + // key should contain exactly one dot |
| 274 | + if (key.find('.') == std::string::npos || key.find('.') != key.rfind('.')) { |
| 275 | + LOG(fatal) << "Key " << key << " does not contain exactly one dot"; |
279 | 276 | continue; |
280 | 277 | } |
281 | | - AddLayer(name.c_str(), r, z, x0, xrho, resRPhi, resZ, eff, type); |
| 278 | + const std::string firstPart = key.substr(0, key.find('.')); |
| 279 | + if (std::find(layers.begin(), layers.end(), firstPart) == layers.end()) { |
| 280 | + layers.push_back(firstPart); |
| 281 | + } |
| 282 | + } |
| 283 | + // env.Print(); |
| 284 | + // Layers |
| 285 | + for (const auto& layer : layers) { |
| 286 | + LOG(info) << " Reading layer " << layer; |
| 287 | + |
| 288 | + auto getKey = [&layer, &env](const std::string& name) { |
| 289 | + std::string key = layer + "." + name; |
| 290 | + if (!env.Defined(key.c_str())) { |
| 291 | + LOG(warning) << "Key " << key << " not defined in configuration file, getting the default value"; |
| 292 | + } |
| 293 | + LOG(info) << " Getting key " << key; |
| 294 | + return key; |
| 295 | + }; |
| 296 | + const float r = env.GetValue(getKey("r").c_str(), -1.0f); |
| 297 | + LOG(info) << " Layer " << layer << " has radius " << r; |
| 298 | + const float z = env.GetValue(getKey("z").c_str(), -1.0f); |
| 299 | + const float x0 = env.GetValue(getKey("x0").c_str(), 0.0f); |
| 300 | + const float xrho = env.GetValue(getKey("xrho").c_str(), 0.0f); |
| 301 | + const float resRPhi = env.GetValue(getKey("resRPhi").c_str(), 0.0f); |
| 302 | + const float resZ = env.GetValue(getKey("resZ").c_str(), 0.0f); |
| 303 | + const float eff = env.GetValue(getKey("eff").c_str(), 0.0f); |
| 304 | + const int type = env.GetValue(getKey("type").c_str(), 0); |
| 305 | + |
| 306 | + // 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); |
| 307 | + AddLayer(layer.c_str(), r, z, x0, xrho, resRPhi, resZ, eff, type); |
282 | 308 | } |
283 | | - infile.close(); |
284 | 309 | } |
285 | 310 |
|
286 | 311 | float FastTracker::Dist(float z, float r) |
|
0 commit comments