Skip to content

Commit 9ef74a0

Browse files
jokonigjokonig
andauthored
[EMCAL-565, EMCAL-566] Prevent saving/overwriting calib multiple times at EOR (#13045)
- At the EOR the state of the calibration is saved in a root file, to be loaded in the next run - However, in the online case, several EOR signals reach the calibration after the initial EOR - This leads to the original root file being overwritten by another one, containing only a few (~1-20) events - Now, 2 checks are in place that should circumvent that the calibration files are overwritten: The variable mRunStopRequested was introduced in the CalibSpec which is set to true after the initial EOR signal, preventing further data processing A check on the minimum number of events for the calibration (minNEventsSaveSlot, configurable in the calibParams) that only allows saving the calibration file if a reasonable statistics is reached Co-authored-by: jokonig <jokonig@cern.ch>
1 parent 776e342 commit 9ef74a0

File tree

3 files changed

+23
-4
lines changed

3 files changed

+23
-4
lines changed

Detectors/EMCAL/calibration/include/EMCALCalibration/EMCALCalibParams.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ struct EMCALCalibParams : public o2::conf::ConfigurableParamHelper<EMCALCalibPar
8787
bool requireSameFill = false; ///< if loading calib objects from previous run, require it to be in the same fill as the current one
8888
bool requireSameRunType = true; ///< if loading calib objects from previous run, require it to be the same run type
8989
int tsDiffMax = 48; ///< if loading calib objects from previous run, limit time between the object being stored and loaded again (in hours)
90+
unsigned int minNEventsSaveSlot = 100000; ///< minimum amount a slot has to have in order to be taken into accoutn in finalize slot. THis is also relevant if the slot should be saved at the EOR
9091

9192
// Parameters for pedestal calibration
9293
short maxPedestalRMS = 10; ///< Maximum value for RMS for pedestals (has to be tuned)

Detectors/EMCAL/calibration/include/EMCALCalibration/EMCALChannelCalibrator.h

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,11 @@ void EMCALChannelCalibrator<DataInput, DataOutput>::finalizeSlot(o2::calibration
167167
// Extract results for the single slot
168168
DataInput* c = slot.getContainer();
169169
LOG(info) << "Finalize slot " << slot.getTFStart() << " <= TF <= " << slot.getTFEnd();
170+
// check if slot contains a minimum amount of data
171+
if (c->getNEvents() < EMCALCalibParams::Instance().minNEventsSaveSlot) {
172+
LOG(info) << "Slot only contains " << c->getNEvents() << " events. Not saving this slot. " << EMCALCalibParams::Instance().minNEventsSaveSlot << " required";
173+
return;
174+
}
170175

171176
if constexpr (std::is_same<DataInput, o2::emcal::EMCALChannelData>::value) {
172177
if (c->getNEvents() < EMCALCalibParams::Instance().minNEvents_bc) {
@@ -260,7 +265,7 @@ template <typename DataInput, typename DataOutput>
260265
bool EMCALChannelCalibrator<DataInput, DataOutput>::saveLastSlotData(TFile& fl)
261266
{
262267
LOG(info) << "EMC calib histos are saved in " << fl.GetName();
263-
// does this work?
268+
// we only have 1 slot
264269
auto& cont = o2::calibration::TimeSlotCalibration<DataInput>::getSlots();
265270
auto& slot = cont.at(0);
266271
DataInput* c = slot.getContainer();
@@ -279,7 +284,7 @@ bool EMCALChannelCalibrator<DataInput, DataOutput>::saveLastSlotData(TFile& fl)
279284
TH1I hGlobalProperties("hGlobalProperties", "hGlobalProperties", 3, -0.5, 2.5);
280285
hGlobalProperties.GetXaxis()->SetBinLabel(1, "Fill nr.");
281286
hGlobalProperties.GetXaxis()->SetBinLabel(2, "run type");
282-
hGlobalProperties.GetXaxis()->SetBinLabel(2, "ts in hours");
287+
hGlobalProperties.GetXaxis()->SetBinLabel(3, "ts in hours");
283288
hGlobalProperties.SetBinContent(1, mFillNr);
284289
hGlobalProperties.SetBinContent(2, mRunType);
285290
hGlobalProperties.SetBinContent(3, timeNow);
@@ -297,7 +302,7 @@ bool EMCALChannelCalibrator<DataInput, DataOutput>::saveLastSlotData(TFile& fl)
297302
TH1I hGlobalProperties("hGlobalProperties", "hGlobalProperties", 3, -0.5, 2.5);
298303
hGlobalProperties.GetXaxis()->SetBinLabel(1, "Fill nr.");
299304
hGlobalProperties.GetXaxis()->SetBinLabel(2, "run type");
300-
hGlobalProperties.GetXaxis()->SetBinLabel(2, "ts in hours");
305+
hGlobalProperties.GetXaxis()->SetBinLabel(3, "ts in hours");
301306
hGlobalProperties.SetBinContent(1, mFillNr);
302307
hGlobalProperties.SetBinContent(2, mRunType);
303308
hGlobalProperties.SetBinContent(3, timeNow);

Detectors/EMCAL/calibration/testWorkflow/EMCALChannelCalibratorSpec.h

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,14 @@ class EMCALChannelCalibDevice : public o2::framework::Task
172172
timeMeas[0] = std::chrono::duration_cast<std::chrono::nanoseconds>(std::chrono::high_resolution_clock::now().time_since_epoch()).count();
173173
}
174174

175+
const auto& tinfo = pc.services().get<o2::framework::TimingInfo>();
176+
if (tinfo.globalRunNumberChanged) { // new run is starting
177+
mRunStopRequested = false;
178+
}
179+
if (mRunStopRequested) {
180+
return;
181+
}
182+
175183
o2::base::GRPGeomHelper::instance().checkUpdates(pc);
176184
if (mTimeCalibrator) {
177185
o2::base::TFIDInfoHelper::fillTFIDInfo(pc, mTimeCalibrator->getCurrentTFInfo());
@@ -314,7 +322,7 @@ class EMCALChannelCalibDevice : public o2::framework::Task
314322

315323
if (pc.transitionState() == TransitionHandlingState::Requested) {
316324
LOG(debug) << "Run stop requested, finalizing";
317-
// mRunStopRequested = true;
325+
mRunStopRequested = true;
318326
if (isBadChannelCalib) {
319327
mBadChannelCalibrator->setSaveAtEOR(true);
320328
mBadChannelCalibrator->checkSlotsToFinalize(o2::calibration::INFINITE_TF);
@@ -337,6 +345,9 @@ class EMCALChannelCalibDevice : public o2::framework::Task
337345

338346
void endOfStream(o2::framework::EndOfStreamContext& ec) final
339347
{
348+
if (mRunStopRequested) {
349+
return;
350+
}
340351
if (isBadChannelCalib) {
341352
mBadChannelCalibrator->setSaveAtEOR(true);
342353
mBadChannelCalibrator->checkSlotsToFinalize(o2::calibration::INFINITE_TF);
@@ -346,6 +357,7 @@ class EMCALChannelCalibDevice : public o2::framework::Task
346357
mTimeCalibrator->checkSlotsToFinalize(o2::calibration::INFINITE_TF);
347358
sendOutput<o2::emcal::TimeCalibrationParams>(ec.outputs());
348359
}
360+
mRunStopRequested = true;
349361
}
350362

351363
static const char* getCellBinding() { return "EMCCells"; }
@@ -368,6 +380,7 @@ class EMCALChannelCalibDevice : public o2::framework::Task
368380
bool mRejectL0Triggers = true; ///! reject EMCal Gamma and Jet triggers in the online calibration
369381
bool mApplyGainCalib = true; ///! switch if gain calibration should be applied during filling of histograms or not
370382
bool mGainCalibFactorsInitialized = false; ///! Gain calibration init status
383+
bool mRunStopRequested = false; ///< flag that the run has stopped
371384
std::array<double, 2> timeMeas; ///! Used for time measurement and holds the start and end time in the run function
372385
std::vector<uint64_t> mSelectedClassMasks = {}; ///! EMCal minimum bias trigger bit. Only this bit will be used for calibration
373386
std::unique_ptr<CalibInputDownsampler> mDownsampler;

0 commit comments

Comments
 (0)