16
16
* See the License for the specific language governing permissions and
17
17
* limitations under the License.
18
18
*/
19
-
20
- #include < GaudiKernel/IEventProcessor.h>
21
-
22
- #include " k4MarlinWrapper/LCEventWrapper.h"
23
19
#include " k4MarlinWrapper/LcioEventAlgo.h"
20
+ #include " k4MarlinWrapper/LCEventWrapper.h"
24
21
25
22
#include " marlin/Global.h"
26
23
#include " marlin/StringParameters.h"
27
24
28
25
#include < EVENT/LCIO.h>
29
26
#include < MT/LCReader.h>
30
27
31
- #include < memory>
28
+ #include < GaudiKernel/IEventProcessor.h>
29
+
30
+ #include < stdexcept>
32
31
#include < string>
33
32
34
33
DECLARE_COMPONENT (LcioEvent)
@@ -44,54 +43,42 @@ StatusCode LcioEvent::initialize() {
44
43
45
44
m_reader = new MT::LCReader (0 );
46
45
m_reader->open (m_fileNames);
47
- info () << " Initialized the LcioEvent Algo: " << m_fileNames[0 ] << endmsg;
46
+ m_numberOfEvents = m_reader->getNumberOfEvents ();
47
+ info () << " Initialized the LcioEvent Algo. Reading from " << m_fileNames.size () << " with " << m_numberOfEvents
48
+ << " events in total." << endmsg;
48
49
return StatusCode::SUCCESS;
49
50
}
50
51
51
52
StatusCode LcioEvent::execute (const EventContext&) const {
53
+ debug () << " Reading event " << ++m_currentEvent << " / " << m_numberOfEvents << endmsg;
52
54
auto theEvent = m_reader->readNextEvent (EVENT::LCIO::UPDATE);
53
55
54
- if (!theEvent) {
55
- // Store flag to indicate there was NOT a LCEvent
56
- auto pStatus = std::make_unique<LCEventWrapperStatus>(false );
57
- const StatusCode scStatus = eventSvc ()->registerObject (" /Event/LCEventStatus" , pStatus.release ());
58
- if (scStatus.isFailure ()) {
59
- error () << " Failed to store flag for underlying LCEvent: MarlinProcessorWrapper may try to run over non existing "
60
- " event"
61
- << endmsg;
62
- return scStatus;
63
- }
56
+ if (theEvent == nullptr ) {
57
+ fatal () << " Failed to read event " << m_currentEvent << endmsg;
58
+ throw std::runtime_error (" LCEvent could not be read" );
59
+ }
64
60
65
- auto svc = service<IEventProcessor>(" ApplicationMgr" );
66
- if (svc) {
67
- svc->stopRun ().ignore ();
68
- svc->release ();
69
- } else {
70
- abort ();
61
+ // Since this is presumably the first algorithm to run we have to check here
62
+ // to see if we need to stop the run. Events in flight will still be
63
+ // processed, so technically this signals that we want to end the run after
64
+ // all of the algorithms for this event have finished.
65
+ if (m_currentEvent >= m_numberOfEvents) {
66
+ info () << " This is the last event in the input files. Stopping the run" << endmsg;
67
+ auto evtProcService = service<IEventProcessor>(" ApplicationMgr" , false );
68
+ if (!evtProcService) {
69
+ fatal () << " Could not get the ApplicationMgr for stopping the run" << endmsg;
71
70
}
72
- } else {
73
- // pass theEvent to the DataStore, so we can access them in our processor
74
- // wrappers
75
- info () << " Reading from file: " << m_fileNames[0 ] << endmsg;
76
-
77
- auto myEvWr = new LCEventWrapper (std::move (theEvent));
78
- const StatusCode sc = eventSvc ()->registerObject (" /Event/LCEvent" , myEvWr);
79
- if (sc.isFailure ()) {
80
- error () << " Failed to store the LCEvent" << endmsg;
81
- return sc;
82
- } else {
83
- // Store flag to indicate there was a LCEvent
84
- auto pStatus = std::make_unique<LCEventWrapperStatus>(true );
85
- std::cout << " Saving status: " << pStatus->hasLCEvent << std::endl;
86
- const StatusCode scStatus = eventSvc ()->registerObject (" /Event/LCEventStatus" , pStatus.release ());
87
- if (scStatus.isFailure ()) {
88
- error () << " Failed to store flag for underlying LCEvent: MarlinProcessorWrapper may try to run over non "
89
- " existing event"
90
- << endmsg;
91
- return scStatus;
92
- }
71
+ if (evtProcService->stopRun ().isFailure ()) {
72
+ error () << " Out of events, but could not signal to stop the run" << endmsg;
93
73
}
94
74
}
95
75
76
+ auto myEvWr = new LCEventWrapper (std::move (theEvent));
77
+ const StatusCode sc = eventSvc ()->registerObject (" /Event/LCEvent" , myEvWr);
78
+ if (sc.isFailure ()) {
79
+ error () << " Failed to store the LCEvent" << endmsg;
80
+ return sc;
81
+ }
82
+
96
83
return StatusCode::SUCCESS;
97
84
}
0 commit comments