Skip to content

Commit 235ce9d

Browse files
authored
[ALICE3] Support CCDB fetching of LUTs (#13016)
1 parent 79cee8e commit 235ce9d

File tree

3 files changed

+89
-41
lines changed

3 files changed

+89
-41
lines changed

ALICE3/Core/DelphesO2TrackSmearer.cxx

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@
3636

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

39+
#include <Framework/Logger.h>
40+
3941
namespace o2
4042
{
4143
namespace delphes
@@ -45,11 +47,38 @@ namespace delphes
4547

4648
bool TrackSmearer::loadTable(int pdg, const char* filename, bool forceReload)
4749
{
48-
auto ipdg = getIndexPDG(pdg);
50+
if (!filename || filename[0] == '\0') {
51+
LOG(info) << " --- No LUT file provided for PDG " << pdg << ". Skipping load.";
52+
return false;
53+
}
54+
const auto ipdg = getIndexPDG(pdg);
55+
LOGF(info, "Will load %s lut file ..: '%s'", getParticleName(pdg), filename);
4956
if (mLUTHeader[ipdg] && !forceReload) {
5057
std::cout << " --- LUT table for PDG " << pdg << " has been already loaded with index " << ipdg << std::endl;
5158
return false;
5259
}
60+
if (strncmp(filename, "ccdb:", 5) == 0) { // Check if filename starts with "ccdb:"
61+
LOG(info) << " --- LUT file source identified as CCDB.";
62+
std::string path = std::string(filename).substr(5); // Remove "ccdb:" prefix
63+
const std::string outPath = "/tmp/LUTs/";
64+
filename = Form("%s/%s/snapshot.root", outPath.c_str(), path.c_str());
65+
std::ifstream checkFile(filename); // Check if file already exists
66+
if (!checkFile.is_open()) { // File does not exist, retrieve from CCDB
67+
LOG(info) << " --- CCDB source detected for PDG " << pdg << ": " << path;
68+
if (!mCcdbManager) {
69+
LOG(fatal) << " --- CCDB manager not set. Please set it before loading LUT from CCDB.";
70+
}
71+
std::map<std::string, std::string> metadata;
72+
mCcdbManager->getCCDBAccessor().retrieveBlob(path, outPath, metadata, 1);
73+
// Add CCDB handling logic here if needed
74+
LOG(info) << " --- Now retrieving LUT file from CCDB to: " << filename;
75+
} else { // File exists, proceed to load
76+
LOG(info) << " --- LUT file already exists: " << filename << ". Skipping download.";
77+
checkFile.close();
78+
}
79+
return loadTable(pdg, filename, forceReload);
80+
}
81+
5382
mLUTHeader[ipdg] = new lutHeader_t;
5483

5584
std::ifstream lutFile(filename, std::ifstream::binary);

ALICE3/Core/DelphesO2TrackSmearer.h

Lines changed: 38 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,14 @@
2424
#ifndef ALICE3_CORE_DELPHESO2TRACKSMEARER_H_
2525
#define ALICE3_CORE_DELPHESO2TRACKSMEARER_H_
2626

27-
#include <map>
28-
#include <iostream>
29-
#include <fstream>
27+
#include <CCDB/BasicCCDBManager.h>
28+
#include <ReconstructionDataFormats/Track.h>
3029

31-
#include "TRandom.h"
32-
#include "ReconstructionDataFormats/Track.h"
30+
#include <TRandom.h>
31+
32+
#include <fstream>
33+
#include <iostream>
34+
#include <map>
3335

3436
///////////////////////////////
3537
/// DelphesO2/src/lutCovm.hh //
@@ -85,7 +87,7 @@ struct map_t {
8587
if (bin > nbins - 1)
8688
return nbins - 1;
8789
return bin;
88-
} //;
90+
} //;
8991
void print() { printf("nbins = %d, min = %f, max = %f, log = %s \n", nbins, min, max, log ? "on" : "off"); } //;
9092
};
9193

@@ -214,10 +216,34 @@ class TrackSmearer
214216
return 7; // Helium3
215217
default:
216218
return 2; // Default: pion
217-
} //;
218-
} //;
219+
}
220+
}
219221

220-
void setdNdEta(float val) { mdNdEta = val; } //;
222+
const char* getParticleName(int pdg)
223+
{
224+
switch (abs(pdg)) {
225+
case 11:
226+
return "electron";
227+
case 13:
228+
return "muon";
229+
case 211:
230+
return "pion";
231+
case 321:
232+
return "kaon";
233+
case 2212:
234+
return "proton";
235+
case 1000010020:
236+
return "deuteron";
237+
case 1000010030:
238+
return "triton";
239+
case 1000020030:
240+
return "helium3";
241+
default:
242+
return "pion"; // Default: pion
243+
}
244+
}
245+
void setdNdEta(float val) { mdNdEta = val; } //;
246+
void setCcdbManager(o2::ccdb::BasicCCDBManager* mgr) { mCcdbManager = mgr; } //;
221247

222248
protected:
223249
static constexpr unsigned int nLUTs = 8; // Number of LUT available
@@ -228,6 +254,9 @@ class TrackSmearer
228254
bool mSkipUnreconstructed = true; // don't smear tracks that are not reco'ed
229255
int mWhatEfficiency = 1;
230256
float mdNdEta = 1600.;
257+
258+
private:
259+
o2::ccdb::BasicCCDBManager* mCcdbManager = nullptr;
231260
};
232261

233262
} // namespace delphes

ALICE3/TableProducer/OTF/onTheFlyTracker.cxx

Lines changed: 21 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -239,42 +239,32 @@ struct OnTheFlyTracker {
239239

240240
// For TGenPhaseSpace seed
241241
TRandom3 rand;
242+
Service<o2::ccdb::BasicCCDBManager> ccdb;
242243

243244
void init(o2::framework::InitContext&)
244245
{
246+
247+
ccdb->setURL("http://alice-ccdb.cern.ch");
248+
ccdb->setTimestamp(-1);
249+
245250
if (enableLUT) {
246-
std::map<int, const char*> mapPdgLut;
247-
const char* lutElChar = lutEl->c_str();
248-
const char* lutMuChar = lutMu->c_str();
249-
const char* lutPiChar = lutPi->c_str();
250-
const char* lutKaChar = lutKa->c_str();
251-
const char* lutPrChar = lutPr->c_str();
252-
253-
LOGF(info, "Will load electron lut file ..: %s", lutElChar);
254-
LOGF(info, "Will load muon lut file ......: %s", lutMuChar);
255-
LOGF(info, "Will load pion lut file ......: %s", lutPiChar);
256-
LOGF(info, "Will load kaon lut file ......: %s", lutKaChar);
257-
LOGF(info, "Will load proton lut file ....: %s", lutPrChar);
258-
259-
mapPdgLut.insert(std::make_pair(11, lutElChar));
260-
mapPdgLut.insert(std::make_pair(13, lutMuChar));
261-
mapPdgLut.insert(std::make_pair(211, lutPiChar));
262-
mapPdgLut.insert(std::make_pair(321, lutKaChar));
263-
mapPdgLut.insert(std::make_pair(2212, lutPrChar));
264-
265-
if (enableNucleiSmearing) {
266-
const char* lutDeChar = lutDe->c_str();
267-
const char* lutTrChar = lutTr->c_str();
268-
const char* lutHe3Char = lutHe3->c_str();
269-
mapPdgLut.insert(std::make_pair(1000010020, lutDeChar));
270-
mapPdgLut.insert(std::make_pair(1000010030, lutTrChar));
271-
mapPdgLut.insert(std::make_pair(1000020030, lutHe3Char));
272-
}
273-
for (const auto& e : mapPdgLut) {
274-
if (!mSmearer.loadTable(e.first, e.second)) {
275-
LOG(fatal) << "Having issue with loading the LUT " << e.first << " " << e.second;
251+
mSmearer.setCcdbManager(ccdb.operator->());
252+
253+
auto loadLUT = [&](int pdg, const std::string& lutFile) {
254+
bool success = mSmearer.loadTable(pdg, lutFile.c_str());
255+
if (!success && !lutFile.empty()) {
256+
LOG(fatal) << "Having issue with loading the LUT " << pdg << " " << lutFile;
276257
}
277-
}
258+
};
259+
loadLUT(11, lutEl.value);
260+
loadLUT(13, lutMu.value);
261+
loadLUT(211, lutPi.value);
262+
loadLUT(321, lutKa.value);
263+
loadLUT(2212, lutPr.value);
264+
loadLUT(1000010020, lutDe.value);
265+
loadLUT(1000010030, lutTr.value);
266+
loadLUT(1000020030, lutHe3.value);
267+
278268
// interpolate efficiencies if requested to do so
279269
mSmearer.interpolateEfficiency(static_cast<bool>(interpolateLutEfficiencyVsNch));
280270

0 commit comments

Comments
 (0)