ATLAS Offline Software
Loading...
Searching...
No Matches
AthenaHiveEventLoopMgr.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3*/
4
5#include <GaudiKernel/DataIncident.h>
6
7#include <memory>
8#define ATHENASERVICES_ATHENAHIVEEVENTLOOPMGR_CPP
9
10#include <cassert>
11#include <ios>
12#include <iostream>
13#include <fstream> /* ofstream */
14#include <iomanip>
15#include <memory>
16#include <print>
17
18// Athena includes
28
29#include "GaudiKernel/IAlgorithm.h"
30#include "GaudiKernel/SmartIF.h"
31#include "GaudiKernel/Incident.h"
32#include "GaudiKernel/DataObject.h"
33#include "GaudiKernel/IIncidentSvc.h"
34#include "GaudiKernel/IEvtSelector.h"
35#include "GaudiKernel/IDataManagerSvc.h"
36#include "GaudiKernel/IDataProviderSvc.h"
37#include "GaudiKernel/IConversionSvc.h"
38#include "GaudiKernel/GaudiException.h"
39#include "GaudiKernel/AppReturnCode.h"
40#include "GaudiKernel/MsgStream.h"
41#include "Gaudi/Property.h"
42#include "GaudiKernel/EventIDBase.h"
43#include "GaudiKernel/ThreadLocalContext.h"
44
46
47#include "EventInfo/EventInfo.h"
48#include "EventInfo/EventID.h"
49#include "EventInfo/EventType.h"
52
54
55#include <GaudiKernel/IScheduler.h>
56// External libraries
57#include "tbb/tick_count.h"
58
59
60
61//=========================================================================
62// Standard Constructor
63//=========================================================================
65 ISvcLocator* svcLoc)
66 : base_class(nam, svcLoc),
67 AthMessaging (nam),
68 m_incidentSvc ( "IncidentSvc", nam ),
69 m_eventStore( "StoreGateSvc", nam ),
71 m_histoDataMgrSvc( "HistogramDataSvc", nam ),
72 m_histoPersSvc ( "HistogramPersistencySvc", nam ),
73 m_evtIdModSvc ( "", nam ),
74 m_currentRun(0), m_firstRun(true), m_tools(this), m_nevt(0), m_writeHists(false),
75 m_nev(0), m_proc(0), m_useTools(false),m_doEvtHeartbeat(false),
76 m_conditionsCleaner( "Athena::ConditionsCleanerSvc", nam )
77{
78 declareProperty("EvtSel", m_evtsel,
79 "Name of Event Selector to use. If empty string (default) "
80 "take value from ApplicationMgr");
81 declareProperty("HistogramPersistency", m_histPersName="",
82 "Histogram persistency technology to use: ROOT, HBOOK, NONE. "
83 "By default (empty string) get property value from "
84 "ApplicationMgr");
85 declareProperty("HistWriteInterval", m_writeInterval=0 ,
86 "histogram write/update interval");
87 declareProperty("FailureMode", m_failureMode=1 ,
88 "Controls behaviour of event loop depending on return code of"
89 " Algorithms. 0: all non-SUCCESSes terminate job. "
90 "1: RECOVERABLE skips to next event, FAILURE terminates job "
91 "(DEFAULT). 2: RECOVERABLE and FAILURE skip to next events");
92 declareProperty("EventPrintoutInterval", m_eventPrintoutInterval=1,
93 "Print event heartbeat printouts every m_eventPrintoutInterval events");
94 declareProperty("PreSelectTools",m_tools,"AlgTools for event pre-selection")->
95 declareUpdateHandler( &AthenaHiveEventLoopMgr::setupPreSelectTools, this ); ;
96
97 declareProperty("SchedulerSvc", m_schedulerName="ForwardSchedulerSvc",
98 "Name of the scheduler to be used");
99
100 declareProperty("WhiteboardSvc", m_whiteboardName="EventDataSvc",
101 "Name of the Whiteboard to be used");
102
103 declareProperty("EventStore", m_eventStore);
104 declareProperty("ConditionsCleanerSvc", m_conditionsCleaner);
105
106 declareProperty("EvtIdModifierSvc", m_evtIdModSvc,
107 "ServiceHandle for EvtIdModifierSvc");
108
109 declareProperty("FakeLumiBlockInterval", m_flmbi = 0,
110 "Event interval at which to increment lumiBlock# when "
111 "creating events without an EventSelector. Zero means "
112 "don't increment it");
113 declareProperty("FakeTimestampInterval", m_timeStampInt = 1,
114 "timestamp interval between events when creating Events "
115 "without an EventSelector");
116 declareProperty("RequireInputAttributeList", m_requireInputAttributeList = false,
117 "Require valid input attribute list to be present");
118 declareProperty("UseSecondaryEventNumber", m_useSecondaryEventNumber = false,
119 "In case of DoubleEventSelector use event number from secondary input");
120
121 declareProperty("FirstEventAlone", m_firstEventAlone = true,
122 "process all of first event before scheduling any more");
123
124 m_scheduledStop = false;
125
126}
127
128//=========================================================================
129// Standard Destructor
130//=========================================================================
134
135//=========================================================================
136// implementation of IAppMgrUI::initalize
137//=========================================================================
139{
140
141 ATH_MSG_INFO ( "Initializing {}", name() );
142
143
144 StatusCode sc = MinimalEventLoopMgr::initialize();
145 if ( !sc.isSuccess() )
146 {
147 ATH_MSG_ERROR ( "Failed to initialize base class MinimalEventLoopMgr" );
148 return sc;
149 }
150
151//-------------------------------------------------------------------------
152// Setup stuff for hive
153//-------------------------------------------------------------------------
154
155 m_whiteboard = serviceLocator()->service(m_whiteboardName);
156 if( !m_whiteboard.isValid() ) {
157 ATH_MSG_FATAL ( "Error retrieving {} interface IHiveWhiteBoard.", m_whiteboardName );
158 return StatusCode::FAILURE;
159 }
160
161 m_schedulerSvc = serviceLocator()->service(m_schedulerName);
162 if ( !m_schedulerSvc.isValid()){
163 ATH_MSG_FATAL ( "Error retrieving SchedulerSvc interface ISchedulerSvc." );
164 return StatusCode::FAILURE;
165 }
166 // Setup algorithm resource pool
167 m_algResourcePool = serviceLocator()->service("AlgResourcePool");
168 if( !m_algResourcePool.isValid() ) {
169 ATH_MSG_FATAL ( "Error retrieving AlgResourcePool" );
170 return StatusCode::FAILURE;
171 }
172
173 m_aess = serviceLocator()->service("AlgExecStateSvc");
174 if( !m_aess.isValid() ) {
175 ATH_MSG_FATAL ( "Error retrieving AlgExecStateSvc" );
176 return StatusCode::FAILURE;
177 }
178
179 sc = m_eventStore.retrieve();
180 if( !sc.isSuccess() )
181 {
182 ATH_MSG_FATAL ( "Error retrieving pointer to StoreGateSvc" );
183 return sc;
184 }
185
186//--------------------------------------------------------------------------
187// Get the references to the services that are needed by the ApplicationMgr
188// itself
189//--------------------------------------------------------------------------
190 sc = m_incidentSvc.retrieve();
191 if( !sc.isSuccess() )
192 {
193 ATH_MSG_FATAL ( "Error retrieving IncidentSvc." );
194 return sc;
195 }
196
197//--------------------------------------------------------------------------
198// Access Property Manager interface:
199//--------------------------------------------------------------------------
200 SmartIF<IProperty> prpMgr(serviceLocator());
201 if ( !prpMgr.isValid() )
202 {
203 ATH_MSG_FATAL ( "IProperty interface not found in ApplicationMgr." );
204 return StatusCode::FAILURE;
205 }
206
207
208//--------------------------------------------------------------------------
209// Set up the Histogram Service
210//--------------------------------------------------------------------------
211 sc = m_histoDataMgrSvc.retrieve();
212 if( !sc.isSuccess() )
213 {
214 ATH_MSG_FATAL ( "Error retrieving HistogramDataSvc" );
215 return sc;
216 }
217
218 const std::string& histPersName(m_histPersName.value());
219 if ( histPersName.length() == 0 )
220 {
221 CHECK(setProperty(prpMgr->getProperty("HistogramPersistency")));
222 }
223
224 if ( histPersName != "NONE" ) {
225
226 m_histoPersSvc = IConversionSvc_t( "HistogramPersistencySvc",
227 this->name() );
228
229 SmartIF<IProperty> histSvc;
230 if (histPersName == "ROOT") {
231 histSvc = serviceLocator()->service("RootHistSvc");
232 } else if ( histPersName == "HBOOK" ) {
233 histSvc = serviceLocator()->service("HbookHistSvc");
234 }
235
236 if (!histSvc) {
237 ATH_MSG_ERROR ( "could not locate actual Histogram persistency service" );
238 } else {
239 const Gaudi::Details::PropertyBase &prop = histSvc->getProperty("OutputFile");
240 std::string val;
241 try {
242 const StringProperty &sprop = dynamic_cast<const StringProperty&>( prop );
243 val = sprop.value();
244 } catch (...) {
245 ATH_MSG_VERBOSE ( "could not dcast OutputFile property to a StringProperty."
246 " Need to fix Gaudi." );
247 val = prop.toString();
248 }
249
250 if (val != "" &&
251 val != "UndefinedROOTOutputFileName" &&
252 val != "UndefinedHbookOutputFileName" ) {
253 m_writeHists = true;
254 }
255 }
256 } else {
257 ATH_MSG_DEBUG ( "Histograms saving not required." );
258 }
259
260
261//--------------------------------------------------------------------------
262// Set up the EventID modifier Service
263//--------------------------------------------------------------------------
264 if( m_evtIdModSvc.empty() ) {
265 ATH_MSG_DEBUG ( "EventID modifier Service not set. No run number, ... overrides will be applied." );
266 }
267 else if ( !m_evtIdModSvc.retrieve().isSuccess() ) {
268 ATH_MSG_INFO ( "Could not find EventID modifier Service. No run number, ... overrides will be applied." );
269 }
270
271//-------------------------------------------------------------------------
272// Setup EventSelector service
273//-------------------------------------------------------------------------
274 const std::string& selName(m_evtsel.value());
275 // the evt sel is usually specified as a property of ApplicationMgr
276 if (selName.empty())
277 sc = setProperty(prpMgr->getProperty("EvtSel"));
278 if (sc.isFailure()) ATH_MSG_WARNING ( "Unable to set EvtSel property" );
279
280 // We do not expect a Event Selector necessarily being declared
281 if( !selName.empty() && selName != "NONE") {
282 SmartIF<IEvtSelector> theEvtSel{serviceLocator()->service( selName )};
283 if( theEvtSel && ( theEvtSel != m_evtSelector ) ) {
284 // Event Selector changed (or setup for the first time)
285 m_evtSelector = theEvtSel;
286
287 // reset iterator
288 if (m_evtSelector->createContext(m_evtContext).isFailure()) {
289 ATH_MSG_FATAL ( "Can not create the event selector Context." );
290 return StatusCode::FAILURE;
291 }
292 if (msgLevel(MSG::INFO)) {
293 SmartIF<INamedInterface> named(theEvtSel);
294 if (named) {
295 ATH_MSG_INFO ( "Setup EventSelector service {}", named->name( ) );
296 }
297 }
298 } else if (sc.isFailure()) {
299 ATH_MSG_FATAL ( "No valid event selector called {}", selName );
300 return StatusCode::FAILURE;
301 }
302 }
303
304 // Listen to the BeforeFork and EndAlgorithms incidents
305 m_incidentSvc->addListener(this,"BeforeFork",0);
306 m_incidentSvc->addListener(this, "EndAlgorithms",0);
307
308 CHECK( m_conditionsCleaner.retrieve() );
309
310 // Print if we override the event number using the one from secondary event
312 {
313 ATH_MSG_INFO ( "Using secondary event number." );
314 }
315
316 return sc;
317}
318
319//=========================================================================
320// property handlers
321//=========================================================================
322void
323AthenaHiveEventLoopMgr::setupPreSelectTools(Gaudi::Details::PropertyBase&) {
324
325 m_toolInvoke.clear();
326 m_toolReject.clear();
327 m_toolAccept.clear();
328
329 m_tools.retrieve().ignore();
330 if(m_tools.size() > 0) {
331 m_useTools=true;
332 m_toolInvoke.resize(m_tools.size());
333 m_toolReject.resize(m_tools.size());
334 m_toolAccept.resize(m_tools.size());
335
336 tool_iterator firstTool = m_tools.begin();
337 tool_iterator lastTool = m_tools.end();
338 unsigned int toolCtr = 0;
339 for ( ; firstTool != lastTool; ++firstTool )
340 {
341 // reset statistics
342 m_toolInvoke[toolCtr] = 0;
343 m_toolReject[toolCtr] = 0;
344 m_toolAccept[toolCtr] = 0;
345 toolCtr++;
346 }
347 }
348
349 return;
350
351}
352
353//=========================================================================
354// implementation of IAppMgrUI::finalize
355//=========================================================================
357{
358
359 StatusCode sc = MinimalEventLoopMgr::finalize();
360 if (sc.isFailure())
361 {
362 ATH_MSG_ERROR ( "Error in Service base class Finalize" );
363 }
364
365 StatusCode sc2 = writeHistograms(true);
366 if (sc2.isFailure())
367 {
368 ATH_MSG_ERROR ( "Error in writing Histograms" );
369 }
370
371 // Release all interfaces (ignore StatusCodes)
372 m_histoDataMgrSvc.release().ignore();
373 m_histoPersSvc.release().ignore();
374
375 m_whiteboard = 0;
377 m_schedulerSvc = 0;
378 // m_evtDataSvc = 0;
379
380 m_incidentSvc.release().ignore();
381
382 // Release event selector context
383 if ( m_evtSelector && m_evtContext ) {
384 m_evtSelector->releaseContext(m_evtContext).ignore();
385 // m_evtSelector = releaseInterface(m_evtSelector);
386 delete m_evtContext; m_evtContext = 0;
387 }
388
389
390 if(m_useTools) {
391 tool_iterator firstTool = m_tools.begin();
392 tool_iterator lastTool = m_tools.end();
393 unsigned int toolCtr = 0;
394 ATH_MSG_INFO ( "Summary of AthenaEvtLoopPreSelectTool invocation: (invoked/success/failure)" );
395 ATH_MSG_INFO ( "-----------------------------------------------------" );
396
397 for ( ; firstTool != lastTool; ++firstTool ) {
398 ATH_MSG_INFO ( "{:>2}.) {:.<48} ({:>6}/{:>6}/{:>6})",
399 toolCtr+1,
400 (*firstTool)->name(),
401 m_toolInvoke[toolCtr],
402 m_toolAccept[toolCtr],
403 m_toolReject[toolCtr]);
404 toolCtr++;
405 }
406 }
407 return ( sc.isFailure() || sc2.isFailure() ) ? StatusCode::FAILURE :
408 StatusCode::SUCCESS;
409
410}
411
412//=========================================================================
413// write out the histograms
414//=========================================================================
416
417 StatusCode sc (StatusCode::SUCCESS);
418
419 if ( 0 != m_histoPersSvc && m_writeHists ) {
420 std::vector<DataObject*> objects;
421 sc = m_histoDataMgrSvc->traverseTree( [&objects]( IRegistry* reg, int ) {
422 DataObject* obj = reg->object();
423 if ( !obj || obj->clID() == CLID_StatisticsFile ) return false;
424 objects.push_back( obj );
425 return true;
426 } );
427
428 if ( !sc.isSuccess() ) {
429 ATH_MSG_ERROR ( "Error while traversing Histogram data store" );
430 return sc;
431 }
432
433 if ( objects.size() > 0) {
434 int writeInterval(m_writeInterval.value());
435
436 if ( m_nevt == 1 || force ||
437 (writeInterval != 0 && m_nevt%writeInterval == 0) ) {
438
439 // skip /stat entry!
440 sc = std::accumulate( begin( objects ), end( objects ), sc, [&]( StatusCode isc, auto& i ) {
441 IOpaqueAddress* pAddr = nullptr;
442 StatusCode iret = m_histoPersSvc->createRep( i, pAddr );
443 if ( iret.isFailure() ) return iret;
444 i->registry()->setAddress( pAddr );
445 return isc;
446 } );
447 sc = std::accumulate( begin( objects ), end( objects ), sc, [&]( StatusCode isc, auto& i ) {
448 IRegistry* reg = i->registry();
449 StatusCode iret = m_histoPersSvc->fillRepRefs( reg->address(), i );
450 return iret.isFailure() ? iret : isc;
451 } );
452 if ( ! sc.isSuccess() ) {
453 ATH_MSG_ERROR ( "Error while saving Histograms." );
454 }
455 }
456
457 if (force || (writeInterval != 0 && m_nevt%writeInterval == 0) ) {
458 ATH_MSG_DEBUG ( "committing Histograms" );
459 m_histoPersSvc->conversionSvc()->commitOutput("",true).ignore();
460 }
461 }
462
463 }
464
465 return sc;
466}
467
468//=========================================================================
469// Call sysInitialize() on all algorithms and output streams
470//=========================================================================
472
473 return StatusCode::SUCCESS;
474}
475
476//=========================================================================
477// Run the algorithms for the current event
478//=========================================================================
480
481 return StatusCode::SUCCESS;
482}
483
484
485//=========================================================================
486// executeEvent( EventContext &&ctx )
487//=========================================================================
488StatusCode AthenaHiveEventLoopMgr::executeEvent( EventContext &&ctx )
489{
490
491 // An incident may schedule a stop, in which case is better to exit before the actual execution.
492 if ( m_scheduledStop ) {
493 ATH_MSG_ALWAYS ( "A stopRun was requested by an incidentListener. "
494 "Do not process this event." );
495 m_terminateLoop = true;
496 return (StatusCode::SUCCESS);
497 }
498
499 m_aess->reset( ctx );
500
501 // Make sure context with slot is set before calling es->next().
502 Gaudi::Hive::setCurrentContext ( ctx );
503
504 int declEvtRootSc = declareEventRootAddress( ctx );
505 if (declEvtRootSc == 0 ) { // We ran out of events!
506 m_terminateLoop = true; // we have finished!
507 return StatusCode::SUCCESS;
508 } else if ( declEvtRootSc == -1) {
509 // No std::format for EventContext
510 ATH_MSG_ERROR ( "declareEventRootAddress for context " << ctx << " failed" );
511 return StatusCode::FAILURE;
512 }
513
514 EventID::event_number_t evtNumber = ctx.eventID().event_number();
515 unsigned int conditionsRun = ctx.eventID().run_number();
516 if (!m_evtIdModSvc.isSet()) {
517 const AthenaAttributeList* attr = nullptr;
518 if (m_eventStore->contains<AthenaAttributeList> ("Input") &&
519 m_eventStore->retrieve(attr, "Input").isSuccess()) {
520 if (attr->exists ("ConditionsRun")) {
521 conditionsRun = (*attr)["ConditionsRun"].data<unsigned int>();
522 }
523 }
524 }
526 Gaudi::Hive::setCurrentContext ( ctx );
527
528 // Record EventContext in current whiteboard
529 if (m_eventStore->record(std::make_unique<EventContext> (ctx),
530 "EventContext").isFailure())
531 {
532 ATH_MSG_ERROR ( "Error recording event context object" );
533 return (StatusCode::FAILURE);
534 }
535
537 if (m_firstRun || (m_currentRun != ctx.eventID().run_number()) ) {
538 // Fire EndRun incident unless this is the first run
539 if (!m_firstRun) {
540 // FIXME!!!
541 m_incidentSvc->fireIncident(Incident(name(), IncidentType::EndRun));
542 }
543 m_firstRun=false;
544 m_currentRun = ctx.eventID().run_number();
545
546 ATH_MSG_INFO ( " ===>>> start of run {} <<<===", m_currentRun);
547
548 // FIXME!!! Fire BeginRun "Incident"
549 m_incidentSvc->fireIncident(Incident(name(),IncidentType::BeginRun,ctx));
550
551 }
552
553 bool toolsPassed=true;
554 // CGL: FIXME
555 // bool eventFailed = false;
556
557 // Call any attached tools to reject events early
558 unsigned int toolCtr=0;
559 if(m_useTools) {
560 tool_store::iterator theTool = m_tools.begin();
561 tool_store::iterator lastTool = m_tools.end();
562 while(toolsPassed && theTool!=lastTool )
563 {
564 toolsPassed = (*theTool)->passEvent(ctx.eventID());
565 m_toolInvoke[toolCtr]++;
566 {toolsPassed ? m_toolAccept[toolCtr]++ : m_toolReject[toolCtr]++;}
567 ++toolCtr;
568 ++theTool;
569 }
570 }
571
573 0 == (m_nev % m_eventPrintoutInterval.value()));
574 if (m_doEvtHeartbeat) {
575 if(!m_useTools) {
576 ATH_MSG_INFO ( " ===>>> start processing event #{}, run #{} on slot {}, {} events processed so far <<<===",
577 evtNumber, m_currentRun, ctx.slot(), m_proc);
578 }
579 else {
580 ATH_MSG_INFO ( " ===>>> start processing event #{}, run #{} on slot {}, {} events read and {} events processed so far <<<===",
581 evtNumber, m_currentRun, ctx.slot(), m_nev, m_proc);
582 }
583 }
584
585 if(toolsPassed) {
586
587 if (submitEvent(ctx).isFailure()) {
588 m_whiteboard->clearStore(ctx.slot()).ignore();
589 clearWBSlot(ctx.slot()).ignore();
590 Gaudi::Hive::setCurrentContext(EventContext());
591 return StatusCode::FAILURE;
592 }
593
594 } else {
595 ++m_nev;
596 ++m_nevt;
597 }
598
599 // invalidate thread local context once outside of event execute loop
600 Gaudi::Hive::setCurrentContext( EventContext() );
601
602 return StatusCode::SUCCESS;
603
604}
605
606//=========================================================================
607// implementation of IEventProcessor::executeRun
608//=========================================================================
610{
611
612 StatusCode sc;
613 bool eventfailed = false;
614
615 // Call now the nextEvent(...)
616 sc = nextEvent(maxevt);
617 if (!sc.isSuccess())
618 eventfailed = true;
619
620 if (eventfailed)
621 return StatusCode::FAILURE;
622
623 m_incidentSvc->fireIncident(Incident(name(),"EndEvtLoop"));
624 return StatusCode::SUCCESS;
625}
626//-----------------------------------------------------------------------------
627// Implementation of IEventProcessor::stopRun()
628//-----------------------------------------------------------------------------
630 // Set the application return code
631 SmartIF<IProperty> appmgr(serviceLocator());
632 if(Gaudi::setAppReturnCode(appmgr, Gaudi::ReturnCode::ScheduledStop, true).isFailure()) {
633 ATH_MSG_ERROR ( "Could not set return code of the application ({})",
634 Gaudi::ReturnCode::ScheduledStop);
635 }
636 m_scheduledStop = true;
637 return StatusCode::SUCCESS;
638}
639
640
641//-----------------------------------------------------------------------------
642// Implementation of IService::stop()
643//-----------------------------------------------------------------------------
645{
646 // To enable conditions access during stop we set an invalid EventContext
647 // (no event/slot number) but with valid EventID (and extended EventContext).
648 m_lastEventContext.setValid(false);
649 Gaudi::Hive::setCurrentContext( m_lastEventContext );
650
651 StatusCode sc = MinimalEventLoopMgr::stop();
652
653 // If we exit the event loop early due to an error, some event stores
654 // may not have been cleared. This can lead to segfaults later,
655 // as DetectorStore will usually get finalized before HiveSvcMgr.
656 // So make sure that all stores have been cleared at this point.
657 size_t nslot = m_whiteboard ? m_whiteboard->getNumberOfStores() : 0;
658 for (size_t islot = 0; islot < nslot; islot++) {
659 sc &= clearWBSlot (islot);
660 }
661
662 Gaudi::Hive::setCurrentContext( EventContext() );
663 return sc;
664}
665
666
667//=========================================================================
668// implementation of IAppMgrUI::nextEvent
669//=========================================================================
671{
672 // make nextEvent(0) a dummy call
673 if (0 == maxevt) return StatusCode::SUCCESS;
674
675 // Reset the application return code.
676 Gaudi::setAppReturnCode(m_appMgrProperty, Gaudi::ReturnCode::Success, true).ignore();
677
678 int finishedEvts =0;
679 int createdEvts =0;
680 ATH_MSG_INFO ( "Starting loop on events" );
681
682 // loop over events if the maxevt (received as input) is different from -1.
683 // if evtmax is -1 it means infinite loop (till time limit that is)
684 // int nevt(0);
685 // CGL: FIXME
686 // bool noTimeLimit(false);
687 bool loop_ended=false;
688 StatusCode sc(StatusCode::SUCCESS);
689
690 bool newEvtAllowed = ! m_firstEventAlone;
691
692 // Calculate runtime
693 auto start_time = tbb::tick_count::now();
694 auto secsFromStart = [&start_time]()->double{
695 return (tbb::tick_count::now()-start_time).seconds();
696 };
697
698 while ( !loop_ended and ( (maxevt < 0) or (finishedEvts < maxevt) ) ){
699
700 ATH_MSG_DEBUG ( " -> createdEvts: {}", createdEvts );
701
702 if ( ( !m_terminateLoop ) && // The events are not finished with an unlimited number of events
703 (newEvtAllowed || createdEvts == 0) && // Launch first event alone
704 ( (createdEvts < maxevt) or (maxevt<0) ) && // The events are not finished with a limited number of events
705 (m_schedulerSvc->freeSlots()>0) ){ // There are still free slots in the scheduler
706
707 ATH_MSG_DEBUG ( "createdEvts: {}, freeslots: {}",
708 createdEvts, m_schedulerSvc->freeSlots());
709
710 auto ctx = createEventContext();
711
712 if ( !ctx.valid() ) {
713 sc = StatusCode::FAILURE;
714 } else {
715 sc = executeEvent( std::move(ctx) );
716 }
717
718 if (sc.isFailure()) {
719 ATH_MSG_ERROR ( "Terminating event processing loop due to errors" );
720 loop_ended = true;
721 } else {
722 ++createdEvts;
723 }
724
725 } // end if condition createdEvts < maxevt
726
727 else {
728 // all the events were created but not all finished or the slots were
729 // all busy: the scheduler should finish its job
730
731 ATH_MSG_DEBUG ( "Draining the scheduler" );
732
733 // Pull out of the scheduler the finished events
734 int ir = drainScheduler(finishedEvts);
735 if (ir < 0) {
736 // some sort of error draining scheduler;
737 loop_ended = true;
738 sc = StatusCode::FAILURE;
739 } else if (ir == 0) {
740 // no more events in scheduler. we're done
741 loop_ended = true;
742 sc = StatusCode::SUCCESS;
743 } else {
744 // keep going!
745 }
746 newEvtAllowed = true;
747
748 }
749 } // end main loop on finished events
750
751 ATH_MSG_INFO ( "---> Loop Finished (seconds): {}", secsFromStart() );
752
753
754 return sc;
755
756
757}
758
759
760//=========================================================================
761// Seek to a given event.
762// The event selector must support the IEventSeek interface for this to work.
763//=========================================================================
765{
766 IEvtSelectorSeek* is = dynamic_cast<IEvtSelectorSeek*> (m_evtSelector);
767 if (is == 0) {
768 ATH_MSG_ERROR ( "Seek failed; unsupported by event selector" );
769 return StatusCode::FAILURE;
770 }
771 //cppcheck-suppress nullPointerRedundantCheck
772 if (!m_evtContext) {
773 if (m_evtSelector->createContext(m_evtContext).isFailure()) {
774 ATH_MSG_FATAL ( "Can not create the event selector Context." );
775 return StatusCode::FAILURE;
776 }
777 }
778 //m_evtContext cannot be null if createContext succeeded
779 //cppcheck-suppress nullPointerRedundantCheck
780 StatusCode sc = is->seek (*m_evtContext, evt);
781 if (sc.isSuccess()) {
782 m_incidentSvc->fireIncident(ContextIncident<std::tuple<int, int>>(
783 name(), "SkipEvents", std::tuple<int, int>(m_nevt, evt)));
784 m_nevt = evt;
785 }
786 else {
787 ATH_MSG_ERROR ( "Seek failed." );
788 }
789 return sc;
790}
791
792
793//=========================================================================
794// Return the current event count.
795//=========================================================================
797{
798 return m_nevt;
799}
800
801//=========================================================================
802// Return the collection size
803//=========================================================================
805{
806 IEvtSelectorSeek* cs = dynamic_cast<IEvtSelectorSeek*> (m_evtSelector);
807 if (cs == 0) {
808 ATH_MSG_ERROR ( "Collection size unsupported by event selector" );
809 return -1;
810 }
811 //cppcheck-suppress nullPointerRedundantCheck
812 if (!m_evtContext) {
813 if (m_evtSelector->createContext(m_evtContext).isFailure()) {
814 ATH_MSG_FATAL ( "Can not create the event selector Context." );
815 return -1;
816 }
817 }
818 //m_evtContext cannot be null if createContext succeeded
819 //cppcheck-suppress nullPointerRedundantCheck
820 return cs->size (*m_evtContext);
821}
822
823//=========================================================================
824// Handle Incidents
825//=========================================================================
826void AthenaHiveEventLoopMgr::handle(const Incident& inc)
827{
828
829 if(inc.type() == "EndAlgorithms") {
830 if (!clearStoreOnEndAlgorithms()) return;
831 // Clear the store at the end of the event.
832 // Do it here so that it executes in an algorithm context and thus
833 // multiple stores can be cleared at the same time.
834 StatusCode sc = m_whiteboard->clearStore(inc.context().slot());
835 if( !sc.isSuccess() ) {
836 ATH_MSG_WARNING ( "Clear of Event data store failed" );
837 }
838 return;
839 }
840
841 if(inc.type()!="BeforeFork")
842 return;
843
844 if(!m_evtContext || !m_firstRun) {
845 ATH_MSG_WARNING ( "Skipping BeforeFork handler. Either no event selector is provided or begin run has already passed" );
846 }
847
848 // Initialize Algorithms and Output Streams
849 StatusCode sc = initializeAlgorithms();
850 if(sc.isFailure()) {
851 ATH_MSG_ERROR ( "Failed to initialize Algorithms" );
852 return;
853 }
854
855 // Construct EventInfo
856 sc = m_evtSelector->next(*m_evtContext);
857 if(!sc.isSuccess()) {
858 ATH_MSG_INFO ( "No more events in event selection " );
859 return;
860 }
861 IOpaqueAddress* addr{nullptr};
862 sc = m_evtSelector->createAddress(*m_evtContext, addr);
863 if (sc.isFailure()) {
864 ATH_MSG_ERROR ( "Could not create an IOpaqueAddress" );
865 return;
866 }
867 if (0 != addr) {
868 //create its proxy
869 sc = m_eventStore->recordAddress(addr);
870 if(!sc.isSuccess()) {
871 ATH_MSG_ERROR ( "Error declaring Event object" );
872 return;
873 }
874 }
875
876 if(m_eventStore->loadEventProxies().isFailure()) {
877 ATH_MSG_WARNING ( "Error loading Event proxies" );
878 return;
879 }
880
881 // Retrieve the legacy EventInfo object
882 const EventInfo* pEvent{nullptr};
883 sc = m_eventStore->retrieve(pEvent);
884 if(!sc.isSuccess()) {
885 ATH_MSG_ERROR ( "Unable to retrieve Event root object" );
886 return;
887 }
888
889 m_firstRun=false;
890 m_currentRun = pEvent->event_ID()->run_number();
891
892 // Clear Store
893 sc = m_eventStore->clearStore();
894 if(!sc.isSuccess()) {
895 ATH_MSG_ERROR ( "Clear of Event data store failed" );
896 }
897}
898
899//---------------------------------------------------------------------------
900
902StatusCode AthenaHiveEventLoopMgr::getEventRoot(IOpaqueAddress*& refpAddr) {
903 refpAddr = 0;
904 StatusCode sc = m_evtSelector->next(*m_evtContext);
905 if ( !sc.isSuccess() ) {
906 return sc;
907 }
908 // Create root address and assign address to data service
909 sc = m_evtSelector->createAddress(*m_evtContext,refpAddr);
910 if( !sc.isSuccess() ) {
911 sc = m_evtSelector->next(*m_evtContext);
912 if ( sc.isSuccess() ) {
913 sc = m_evtSelector->createAddress(*m_evtContext,refpAddr);
914 if ( !sc.isSuccess() ) {
915 ATH_MSG_WARNING ( "Error creating IOpaqueAddress." );
916 }
917 }
918 }
919 return sc;
920}
921
922//---------------------------------------------------------------------------
923
925
926 // return codes:
927 // -1 : error
928 // 0 : no more events in selection
929 // 1 : ok
930
931 StatusCode sc(StatusCode::SUCCESS);
932
933 //-----------------------------------------------------------------------
934 // we need an EventInfo Object to fire the incidents.
935 //-----------------------------------------------------------------------
936 std::unique_ptr<const EventInfo> pEvent{};
937 if ( m_evtContext ) {
938 // Deal with the case when an EventSelector is provided
939 //
940 // FIXME: flow control if no more events in selector, etc.
941 //
942
943 IOpaqueAddress* addr{};
944
945 sc = m_evtSelector->next(*m_evtContext);
946
947 if ( !sc.isSuccess() ) {
948 // This is the end of the loop. No more events in the selection
949 ATH_MSG_INFO ( "No more events in event selection " );
950 return 0;
951 }
952
953 if (m_evtSelector->createAddress(*m_evtContext, addr).isFailure()) {
954 ATH_MSG_ERROR ( "Could not create an IOpaqueAddress" );
955 return -1;
956 }
957
958
959 // Most iterators provide the IOA of an event header (EventInfo, DataHeader)
960 if (0 != addr) {
961 //create its proxy
962 sc = m_eventStore->recordAddress(addr);
963 if( !sc.isSuccess() ) {
965 ATH_MSG_WARNING ( "Error declaring Event object" );
966 return 0;
967 }
968 } if ((sc=m_eventStore->loadEventProxies()).isFailure()) {
969 ATH_MSG_ERROR ( "Error loading Event proxies" );
970 return -1;
971 }
972
973 bool consume_modifier_stream = false;
974 // First try to build a legacy EventInfo object from the TAG information
975 // Read the attribute list
976 const AthenaAttributeList* pAttrList = m_eventStore->tryConstRetrieve<AthenaAttributeList>("Input");
977 if ( pAttrList != nullptr && pAttrList->size() > 6 ) { // Try making EventID-only EventInfo object from in-file TAG
978 try {
979 unsigned int runNumber = (*pAttrList)["RunNumber"].data<unsigned int>();
980 unsigned long long eventNumber = (*pAttrList)["EventNumber"].data<unsigned long long>();
981 unsigned int eventTime = (*pAttrList)["EventTime"].data<unsigned int>();
982 unsigned int eventTimeNS = (*pAttrList)["EventTimeNanoSec"].data<unsigned int>();
983 unsigned int lumiBlock = (*pAttrList)["LumiBlockN"].data<unsigned int>();
984 unsigned int bunchId = (*pAttrList)["BunchId"].data<unsigned int>();
985
986 ATH_MSG_DEBUG ( "use TAG with runNumber={}", runNumber );
987 consume_modifier_stream = true;
988 // an option to override primary eventNumber with the secondary one in case of DoubleEventSelector
990 unsigned long long eventNumberSecondary{};
991 if ( !(pAttrList->exists("hasSecondaryInput") && (*pAttrList)["hasSecondaryInput"].data<bool>()) ) {
992 ATH_MSG_FATAL ( "Secondary EventNumber requested, but secondary input does not exist!" );
993 return -1;
994 }
995 if ( pAttrList->exists("EventNumber_secondary") ) {
996 eventNumberSecondary = (*pAttrList)["EventNumber_secondary"].data<unsigned long long>();
997 }
998 else {
999 // try legacy EventInfo if secondary input did not have attribute list
1000 // primary input should not have this EventInfo type
1001 const EventInfo* pEventSecondary = m_eventStore->tryConstRetrieve<EventInfo>();
1002 if (pEventSecondary) {
1003 eventNumberSecondary = pEventSecondary->event_ID()->event_number();
1004 }
1005 else {
1006 ATH_MSG_FATAL ( "Secondary EventNumber requested, but it does not exist!" );
1007 return -1;
1008 }
1009 }
1010 if (eventNumberSecondary != 0) {
1011 m_doEvtHeartbeat = (m_eventPrintoutInterval.value() > 0 &&
1012 0 == (m_nev % m_eventPrintoutInterval.value()));
1013 if (m_doEvtHeartbeat) {
1014 ATH_MSG_INFO ( " ===>>> using secondary event #{} instead of #{} <<<===",
1015 eventNumberSecondary, eventNumber);
1016 }
1017 eventNumber = eventNumberSecondary;
1018 }
1019 }
1020
1021 pEvent = std::make_unique<EventInfo>(
1022 std::make_unique<EventID>(runNumber, eventNumber, eventTime,
1023 eventTimeNS, lumiBlock, bunchId),
1024 nullptr);
1025 } catch (...) {
1026 }
1027 } else if (m_requireInputAttributeList) {
1028 ATH_MSG_FATAL ( "Valid input attribute list required but not present!" );
1029 return -1;
1030 }
1031 // In the case that there is no TAG information
1032 const EventInfo* pEventObserver{pEvent.get()};
1033 if (!pEventObserver) {
1034 // Secondly try to retrieve a legacy EventInfo object from the input file
1035 // Again, m_nevt is incremented after executeEvent in the Hive manager so we don't need a -1
1037 pEventObserver = m_eventStore->tryConstRetrieve<EventInfo>();
1038 if (pEventObserver) {
1039 consume_modifier_stream = false; // stream will already have been consumed during EventInfo TP conversion
1040 ATH_MSG_DEBUG ( "use EventInfo" );
1041 } else {
1042 // Finally try to retrieve an xAOD::EventInfo object from the
1043 // input file and build a legacy EventInfo object from that.
1044 const xAOD::EventInfo* pXEvent{nullptr};
1045 sc = m_eventStore->retrieve(pXEvent);
1046 if( !sc.isSuccess() ) {
1047 ATH_MSG_ERROR ( "Unable to retrieve Event root object" );
1048 return -1;
1049 }
1050 consume_modifier_stream = true;
1051 ATH_MSG_DEBUG ( "use xAOD::EventInfo with runNumber={}", pXEvent->runNumber() );
1052 // Build the old-style Event Info object for those clients that still need it
1053 pEvent = std::make_unique<EventInfo>(
1054 std::make_unique<EventID>(eventIDFromxAOD(pXEvent)),
1055 std::make_unique<EventType>(eventTypeFromxAOD(pXEvent)));
1056 pEventObserver = pEvent.get();
1057 sc = m_eventStore->record(std::move(pEvent), "");
1058 if( !sc.isSuccess() ) {
1059 ATH_MSG_ERROR ( "Error declaring event data object" );
1060 return -1;
1061 }
1062 }
1063 }
1064
1065 modifyEventContext(ctx, *(pEventObserver->event_ID()),
1066 consume_modifier_stream);
1067
1068 }
1069 else {
1070 // No EventSelector is provided, so with no iterator it's up to us
1071 // to create an EventInfo
1072 // first event # == 1
1073 unsigned int runNmb{1}, evtNmb{m_nevt + 1};
1074
1075 // increment the run/lumiBlock number if desired
1076 if (m_flmbi != 0) {
1077 runNmb = m_nevt / m_flmbi + 1;
1078 evtNmb = m_nevt % m_flmbi + 1;
1079 }
1080 auto eid = std::make_unique<EventID> (runNmb,evtNmb, m_timeStamp);
1081 // Change lumiBlock# to match runNumber
1082 eid->set_lumi_block( runNmb );
1083
1085
1086 pEvent = std::make_unique<EventInfo>(std::move(eid),
1087 std::make_unique<EventType>());
1088
1089 bool consume_modifier_stream = true;
1090 // EventInfo TP Conversion not called in this case, so we would
1091 // want to consume the next IoV from the list in the
1092 // EvtIdModifierSvc.
1093 modifyEventContext(ctx,*(pEvent->event_ID()), consume_modifier_stream);
1094
1095 ATH_MSG_DEBUG ( "selecting store: {}", ctx.slot() );
1096
1097 m_whiteboard->selectStore( ctx.slot() ).ignore();
1098
1099 // EventInfo not working with format
1100 ATH_MSG_DEBUG ( "recording EventInfo " << *pEvent->event_ID() << " in "
1101 << m_eventStore->name() );
1102
1103 sc = m_eventStore->record(std::move(pEvent), "McEventInfo");
1104 if( !sc.isSuccess() ) {
1105 ATH_MSG_ERROR ( "Error declaring event data object" );
1106 return -1;
1107 }
1108 }
1109
1110 return 1;
1111}
1112
1113//---------------------------------------------------------------------------
1114
1115void AthenaHiveEventLoopMgr::modifyEventContext(EventContext& ctx, const EventID& eID, bool consume_modifier_stream) {
1116
1117 if(m_evtIdModSvc.isSet()) {
1118 EventID new_eID(eID);
1119 // In Hive EventLoopMgr ctx.evt() gets set to m_nevt and *then* m_nevt is
1120 // incremented later so it's zero-indexed and we don't need to subtract one
1121 m_evtIdModSvc->modify_evtid(new_eID, ctx.evt(), consume_modifier_stream);
1122 if (msgLevel(MSG::DEBUG)) {
1123 unsigned int oldrunnr=eID.run_number();
1124 unsigned int oldLB=eID.lumi_block();
1125 unsigned int oldTS=eID.time_stamp();
1126 unsigned int oldTSno=eID.time_stamp_ns_offset();
1127 ATH_MSG_DEBUG ( "modifyEventContext: use evtIdModSvc runnr={} -> {}",
1128 oldrunnr, new_eID.run_number());
1129 ATH_MSG_DEBUG ( "modifyEventContext: use evtIdModSvc LB={} -> {}",
1130 oldLB, new_eID.lumi_block());
1131 ATH_MSG_DEBUG ( "modifyEventContext: use evtIdModSvc TimeStamp={} -> {}",
1132 oldTS, new_eID.time_stamp());
1133 ATH_MSG_DEBUG ( "modifyEventContext: use evtIdModSvc TimeStamp ns Offset={} -> {}",
1134 oldTSno, new_eID.time_stamp_ns_offset());
1135 }
1136 ctx.setEventID( new_eID );
1137 Atlas::getExtendedEventContext(ctx).setConditionsRun( ctx.eventID().run_number() );
1138 return;
1139 }
1140
1141 ctx.setEventID( eID );
1142}
1143
1144//---------------------------------------------------------------------------
1148
1149EventContext AthenaHiveEventLoopMgr::allocateEventContext(size_t eventNumber) {
1150 const size_t slot = m_whiteboard->allocateStore(eventNumber);
1151 if (slot == std::string::npos) {
1152 ATH_MSG_ERROR("No free whiteboard slot");
1153 return EventContext{};
1154 }
1155 if (m_whiteboard->selectStore(slot).isFailure()) {
1156 ATH_MSG_ERROR("Could not select whiteboard slot {}", slot);
1157 m_whiteboard->freeStore(slot).ignore();
1158 return EventContext{};
1159 }
1160 EventContext ctx{eventNumber, slot};
1162 ctx, Atlas::ExtendedEventContext(m_eventStore->hiveProxyDict()));
1163 return ctx;
1164}
1165
1166StatusCode AthenaHiveEventLoopMgr::submitEvent(EventContext& ctx) {
1167 CHECK(m_conditionsCleaner->event(ctx, true));
1169 m_lastEventContext = ctx;
1170
1171 auto submitted = std::make_unique<EventContext>(ctx);
1172 m_incidentSvc->fireIncident(
1173 Incident(name(), IncidentType::BeginProcessing, ctx));
1174 if (m_schedulerSvc->pushNewEvent(submitted.get()).isFailure()) {
1175 m_incidentSvc->fireIncident(
1176 Incident(name(), IncidentType::EndProcessing, ctx));
1177 ATH_MSG_ERROR("Scheduler refused event {}", ctx.evt());
1178 return StatusCode::FAILURE;
1179 }
1180 submitted.release(); // Ownership transferred to the scheduler.
1181 ++m_nev;
1182 ++m_nevt;
1183 ctx = EventContext();
1184 return StatusCode::SUCCESS;
1185}
1186
1187StatusCode AthenaHiveEventLoopMgr::eventFinished(const EventContext& ctx) {
1188 if (m_aess->eventStatus(ctx) != EventStatus::Success) {
1189 // EventContext not working with std::format
1190 ATH_MSG_ERROR("Failed event " << ctx << " with status "
1191 << m_aess->eventStatus(ctx));
1192 return StatusCode::FAILURE;
1193 }
1194 return StatusCode::SUCCESS;
1195}
1196
1197StatusCode AthenaHiveEventLoopMgr::finishEvent(const EventContext& ctx) {
1198 StatusCode result = m_whiteboard->selectStore(ctx.slot());
1199 if (result.isSuccess()) {
1200 Gaudi::Hive::setCurrentContext(ctx);
1201 result = eventFinished(ctx);
1202 m_incidentSvc->fireIncident(
1203 Incident(name(), IncidentType::EndProcessing, ctx));
1204 } else {
1205 ATH_MSG_ERROR("Could not select completed slot {}", ctx.slot());
1206 }
1207
1208 // Result handling may fail; the event has nevertheless left the scheduler
1209 // and must relinquish its slot. Successful batch jobs already cleared at
1210 // EndAlgorithms, but a failed/stalled graph may never fire that incident.
1211 // Clear failed events here as well so drivers which tolerate failure can
1212 // reuse the slot without stale EventInfo or payload objects.
1214 m_aess->eventStatus(ctx) != EventStatus::Success) {
1215 result &= m_whiteboard->clearStore(ctx.slot());
1216 }
1217 result &= clearWBSlot(ctx.slot());
1218 if (result.isFailure()) {
1219 Gaudi::Hive::setCurrentContext(EventContext());
1220 return result;
1221 }
1222 writeHistograms().ignore();
1223 ++m_proc;
1224 if (m_doEvtHeartbeat) {
1225 const auto n_evt = ctx.eventID().event_number();
1226 const auto n_run = ctx.eventID().run_number();
1227 ATH_MSG_INFO(" ===>>> done processing event #{}, run #{} on slot {}, {} events processed so far <<<===",
1228 n_evt, n_run, ctx.slot(), m_proc);
1229 std::ofstream outfile("eventLoopHeartBeat.txt");
1230 if (!outfile) {
1231 ATH_MSG_ERROR("Unable to open eventLoopHeartBeat.txt");
1232 Gaudi::Hive::setCurrentContext(EventContext());
1233 return StatusCode::FAILURE;
1234 }
1235 std::println(outfile, " done processing event #{}, run #{} {} events read so far <<<===",
1236 n_evt, n_run, m_nev);
1237 }
1238 Gaudi::Hive::setCurrentContext(EventContext());
1239 return StatusCode::SUCCESS;
1240}
1241
1242//---------------------------------------------------------------------------
1243
1244int
1246
1247 StatusCode sc(StatusCode::SUCCESS);
1248
1249 // maybe we can do better
1250 std::vector<std::unique_ptr<EventContext>> finishedEvtContexts;
1251
1252 EventContext* finishedEvtContext(nullptr);
1253
1254 // Here we wait not to loose cpu resources
1255 ATH_MSG_DEBUG ( "drainScheduler: [{}] Waiting for a context", finishedEvts);
1256 sc = m_schedulerSvc->popFinishedEvent(finishedEvtContext);
1257
1258 // We got past it: cache the pointer
1259 if (sc.isSuccess()){
1260 // EventContext not working with std::format
1261 ATH_MSG_DEBUG ( "drainScheduler: scheduler not empty: Context "
1262 << finishedEvtContext );
1263 finishedEvtContexts.emplace_back(finishedEvtContext);
1264 } else{
1265 // no more events left in scheduler to be drained
1266 ATH_MSG_DEBUG ( "drainScheduler: scheduler empty" );
1267 return 0;
1268 }
1269
1270 // Let's see if we can pop other event contexts
1271 while (m_schedulerSvc->tryPopFinishedEvent(finishedEvtContext).isSuccess()){
1272 finishedEvtContexts.emplace_back(finishedEvtContext);
1273 }
1274
1275 // Now we flush them
1276 bool fail(false);
1277 for (auto& thisFinishedEvtContext : finishedEvtContexts){
1278 if (!thisFinishedEvtContext) {
1279 ATH_MSG_FATAL ( "Detected nullptr ctxt while clearing WB!");
1280 fail = true;
1281 continue;
1282 }
1283
1284 if (finishEvent(*thisFinishedEvtContext).isFailure()) {
1285 fail = true;
1286 } else {
1287 ++finishedEvts;
1288 }
1289
1290 }
1291
1292 return ( fail ? -1 : 1 );
1293
1294}
1295
1296//---------------------------------------------------------------------------
1297
1299 return m_whiteboard->freeStore(evtSlot);
1300}
1301//---------------------------------------------------------------------------
#define ATH_MSG_DEBUG(x,...)
#define ATH_MSG_ERROR(x,...)
#define ATH_MSG_ALWAYS(x,...)
#define ATH_MSG_WARNING(x,...)
#define ATH_MSG_VERBOSE(x,...)
#define ATH_MSG_INFO(x,...)
#define ATH_MSG_FATAL(x,...)
The default ATLAS batch event loop manager.
Helpers for checking error return status codes and reporting errors.
#define CHECK(...)
Evaluate an expression and check for errors.
Assign a CLID to EventContext.
This class provides a unique identification for each event, in terms of run/event number and/or a tim...
EventID eventIDFromxAOD(const xAOD::EventInfo *xaod)
Create EventID object from xAOD::EventInfo.
EventType eventTypeFromxAOD(const xAOD::EventInfo *xaod)
Create EventType object from xAOD::EventInfo.
This class provides general information about an event.
This file contains the class definition for the IAthenaEvtLoopPreSelectTool class.
Abstract interface for seeking within an event stream.
Extension to IEvtSelector to allow for seeking.
static Double_t sc
void setProperty(columnar::PythonToolHandle &self, const std::string &key, nb::object value)
An AttributeList represents a logical row of attributes in a metadata table.
AthMessaging(IMessageSvc *msgSvc, const std::string &name)
Constructor.
An AttributeList represents a logical row of attributes in a metadata table.
UnsignedIntegerProperty m_eventPrintoutInterval
IEvtSelector * m_evtSelector
Reference to the Event Selector.
virtual StatusCode stopRun() override
implementation of IEventProcessor::stopRun()
virtual void handle(const Incident &inc) override
IIncidentListenet interfaces.
ServiceHandle< IConversionSvc > IConversionSvc_t
virtual StatusCode initialize() override
implementation of IAppMgrUI::initalize
SmartIF< IHiveWhiteBoard > m_whiteboard
Reference to the Whiteboard interface.
StatusCode getEventRoot(IOpaqueAddress *&refpAddr)
Create event address using event selector.
int drainScheduler(int &finishedEvents)
Drain the scheduler from all actions that may be queued.
number_type m_currentRun
current run number
virtual int size() override
Return the size of the collection.
SmartIF< IAlgExecStateSvc > m_aess
Reference to the Algorithm Execution State Svc.
virtual const std::string & name() const override
std::string m_schedulerName
Name of the scheduler to be used.
UnsignedIntegerProperty m_writeInterval
virtual StatusCode eventFinished(const EventContext &ctx)
Process an event's result and decide whether the driving loop may continue.
EventContext allocateEventContext(size_t eventNumber)
std::string m_whiteboardName
Name of the Whiteboard to be used.
tool_stats m_toolAccept
tool returns StatusCode::SUCCESS counter
virtual StatusCode executeRun(int maxevt) override
implementation of IEventProcessor::executeRun(int maxevt)
tool_store::const_iterator tool_iterator
unsigned int m_nev
events processed
tool_stats m_toolInvoke
tool called counter
IIncidentSvc_t m_incidentSvc
Reference to the incident service.
virtual StatusCode stop() override
implementation of IService::stop
bool m_useSecondaryEventNumber
read event number from secondary input
bool m_requireInputAttributeList
require input attribute list
StatusCode submitEvent(EventContext &ctx)
Submit a recorded context; the scheduler receives its own copy.
SmartIF< IProperty > m_appMgrProperty
Property interface of ApplicationMgr.
StoreGateSvc_t m_eventStore
Reference to StoreGateSvc;.
EvtContext * m_evtContext
Gaudi event selector Context (may be used as a cursor by the evt selector).
virtual StatusCode seek(int evt) override
Seek to a given event.
int declareEventRootAddress(EventContext &)
Declare the root address of the event.
AthenaHiveEventLoopMgr()=delete
virtual StatusCode finalize() override
implementation of IAppMgrUI::finalize
virtual StatusCode executeEvent(EventContext &&ctx) override
implementation of IEventProcessor::executeEvent(void* par)
IDataManagerSvc_t m_histoDataMgrSvc
Reference to the Histogram Data Service.
bool m_scheduledStop
Scheduled stop of event processing.
virtual EventContext createEventContext() override
Create event context.
StatusCode initializeAlgorithms()
Initialize all algorithms and output streams.
virtual ~AthenaHiveEventLoopMgr()
Standard Destructor.
virtual bool clearStoreOnEndAlgorithms() const
Batch jobs clear in the algorithm context; external drivers can retain the store until eventFinished(...
StatusCode clearWBSlot(int evtSlot)
Clear a slot in the WB.
ServiceHandle< Athena::IConditionsCleanerSvc > m_conditionsCleaner
tool_store m_tools
internal tool store
StatusCode finishEvent(const EventContext &ctx)
Finish one scheduler-returned event on the driving thread.
virtual void modifyEventContext(EventContext &ctx, const EventID &eID, bool consume_modifier_stream)
virtual StatusCode writeHistograms(bool force=false)
Dump out histograms as needed.
void setupPreSelectTools(Gaudi::Details::PropertyBase &)
property update handler:sets up the Pre-selection tools
SmartIF< IScheduler > m_schedulerSvc
A shortcut for the scheduler.
virtual int curEvent() const override
Return the current event count.
tool_stats m_toolReject
tool returns StatusCode::FAILURE counter
IEvtIdModifierSvc_t m_evtIdModSvc
SmartIF< IAlgResourcePool > m_algResourcePool
Reference to the Algorithm resource pool.
virtual StatusCode nextEvent(int maxevt) override
implementation of IAppMgrUI::nextEvent. maxevt==0 returns immediately
virtual StatusCode executeAlgorithms()
Run the algorithms for the current event.
void resetTimeout(Timeout &instance)
Reset timeout.
Definition Timeout.h:83
static Timeout & instance()
Get reference to Timeout singleton.
Definition Timeout.h:64
void setConditionsRun(EventIDBase::number_type conditionsRun)
This class provides a unique identification for each event, in terms of run/event number and/or a tim...
Definition EventID.h:34
This class provides general information about an event.
EventID * event_ID()
the unique identification of the event.
Abstract interface for seeking for an event selector.
virtual StatusCode seek(IEvtSelector::Context &c, int evtnum) const =0
Seek to a given event number.
virtual int size(IEvtSelector::Context &c) const =0
Return the size of the collection, or -1 if we can't get the size.
uint32_t runNumber() const
The current event's run number.
int ir
counter of the current depth
Definition fastadd.cxx:49
void setExtendedEventContext(EventContext &ctx, ExtendedEventContext &&ectx)
Move an extended context into a context object.
const ExtendedEventContext & getExtendedEventContext(const EventContext &ctx)
Retrieve an extended context from a context object.
event_number_t eventIndex
EventInfo_v1 EventInfo
Definition of the latest event info version.