Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion ALICE3/Core/FastTracker.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,11 @@ namespace o2
namespace fastsim
{

std::map<std::string, std::map<std::string, std::string>> GeometryContainer::parseTEnvConfiguration(std::string filename, std::vector<std::string>& layers)
std::map<std::string, std::map<std::string, std::string>> GeometryContainer::parseTEnvConfiguration(std::string& filename, std::vector<std::string>& layers)
{
std::map<std::string, std::map<std::string, std::string>> 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();
Expand Down Expand Up @@ -95,6 +96,16 @@ std::map<std::string, std::string> 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);
Expand All @@ -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)
Expand Down
23 changes: 16 additions & 7 deletions ALICE3/Core/FastTracker.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::string, std::map<std::string, std::string>> parseTEnvConfiguration(std::string filename, std::vector<std::string>& layers);
static std::map<std::string, std::map<std::string, std::string>> parseTEnvConfiguration(std::string& filename, std::vector<std::string>& 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<std::string, std::map<std::string, std::string>> getConfigurations() const { return mConfigurations; }
std::map<std::string, std::string> getConfiguration(const std::string& layerName) const;
std::vector<std::string> getLayerNames() const { return layerNames; }
std::vector<std::string> 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<std::string, std::map<std::string, std::string>> mConfigurations;
std::vector<std::string> layerNames; // Ordered names of the layers
std::string mFileName; // Filename of the geometry
std::map<std::string, std::map<std::string, std::string>> mConfigurations; // Layer configurations
std::vector<std::string> mLayerNames; // Ordered names of the layers
};

// Add a geometry entry from a configuration file
Expand All @@ -79,6 +87,7 @@ class GeometryContainer
std::map<std::string, std::string> 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:
Expand Down
Loading