Skip to content

Commit ccfd43e

Browse files
authored
[ALICE3] Add possibility to use generic geometry (#13086)
1 parent ace2c2c commit ccfd43e

File tree

2 files changed

+65
-2
lines changed

2 files changed

+65
-2
lines changed

ALICE3/Core/FastTracker.cxx

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ namespace fastsim
3030

3131
void FastTracker::AddLayer(TString name, float r, float z, float x0, float xrho, float resRPhi, float resZ, float eff, int type)
3232
{
33+
LOG(debug) << "Adding layer " << name << " r=" << r << " z=" << z << " x0=" << x0 << " xrho=" << xrho << " resRPhi=" << resRPhi << " resZ=" << resZ << " eff=" << eff << " type=" << type;
3334
DetLayer newLayer(name, r, z, x0, xrho, resRPhi, resZ, eff, type);
3435
// Check that efficient layers are not inert layers
3536
if (newLayer.getEfficiency() > 0.0f && newLayer.isInert()) {
@@ -232,6 +233,56 @@ void FastTracker::AddTPC(float phiResMean, float zResMean)
232233
}
233234
}
234235

236+
void FastTracker::AddGenericDetector(std::string filename, o2::ccdb::BasicCCDBManager* ccdbManager)
237+
{
238+
LOG(info) << " Adding generic detector from file " << filename;
239+
// If the filename starts with ccdb: then take the file from the ccdb
240+
if (filename.rfind("ccdb:", 0) == 0) {
241+
std::string ccdbPath = filename.substr(5); // remove "ccdb:" prefix
242+
if (ccdbManager == nullptr) {
243+
LOG(fatal) << "CCDB manager is null, cannot retrieve file " << ccdbPath;
244+
return;
245+
}
246+
const std::string outPath = "/tmp/DetGeo/";
247+
filename = Form("%s/%s/snapshot.root", outPath.c_str(), ccdbPath.c_str());
248+
std::ifstream checkFile(filename); // Check if file already exists
249+
if (!checkFile.is_open()) { // File does not exist, retrieve from CCDB
250+
LOG(info) << " --- CCDB source detected for detector geometry " << filename;
251+
std::map<std::string, std::string> metadata;
252+
ccdbManager->getCCDBAccessor().retrieveBlob(ccdbPath, outPath, metadata, 1);
253+
// Add CCDB handling logic here if needed
254+
LOG(info) << " --- Now retrieving geometry configuration from CCDB to: " << filename;
255+
} else { // File exists, proceed to load
256+
LOG(info) << " --- Geometry configuration file already exists: " << filename << ". Skipping download.";
257+
checkFile.close();
258+
}
259+
AddGenericDetector(filename, nullptr);
260+
return;
261+
}
262+
263+
std::ifstream infile(filename);
264+
if (!infile.is_open()) {
265+
LOG(fatal) << "Could not open detector configuration file: " << filename;
266+
return;
267+
}
268+
269+
std::string line;
270+
while (std::getline(infile, line)) {
271+
if (line.empty() || line[0] == '#')
272+
continue; // skip comments and empty lines
273+
std::istringstream iss(line);
274+
std::string name;
275+
float r, z, x0, xrho, resRPhi, resZ, eff;
276+
int type;
277+
if (!(iss >> name >> r >> z >> x0 >> xrho >> resRPhi >> resZ >> eff >> type)) {
278+
LOG(error) << "Malformed line in detector config: " << line;
279+
continue;
280+
}
281+
AddLayer(name.c_str(), r, z, x0, xrho, resRPhi, resZ, eff, type);
282+
}
283+
infile.close();
284+
}
285+
235286
float FastTracker::Dist(float z, float r)
236287
{
237288
// porting of DetektorK::Dist

ALICE3/Core/FastTracker.h

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,10 @@
1414

1515
#include "DetLayer.h"
1616

17-
#include "ReconstructionDataFormats/Track.h"
17+
#include <CCDB/BasicCCDBManager.h>
18+
#include <ReconstructionDataFormats/Track.h>
1819

19-
#include <fairlogger/Logger.h> // not a system header but megalinter thinks so
20+
#include <fairlogger/Logger.h>
2021

2122
#include <string>
2223
#include <vector>
@@ -61,6 +62,17 @@ class FastTracker
6162
void AddSiliconALICE3v2(std::vector<float> pixelResolution);
6263
void AddSiliconALICE3(float scaleX0VD, std::vector<float> pixelResolution);
6364
void AddTPC(float phiResMean, float zResMean);
65+
/**
66+
* @brief Adds a generic detector configuration from the specified file.
67+
*
68+
* This function loads and integrates a detector configuration into the tracker
69+
* using the provided filename. The file should contain the necessary parameters
70+
* and settings for the detector to be added.
71+
*
72+
* @param filename Path to the configuration file describing the detector.
73+
* @param ccdbManager Pointer to a BasicCCDBManager instance for database access (if needed).
74+
*/
75+
void AddGenericDetector(std::string filename, o2::ccdb::BasicCCDBManager* ccdbManager = nullptr);
6476

6577
void Print();
6678

0 commit comments

Comments
 (0)