Skip to content

Commit 217a2d2

Browse files
Merge branch 'master' into master
2 parents 9b6b789 + 7262b17 commit 217a2d2

File tree

141 files changed

+4449
-2566
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

141 files changed

+4449
-2566
lines changed

ALICE3/Core/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,15 @@ o2physics_add_library(ALICE3Core
1313
SOURCES TOFResoALICE3.cxx
1414
TrackUtilities.cxx
1515
DelphesO2TrackSmearer.cxx
16+
GeometryContainer.cxx
1617
PUBLIC_LINK_LIBRARIES O2::Framework
1718
O2Physics::AnalysisCore)
1819

1920
o2physics_target_root_dictionary(ALICE3Core
2021
HEADERS TOFResoALICE3.h
2122
TrackUtilities.h
2223
DelphesO2TrackSmearer.h
24+
GeometryContainer.h
2325
LINKDEF ALICE3CoreLinkDef.h)
2426

2527
o2physics_add_library(FastTracker

ALICE3/Core/DelphesO2TrackSmearer.cxx

Lines changed: 6 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@
3636

3737
#include "ALICE3/Core/DelphesO2TrackSmearer.h"
3838

39+
#include "ALICE3/Core/GeometryContainer.h"
40+
3941
#include <CommonConstants/PhysicsConstants.h>
4042
#include <Framework/Logger.h>
4143

@@ -61,42 +63,13 @@ bool TrackSmearer::loadTable(int pdg, const char* filename, bool forceReload)
6163
LOG(info) << " --- LUT table for PDG " << pdg << " has been already loaded with index " << ipdg << std::endl;
6264
return false;
6365
}
64-
if (strncmp(filename, "ccdb:", 5) == 0) { // Check if filename starts with "ccdb:"
65-
LOG(info) << " --- LUT file source identified as CCDB.";
66-
std::string path = std::string(filename).substr(5); // Remove "ccdb:" prefix
67-
filename = Form("%s/%s/snapshot.root", mOutPath.c_str(), path.c_str());
68-
LOG(info) << " --- Local LUT filename will be: " << filename;
69-
std::ifstream checkFile(filename); // Check if file already exists
70-
if (!checkFile.is_open()) { // File does not exist, retrieve from CCDB
71-
LOG(info) << " --- CCDB source detected for PDG " << pdg << ": " << path;
72-
if (!mCcdbManager) {
73-
LOG(fatal) << " --- CCDB manager not set. Please set it before loading LUT from CCDB.";
74-
}
75-
std::map<std::string, std::string> metadata;
76-
mCcdbManager->getCCDBAccessor().retrieveBlob(path, mOutPath, metadata, 1);
77-
// Add CCDB handling logic here if needed
78-
LOG(info) << " --- Now retrieving LUT file from CCDB to: " << filename;
79-
if (mCleanupDownloadedFile) { // Clean up the downloaded file if needed
80-
bool status = loadTable(pdg, filename, forceReload);
81-
if (std::remove(filename) != 0) {
82-
LOG(warn) << " --- Could not remove temporary LUT file: " << filename;
83-
} else {
84-
LOG(info) << " --- Removed temporary LUT file: " << filename;
85-
}
86-
return status;
87-
}
88-
} else { // File exists, proceed to load
89-
LOG(info) << " --- LUT file already exists: " << filename << ". Skipping download.";
90-
checkFile.close();
91-
}
92-
return loadTable(pdg, filename, forceReload);
93-
}
9466

67+
const std::string localFilename = o2::fastsim::GeometryEntry::accessFile(filename, "./.ALICE3/LUTs/", mCcdbManager, 10);
9568
mLUTHeader[ipdg] = new lutHeader_t;
9669

97-
std::ifstream lutFile(filename, std::ifstream::binary);
70+
std::ifstream lutFile(localFilename, std::ifstream::binary);
9871
if (!lutFile.is_open()) {
99-
LOG(info) << " --- cannot open covariance matrix file for PDG " << pdg << ": " << filename << std::endl;
72+
LOG(info) << " --- cannot open covariance matrix file for PDG " << pdg << ": " << localFilename << std::endl;
10073
delete mLUTHeader[ipdg];
10174
mLUTHeader[ipdg] = nullptr;
10275
return false;
@@ -147,7 +120,7 @@ bool TrackSmearer::loadTable(int pdg, const char* filename, bool forceReload)
147120
mLUTEntry[ipdg][inch][irad][ieta][ipt] = new lutEntry_t;
148121
lutFile.read(reinterpret_cast<char*>(mLUTEntry[ipdg][inch][irad][ieta][ipt]), sizeof(lutEntry_t));
149122
if (lutFile.gcount() != sizeof(lutEntry_t)) {
150-
LOG(info) << " --- troubles reading covariance matrix entry for PDG " << pdg << ": " << filename << std::endl;
123+
LOG(info) << " --- troubles reading covariance matrix entry for PDG " << pdg << ": " << localFilename << std::endl;
151124
LOG(info) << " --- expected/detected " << sizeof(lutHeader_t) << "/" << lutFile.gcount() << std::endl;
152125
return false;
153126
}

ALICE3/Core/DelphesO2TrackSmearer.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -251,8 +251,6 @@ class TrackSmearer
251251
}
252252
void setdNdEta(float val) { mdNdEta = val; } //;
253253
void setCcdbManager(o2::ccdb::BasicCCDBManager* mgr) { mCcdbManager = mgr; } //;
254-
void setCleanupDownloadedFile(bool val) { mCleanupDownloadedFile = val; } //;
255-
void setDownloadPath(const std::string& path) { mOutPath = path; } //;
256254

257255
protected:
258256
static constexpr unsigned int nLUTs = 9; // Number of LUT available
@@ -266,8 +264,6 @@ class TrackSmearer
266264

267265
private:
268266
o2::ccdb::BasicCCDBManager* mCcdbManager = nullptr;
269-
bool mCleanupDownloadedFile = true; // Flag to cleanup the LUT after it's used
270-
std::string mOutPath = "./.ALICE3/LUTs/"; // Path where to download LUTs from CCDB
271267
};
272268

273269
} // namespace delphes

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)