@@ -492,6 +492,10 @@ void art::ArtdaqInputHelper<U>::readAndConstructPrincipal(std::unique_ptr<TBuffe
492492 << " Unable to fetch a high-resolution time with clock_gettime for art::SubRun Timestamp. " ;
493493 }
494494
495+ TLOG (TLVL_DEBUG + 37 , " ArtdaqInputHelper" ) << " inR: " << static_cast <void *>(inR) << " run " << (inR ? std::to_string (inR->run ()) : " invalid" )
496+ << " , inSR: " << static_cast <void *>(inSR) << " run " << (inSR ? std::to_string (inSR->run ()) : " invalid" )
497+ << " , subrun " << (inSR ? std::to_string (inSR->subRun ()) : " invalid" );
498+
495499 // Process Run Aux
496500 TLOG (TLVL_DEBUG + 37 , " ArtdaqInputHelper" ) << " readAndConstructPrincipal: "
497501 << " processing Run auxiliary ..." ;
@@ -515,7 +519,7 @@ void art::ArtdaqInputHelper<U>::readAndConstructPrincipal(std::unique_ptr<TBuffe
515519 TLOG (TLVL_DEBUG + 39 , " ArtdaqInputHelper" ) << " readAndConstructPrincipal: "
516520 << " finished processing Run auxiliary." ;
517521
518- if (msg_type_code != artdaq::NetMonHeader::MessageType::Run)
522+ if (msg_type_code != artdaq::NetMonHeader::MessageType::Run) // SubRun or Event
519523 {
520524 TLOG (TLVL_DEBUG + 38 , " ArtdaqInputHelper" ) << " readAndConstructPrincipal: "
521525 << " processing SubRun auxiliary ..." ;
@@ -548,13 +552,6 @@ void art::ArtdaqInputHelper<U>::readAndConstructPrincipal(std::unique_ptr<TBuffe
548552 TLOG (TLVL_DEBUG + 39 , " ArtdaqInputHelper" ) << " readAndConstructPrincipal: "
549553 << " finished processing SubRun auxiliary." ;
550554 }
551- else if (inSR == nullptr || !inSR->subRunID ().isValid ())
552- {
553- TLOG (TLVL_DEBUG + 39 , " ArtdaqInputHelper" ) << " readAndConstructPrincipal: Faking Subrun 1 because there was no input Subrun for Run message" ;
554-
555- art::SubRunID subrun_guess (outR->runID (), 1 );
556- outSR = pm_.makeSubRunPrincipal (subrun_guess, currentTime);
557- }
558555
559556 if (msg_type_code == artdaq::NetMonHeader::MessageType::Event)
560557 { // Event message.
@@ -584,23 +581,23 @@ void art::ArtdaqInputHelper<U>::readAndConstructPrincipal(std::unique_ptr<TBuffe
584581 TLOG (TLVL_DEBUG + 39 , " ArtdaqInputHelper" ) << " readAndConstructPrincipal: "
585582 << " finished processing Event auxiliary." ;
586583 }
587-
588- if (!outR && !outSR && !outE)
584+ else if (msg_type_code == artdaq::NetMonHeader::MessageType::Subrun)
589585 {
590- TLOG (TLVL_DEBUG + 39 , " ArtdaqInputHelper" ) << " No principals created, making Flush Event based on whether there was an existing SubRun" ;
591-
592- if (!inSR || !inSR->subRunID ().isValid ())
586+ if (outSR == nullptr )
593587 {
594- TLOG (TLVL_DEBUG + 39 , " ArtdaqInputHelper" ) << " readAndConstructPrincipal: Making run flush event" ;
595- art::EventID const flush_evid (art::EventID::flushEvent (inR->runID ()));
596- outSR = pm_.makeSubRunPrincipal (flush_evid.subRunID (), currentTime);
597- outE = pm_.makeEventPrincipal (flush_evid, currentTime);
588+ TLOG (TLVL_DEBUG + 43 , " ArtdaqInputHelper" ) << " SubrunDataFragment for current Subrun received, returning Flush event" ;
589+ art::EventID const evid (art::EventID::flushEvent (inSR->subRunID ()));
590+ outE = pm_.makeEventPrincipal (evid, currentTime);
598591 }
599- else
592+ }
593+ else if (msg_type_code == artdaq::NetMonHeader::MessageType::Run)
594+ {
595+ if (outR == nullptr )
600596 {
601- TLOG (TLVL_DEBUG + 39 , " ArtdaqInputHelper" ) << " readAndConstructPrincipal: Making subrun flush event" ;
602- art::EventID const flush_evid (art::EventID::flushEvent (inSR->subRunID ()));
603- outE = pm_.makeEventPrincipal (flush_evid, currentTime);
597+ TLOG (TLVL_DEBUG + 43 , " ArtdaqInputHelper" ) << " RunDataFragment for current Run received, returning Flush subrun/event" ;
598+ art::EventID const evid (art::EventID::flushEvent (inR->runID ()));
599+ outSR = pm_.makeSubRunPrincipal (evid.subRunID (), currentTime);
600+ outE = pm_.makeEventPrincipal (evid, currentTime);
604601 }
605602 }
606603}
@@ -646,64 +643,22 @@ bool art::ArtdaqInputHelper<U>::constructPrincipal(std::shared_ptr<ArtdaqEvent>
646643 << " The art::Event Timestamp will be zero for event " << eventPtr->header ->event_id ;
647644 }
648645
649- if (eventPtr->FirstFragmentType () == artdaq::Fragment::EndOfRunFragmentType)
650- {
651- TLOG (TLVL_DEBUG + 43 , " ArtdaqInputHelper" ) << " EndOfRunFragment received, returning Flush event" ;
652- art::EventID const evid (art::EventID::flushEvent ());
653- outR = pm_.makeRunPrincipal (evid.runID (), currentTime);
654- outSR = pm_.makeSubRunPrincipal (evid.subRunID (), currentTime);
655- outE = pm_.makeEventPrincipal (evid, currentTime);
656- return true ;
657- }
658-
659- if (eventPtr->FirstFragmentType () == artdaq::Fragment::EndOfSubrunFragmentType)
660- {
661- TLOG (TLVL_DEBUG + 43 , " ArtdaqInputHelper" ) << " EndOfSubrunFragment received, creating new Subrun Principal" ;
662- // Check if inR == 0 or is a new run
663- if (inR == nullptr || !inR->runID ().isValid () || inR->run () != eventPtr->header ->run_id )
664- {
665- TLOG (TLVL_DEBUG + 43 , " ArtdaqInputHelper" ) << " Making subrun principal with subrun_id " << eventPtr->header ->subrun_id ;
666- if (outSR) delete outSR;
667- outSR = pm_.makeSubRunPrincipal (eventPtr->header ->run_id , eventPtr->header ->subrun_id , currentTime);
668- art::EventID const evid (art::EventID::flushEvent (outSR->subRunID ()));
669- outE = pm_.makeEventPrincipal (evid, currentTime);
670- }
671- else
672- {
673- // If the previous subrun was neither 0 nor flush and was identical with the current
674- // subrun, then it must have been associated with a data event. In that case, we need
675- // to generate a flush event with a valid run but flush subrun and event number in order
676- // to end the subrun.
677- if (inSR != nullptr && !inSR->subRunID ().isFlush () && inSR->subRun () == eventPtr->header ->subrun_id )
678- {
679- TLOG (TLVL_DEBUG + 43 , " ArtdaqInputHelper" ) << " Flushing old run id " << inR->runID ();
680- art::EventID const evid (art::EventID::flushEvent (inR->runID ()));
681- outSR = pm_.makeSubRunPrincipal (evid.subRunID (), currentTime);
682- outE = pm_.makeEventPrincipal (evid, currentTime);
683- // If this is either a new or another empty subrun, then generate a flush event with
684- // valid run and subrun numbers but flush event number
685- // } else if(inSR==0 || inSR->id().isFlush()){
686- }
687- else
688- {
689- TLOG (TLVL_DEBUG + 43 , " ArtdaqInputHelper" ) << " Making subrun principal with subrun_id " << eventPtr->header ->subrun_id ;
690- outSR = pm_.makeSubRunPrincipal (eventPtr->header ->run_id , eventPtr->header ->subrun_id , currentTime);
691- art::EventID const evid (art::EventID::flushEvent (outSR->subRunID ()));
692- outE = pm_.makeEventPrincipal (evid, currentTime);
693- // Possible error condition
694- // } else {
695- }
696- }
697- return true ;
698- }
699-
700646 // make new run if inR is 0 or if the run has changed
701647 if (inR == nullptr || !inR->runID ().isValid () || inR->run () != eventPtr->header ->run_id )
702648 {
703649 TLOG (TLVL_DEBUG + 43 , " ArtdaqInputHelper" ) << " Making run principal with run_id " << eventPtr->header ->run_id ;
704650 outR = pm_.makeRunPrincipal (eventPtr->header ->run_id , currentTime);
705651 }
706652
653+ if (eventPtr->FirstFragmentType () == artdaq::Fragment::EndOfRunFragmentType)
654+ {
655+ TLOG (TLVL_DEBUG + 43 , " ArtdaqInputHelper" ) << " EndOfRunFragment received, returning Flush subrun/event" ;
656+ art::EventID const evid (art::EventID::flushEvent (outR != nullptr ? outR->runID () : inR->runID ()));
657+ outSR = pm_.makeSubRunPrincipal (evid.subRunID (), currentTime);
658+ outE = pm_.makeEventPrincipal (evid, currentTime);
659+ return true ;
660+ }
661+
707662 // make new subrun if inSR is 0 or if the subrun has changed
708663 art::SubRunID subrun_check (eventPtr->header ->run_id , eventPtr->header ->subrun_id );
709664 if (inSR == nullptr || !inSR->subRunID ().isValid () || subrun_check != inSR->subRunID ())
@@ -712,6 +667,14 @@ bool art::ArtdaqInputHelper<U>::constructPrincipal(std::shared_ptr<ArtdaqEvent>
712667 outSR = pm_.makeSubRunPrincipal (eventPtr->header ->run_id , eventPtr->header ->subrun_id , currentTime);
713668 }
714669
670+ if (eventPtr->FirstFragmentType () == artdaq::Fragment::EndOfSubrunFragmentType)
671+ {
672+ TLOG (TLVL_DEBUG + 43 , " ArtdaqInputHelper" ) << " EndOfSubrunFragment received, returning Flush event" ;
673+ art::EventID const evid (art::EventID::flushEvent (outSR != nullptr ? outSR->subRunID () : inSR->subRunID ()));
674+ outE = pm_.makeEventPrincipal (evid, currentTime);
675+ return true ;
676+ }
677+
715678 TLOG (TLVL_DEBUG + 43 , " ArtdaqInputHelper" ) << " Making event principal with event_id " << eventPtr->header ->event_id ;
716679 outE = pm_.makeEventPrincipal (eventPtr->header ->run_id , eventPtr->header ->subrun_id , eventPtr->header ->event_id , currentTime);
717680 return true ;
@@ -1002,28 +965,7 @@ bool art::ArtdaqInputHelper<U>::readNext(art::RunPrincipal* const inR, art::SubR
1002965 TLOG (TLVL_DEBUG + 32 , " ArtdaqInputHelper" ) << " First Fragment type is " << static_cast <int >(firstFragmentType);
1003966 if (constructPrincipal (eventMap, inR, inSR, outR, outSR, outE))
1004967 {
1005- auto rfret = readFragments (eventMap->fragments , outR ? outR : inR, outSR ? outSR : inSR, outE);
1006-
1007- // No event data
1008- if (!rfret.second )
1009- {
1010- delete outE;
1011- outE = nullptr ;
1012-
1013- if (inSR != nullptr && outSR != nullptr )
1014- {
1015- // No products added to subrun
1016- if (!rfret.first )
1017- {
1018- // New subrun is identical to old
1019- if (inSR->subRunID () == outSR->subRunID ())
1020- {
1021- delete outSR;
1022- outSR = nullptr ;
1023- }
1024- }
1025- }
1026- }
968+ readFragments (eventMap->fragments , outR ? outR : inR, outSR ? outSR : inSR, outE);
1027969 }
1028970 }
1029971 else
@@ -1091,25 +1033,6 @@ bool art::ArtdaqInputHelper<U>::readNext(art::RunPrincipal* const inR, art::SubR
10911033 }
10921034 else if (msg_type_code == artdaq::NetMonHeader::MessageType::Subrun)
10931035 {
1094- // EndSubRun message.
1095- // From the code above, EndRun and EndSubRun messages cause
1096- // the construction of principals that have:
1097- // Run:Subrun:Event=flush:flush:flush.
1098- // This is a problem when you have two neighboring EndSubRuns
1099- // which are both associated with empty subruns because art will
1100- // complain that you a new subrun with a subrun number identical
1101- // to that of the previous subrun. So the solution is to not
1102- // return new principals.
1103- if (inR != nullptr && inSR != nullptr && outR != nullptr && outSR != nullptr )
1104- {
1105- if (inR->runID ().isFlush () && inSR->subRunID ().isFlush () && outR->runID ().isFlush () &&
1106- outSR->subRunID ().isFlush ())
1107- {
1108- outR = nullptr ;
1109- outSR = nullptr ;
1110- return outE ? true : false ;
1111- }
1112- }
11131036 // FIXME: We need to merge these into the input SubRunPrincipal.
11141037 readDataProducts (msgs, outSR ? outSR : inSR);
11151038 }
@@ -1122,8 +1045,6 @@ bool art::ArtdaqInputHelper<U>::readNext(art::RunPrincipal* const inR, art::SubR
11221045 {
11231046 readFragments (eventMap->fragments , outR ? outR : inR, outSR ? outSR : inSR, outE);
11241047 }
1125-
1126- TLOG (TLVL_DEBUG + 47 , " ArtdaqInputHelper" ) << " readNext: returning true on Event message." ;
11271048 }
11281049 else
11291050 {
0 commit comments