From a74a1c1d39c426d301790ccd8608fe98061ecbaf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=B2=20Jacazio?= Date: Mon, 22 Sep 2025 23:30:42 +0200 Subject: [PATCH 1/2] Use TEnv for config --- ALICE3/Core/FastTracker.cxx | 60 +++++++++++++++++++++---------- ALICE3/macros/testFastTracker.cxx | 30 ++++++++++++++++ 2 files changed, 72 insertions(+), 18 deletions(-) create mode 100644 ALICE3/macros/testFastTracker.cxx diff --git a/ALICE3/Core/FastTracker.cxx b/ALICE3/Core/FastTracker.cxx index 0f45e47291e..005cd4fc301 100644 --- a/ALICE3/Core/FastTracker.cxx +++ b/ALICE3/Core/FastTracker.cxx @@ -17,7 +17,11 @@ #include "TMatrixD.h" #include "TMatrixDSymEigen.h" #include "TRandom.h" +#include +#include +#include +#include #include #include @@ -260,27 +264,47 @@ void FastTracker::AddGenericDetector(std::string filename, o2::ccdb::BasicCCDBMa return; } - std::ifstream infile(filename); - if (!infile.is_open()) { - LOG(fatal) << "Could not open detector configuration file: " << filename; - return; - } - - std::string line; - while (std::getline(infile, line)) { - if (line.empty() || line[0] == '#') - continue; // skip comments and empty lines - std::istringstream iss(line); - std::string name; - float r, z, x0, xrho, resRPhi, resZ, eff; - int type; - if (!(iss >> name >> r >> z >> x0 >> xrho >> resRPhi >> resZ >> eff >> type)) { - LOG(error) << "Malformed line in detector config: " << line; + TEnv env(filename.c_str()); + THashList* table = env.GetTable(); + std::vector layers; + for (int i = 0; i < table->GetEntries(); ++i) { + const std::string key = table->At(i)->GetName(); + // key should contain exactly one dot + if (key.find('.') == std::string::npos || key.find('.') != key.rfind('.')) { + LOG(fatal) << "Key " << key << " does not contain exactly one dot"; continue; } - AddLayer(name.c_str(), r, z, x0, xrho, resRPhi, resZ, eff, type); + const std::string firstPart = key.substr(0, key.find('.')); + if (std::find(layers.begin(), layers.end(), firstPart) == layers.end()) { + layers.push_back(firstPart); + } + } + // env.Print(); + // Layers + for (const auto& layer : layers) { + LOG(info) << " Reading layer " << layer; + + auto getKey = [&layer, &env](const std::string& name) { + std::string key = layer + "." + name; + if (!env.Defined(key.c_str())) { + LOG(warning) << "Key " << key << " not defined in configuration file, getting the default value"; + } + LOG(info) << " Getting key " << key; + return key.c_str(); + }; + const float r = env.GetValue(getKey("r"), -1.0f); + LOG(info) << " Layer " << layer << " has radius " << r; + const float z = env.GetValue(getKey("z"), -1.0f); + const float x0 = env.GetValue(getKey("x0"), 0.0f); + const float xrho = env.GetValue(getKey("xrho"), 0.0f); + const float resRPhi = env.GetValue(getKey("resRPhi"), 0.0f); + const float resZ = env.GetValue(getKey("resZ"), 0.0f); + const float eff = env.GetValue(getKey("eff"), 0.0f); + const int type = env.GetValue(getKey("type"), 0); + + // 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); + AddLayer(layer.c_str(), r, z, x0, xrho, resRPhi, resZ, eff, type); } - infile.close(); } float FastTracker::Dist(float z, float r) diff --git a/ALICE3/macros/testFastTracker.cxx b/ALICE3/macros/testFastTracker.cxx new file mode 100644 index 00000000000..ecca4c6de85 --- /dev/null +++ b/ALICE3/macros/testFastTracker.cxx @@ -0,0 +1,30 @@ +// Copyright 2019-2020 CERN and copyright holders of ALICE O2. +// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders. +// All rights not expressly granted are reserved. +// +// This software is distributed under the terms of the GNU General Public +// License v3 (GPL Version 3), copied verbatim in the file "COPYING". +// +// In applying this license CERN does not waive the privileges and immunities +// granted to it by virtue of its status as an Intergovernmental Organization +// or submit itself to any jurisdiction. + +/// \file testFastTracker.C +/// \author Nicolò Jacazio nicolo.jacazio@cern.ch +/// \brief Test the FastTracker functionality + +#include "ALICE3/Core/FastTracker.h" + +#include "CCDB/BasicCCDBManager.h" +#include "DataFormatsParameters/GRPLHCIFData.h" + +void testFastTracker(std::string geometryFile = "a3geo.ini") +{ + + // auto& ccdb = o2::ccdb::BasicCCDBManager::instance(); + // ccdb.setURL("http://alice-ccdb.cern.ch"); + o2::fastsim::FastTracker fastTracker; + fastTracker.AddGenericDetector(geometryFile); + // fastTracker.AddGenericDetector(geometryFile, &ccdb); + fastTracker.Print(); +} From b1650d76a94d1dc79778db93231059586eeeaa5c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=B2=20Jacazio?= Date: Tue, 23 Sep 2025 09:37:54 +0200 Subject: [PATCH 2/2] Fix key handling in FastTracker configuration --- ALICE3/Core/FastTracker.cxx | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/ALICE3/Core/FastTracker.cxx b/ALICE3/Core/FastTracker.cxx index 005cd4fc301..84fa174c224 100644 --- a/ALICE3/Core/FastTracker.cxx +++ b/ALICE3/Core/FastTracker.cxx @@ -290,17 +290,17 @@ void FastTracker::AddGenericDetector(std::string filename, o2::ccdb::BasicCCDBMa LOG(warning) << "Key " << key << " not defined in configuration file, getting the default value"; } LOG(info) << " Getting key " << key; - return key.c_str(); + return key; }; - const float r = env.GetValue(getKey("r"), -1.0f); + const float r = env.GetValue(getKey("r").c_str(), -1.0f); LOG(info) << " Layer " << layer << " has radius " << r; - const float z = env.GetValue(getKey("z"), -1.0f); - const float x0 = env.GetValue(getKey("x0"), 0.0f); - const float xrho = env.GetValue(getKey("xrho"), 0.0f); - const float resRPhi = env.GetValue(getKey("resRPhi"), 0.0f); - const float resZ = env.GetValue(getKey("resZ"), 0.0f); - const float eff = env.GetValue(getKey("eff"), 0.0f); - const int type = env.GetValue(getKey("type"), 0); + const float z = env.GetValue(getKey("z").c_str(), -1.0f); + const float x0 = env.GetValue(getKey("x0").c_str(), 0.0f); + const float xrho = env.GetValue(getKey("xrho").c_str(), 0.0f); + const float resRPhi = env.GetValue(getKey("resRPhi").c_str(), 0.0f); + const float resZ = env.GetValue(getKey("resZ").c_str(), 0.0f); + const float eff = env.GetValue(getKey("eff").c_str(), 0.0f); + const int type = env.GetValue(getKey("type").c_str(), 0); // 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); AddLayer(layer.c_str(), r, z, x0, xrho, resRPhi, resZ, eff, type);