Skip to content

Commit 94264e2

Browse files
committed
Separate the geometry into a separate header
1 parent 37b20de commit 94264e2

File tree

5 files changed

+325
-197
lines changed

5 files changed

+325
-197
lines changed

ALICE3/Core/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ o2physics_add_library(FastTracker
2626
SOURCES FastTracker.cxx
2727
DetLayer.cxx
2828
DelphesO2LutWriter.cxx
29+
GeometryContainer.cxx
2930
PUBLIC_LINK_LIBRARIES O2::Framework
3031
O2Physics::AnalysisCore
3132
O2Physics::ALICE3Core)
@@ -34,4 +35,5 @@ o2physics_target_root_dictionary(FastTracker
3435
HEADERS FastTracker.h
3536
DetLayer.h
3637
DelphesO2LutWriter.h
38+
GeometryContainer.h
3739
LINKDEF FastTrackerLinkDef.h)

ALICE3/Core/FastTracker.cxx

Lines changed: 1 addition & 127 deletions
Original file line numberDiff line numberDiff line change
@@ -36,132 +36,6 @@ namespace o2
3636
namespace fastsim
3737
{
3838

39-
std::map<std::string, std::map<std::string, std::string>> GeometryContainer::parseTEnvConfiguration(std::string& filename, std::vector<std::string>& layers)
40-
{
41-
std::map<std::string, std::map<std::string, std::string>> configMap;
42-
filename = gSystem->ExpandPathName(filename.c_str());
43-
LOG(info) << "Parsing TEnv configuration file: " << filename;
44-
TEnv env(filename.c_str());
45-
THashList* table = env.GetTable();
46-
layers.clear();
47-
for (int i = 0; i < table->GetEntries(); ++i) {
48-
const std::string key = table->At(i)->GetName();
49-
// key should contain exactly one dot
50-
if (key.find('.') == std::string::npos || key.find('.') != key.rfind('.')) {
51-
LOG(fatal) << "Key " << key << " does not contain exactly one dot";
52-
continue;
53-
}
54-
const std::string firstPart = key.substr(0, key.find('.'));
55-
if (std::find(layers.begin(), layers.end(), firstPart) == layers.end()) {
56-
layers.push_back(firstPart);
57-
}
58-
}
59-
env.Print();
60-
// Layers
61-
for (const auto& layer : layers) {
62-
LOG(info) << " Reading layer " << layer;
63-
for (int i = 0; i < table->GetEntries(); ++i) {
64-
const std::string key = table->At(i)->GetName();
65-
if (key.find(layer + ".") == 0) {
66-
const std::string paramName = key.substr(key.find('.') + 1);
67-
const std::string value = env.GetValue(key.c_str(), "");
68-
configMap[layer][paramName] = value;
69-
}
70-
}
71-
}
72-
return configMap;
73-
}
74-
75-
void GeometryContainer::init(o2::framework::InitContext& initContext)
76-
{
77-
std::vector<std::string> detectorConfiguration;
78-
const bool foundDetectorConfiguration = common::core::getTaskOptionValue(initContext, "on-the-fly-detector-geometry-provider", "detectorConfiguration", detectorConfiguration, false);
79-
if (!foundDetectorConfiguration) {
80-
LOG(fatal) << "Could not retrieve detector configuration from OnTheFlyDetectorGeometryProvider task.";
81-
return;
82-
}
83-
LOG(info) << "Size of detector configuration: " << detectorConfiguration.size();
84-
85-
bool cleanLutWhenLoaded;
86-
const bool foundCleanLutWhenLoaded = common::core::getTaskOptionValue(initContext, "on-the-fly-detector-geometry-provider", "cleanLutWhenLoaded", cleanLutWhenLoaded, false);
87-
if (!foundCleanLutWhenLoaded) {
88-
LOG(fatal) << "Could not retrieve foundCleanLutWhenLoaded option from OnTheFlyDetectorGeometryProvider task.";
89-
return;
90-
}
91-
92-
for (std::string& configFile : detectorConfiguration) {
93-
if (configFile.rfind("ccdb:", 0) == 0) {
94-
LOG(info) << "ccdb source detected from on-the-fly-detector-geometry-provider";
95-
const std::string ccdbPath = configFile.substr(5); // remove "ccdb:" prefix
96-
const std::string outPath = "./.ALICE3/Configuration/";
97-
configFile = Form("%s/%s/snapshot.root", outPath.c_str(), ccdbPath.c_str());
98-
99-
int timeout = 600; // Wait max 10 minutes
100-
while (--timeout > 0) {
101-
std::ifstream file(configFile);
102-
if (file.good()) {
103-
break;
104-
}
105-
106-
std::this_thread::sleep_for(std::chrono::seconds(1));
107-
}
108-
109-
std::ifstream checkFile(configFile);
110-
if (!checkFile.good()) {
111-
LOG(fatal) << "Timed out waiting for geometry snapshot: " << configFile;
112-
return;
113-
}
114-
}
115-
116-
LOG(info) << "Detector geometry configuration file used: " << configFile;
117-
addEntry(configFile);
118-
setLutCleanupSetting(cleanLutWhenLoaded);
119-
}
120-
}
121-
122-
std::map<std::string, std::string> GeometryContainer::GeometryEntry::getConfiguration(const std::string& layerName) const
123-
{
124-
auto it = mConfigurations.find(layerName);
125-
if (it != mConfigurations.end()) {
126-
return it->second;
127-
} else {
128-
LOG(fatal) << "Layer " << layerName << " not found in geometry configurations.";
129-
return {};
130-
}
131-
}
132-
133-
bool GeometryContainer::GeometryEntry::hasValue(const std::string& layerName, const std::string& key) const
134-
{
135-
auto layerIt = mConfigurations.find(layerName);
136-
if (layerIt != mConfigurations.end()) {
137-
auto keyIt = layerIt->second.find(key);
138-
return keyIt != layerIt->second.end();
139-
}
140-
return false;
141-
}
142-
143-
std::string GeometryContainer::GeometryEntry::getValue(const std::string& layerName, const std::string& key, bool require) const
144-
{
145-
auto layer = getConfiguration(layerName);
146-
auto entry = layer.find(key);
147-
if (entry != layer.end()) {
148-
return layer.at(key);
149-
} else if (require) {
150-
LOG(fatal) << "Key " << key << " not found in layer " << layerName << " configurations.";
151-
return "";
152-
} else {
153-
return "";
154-
}
155-
}
156-
157-
void GeometryContainer::GeometryEntry::replaceValue(const std::string& layerName, const std::string& key, const std::string& value)
158-
{
159-
if (!hasValue(layerName, key)) { // check that the key exists
160-
LOG(fatal) << "Key " << key << " does not exist in layer " << layerName << ". Cannot replace value.";
161-
}
162-
setValue(layerName, key, value);
163-
}
164-
16539
// +-~-<*>-~-+-~-<*>-~-+-~-<*>-~-+-~-<*>-~-+-~-<*>-~-+-~-<*>-~-+-~-<*>-~-+-~-<*>-~-+
16640

16741
DetLayer* FastTracker::AddLayer(TString name, float r, float z, float x0, float xrho, float resRPhi, float resZ, float eff, int type)
@@ -267,7 +141,7 @@ void FastTracker::AddTPC(float phiResMean, float zResMean)
267141
}
268142
}
269143

270-
void FastTracker::AddGenericDetector(GeometryContainer::GeometryEntry configMap, o2::ccdb::BasicCCDBManager* ccdbManager)
144+
void FastTracker::AddGenericDetector(o2::fastsim::GeometryEntry configMap, o2::ccdb::BasicCCDBManager* ccdbManager)
271145
{
272146
// Layers
273147
for (const auto& layer : configMap.getLayerNames()) {

ALICE3/Core/FastTracker.h

Lines changed: 2 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#define ALICE3_CORE_FASTTRACKER_H_
1414

1515
#include "DetLayer.h"
16+
#include "GeometryContainer.h"
1617

1718
#include <CCDB/BasicCCDBManager.h>
1819
#include <Framework/InitContext.h>
@@ -28,75 +29,6 @@ namespace o2
2829
namespace fastsim
2930
{
3031

31-
class GeometryContainer
32-
{
33-
public:
34-
GeometryContainer() = default;
35-
virtual ~GeometryContainer() = default;
36-
37-
void init(o2::framework::InitContext& initContext);
38-
39-
/**
40-
* @brief Parses a TEnv configuration file and returns the key-value pairs split per entry
41-
* @param filename Path to the TEnv configuration file
42-
* @param layers Vector to store the order of the layers as they appear in the file
43-
* @return A map where each key is a layer name and the value is another map of key-value pairs for that layer
44-
*/
45-
static std::map<std::string, std::map<std::string, std::string>> parseTEnvConfiguration(std::string& filename, std::vector<std::string>& layers);
46-
47-
// A container for the geometry info
48-
struct GeometryEntry {
49-
// Default constructor
50-
GeometryEntry() = default;
51-
explicit GeometryEntry(std::string filename)
52-
{
53-
mFileName = filename;
54-
mConfigurations = GeometryContainer::parseTEnvConfiguration(mFileName, mLayerNames);
55-
LOG(info) << "Loaded geometry configuration from file: " << filename << " with " << mLayerNames.size() << " layers.";
56-
if (mLayerNames.empty()) {
57-
LOG(warning) << "No layers found in geometry configuration file: " << filename;
58-
}
59-
}
60-
std::map<std::string, std::map<std::string, std::string>> getConfigurations() const { return mConfigurations; }
61-
std::map<std::string, std::string> getConfiguration(const std::string& layerName) const;
62-
std::vector<std::string> getLayerNames() const { return mLayerNames; }
63-
bool hasValue(const std::string& layerName, const std::string& key) const;
64-
std::string getValue(const std::string& layerName, const std::string& key, bool require = true) const;
65-
void setValue(const std::string& layerName, const std::string& key, const std::string& value) { mConfigurations[layerName][key] = value; }
66-
void replaceValue(const std::string& layerName, const std::string& key, const std::string& value);
67-
float getFloatValue(const std::string& layerName, const std::string& key) const { return std::stof(getValue(layerName, key)); }
68-
int getIntValue(const std::string& layerName, const std::string& key) const { return std::stoi(getValue(layerName, key)); }
69-
70-
private:
71-
std::string mFileName; // Filename of the geometry
72-
std::map<std::string, std::map<std::string, std::string>> mConfigurations; // Layer configurations
73-
std::vector<std::string> mLayerNames; // Ordered names of the layers
74-
};
75-
76-
// Add a geometry entry from a configuration file
77-
void addEntry(const std::string& filename) { entries.emplace_back(filename); }
78-
void setLutCleanupSetting(const bool cleanLutWhenLoaded) { mCleanLutWhenLoaded = cleanLutWhenLoaded; }
79-
80-
// Getters
81-
int getNumberOfConfigurations() const { return entries.size(); }
82-
const std::vector<GeometryEntry>& getEntries() const { return entries; }
83-
const GeometryEntry& getEntry(const int id) const { return entries.at(id); }
84-
GeometryEntry getGeometryEntry(const int id) const { return entries.at(id); }
85-
bool cleanLutWhenLoaded() const { return mCleanLutWhenLoaded; }
86-
87-
// Get configuration maps
88-
std::map<std::string, std::map<std::string, std::string>> getConfigurations(const int id) const { return entries.at(id).getConfigurations(); }
89-
std::map<std::string, std::string> getConfiguration(const int id, const std::string& layerName) const { return entries.at(id).getConfiguration(layerName); }
90-
91-
// Get specific values
92-
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); }
93-
float getFloatValue(const int id, const std::string& layerName, const std::string& key) const { return entries.at(id).getFloatValue(layerName, key); }
94-
95-
private:
96-
std::vector<GeometryEntry> entries;
97-
bool mCleanLutWhenLoaded = true;
98-
};
99-
10032
// +-~-<*>-~-+-~-<*>-~-+-~-<*>-~-+-~-<*>-~-+-~-<*>-~-+-~-<*>-~-+-~-<*>-~-+-~-<*>-~-+
10133

10234
// this class implements a synthetic smearer that allows
@@ -145,7 +77,7 @@ class FastTracker
14577
*
14678
* @param configMap Configuration map describing the detector.
14779
*/
148-
void AddGenericDetector(GeometryContainer::GeometryEntry configMap, o2::ccdb::BasicCCDBManager* ccdbManager = nullptr);
80+
void AddGenericDetector(o2::fastsim::GeometryEntry configMap, o2::ccdb::BasicCCDBManager* ccdbManager = nullptr);
14981

15082
void Print();
15183

0 commit comments

Comments
 (0)