diff --git a/ALICE3/Core/FastTracker.cxx b/ALICE3/Core/FastTracker.cxx index 41c6637d59b..e20eb4b4227 100644 --- a/ALICE3/Core/FastTracker.cxx +++ b/ALICE3/Core/FastTracker.cxx @@ -34,10 +34,11 @@ namespace o2 namespace fastsim { -std::map> GeometryContainer::parseTEnvConfiguration(std::string filename, std::vector& layers) +std::map> GeometryContainer::parseTEnvConfiguration(std::string& filename, std::vector& layers) { std::map> configMap; filename = gSystem->ExpandPathName(filename.c_str()); + LOG(info) << "Parsing TEnv configuration file: " << filename; TEnv env(filename.c_str()); THashList* table = env.GetTable(); layers.clear(); @@ -95,6 +96,16 @@ std::map GeometryContainer::GeometryEntry::getConfigur } } +bool GeometryContainer::GeometryEntry::hasValue(const std::string& layerName, const std::string& key) const +{ + auto layerIt = mConfigurations.find(layerName); + if (layerIt != mConfigurations.end()) { + auto keyIt = layerIt->second.find(key); + return keyIt != layerIt->second.end(); + } + return false; +} + std::string GeometryContainer::GeometryEntry::getValue(const std::string& layerName, const std::string& key, bool require) const { auto layer = getConfiguration(layerName); @@ -109,6 +120,14 @@ std::string GeometryContainer::GeometryEntry::getValue(const std::string& layerN } } +void GeometryContainer::GeometryEntry::replaceValue(const std::string& layerName, const std::string& key, const std::string& value) +{ + if (!hasValue(layerName, key)) { // check that the key exists + LOG(fatal) << "Key " << key << " does not exist in layer " << layerName << ". Cannot replace value."; + } + setValue(layerName, key, value); +} + // +-~-<*>-~-+-~-<*>-~-+-~-<*>-~-+-~-<*>-~-+-~-<*>-~-+-~-<*>-~-+-~-<*>-~-+-~-<*>-~-+ DetLayer* FastTracker::AddLayer(TString name, float r, float z, float x0, float xrho, float resRPhi, float resZ, float eff, int type) diff --git a/ALICE3/Core/FastTracker.h b/ALICE3/Core/FastTracker.h index 8703269296e..f0f27e7c4c6 100644 --- a/ALICE3/Core/FastTracker.h +++ b/ALICE3/Core/FastTracker.h @@ -42,27 +42,35 @@ class GeometryContainer * @param layers Vector to store the order of the layers as they appear in the file * @return A map where each key is a layer name and the value is another map of key-value pairs for that layer */ - static std::map> parseTEnvConfiguration(std::string filename, std::vector& layers); + static std::map> parseTEnvConfiguration(std::string& filename, std::vector& layers); // A container for the geometry info struct GeometryEntry { // Default constructor GeometryEntry() = default; - explicit GeometryEntry(std::string filename) : name(filename) + explicit GeometryEntry(std::string filename) { - mConfigurations = GeometryContainer::parseTEnvConfiguration(filename, layerNames); + mFileName = filename; + mConfigurations = GeometryContainer::parseTEnvConfiguration(mFileName, mLayerNames); + LOG(info) << "Loaded geometry configuration from file: " << filename << " with " << mLayerNames.size() << " layers."; + if (mLayerNames.empty()) { + LOG(warning) << "No layers found in geometry configuration file: " << filename; + } } std::map> getConfigurations() const { return mConfigurations; } std::map getConfiguration(const std::string& layerName) const; - std::vector getLayerNames() const { return layerNames; } + std::vector getLayerNames() const { return mLayerNames; } + bool hasValue(const std::string& layerName, const std::string& key) const; std::string getValue(const std::string& layerName, const std::string& key, bool require = true) const; + void setValue(const std::string& layerName, const std::string& key, const std::string& value) { mConfigurations[layerName][key] = value; } + void replaceValue(const std::string& layerName, const std::string& key, const std::string& value); float getFloatValue(const std::string& layerName, const std::string& key) const { return std::stof(getValue(layerName, key)); } int getIntValue(const std::string& layerName, const std::string& key) const { return std::stoi(getValue(layerName, key)); } private: - std::string name; // Filename of the geometry - std::map> mConfigurations; - std::vector layerNames; // Ordered names of the layers + std::string mFileName; // Filename of the geometry + std::map> mConfigurations; // Layer configurations + std::vector mLayerNames; // Ordered names of the layers }; // Add a geometry entry from a configuration file @@ -79,6 +87,7 @@ class GeometryContainer std::map getConfiguration(const int id, const std::string& layerName) const { return entries.at(id).getConfiguration(layerName); } // Get specific values + std::string getValue(const int id, const std::string& layerName, const std::string& key, bool require = true) const { return entries.at(id).getValue(layerName, key, require); } float getFloatValue(const int id, const std::string& layerName, const std::string& key) const { return entries.at(id).getFloatValue(layerName, key); } private: