@@ -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// _____________________________________________________________________________
385376void 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)
505483void 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+
619611void FairRunAna::Reinit (UInt_t runId)
620612{
621613 // reinit procedure
0 commit comments