Skip to content

Commit 6985a74

Browse files
Add option to prevent crash on null CCDB objects
Added a configurable option to prevent crashes when CCDB objects are missing, allowing for dummy values to be filled instead. Initialized histogram pointers to nullptr.
1 parent cfcd737 commit 6985a74

File tree

1 file changed

+20
-8
lines changed

1 file changed

+20
-8
lines changed

PWGLF/TableProducer/Common/mcCentrality.cxx

Lines changed: 20 additions & 8 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
};

0 commit comments

Comments
 (0)