Skip to content

Commit ad09ab0

Browse files
author
Henrik Fribert
committed
Fix: Ccdb handling & syntax fixes
1 parent 3434287 commit ad09ab0

File tree

2 files changed

+56
-40
lines changed

2 files changed

+56
-40
lines changed

ALICE3/Core/DelphesO2TrackSmearer.cxx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,14 +106,15 @@ bool TrackSmearer::loadTable(int pdg, const char* filename, bool forceReload)
106106
return false;
107107
}
108108
bool specialPdgCase = false;
109-
switch (mLUTHeader[ipdg]->pdg) { // Handle special cases
110-
case o2::constants::physics::kAlpha; // Special case: Allow Alpha particles to use He3 LUT
109+
switch (pdg) { // Handle special cases
110+
case o2::constants::physics::kAlpha: // Special case: Allow Alpha particles to use He3 LUT
111111
specialPdgCase = (mLUTHeader[ipdg]->pdg == o2::constants::physics::kHelium3);
112112
if (specialPdgCase)
113113
LOG(info)
114114
<< " --- Alpha particles (PDG " << pdg << ") will use He3 LUT data (PDG " << mLUTHeader[ipdg]->pdg << ")" << std::endl;
115115
break;
116-
default:
116+
default:
117+
break;
117118
}
118119
if (mLUTHeader[ipdg]->pdg != pdg && !specialPdgCase) {
119120
LOG(info) << " --- LUT header PDG mismatch: expected/detected = " << pdg << "/" << mLUTHeader[ipdg]->pdg << std::endl;

ALICE3/TableProducer/OTF/onTheFlyTrackerPid.cxx

Lines changed: 52 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
#include <algorithm>
5858
#include <array>
5959
#include <cmath>
60+
#include <fstream>
6061
#include <map>
6162
#include <memory>
6263
#include <string>
@@ -119,30 +120,39 @@ class ToTLUT
119120
}
120121
}
121122

122-
bool load(int pdg, const std::string& filename, o2::ccdb::BasicCCDBManager* ccdb = nullptr)
123+
void setCcdbManager(o2::ccdb::BasicCCDBManager* mgr) { mCcdbManager = mgr; }
124+
125+
bool load(int pdg, const std::string& filename)
123126
{
124-
if (strncmp(filename, "ccdb:", 5) == 0) { // Check if filename starts with "ccdb:"
125-
// NOTE: this eventually will directly fetch the object from CCDB instead of accessing it via the root file
126-
LOG(info) << " --- ToT LUT file source identified as CCDB.";
127-
std::string path = std::string(filename).substr(5); // Remove "ccdb:" prefix
127+
if (!filename.empty() && strncmp(filename.c_str(), "ccdb:", 5) == 0) {
128+
std::string basePath = std::string(filename).substr(5);
129+
std::string path = basePath + "/PDG_" + std::to_string(pdg);
128130
const std::string outPath = "/tmp/ToTLUTs/";
129-
filename = Form("%s/%s/snapshot.root", outPath.c_str(), path.c_str());
130-
TFile checkFile(filename.c_str(), "READ");
131-
if (!checkFile.IsOpen()) { // File does not exist, retrieve from CCDB
132-
LOG(info) << " --- CCDB source detected for PDG " << pdg << ": " << path;
133-
if (!ccdb) {
134-
LOG(fatal) << " --- CCDB manager not set. Please provide it.";
131+
132+
std::string localFilename = Form("%s/lut_tot_%d.root", outPath.c_str(), pdg);
133+
std::ifstream checkFile(localFilename);
134+
if (!checkFile.is_open()) {
135+
if (!mCcdbManager) {
136+
LOG(fatal) << "CCDB manager not set. Please set it before loading LUT from CCDB.";
135137
}
136138
std::map<std::string, std::string> metadata;
137-
ccdb->getCCDBAccessor().retrieveBlob(path, outPath, metadata, 1);
138-
// Add CCDB handling logic here if needed
139-
LOG(info) << " --- Now retrieving ToT LUT file from CCDB to: " << filename;
140-
} else { // File exists, proceed to load
141-
LOG(info) << " --- ToT LUT file already exists: " << filename << ". Skipping download.";
142-
checkFile.Close();
139+
mCcdbManager->getCCDBAccessor().retrieveBlob(path, outPath, metadata, 1);
140+
141+
std::string foundFile = Form("%s/%s/snapshot.root", outPath.c_str(), path.c_str());
142+
std::ifstream testFile(foundFile);
143+
if (!testFile.is_open()) {
144+
LOG(error) << "Could not find downloaded CCDB file for PDG " << pdg;
145+
return false;
146+
}
147+
testFile.close();
148+
149+
return load(pdg, foundFile);
150+
} else {
151+
checkFile.close();
152+
return load(pdg, localFilename);
143153
}
144-
return load(pdg, filename);
145154
}
155+
146156
TFile* f = TFile::Open(filename.c_str());
147157
if (!f || f->IsZombie()) {
148158
LOG(error) << "Failed to open LUT file: " << filename;
@@ -253,6 +263,9 @@ class ToTLUT
253263

254264
float mEtaBinWidth;
255265
float mPtBinWidth;
266+
267+
private:
268+
o2::ccdb::BasicCCDBManager* mCcdbManager = nullptr;
256269
};
257270

258271
static constexpr int kNumHypothesisParticles = 9;
@@ -352,19 +365,20 @@ struct OnTheFlyTrackerPid {
352365
Produces<aod::UpgradeTrkPids> tableUpgradeTrkPids;
353366

354367
Service<o2::framework::O2DatabasePDG> pdg;
368+
Service<o2::ccdb::BasicCCDBManager> ccdb;
355369
std::unique_ptr<ToTLUT> mToTLUT;
356370

357371
HistogramRegistry histos{"histos", {}, OutputObjHandlingPolicy::AnalysisObject};
358372

359-
Configurable<std::string> lutTotEl{"lutTotEl", "lut_tot_11.root", "ToT LUT for electrons"};
360-
Configurable<std::string> lutTotMu{"lutTotMu", "lut_tot_13.root", "ToT LUT for muons"};
361-
Configurable<std::string> lutTotPi{"lutTotPi", "lut_tot_211.root", "ToT LUT for pions"};
362-
Configurable<std::string> lutTotKa{"lutTotKa", "lut_tot_321.root", "ToT LUT for kaons"};
363-
Configurable<std::string> lutTotPr{"lutTotPr", "lut_tot_2212.root", "ToT LUT for protons"};
364-
Configurable<std::string> lutTotDe{"lutTotDe", "lut_tot_1000010020.root", "ToT LUT for deuteron"};
365-
Configurable<std::string> lutTotTr{"lutTotTr", "lut_tot_1000010030.root", "ToT LUT for triton"};
366-
Configurable<std::string> lutTotHe{"lutTotHe", "lut_tot_1000020030.root", "ToT LUT for helium-3"};
367-
Configurable<std::string> lutTotAl{"lutTotAl", "lut_tot_1000020040.root", "ToT LUT for alphas"};
373+
Configurable<std::string> lutTotEl{"lutTotEl", "ccdb:Users/h/hfribert/ToT_LUTs", "ToT LUT for electrons"};
374+
Configurable<std::string> lutTotMu{"lutTotMu", "ccdb:Users/h/hfribert/ToT_LUTs", "ToT LUT for muons"};
375+
Configurable<std::string> lutTotPi{"lutTotPi", "ccdb:Users/h/hfribert/ToT_LUTs", "ToT LUT for pions"};
376+
Configurable<std::string> lutTotKa{"lutTotKa", "ccdb:Users/h/hfribert/ToT_LUTs", "ToT LUT for kaons"};
377+
Configurable<std::string> lutTotPr{"lutTotPr", "ccdb:Users/h/hfribert/ToT_LUTs", "ToT LUT for protons"};
378+
Configurable<std::string> lutTotDe{"lutTotDe", "ccdb:Users/h/hfribert/ToT_LUTs", "ToT LUT for deuteron"};
379+
Configurable<std::string> lutTotTr{"lutTotTr", "ccdb:Users/h/hfribert/ToT_LUTs", "ToT LUT for triton"};
380+
Configurable<std::string> lutTotHe{"lutTotHe", "ccdb:Users/h/hfribert/ToT_LUTs", "ToT LUT for helium-3"};
381+
Configurable<std::string> lutTotAl{"lutTotAl", "ccdb:Users/h/hfribert/ToT_LUTs", "ToT LUT for alphas"};
368382

369383
Configurable<float> truncationFraction{"truncationFraction", 0.80f, "Fraction of lower entries to consider for truncated standard deviation"};
370384
Configurable<float> dBz{"dBz", 20, "magnetic field (kilogauss) for track propagation"};
@@ -390,7 +404,6 @@ struct OnTheFlyTrackerPid {
390404
1000020030, // Helium-3
391405
1000020040 // Alpha
392406
};
393-
Service<o2::ccdb::BasicCCDBManager> ccdb;
394407

395408
void init(o2::framework::InitContext&)
396409
{
@@ -407,16 +420,18 @@ struct OnTheFlyTrackerPid {
407420
etaBins.value, etaMin.value, etaMax.value,
408421
ptBins.value, ptMin.value, ptMax.value);
409422

423+
mToTLUT->setCcdbManager(ccdb.operator->());
424+
410425
bool loaded = true;
411-
loaded &= mToTLUT->load(11, lutTotEl.value, ccdb);
412-
loaded &= mToTLUT->load(13, lutTotMu.value, ccdb);
413-
loaded &= mToTLUT->load(211, lutTotPi.value, ccdb);
414-
loaded &= mToTLUT->load(321, lutTotKa.value, ccdb);
415-
loaded &= mToTLUT->load(2212, lutTotPr.value, ccdb);
416-
loaded &= mToTLUT->load(1000010020, lutTotDe.value, ccdb);
417-
loaded &= mToTLUT->load(1000010030, lutTotTr.value, ccdb);
418-
loaded &= mToTLUT->load(1000020030, lutTotHe.value, ccdb);
419-
loaded &= mToTLUT->load(1000020040, lutTotAl.value, ccdb);
426+
loaded &= mToTLUT->load(11, lutTotEl.value);
427+
loaded &= mToTLUT->load(13, lutTotMu.value);
428+
loaded &= mToTLUT->load(211, lutTotPi.value);
429+
loaded &= mToTLUT->load(321, lutTotKa.value);
430+
loaded &= mToTLUT->load(2212, lutTotPr.value);
431+
loaded &= mToTLUT->load(1000010020, lutTotDe.value);
432+
loaded &= mToTLUT->load(1000010030, lutTotTr.value);
433+
loaded &= mToTLUT->load(1000020030, lutTotHe.value);
434+
loaded &= mToTLUT->load(1000020040, lutTotAl.value);
420435

421436
if (!loaded) {
422437
LOG(warning) << "Failed to load one or more ToT LUTs. PID results might be incomplete.";

0 commit comments

Comments
 (0)