Skip to content

Commit 68ba72a

Browse files
authored
Refactor filename handling in load method
1 parent 0bc1311 commit 68ba72a

File tree

1 file changed

+25
-26
lines changed

1 file changed

+25
-26
lines changed

ALICE3/TableProducer/OTF/onTheFlyTrackerPid.cxx

Lines changed: 25 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -136,38 +136,37 @@ class ToTLUT
136136

137137
bool load(int pdg, const std::string& filename)
138138
{
139-
if (!filename.empty() && strncmp(filename.c_str(), "ccdb:", 5) == 0) {
140-
std::string basePath = std::string(filename).substr(5);
141-
std::string path = basePath + "/PDG_" + std::to_string(pdg);
142-
const std::string outPath = "/tmp/ToTLUTs/";
143-
144-
std::string localFilename = Form("%s/lut_tot_%d.root", outPath.c_str(), pdg);
139+
if(filename.empty()) {
140+
LOG(warning) << "Provided filename is empty for PDG " << pdg;
141+
return false;
142+
}
143+
if (strncmp(filename.c_str(), "ccdb:", 5) == 0) { // Check if filename starts with "ccdb:"
144+
const std::string basePath = std::string(filename).substr(5);
145+
const std::string outPath = "/tmp/ToTLUTs/" + basePath;
146+
const std::string localFilename = outPath + "/snapshot.root";
145147
std::ifstream checkFile(localFilename);
146-
if (!checkFile.is_open()) {
148+
if (!checkFile.is_open()) { // File is not found, need to download it from CCDB
147149
if (!mCcdbManager) {
148150
LOG(fatal) << "CCDB manager not set. Please set it before loading LUT from CCDB.";
149151
}
150152
std::map<std::string, std::string> metadata;
151-
mCcdbManager->getCCDBAccessor().retrieveBlob(path, outPath, metadata, 1);
152-
153-
std::string foundFile = Form("%s/%s/snapshot.root", outPath.c_str(), path.c_str());
154-
std::ifstream testFile(foundFile);
153+
mCcdbManager->getCCDBAccessor().retrieveBlob(basePath, outPath, metadata, 1);
154+
std::ifstream testFile(localFilename);
155155
if (!testFile.is_open()) {
156-
LOG(error) << "Could not find downloaded CCDB file for PDG " << pdg;
156+
LOG(fatal) << "Could not find downloaded CCDB file for PDG " << pdg;
157157
return false;
158158
}
159159
testFile.close();
160-
161-
return load(pdg, foundFile);
162-
} else {
160+
return load(pdg, localFilename);
161+
} else {// File is found, proceed to load it
163162
checkFile.close();
164163
return load(pdg, localFilename);
165164
}
166165
}
167-
166+
// In case the file is already available locally
168167
TFile* f = TFile::Open(filename.c_str());
169168
if (!f || f->IsZombie()) {
170-
LOG(error) << "Failed to open LUT file: " << filename;
169+
LOG(fatal) << "Failed to open LUT file: " << filename;
171170
return false;
172171
}
173172

@@ -397,15 +396,15 @@ struct OnTheFlyTrackerPid {
397396

398397
HistogramRegistry histos{"histos", {}, OutputObjHandlingPolicy::AnalysisObject};
399398

400-
Configurable<std::string> lutTotEl{"lutTotEl", "ccdb:Users/h/hfribert/ToT_LUTs", "ToT LUT for electrons"};
401-
Configurable<std::string> lutTotMu{"lutTotMu", "ccdb:Users/h/hfribert/ToT_LUTs", "ToT LUT for muons"};
402-
Configurable<std::string> lutTotPi{"lutTotPi", "ccdb:Users/h/hfribert/ToT_LUTs", "ToT LUT for pions"};
403-
Configurable<std::string> lutTotKa{"lutTotKa", "ccdb:Users/h/hfribert/ToT_LUTs", "ToT LUT for kaons"};
404-
Configurable<std::string> lutTotPr{"lutTotPr", "ccdb:Users/h/hfribert/ToT_LUTs", "ToT LUT for protons"};
405-
Configurable<std::string> lutTotDe{"lutTotDe", "ccdb:Users/h/hfribert/ToT_LUTs", "ToT LUT for deuteron"};
406-
Configurable<std::string> lutTotTr{"lutTotTr", "ccdb:Users/h/hfribert/ToT_LUTs", "ToT LUT for triton"};
407-
Configurable<std::string> lutTotHe{"lutTotHe", "ccdb:Users/h/hfribert/ToT_LUTs", "ToT LUT for helium-3"};
408-
Configurable<std::string> lutTotAl{"lutTotAl", "ccdb:Users/h/hfribert/ToT_LUTs", "ToT LUT for alphas"};
399+
Configurable<std::string> lutTotEl{"lutTotEl", "ccdb:Users/h/hfribert/ToT_LUTs/PDG_11/", "ToT LUT for electrons"};
400+
Configurable<std::string> lutTotMu{"lutTotMu", "ccdb:Users/h/hfribert/ToT_LUTs/PDG_13/", "ToT LUT for muons"};
401+
Configurable<std::string> lutTotPi{"lutTotPi", "ccdb:Users/h/hfribert/ToT_LUTs/PDG_211/", "ToT LUT for pions"};
402+
Configurable<std::string> lutTotKa{"lutTotKa", "ccdb:Users/h/hfribert/ToT_LUTs/PDG_321/", "ToT LUT for kaons"};
403+
Configurable<std::string> lutTotPr{"lutTotPr", "ccdb:Users/h/hfribert/ToT_LUTs/PDG_2212/", "ToT LUT for protons"};
404+
Configurable<std::string> lutTotDe{"lutTotDe", "ccdb:Users/h/hfribert/ToT_LUTs/PDG_1000010020/", "ToT LUT for deuteron"};
405+
Configurable<std::string> lutTotTr{"lutTotTr", "ccdb:Users/h/hfribert/ToT_LUTs/PDG_1000010030/", "ToT LUT for triton"};
406+
Configurable<std::string> lutTotHe{"lutTotHe", "ccdb:Users/h/hfribert/ToT_LUTs/PDG_1000020030/", "ToT LUT for helium-3"};
407+
Configurable<std::string> lutTotAl{"lutTotAl", "ccdb:Users/h/hfribert/ToT_LUTs/PDG_1000020040/", "ToT LUT for alphas"};
409408

410409
Configurable<float> dBz{"dBz", 20, "magnetic field (kilogauss) for track propagation"};
411410
Configurable<int> maxBarrelLayers{"maxBarrelLayers", 11, "Maximum number of barrel layers"};

0 commit comments

Comments
 (0)