@@ -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
140140void 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
243237void 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
261250void 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
0 commit comments