Skip to content

Commit e9386b0

Browse files
Proper and optimized retrieval from CCDB (#591)
* Proper and optimized retrieval from CCDB * Default value for no CCDB access
1 parent 7ad83dd commit e9386b0

1 file changed

Lines changed: 46 additions & 18 deletions

File tree

PWGCF/Tasks/dptdptcorrelations.cxx

Lines changed: 46 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
#include <TProfile3D.h>
3434

3535
#include <cmath>
36+
#include <ctime>
3637

3738
using namespace o2;
3839
using namespace o2::framework;
@@ -106,6 +107,12 @@ struct DptDptCorrelationsTask {
106107

107108
const char* tname[2] = {"1", "2"}; ///< the external track names, one and two, for histogram creation
108109
const char* trackPairsNames[4] = {"OO", "OT", "TO", "TT"};
110+
bool ccdbstored = false;
111+
112+
float isCCDBstored()
113+
{
114+
return ccdbstored;
115+
}
109116

110117
/// \brief Returns the potentially phi origin shifted phi
111118
/// \param phi the track azimuthal angle
@@ -182,14 +189,18 @@ struct DptDptCorrelationsTask {
182189

183190
void storeTrackCorrections(TH3* corrs1, TH3* corrs2)
184191
{
192+
LOGF(info, "Stored NUA&NUE corrections for track one %s and track two %s", corrs1 != nullptr ? "yes" : "no", corrs2 != nullptr ? "yes" : "no");
185193
fhNuaNue_vsZEtaPhiPt[0] = corrs1;
186194
fhNuaNue_vsZEtaPhiPt[1] = corrs2;
195+
ccdbstored = true;
187196
}
188197

189198
void storePtAverages(TH2* ptavgs1, TH2* ptavgs2)
190199
{
200+
LOGF(info, "Stored pT average for track one %s and track two %s", ptavgs1 != nullptr ? "yes" : "no", ptavgs2 != nullptr ? "yes" : "no");
191201
fhPtAvg_vsEtaPhi[0] = ptavgs1;
192202
fhPtAvg_vsEtaPhi[1] = ptavgs2;
203+
ccdbstored = true;
193204
}
194205

195206
template <typename TrackListObject>
@@ -495,13 +506,21 @@ struct DptDptCorrelationsTask {
495506
/* the data collecting engine instances */
496507
DataCollectingEngine** dataCE;
497508

509+
/* the input file structure from CCDB */
510+
TList* ccdblst = nullptr;
511+
bool loadfromccdb = false;
512+
498513
Configurable<bool> cfgProcessPairs{"processpairs", false, "Process pairs: false = no, just singles, true = yes, process pairs"};
499514
Configurable<std::string> cfgCentSpec{"centralities", "00-05,05-10,10-20,20-30,30-40,40-50,50-60,60-70,70-80", "Centrality/multiplicity ranges in min-max separated by commas"};
500515

501516
Configurable<o2::analysis::DptDptBinningCuts> cfgBinning{"binning",
502517
{28, -7.0, 7.0, 18, 0.2, 2.0, 16, -0.8, 0.8, 72, 0.5},
503518
"triplets - nbins, min, max - for z_vtx, pT, eta and phi, binning plus bin fraction of phi origin shift"};
504-
Configurable<std::string> cfgCCDBPathName{"ccdbpath", "", "The CCDB path for the input file"};
519+
struct : ConfigurableGroup {
520+
Configurable<std::string> cfgCCDBUrl{"input_ccdburl", "http://ccdb-test.cern.ch:8080", "The CCDB url for the input file"};
521+
Configurable<std::string> cfgCCDBPathName{"input_ccdbpath", "", "The CCDB path for the input file. Default \"\", i.e. don't load from CCDB"};
522+
Configurable<std::string> cfgCCDBDate{"input_ccdbdate", "20220307", "The CCDB date for the input file"};
523+
} cfginputfile;
505524

506525
OutputObj<TList> fOutput{"DptDptCorrelationsData", OutputObjHandlingPolicy::AnalysisObject};
507526

@@ -525,6 +544,7 @@ struct DptDptCorrelationsTask {
525544
phiup = constants::math::TwoPI;
526545
phibinshift = cfgBinning->mPhibinshift;
527546
processpairs = cfgProcessPairs.value;
547+
loadfromccdb = cfginputfile.cfgCCDBPathName->length() > 0;
528548
/* update the potential binning change */
529549
etabinwidth = (etaup - etalow) / float(etabins);
530550
phibinwidth = (phiup - philow) / float(phibins);
@@ -594,7 +614,7 @@ struct DptDptCorrelationsTask {
594614
}
595615
}
596616
/* initialize access to the CCDB */
597-
ccdb->setURL("http://alice-ccdb.cern.ch");
617+
ccdb->setURL(cfginputfile.cfgCCDBUrl);
598618
ccdb->setCaching(true);
599619
ccdb->setLocalObjectValidityChecking();
600620
}
@@ -614,9 +634,15 @@ struct DptDptCorrelationsTask {
614634
return ixDCE;
615635
}
616636

617-
TList* getCCDBInput(const char* ccdbpath)
637+
TList* getCCDBInput(const char* ccdbpath, const char* ccdbdate)
618638
{
619-
TList* lst = ccdb->get<TList>(ccdbpath);
639+
std::tm cfgtm = {};
640+
std::stringstream ss(ccdbdate);
641+
ss >> std::get_time(&cfgtm, "%Y%m%d");
642+
cfgtm.tm_hour = 12;
643+
long timestamp = std::mktime(&cfgtm) * 1000;
644+
645+
TList* lst = ccdb->getForTimeStamp<TList>(ccdbpath, timestamp);
620646
if (lst != nullptr) {
621647
LOGF(info, "Correctly loaded CCDB input object");
622648
} else {
@@ -632,19 +658,20 @@ struct DptDptCorrelationsTask {
632658
{
633659
using namespace correlationstask;
634660

635-
TList* lst = nullptr;
636-
if (cfgCCDBPathName->length() > 0) {
637-
lst = getCCDBInput(cfgCCDBPathName->c_str());
661+
if (ccdblst == nullptr) {
662+
if (loadfromccdb) {
663+
ccdblst = getCCDBInput(cfginputfile.cfgCCDBPathName->c_str(), cfginputfile.cfgCCDBDate->c_str());
664+
}
638665
}
639666

640667
/* locate the data collecting engine for the collision centrality/multiplicity */
641668
int ixDCE = getDCEindex(collision);
642669
if (not(ixDCE < 0)) {
643-
if (lst != nullptr) {
644-
dataCE[ixDCE]->storeTrackCorrections((TH3*)lst->FindObject(TString::Format("correction_%02d-%02d_p1", int(fCentMultMin[ixDCE]), int(fCentMultMax[ixDCE])).Data()),
645-
(TH3*)lst->FindObject(TString::Format("correction_%02d-%02d_m1", int(fCentMultMin[ixDCE]), int(fCentMultMax[ixDCE])).Data()));
646-
dataCE[ixDCE]->storePtAverages((TH2*)lst->FindObject(TString::Format("ptavgetaphi_%02d-%02d_p", int(fCentMultMin[ixDCE]), int(fCentMultMax[ixDCE])).Data()),
647-
(TH2*)lst->FindObject(TString::Format("ptavgetaphi_%02d-%02d_m", int(fCentMultMin[ixDCE]), int(fCentMultMax[ixDCE])).Data()));
670+
if (ccdblst != nullptr and not dataCE[ixDCE]->isCCDBstored()) {
671+
dataCE[ixDCE]->storeTrackCorrections((TH3*)ccdblst->FindObject(TString::Format("correction_%02d-%02d_p1", int(fCentMultMin[ixDCE]), int(fCentMultMax[ixDCE])).Data()),
672+
(TH3*)ccdblst->FindObject(TString::Format("correction_%02d-%02d_m1", int(fCentMultMin[ixDCE]), int(fCentMultMax[ixDCE])).Data()));
673+
dataCE[ixDCE]->storePtAverages((TH2*)ccdblst->FindObject(TString::Format("ptavgetaphi_%02d-%02d_p", int(fCentMultMin[ixDCE]), int(fCentMultMax[ixDCE])).Data()),
674+
(TH2*)ccdblst->FindObject(TString::Format("ptavgetaphi_%02d-%02d_m", int(fCentMultMin[ixDCE]), int(fCentMultMax[ixDCE])).Data()));
648675
}
649676

650677
Partition<o2::aod::ScannedTracks> TracksOne = aod::dptdptfilter::trackacceptedasone == uint8_t(true);
@@ -663,17 +690,18 @@ struct DptDptCorrelationsTask {
663690
{
664691
using namespace correlationstask;
665692

666-
TList* lst = nullptr;
667-
if (cfgCCDBPathName->length() > 0) {
668-
lst = getCCDBInput(cfgCCDBPathName->c_str());
693+
if (ccdblst == nullptr) {
694+
if (loadfromccdb) {
695+
ccdblst = getCCDBInput(cfginputfile.cfgCCDBPathName->c_str(), cfginputfile.cfgCCDBDate->c_str());
696+
}
669697
}
670698

671699
/* locate the data collecting engine for the collision centrality/multiplicity */
672700
int ixDCE = getDCEindex(collision);
673701
if (not(ixDCE < 0)) {
674-
if (lst != nullptr) {
675-
dataCE[ixDCE]->storePtAverages((TH2*)lst->FindObject(TString::Format("trueptavgetaphi_%02d-%02d_p", int(fCentMultMin[ixDCE]), int(fCentMultMax[ixDCE])).Data()),
676-
(TH2*)lst->FindObject(TString::Format("trueptavgetaphi_%02d-%02d_m", int(fCentMultMin[ixDCE]), int(fCentMultMax[ixDCE])).Data()));
702+
if (ccdblst != nullptr and not dataCE[ixDCE]->isCCDBstored()) {
703+
dataCE[ixDCE]->storePtAverages((TH2*)ccdblst->FindObject(TString::Format("trueptavgetaphi_%02d-%02d_p", int(fCentMultMin[ixDCE]), int(fCentMultMax[ixDCE])).Data()),
704+
(TH2*)ccdblst->FindObject(TString::Format("trueptavgetaphi_%02d-%02d_m", int(fCentMultMin[ixDCE]), int(fCentMultMax[ixDCE])).Data()));
677705
}
678706

679707
Partition<o2::aod::ScannedTrueTracks> TracksOne = aod::dptdptfilter::trackacceptedasone == uint8_t(true);

0 commit comments

Comments
 (0)