Skip to content

Commit fbb8769

Browse files
committed
TRD calibration preparation for SSS
1 parent 8373047 commit fbb8769

3 files changed

Lines changed: 47 additions & 42 deletions

File tree

Detectors/TRD/calibration/include/TRDCalibration/CalibratorVdExB.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ class CalibratorVdExB final : public o2::calibration::TimeSlotCalibration<o2::tr
6060
LA,
6161
VD
6262
};
63-
CalibratorVdExB(bool enableOut = false) : mEnableOutput(enableOut) {}
63+
CalibratorVdExB() = default;
6464
~CalibratorVdExB() final = default;
6565

6666
bool hasEnoughData(const Slot& slot) const final { return slot.getContainer()->getNEntries() >= mMinEntriesTotal; }
@@ -90,7 +90,7 @@ class CalibratorVdExB final : public o2::calibration::TimeSlotCalibration<o2::tr
9090
const TRDCalibParams& mParams{TRDCalibParams::Instance()}; ///< reference to calibration parameters
9191
size_t mMinEntriesTotal{mParams.minEntriesChamber}; ///< minimum total number of angular deviations (on average ~3 entries per bin for each TRD chamber)
9292
size_t mMinEntriesChamber{mParams.minEntriesTotal}; ///< minimum number of angular deviations per chamber for accepting refitted value (~3 per bin)
93-
bool mEnableOutput; ///< enable output of calibration fits and tprofiles in a root file instead of the ccdb
93+
bool mEnableOutput{false}; ///< enable output of calibration fits and tprofiles in a root file instead of the ccdb
9494
std::unique_ptr<TFile> mOutFile{nullptr}; ///< output file
9595
std::unique_ptr<TTree> mOutTree{nullptr}; ///< output tree
9696
FitFunctor mFitFunctor; ///< used for minimization procedure

Detectors/TRD/calibration/src/CalibratorVdExB.cxx

Lines changed: 23 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ void CalibratorVdExB::initProcessing()
126126
mFitter.Config().SetMinimizerOptions(opt);
127127

128128
// set tree addresses
129-
if (mEnableOutput && mOutTree) {
129+
if (mEnableOutput) {
130130
mOutTree->Branch("lorentzAngle", &mFitFunctor.laPreCorr);
131131
mOutTree->Branch("vDrift", &mFitFunctor.vdPreCorr);
132132
for (int iDet = 0; iDet < MAXCHAMBER; ++iDet) {
@@ -139,30 +139,24 @@ void CalibratorVdExB::initProcessing()
139139

140140
void CalibratorVdExB::retrievePrev(o2::framework::ProcessingContext& pc)
141141
{
142-
static bool doneOnce = false;
143-
if (!doneOnce) {
144-
doneOnce = true;
145-
mFitFunctor.vdPreCorr.fill(constants::VDRIFTDEFAULT);
146-
mFitFunctor.laPreCorr.fill(constants::EXBDEFAULT);
147-
// We either get a pointer to a valid object from the last ~hour or to the default object
148-
// which is always present. The first has precedence over the latter.
149-
auto dataCalVdriftExB = pc.inputs().get<o2::trd::CalVdriftExB*>("calvdexb");
150-
std::string msg = "Default Object";
151-
// We check if the object we got is the default one by comparing it to the defaults.
152-
for (int iDet = 0; iDet < MAXCHAMBER; ++iDet) {
153-
if (dataCalVdriftExB->getVdrift(iDet) != constants::VDRIFTDEFAULT ||
154-
dataCalVdriftExB->getExB(iDet) != constants::EXBDEFAULT) {
155-
msg = "Previous Object";
156-
break;
157-
}
142+
// We either get a pointer to a valid object from the last ~hour or to the default object
143+
// which is always present. The first has precedence over the latter.
144+
auto dataCalVdriftExB = pc.inputs().get<o2::trd::CalVdriftExB*>("calvdexb");
145+
std::string msg = "Default Object";
146+
// We check if the object we got is the default one by comparing it to the defaults.
147+
for (int iDet = 0; iDet < MAXCHAMBER; ++iDet) {
148+
if (dataCalVdriftExB->getVdrift(iDet) != VDRIFTDEFAULT ||
149+
dataCalVdriftExB->getExB(iDet) != EXBDEFAULT) {
150+
msg = "Previous Object";
151+
break;
158152
}
159-
LOG(info) << "Calibrator: From CCDB retrieved " << msg;
153+
}
154+
LOG(info) << "Calibrator: From CCDB retrieved " << msg;
160155

161-
// Here we set each entry regardless if it is the default or not.
162-
for (int iDet = 0; iDet < MAXCHAMBER; ++iDet) {
163-
mFitFunctor.laPreCorr[iDet] = dataCalVdriftExB->getExB(iDet);
164-
mFitFunctor.vdPreCorr[iDet] = dataCalVdriftExB->getVdrift(iDet);
165-
}
156+
// Here we set each entry regardless if it is the default or not.
157+
for (int iDet = 0; iDet < MAXCHAMBER; ++iDet) {
158+
mFitFunctor.laPreCorr[iDet] = dataCalVdriftExB->getExB(iDet);
159+
mFitFunctor.vdPreCorr[iDet] = dataCalVdriftExB->getVdrift(iDet);
166160
}
167161
}
168162

@@ -209,7 +203,7 @@ void CalibratorVdExB::finalizeSlot(Slot& slot)
209203
LOGF(info, "Done fitting angular residual histograms. CPU time: %f, real time: %f", timer.CpuTime(), timer.RealTime());
210204

211205
// Fill Tree and log to debug
212-
if (mEnableOutput && mOutTree) {
206+
if (mEnableOutput) {
213207
mOutTree->Fill();
214208
for (int iDet = 0; iDet < MAXCHAMBER; ++iDet) {
215209
LOGF(debug, "Fit result for chamber %i: vd=%f, la=%f", iDet, vdFitResults[iDet], laFitResults[iDet] * TMath::RadToDeg());
@@ -242,25 +236,20 @@ Slot& CalibratorVdExB::emplaceNewSlot(bool front, TFType tStart, TFType tEnd)
242236

243237
void CalibratorVdExB::createOutputFile()
244238
{
245-
if (!mEnableOutput) {
246-
return;
247-
}
248-
239+
mEnableOutput = true;
249240
mOutFile = std::make_unique<TFile>("trd_calibVdriftExB.root", "RECREATE");
250241
if (mOutFile->IsZombie()) {
251242
LOG(error) << "Failed to create output file!";
252243
mEnableOutput = false;
253244
return;
254245
}
255-
256246
mOutTree = std::make_unique<TTree>("calib", "VDrift&ExB calibration");
257-
258-
LOG(info) << "Created output file";
247+
LOG(info) << "Created output file trd_calibVdriftExB.root";
259248
}
260249

261250
void CalibratorVdExB::closeOutputFile()
262251
{
263-
if (!mEnableOutput || !mOutTree) {
252+
if (!mEnableOutput) {
264253
return;
265254
}
266255

@@ -273,6 +262,8 @@ void CalibratorVdExB::closeOutputFile()
273262
} catch (std::exception const& e) {
274263
LOG(error) << "Failed to write calibration data file, reason: " << e.what();
275264
}
265+
// after closing, we won't open a new file
266+
mEnableOutput = false;
276267
}
277268

278269
} // namespace o2::trd

Detectors/TRD/workflow/include/TRDWorkflow/VdAndExBCalibSpec.h

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,14 @@ class VdAndExBCalibDevice : public o2::framework::Task
4444
void init(o2::framework::InitContext& ic) final
4545
{
4646
o2::base::GRPGeomHelper::instance().setRequest(mCCDBRequest);
47-
auto enableOutput = ic.options().get<bool>("enable-root-output");
4847
auto slotL = ic.options().get<uint32_t>("sec-per-slot");
4948
auto delay = ic.options().get<uint32_t>("max-delay");
50-
mCalibrator = std::make_unique<o2::trd::CalibratorVdExB>(enableOutput);
49+
mCalibrator = std::make_unique<o2::trd::CalibratorVdExB>();
5150
mCalibrator->setSlotLengthInSeconds(slotL);
5251
mCalibrator->setMaxSlotsDelay(delay);
53-
mCalibrator->createOutputFile(); // internally checks if output is enabled
52+
if (ic.options().get<bool>("enable-root-output")) {
53+
mCalibrator->createOutputFile();
54+
}
5455
}
5556

5657
void finaliseCCDB(o2::framework::ConcreteDataMatcher& matcher, void* obj) final
@@ -60,21 +61,33 @@ class VdAndExBCalibDevice : public o2::framework::Task
6061

6162
void run(o2::framework::ProcessingContext& pc) final
6263
{
63-
auto runStartTime = std::chrono::high_resolution_clock::now();
64+
const auto& tinfo = pc.services().get<o2::framework::TimingInfo>();
65+
if (tinfo.globalRunNumberChanged) { // new run is starting
66+
mRunStopRequested = false;
67+
mCalibrator->retrievePrev(pc); // SOR initialization is performed here
68+
}
69+
if (mRunStopRequested) {
70+
return;
71+
}
6472
o2::base::GRPGeomHelper::instance().checkUpdates(pc);
65-
mCalibrator->retrievePrev(pc);
6673
auto dataAngRes = pc.inputs().get<o2::trd::AngularResidHistos>("input");
6774
o2::base::TFIDInfoHelper::fillTFIDInfo(pc, mCalibrator->getCurrentTFInfo());
6875
LOG(detail) << "Processing TF " << mCalibrator->getCurrentTFInfo().tfCounter << " with " << dataAngRes.getNEntries() << " AngularResidHistos entries";
6976
mCalibrator->process(dataAngRes);
77+
if (pc.transitionState() == TransitionHandlingState::Requested) {
78+
LOG(info) << "Run stop requested, finalizing";
79+
mRunStopRequested = true;
80+
mCalibrator->checkSlotsToFinalize(o2::calibration::INFINITE_TF);
81+
mCalibrator->closeOutputFile();
82+
}
7083
sendOutput(pc.outputs());
71-
std::chrono::duration<double, std::milli> runDuration = std::chrono::high_resolution_clock::now() - runStartTime;
72-
LOGP(debug, "Duration for run method: {} ms", std::chrono::duration_cast<std::chrono::milliseconds>(runDuration).count());
7384
}
7485

7586
void endOfStream(o2::framework::EndOfStreamContext& ec) final
7687
{
77-
LOG(info) << "Finalizing calibration";
88+
if (mRunStopRequested) {
89+
return;
90+
}
7891
mCalibrator->checkSlotsToFinalize(o2::calibration::INFINITE_TF);
7992
mCalibrator->closeOutputFile();
8093
sendOutput(ec.outputs());
@@ -88,6 +101,7 @@ class VdAndExBCalibDevice : public o2::framework::Task
88101
private:
89102
std::unique_ptr<o2::trd::CalibratorVdExB> mCalibrator;
90103
std::shared_ptr<o2::base::GRPGeomRequest> mCCDBRequest;
104+
bool mRunStopRequested = false; // flag that run was stopped (and the last output is sent)
91105
//________________________________________________________________
92106
void sendOutput(DataAllocator& output)
93107
{

0 commit comments

Comments
 (0)