Skip to content

Commit 5be822b

Browse files
chore(FairRun*): Refactor RunId Changes
Introduce a CheckRunIdChanged in FairRunAna and FairRunOnline that handles RunId changes. Fix FairRunAna::RunEventReco: It always used runid 0 for the "new current runid". Now it just uses CheckRunIdChanged as well.
1 parent 5c616a0 commit 5be822b

5 files changed

Lines changed: 68 additions & 59 deletions

File tree

fairroot/base/steer/FairRunAna.cxx

Lines changed: 28 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -324,8 +324,6 @@ void FairRunAna::Run(Int_t Ev_start, Int_t Ev_end)
324324
fRunInfo.Reset();
325325
}
326326

327-
Int_t readEventReturn = 0;
328-
329327
for (int i = Ev_start; i < Ev_end || MaxAllowed == -1; i++) {
330328

331329
gSystem->IgnoreInterrupt();
@@ -337,7 +335,7 @@ void FairRunAna::Run(Int_t Ev_start, Int_t Ev_end)
337335
break;
338336
}
339337

340-
readEventReturn = fRootManager->ReadEvent(i);
338+
auto readEventReturn = fRootManager->ReadEvent(i);
341339

342340
if (readEventReturn != 0) {
343341
LOG(warn) << "FairRunAna::Run() fRootManager->ReadEvent(" << i << ") returned " << readEventReturn
@@ -346,15 +344,8 @@ void FairRunAna::Run(Int_t Ev_start, Int_t Ev_end)
346344
}
347345

348346
FillEventHeader();
347+
CheckRunIdChanged();
349348

350-
auto const tmpId = GetEvtHeaderRunId();
351-
if (tmpId != fRunId) {
352-
fRunId = tmpId;
353-
if (!fStatic) {
354-
Reinit(fRunId);
355-
fTask->ReInitTask();
356-
}
357-
}
358349
// std::cout << "WriteoutBufferData with time: " << fRootManager->GetEventTime();
359350
fRootManager->StoreWriteoutBufferData(fRootManager->GetEventTime());
360351
fTask->ExecuteTask("");
@@ -384,8 +375,6 @@ void FairRunAna::Run(Int_t Ev_start, Int_t Ev_end)
384375
//_____________________________________________________________________________
385376
void FairRunAna::RunEventReco(Int_t Ev_start, Int_t Ev_end)
386377
{
387-
UInt_t tmpId = 0;
388-
389378
Int_t MaxAllowed = fRootManager->CheckMaxEventNo(Ev_end);
390379
if (MaxAllowed != -1) {
391380
if (Ev_end == 0) {
@@ -425,13 +414,9 @@ void FairRunAna::RunEventReco(Int_t Ev_start, Int_t Ev_end)
425414
* if we have simulation files then they have MC Event Header and the Run Id is in it, any way it
426415
* would be better to make FairMCEventHeader a subclass of FairEvtHeader.
427416
*/
428-
if (tmpId != fRunId) {
429-
fRunId = tmpId;
430-
if (!fStatic) {
431-
Reinit(fRunId);
432-
fTask->ReInitTask();
433-
}
434-
}
417+
418+
CheckRunIdChanged();
419+
435420
// FairMCEventHeader* header = dynamic_cast<FairMCEventHeader*>(fRootManager->GetObject("MCEventHeader.");
436421
// std::cout << "WriteoutBufferData with time: " << fRootManager->GetEventTime();
437422
fRootManager->StoreWriteoutBufferData(fRootManager->GetEventTime());
@@ -487,14 +472,7 @@ void FairRunAna::RunMQ(Long64_t entry)
487472
it read a certain event and call the task exec, but no output is written
488473
*/
489474
fRootManager->ReadEvent(entry);
490-
auto const tmpId = GetEvtHeaderRunId();
491-
if (tmpId != fRunId) {
492-
fRunId = tmpId;
493-
if (!fStatic) {
494-
Reinit(fRunId);
495-
fTask->ReInitTask();
496-
}
497-
}
475+
CheckRunIdChanged();
498476
fTask->ExecuteTask("");
499477
FillEventHeader();
500478
fTask->FinishTask();
@@ -505,14 +483,7 @@ void FairRunAna::RunMQ(Long64_t entry)
505483
void FairRunAna::Run(Long64_t entry)
506484
{
507485
fRootManager->ReadEvent(entry);
508-
auto const tmpId = GetEvtHeaderRunId();
509-
if (tmpId != fRunId) {
510-
fRunId = tmpId;
511-
if (!fStatic) {
512-
Reinit(fRunId);
513-
fTask->ReInitTask();
514-
}
515-
}
486+
CheckRunIdChanged();
516487
fTask->ExecuteTask("");
517488
FillEventHeader();
518489
fTask->FinishTask();
@@ -616,6 +587,27 @@ void FairRunAna::TerminateRun()
616587
}
617588
//_____________________________________________________________________________
618589

590+
/**
591+
* \sa FairRunOnline::CheckRunIdChanged
592+
*/
593+
void FairRunAna::CheckRunIdChanged()
594+
{
595+
auto newrunid = GetEvtHeaderRunId();
596+
if (newrunid == fRunId) {
597+
return;
598+
}
599+
600+
LOG(debug) << "FairRunAna::CheckRunIdChanged() Detected changed RunID from " << fRunId << " to " << newrunid;
601+
fRunId = newrunid;
602+
if (fStatic) {
603+
LOG(debug) << "FairRunAna::CheckRunIdChanged: ReInit not called because initialisation is static.";
604+
return;
605+
}
606+
LOG(debug) << "FairRunAna::CheckRunIdChanged: Call Reinit.";
607+
Reinit(fRunId);
608+
fTask->ReInitTask();
609+
}
610+
619611
void FairRunAna::Reinit(UInt_t runId)
620612
{
621613
// reinit procedure

fairroot/base/steer/FairRunAna.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,11 @@ class FairRunAna : public FairRun
130130
/** Flag for Event Header Persistency */
131131
Bool_t fStoreEventHeader; //!
132132

133+
/**
134+
* \brief Internal facade: Handle RunID changes
135+
*/
136+
void CheckRunIdChanged();
137+
133138
ClassDefOverride(FairRunAna, 6);
134139
};
135140

fairroot/base/steer/FairRunAnaProof.cxx

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -284,15 +284,8 @@ void FairRunAnaProof::RunOneEvent(Long64_t entry)
284284
fRootManager->ReadEvent(entry);
285285

286286
FillEventHeader();
287+
CheckRunIdChanged();
287288

288-
auto const tmpId = GetEvtHeaderRunId();
289-
if (tmpId != fRunId) {
290-
fRunId = tmpId;
291-
if (!fStatic) {
292-
Reinit(fRunId);
293-
fTask->ReInitTask();
294-
}
295-
}
296289
fRootManager->StoreWriteoutBufferData(fRootManager->GetEventTime());
297290

298291
fTask->ExecuteTask("");

fairroot/online/steer/FairRunOnline.cxx

Lines changed: 28 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -216,21 +216,8 @@ Int_t FairRunOnline::EventLoop()
216216
signal(SIGINT, handler_ctrlc);
217217

218218
FillEventHeader();
219-
auto const tmpId = GetEvtHeaderRunId();
220-
if (tmpId != fRunId) {
221-
LOG(info) << "FairRunOnline::EventLoop() Detected changed RunID from " << fRunId << " to " << tmpId;
222-
fRunId = tmpId;
223-
if (!fStatic) {
224-
LOG(info) << "FairRunOnline::EventLoop() Call Reinit.";
225-
Reinit(fRunId);
226-
if (!GetSource()->ReInitUnpackers()) {
227-
LOG(fatal) << "FairRunOnline->EventLoop() ReInitUnpackers() failed!";
228-
return 1;
229-
}
230-
fTask->ReInitTask();
231-
} else {
232-
LOG(info) << "FairRunOnline::EventLoop() ReInit not called because initialisation is static.";
233-
}
219+
if (!CheckRunIdChanged()) {
220+
return 1;
234221
}
235222

236223
fRootManager->StoreWriteoutBufferData(fRootManager->GetEventTime());
@@ -348,6 +335,32 @@ void FairRunOnline::RegisterHttpCommand(TString name, TString command)
348335
}
349336
}
350337

338+
/**
339+
* \sa FairRunAna::CheckRunIdChanged
340+
*/
341+
bool FairRunOnline::CheckRunIdChanged()
342+
{
343+
auto const tmpId = GetEvtHeaderRunId();
344+
if (tmpId == fRunId) {
345+
return true;
346+
}
347+
348+
LOG(info) << "FairRunOnline::CheckRunIdChanged: Detected changed RunID from " << fRunId << " to " << tmpId;
349+
fRunId = tmpId;
350+
if (fStatic) {
351+
LOG(info) << "FairRunOnline::CheckRunIdChanged: ReInit not called because initialisation is static.";
352+
return true;
353+
}
354+
LOG(info) << "FairRunOnline::CheckRunIdChanged: Call Reinit.";
355+
Reinit(fRunId);
356+
if (!GetSource()->ReInitUnpackers()) {
357+
LOG(fatal) << "FairRunOnline::CheckRunIdChanged: ReInitUnpackers() failed!";
358+
return false;
359+
}
360+
fTask->ReInitTask();
361+
return true;
362+
}
363+
351364
void FairRunOnline::Reinit(UInt_t runId)
352365
{
353366
// reinit procedure

fairroot/online/steer/FairRunOnline.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,12 @@ class FairRunOnline : public FairRun
8888
/** Main Event loop **/
8989
Int_t EventLoop();
9090

91+
/**
92+
* \brief Internal facade: Handle RunID changes
93+
* \return false on error
94+
*/
95+
bool CheckRunIdChanged();
96+
9197
protected:
9298
/** This variable became true after Init is called*/
9399
Bool_t fIsInitialized;

0 commit comments

Comments
 (0)