Skip to content

Commit 2925a0e

Browse files
[PWGLF] Add option to prevent crash on null CCDB objects (#14647)
1 parent bd16183 commit 2925a0e

File tree

1 file changed

+29
-11
lines changed

1 file changed

+29
-11
lines changed

PWGLF/TableProducer/Common/mcCentrality.cxx

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -66,12 +66,13 @@ struct McCentrality {
6666
ConfigurableAxis binsMultiplicity{"binsMultiplicity", {1000, 0, 5000}, "Binning of the multiplicity axis"};
6767
Configurable<bool> fillFt0A{"fillFt0A", false, "Fills the FT0A histogram"};
6868
Configurable<bool> fillFt0C{"fillFt0C", false, "Fills the FT0C histogram"};
69+
Configurable<bool> doNotCrashOnNull{"doNotCrashOnNull", false, "If ccdb object does not exist, fill with dummy values"};
6970

7071
HistogramRegistry histos{"histos", {}, OutputObjHandlingPolicy::AnalysisObject};
7172

72-
TH1F* h1dFT0M;
73-
TH1F* h1dFT0A;
74-
TH1F* h1dFT0C;
73+
TH1F* h1dFT0M = nullptr;
74+
TH1F* h1dFT0A = nullptr;
75+
TH1F* h1dFT0C = nullptr;
7576
// TH1F* h1dFDD;
7677
// TH1F* h1dNTP;
7778

@@ -99,13 +100,17 @@ struct McCentrality {
99100
histos.add("FT0C/percentilevsMult", "FT0C percentile.", HistType::kTH2D, {{binsPercentile, "FT0C percentile"}, {binsMultiplicity, "FT0C mult."}});
100101
}
101102

102-
TList* lOfInput;
103+
TList* lOfInput = nullptr;
103104
if (path.value.rfind("ccdb://", 0) == 0) { // Getting post calib. from CCDB
104105
path.value.replace(0, 7, "");
105106
lOfInput = ccdb->get<TList>(path);
106107
if (!lOfInput) {
107-
LOG(fatal) << "Could not find the calibration TList from CCDB in path " << path;
108-
return;
108+
if (doNotCrashOnNull) {
109+
LOG(info) << "Could not find the calibration TList from CCDB in path " << path << ", will fill tables with dummy values";
110+
} else {
111+
LOG(fatal) << "Could not find the calibration TList from CCDB in path " << path;
112+
return;
113+
}
109114
}
110115
} else { // Getting post calib. from file
111116
TFile* f = TFile::Open(path.value.c_str(), "READ");
@@ -121,11 +126,18 @@ struct McCentrality {
121126
LOG(fatal) << "The input file " << path.value << " does not contain the TList ccdb_object";
122127
}
123128
}
124-
auto getHist = [lOfInput](const char* name) -> TH1F* {
129+
auto getHist = [this, lOfInput](const char* name) -> TH1F* {
130+
if (!lOfInput) {
131+
return nullptr;
132+
}
125133
auto hist = static_cast<TH1F*>(lOfInput->FindObject(name));
126134
if (!hist) {
127135
lOfInput->ls();
128-
LOG(fatal) << "Could not open histogram " << name << " from TList";
136+
if (this->doNotCrashOnNull) {
137+
LOG(info) << "Could not open histogram " << name << " from TList, will fill tables with dummy values";
138+
} else {
139+
LOG(fatal) << "Could not open histogram " << name << " from TList";
140+
}
129141
}
130142
return hist;
131143
};
@@ -147,13 +159,19 @@ struct McCentrality {
147159
const float nFT0M = nFT0A + nFT0C;
148160
// const float nFV0A = mCounter.countFV0A(mcParticles);
149161

150-
const float valueCentFT0M = h1dFT0M->GetBinContent(h1dFT0M->FindBin(nFT0M));
162+
float valueCentFT0M = 105.0f;
163+
if (h1dFT0M)
164+
valueCentFT0M = h1dFT0M->GetBinContent(h1dFT0M->FindBin(nFT0M));
151165
if (fillFt0A) {
152-
const float valueCentFT0A = h1dFT0M->GetBinContent(h1dFT0M->FindBin(nFT0A));
166+
float valueCentFT0A = 105.0f;
167+
if (h1dFT0A)
168+
valueCentFT0A = h1dFT0A->GetBinContent(h1dFT0A->FindBin(nFT0A));
153169
centFT0A(valueCentFT0A);
154170
}
155171
if (fillFt0C) {
156-
const float valueCentFT0C = h1dFT0M->GetBinContent(h1dFT0M->FindBin(nFT0C));
172+
float valueCentFT0C = 105.0f;
173+
if (h1dFT0C)
174+
valueCentFT0C = h1dFT0C->GetBinContent(h1dFT0C->FindBin(nFT0C));
157175
centFT0C(valueCentFT0C);
158176
}
159177
// const float valueCentFV0A = h1dFT0M->GetBinContent(h1dFT0M->FindBin(nFV0A));

0 commit comments

Comments
 (0)