|
ATLAS Offline Software
|
Go to the documentation of this file.
5 #define GAUDISVC_EVENTLOOPMGR_CPP
27 #include "GaudiKernel/IAlgManager.h"
28 #include "GaudiKernel/IAlgorithm.h"
29 #include "GaudiKernel/SmartIF.h"
30 #include "GaudiKernel/Incident.h"
31 #include "GaudiKernel/DataObject.h"
32 #include "GaudiKernel/IIncidentSvc.h"
33 #include "GaudiKernel/IEvtSelector.h"
34 #include "GaudiKernel/IDataManagerSvc.h"
35 #include "GaudiKernel/IConversionSvc.h"
36 #include "GaudiKernel/GaudiException.h"
37 #include "GaudiKernel/EventContext.h"
38 #include "GaudiKernel/EventIDBase.h"
39 #include "GaudiKernel/ThreadLocalContext.h"
40 #include "GaudiKernel/Algorithm.h"
44 #include "EventInfo/EventInfo.h"
65 : base_class(nam, svcLoc),
67 m_incidentSvc (
"IncidentSvc", nam ),
68 m_eventStore(
"StoreGateSvc", nam ),
69 m_evtSelector(nullptr), m_evtSelCtxt(nullptr),
70 m_histoDataMgrSvc(
"HistogramDataSvc", nam ),
71 m_histoPersSvc (
"HistogramPersistencySvc", nam ),
72 m_evtIdModSvc (
"", nam ),
74 m_currentRun(0), m_firstRun(true), m_tools(this),
75 m_nevt(0), m_writeHists(false),
76 m_nev(0), m_proc(0), m_useTools(false),
77 m_chronoStatSvc(
"ChronoStatSvc", nam ),
78 m_conditionsCleaner(
"Athena::ConditionsCleanerSvc", nam )
80 declareProperty(
"EvtStore",
m_eventStore,
"The StoreGateSvc instance to interact with for event payload" );
82 "Name of Event Selector to use. If empty string (default) "
83 "take value from ApplicationMgr");
85 "Histogram persistency technology to use: ROOT, HBOOK, NONE. "
86 "By default (empty string) get property value from "
89 "histogram write/update interval");
91 "Controls behaviour of event loop depending on return code of"
92 " Algorithms. 0: all non-SUCCESSes terminate job. "
93 "1: RECOVERABLE skips to next event, FAILURE terminates job "
94 "(DEFAULT). 2: RECOVERABLE and FAILURE skip to next events");
96 "Print event heartbeat printouts every m_eventPrintoutInterval events");
98 "heartbeat time interval is seconds rather than events"
99 "you also get a nice event rate printout then");
100 declareProperty(
"DoLiteLoop",
m_liteLoop=
false,
"Runs the bare minimum during executeEvent");
101 declareProperty(
"UseDetailChronoStat",
m_doChrono=
false);
102 declareProperty(
"ClearStorePolicy",
104 "Configure the policy wrt handling of when the "
105 "'clear-the-event-store' event shall happen: at EndEvent "
106 "(default as it is makes things easier for memory management"
107 ") or at BeginEvent (easier e.g. for interactive use)");
108 declareProperty(
"PreSelectTools",
m_tools,
"AlgTools for event pre-selection")->
111 "Require valid input attribute list to be present");
113 "In case of DoubleEventSelector use event number from secondary input");
115 "ServiceHandle for EvtIdModifierSvc");
117 "List of algorithms/sequences to execute during PreFork");
134 m_autoRetrieveTools =
false;
135 m_checkToolDeps =
false;
138 if ( !
sc.isSuccess() )
140 ATH_MSG_ERROR (
"Failed to initialize base class MinimalEventLoopMgr" );
149 if( !
sc.isSuccess() )
151 ATH_MSG_FATAL (
"Error retrieving pointer to StoreGateSvc" );
160 if( !
sc.isSuccess() )
169 SmartIF<IProperty> prpMgr(serviceLocator());
170 if ( !prpMgr.isValid() )
172 ATH_MSG_FATAL (
"IProperty interface not found in ApplicationMgr." );
173 return StatusCode::FAILURE;
181 if( !
sc.isSuccess() )
188 if ( histPersName.length() == 0 )
190 CHECK(setProperty(prpMgr->getProperty(
"HistogramPersistency")));
193 if ( histPersName !=
"NONE" ) {
198 if( !sc.isSuccess() ) {
199 ATH_MSG_WARNING (
"Histograms cannot not be saved - though required." );
203 if (histPersName ==
"ROOT") {
204 histSvc = serviceLocator()->service(
"RootHistSvc");
205 }
else if ( histPersName ==
"HBOOK" ) {
206 histSvc = serviceLocator()->service(
"HbookHistSvc");
210 ATH_MSG_ERROR (
"could not locate actual Histogram persistency service" );
212 const Gaudi::Details::PropertyBase &prop =
histSvc->getProperty(
"OutputFile");
215 const StringProperty &sprop =
dynamic_cast<const StringProperty&
>( prop );
220 ATH_MSG_VERBOSE (
"could not dcast OutputFile property to a StringProperty."
221 <<
" Need to fix Gaudi." );
223 val = prop.toString();
228 val !=
"UndefinedROOTOutputFileName" &&
229 val !=
"UndefinedHbookOutputFileName" ) {
243 ATH_MSG_DEBUG (
"EventID modifier Service not set. No run number, ... overrides will be applied." );
246 ATH_MSG_INFO (
"Could not find EventID modifier Service. No run number, ... overrides will be applied." );
255 sc = setProperty(prpMgr->getProperty(
"EvtSel"));
260 SmartIF<IEvtSelector> theEvtSel{serviceLocator()->service(
selName )};
269 return StatusCode::FAILURE;
271 if (msgLevel(MSG::INFO)) {
272 SmartIF<INamedInterface> named(theEvtSel);
274 ATH_MSG_INFO (
"Setup EventSelector service " << named->name( )
278 }
else if (
sc.isFailure()) {
281 return StatusCode::FAILURE;
291 return StatusCode::FAILURE;
295 m_aess = serviceLocator()->service(
"AlgExecStateSvc");
298 return StatusCode::FAILURE;
322 if ( policyName !=
"BeginEvent" &&
323 policyName !=
"EndEvent" ) {
326 <<
"] for the 'ClearStore-policy !"
328 <<
"Valid values are: BeginEvent, EndEvent"
330 throw GaudiException(
"Can not setup 'ClearStore'-policy",
332 StatusCode::FAILURE);
354 unsigned int toolCtr = 0;
355 for ( ; firstTool != lastTool; ++firstTool )
376 if (
sc.isFailure()) {
381 if (sc2.isFailure()) {
397 unsigned int toolCtr = 0;
398 ATH_MSG_INFO (
"Summary of AthenaEvtLoopPreSelectTool invocation: (invoked/success/failure)" );
399 ATH_MSG_INFO (
"-----------------------------------------------------" );
401 for ( ; firstTool != lastTool; ++firstTool ) {
402 ATH_MSG_INFO ( std::setw(2) << std::setiosflags(std::ios_base::right)
403 << toolCtr+1 <<
".) " << std::resetiosflags(std::ios_base::right)
404 << std::setw(48) << std::setfill(
'.')
405 << std::setiosflags(std::ios_base::left)
406 << (*firstTool)->name() << std::resetiosflags(std::ios_base::left)
409 << std::setw(6) << std::setiosflags(std::ios_base::right)
420 return (
sc.isFailure() || sc2.isFailure() ) ? StatusCode::FAILURE :
433 std::vector<DataObject*>
objects;
435 DataObject*
obj = reg->object();
436 if ( !
obj ||
obj->clID() == CLID_StatisticsFile )
return false;
441 if ( !
sc.isSuccess() ) {
442 ATH_MSG_ERROR (
"Error while traversing Histogram data store" );
450 (writeInterval != 0 &&
m_nevt%writeInterval == 0) ) {
454 IOpaqueAddress* pAddr =
nullptr;
456 if ( iret.isFailure() )
return iret;
457 i->registry()->setAddress( pAddr );
461 IRegistry* reg =
i->registry();
463 return iret.isFailure() ? iret : isc;
465 if ( !
sc.isSuccess() ) {
470 if (
force || (writeInterval != 0 &&
m_nevt%writeInterval == 0) ) {
489 for ( ita = m_topAlgList.begin(); ita != m_topAlgList.end(); ++ita )
502 for (ita = m_outStreamList.begin(); ita != m_outStreamList.end(); ++ita )
505 if(
sc.isFailure() ) {
513 return StatusCode::SUCCESS;
523 ita != m_topAlgList.end();
530 m_aess->algExecState(*ita,ctx).setState(AlgExecState::State::Done,
sc);
531 if ( !
sc.isSuccess() ) {
533 << (*ita)->name() <<
" failed with StatusCode::" <<
sc );
538 return StatusCode::SUCCESS;
549 m_incidentSvc->fireIncident(Incident(
"BeginEvent",IncidentType::BeginEvent));
551 m_incidentSvc->fireIncident(Incident(
"EndEvent",IncidentType::EndEvent));
573 bool toolsPassed=
true;
574 bool eventFailed =
false;
576 unsigned int toolCtr=0;
581 while(toolsPassed && theTool!=lastTool )
583 toolsPassed = (*theTool)->passEvent(ctx.eventID());
592 uint64_t evtNumber = ctx.eventID().event_number();
596 if (doEvtHeartbeat) {
598 ATH_MSG_INFO (
" ===>>> start processing event #" << evtNumber <<
", run #" <<
m_currentRun <<
" " <<
m_nev <<
" events processed so far <<<===" );
607 <<
" events processed so far <<<===" );
617 if ( m_scheduledStop ) {
618 ATH_MSG_ALWAYS (
"A stopRun was requested by an incidentListener. "
619 <<
"Do not process this event." );
620 return (StatusCode::SUCCESS);
628 if(!
sc.isSuccess()) {
630 m_aess->setEventStatus( EventStatus::AlgFail, ctx );
637 <<
"Skipping remaining algorithms." << std::endl
638 <<
"\tNo output will be written for this event, "
639 <<
"but job will continue to next event" );
645 ATH_MSG_INFO (
"Skipping remaining algorithms." << std::endl
646 <<
"\tNo output will be written for this event, "
647 <<
"but job will continue to next event" );
653 m_aess->setEventStatus( EventStatus::Success, ctx );
657 ito != m_outStreamList.end(); ++ito ) {
658 sc = (*ito)->sysExecute(ctx);
659 if( !
sc.isSuccess() ) {
673 if (doEvtHeartbeat) {
677 <<
" " <<
m_nev <<
" events processed so far <<<===");
681 <<
" events processed so far <<<===");
683 std::ofstream
outfile(
"eventLoopHeartBeat.txt");
688 <<
" " <<
m_nev <<
" events read so far <<<===" << std::endl;
697 return eventFailed?StatusCode::FAILURE:StatusCode::SUCCESS;
706 if (!(this->
nextEvent(maxevt)).isSuccess())
return StatusCode::FAILURE;
710 return StatusCode::SUCCESS;
719 if (0 == maxevt)
return StatusCode::SUCCESS;
721 static int total_nevt = 0;
745 while(maxevt == -1 ||
m_nevt < maxevt) {
751 if ( m_scheduledStop ) {
752 m_scheduledStop =
false;
753 ATH_MSG_ALWAYS (
"A stopRun was requested. Terminating event loop." );
766 if( !
sc.isSuccess() ) {
781 IOpaqueAddress* addr =
nullptr;
785 if ( !
sc.isSuccess() )
789 sc = StatusCode::SUCCESS;
800 if (
nullptr != addr) {
803 if( !
sc.isSuccess() ) {
808 if ((
sc=
eventStore()->loadEventProxies()).isFailure()) {
821 if( !
sc.isSuccess() )
823 ATH_MSG_ERROR (
"Terminating event processing loop due to errors" );
832 if( !
sc.isSuccess() ) {
856 ATH_MSG_ERROR (
"Seek failed; unsupported by event selector" );
857 return StatusCode::FAILURE;
862 ATH_MSG_FATAL (
"Can not create the event selector Context." );
863 return StatusCode::FAILURE;
869 if (
sc.isSuccess()) {
894 ATH_MSG_ERROR (
"Collection size unsupported by event selector" );
900 ATH_MSG_FATAL (
"Can not create the event selector Context." );
914 if(inc.type()!=
"BeforeFork")
918 ATH_MSG_WARNING (
"Skipping BeforeFork handler. Begin run has already passed" );
930 ATH_MSG_WARNING (
"Skipping BeforeFork handler. No event selector is provided" );
935 IOpaqueAddress* addr =
nullptr;
937 if(!
sc.isSuccess()) {
942 if (
sc.isFailure()) {
946 if (
nullptr != addr) {
949 if(!
sc.isSuccess()) {
955 if(
eventStore()->loadEventProxies().isFailure()) {
967 throw std::runtime_error(
"Error installing event context object" );
976 ATH_MSG_ERROR (
"Unable to execute requested algorithms/sequences during PreFork!" );
984 if(!
sc.isSuccess()) {
994 IAlgManager* algMgr = Gaudi::svcLocator()->as<IAlgManager>();
998 SmartIF<IAlgorithm>&
alg = algMgr->algorithm(
name,
false);
1001 sc &=
alg->sysExecute(ctx);
1020 std::unique_ptr<EventInfo> eventInfo;
1022 unsigned int conditionsRun = EventIDBase::UNDEFNUM;
1023 bool consume_modifier_stream =
false;
1030 if (pAttrList !=
nullptr && pAttrList->size() > 6) {
1033 unsigned int runNumber = (*pAttrList)[
"RunNumber"].data<
unsigned int>();
1034 unsigned long long eventNumber = (*pAttrList)[
"EventNumber"].data<
unsigned long long>();
1035 unsigned int eventTime = (*pAttrList)[
"EventTime"].data<
unsigned int>();
1036 unsigned int eventTimeNS = (*pAttrList)[
"EventTimeNanoSec"].data<
unsigned int>();
1037 unsigned int lumiBlock = (*pAttrList)[
"LumiBlockN"].data<
unsigned int>();
1038 unsigned int bunchId = (*pAttrList)[
"BunchId"].data<
unsigned int>();
1041 consume_modifier_stream =
true;
1045 unsigned long long eventNumberSecondary{};
1046 if (!(pAttrList->exists(
"hasSecondaryInput") &&
1047 (*pAttrList)[
"hasSecondaryInput"].data<
bool>())) {
1048 ATH_MSG_FATAL(
"Secondary EventNumber requested, but secondary input does not exist!");
1049 return StatusCode::FAILURE;
1051 if (pAttrList->exists(
"EventNumber_secondary")) {
1052 eventNumberSecondary = (*pAttrList)[
"EventNumber_secondary"].data<
unsigned long long>();
1057 if (pEventSecondary) {
1058 eventNumberSecondary = pEventSecondary->
event_ID()->event_number();
1060 ATH_MSG_FATAL(
"Secondary EventNumber requested, but it does not exist!");
1061 return StatusCode::FAILURE;
1064 if (eventNumberSecondary != 0) {
1067 if (doEvtHeartbeat) {
1069 << eventNumberSecondary <<
" instead of #"
1076 eventInfo = std::make_unique<EventInfo>(
1080 eventID = *(eventInfo->
event_ID());
1082 if (!
m_evtIdModSvc.isSet() && pAttrList->exists(
"ConditionsRun")) {
1083 conditionsRun = (*pAttrList)[
"ConditionsRun"].data<
unsigned int>();
1103 ATH_MSG_FATAL(
"Valid input attribute list required but not present!");
1104 return StatusCode::FAILURE;
1118 if (xAODEvent ==
nullptr) {
1119 ATH_MSG_ERROR(
"Failed to get EventID from input. Tried old-style and xAOD::EventInfo");
1120 return StatusCode::FAILURE;
1124 eventInfo = std::make_unique<EventInfo>(
1127 eventID = *(eventInfo->
event_ID());
1129 if (!
sc.isSuccess()) {
1131 return StatusCode::FAILURE;
1138 eventInfo = std::make_unique<EventInfo>(
1139 std::make_unique<EventID>(1,
m_nevt, 0), std::make_unique<EventType>());
1141 eventID = *(eventInfo->
event_ID());
1143 if (!
sc.isSuccess()) {
1145 return (StatusCode::FAILURE);
1149 ctx.setEventID( eventID );
1155 Gaudi::Hive::setCurrentContext( ctx );
1158 if (
eventStore()->record(std::make_unique<EventContext> ( ctx ),
1159 "EventContext").isFailure())
1162 return (StatusCode::FAILURE);
1165 return StatusCode::SUCCESS;
1176 unsigned int oldrunnr=eID.run_number();
1177 unsigned int oldLB=eID.lumi_block();
1178 unsigned int oldTS=eID.time_stamp();
1179 unsigned int oldTSno=eID.time_stamp_ns_offset();
1180 ATH_MSG_DEBUG (
"modifyEventContext: use evtIdModSvc runnr=" << oldrunnr <<
" -> " << new_eID.run_number() );
1181 ATH_MSG_DEBUG (
"modifyEventContext: use evtIdModSvc LB=" << oldLB <<
" -> " << new_eID.lumi_block() );
1182 ATH_MSG_DEBUG (
"modifyEventContext: use evtIdModSvc TimeStamp=" << oldTS <<
" -> " << new_eID.time_stamp() );
1183 ATH_MSG_DEBUG (
"modifyEventContext: use evtIdModSvc TimeStamp ns Offset=" << oldTSno <<
" -> " << new_eID.time_stamp_ns_offset() );
1185 ctx.setEventID( new_eID );
1190 ctx.setEventID( eID );
JetConstituentVector::iterator iterator
StatusCode record(T *p2BRegistered, const TKEY &key)
Record an object with a key.
virtual int curEvent() const
Return the current event count.
virtual int size()
Return the size of the collection.
IEvtIdModifierSvc_t m_evtIdModSvc
def finalize(self)
_info( "content of StoreGate..." ) self.sg.dump()
tool_stats m_toolAccept
tool returns StatusCode::SUCCESS counter
tool_store m_tools
internal tool store
IEvtSelector::Context * m_evtSelCtxt
Gaudi EventSelector Context (may be used as a cursor by the evt selector)
Abstract interface for seeking within an event stream.
StoreGateSvc * eventStore() const
virtual const std::string & name() const
virtual StatusCode initialize()
implementation of IAppMgrUI::initalize
ServiceHandle< Athena::IConditionsCleanerSvc > m_conditionsCleaner
bool accumulate(AccumulateMap &map, std::vector< module_t > const &modules, FPGATrackSimMatrixAccumulator const &acc)
Accumulates an accumulator (e.g.
The default ATLAS batch event loop manager.
StringProperty m_histPersName
ClearStorePolicy::Type clearStorePolicy(const std::string &policyName, MsgStream &msg)
returns the enum-version of the policy (by name)
virtual StatusCode executeRun(int maxevt)
implementation of IEventProcessor::executeRun(int maxevt)
IEvtSelector * m_evtSelector
Reference to the Event Selector.
This class provides general information about an event. It extends EventInfo with a list of sub-evts ...
IntegerProperty m_failureMode
#define ATH_MSG_VERBOSE(x)
IIncidentSvc_t m_incidentSvc
Reference to the incident service.
Assign a CLID to EventContext.
StoreGateSvc_t m_eventStore
Reference to StoreGateSvc;.
uint32_t runNumber() const
The current event's run number.
IntegerProperty m_writeInterval
number_type m_currentRun
current run number
unsigned int m_nev
events processed
virtual ~AthenaEventLoopMgr()
Standard Destructor.
virtual void modifyEventContext(EventContext &ctx, const EventID &eID, bool consume_modifier_stream)
StatusCode installEventContext(EventContext &ctx)
ATLAS_NO_CHECK_FILE_THREAD_SAFETY
const ExtendedEventContext & getExtendedEventContext(const EventContext &ctx)
Retrieve an extended context from a context object.
virtual StatusCode seek(IEvtSelector::Context &c, int evtnum) const =0
Seek to a given event number.
virtual StatusCode nextEvent(int maxevt)
implementation of IAppMgrUI::nextEvent. maxevt==0 returns immediately
The Athena Transient Store API.
StatusCode initializeAlgorithms()
Initialize all algorithms and output streams.
This class provides a unique identification for each event, in terms of run/event number and/or a tim...
ServiceHandle< IConversionSvc > IConversionSvc_t
StatusCode execAtPreFork(const EventContext &ctx) const
Execute certain algorithms/sequences in PreFork.
void handle(const Incident &inc)
IIncidentListenet interfaces.
bool m_requireInputAttributeList
require input attribute list
IConversionSvc_t m_histoPersSvc
::StatusCode StatusCode
StatusCode definition for legacy code.
SmartIF< IAlgExecStateSvc > m_aess
Reference to the Algorithm Execution State Svc.
EventID * event_ID()
the unique identification of the event.
virtual int size(IEvtSelector::Context &c) const =0
Return the size of the collection, or -1 if we can't get the size.
virtual StatusCode seek(int evt)
Seek to a given event.
StringArrayProperty m_execAtPreFork
Class to provide easy MsgStream access and capabilities.
#define ATH_MSG_ALWAYS(x)
virtual StatusCode finalize()
implementation of IAppMgrUI::finalize
An AttributeList represents a logical row of attributes in a metadata table. The name and type of eac...
#define CHECK(...)
Evaluate an expression and check for errors.
UnsignedIntegerProperty m_eventPrintoutInterval
virtual StatusCode clearStore(bool forceRemove=false) override final
clear DataStore contents: called by the event loop mgrs
static Timeout & instance()
Get reference to Timeout singleton.
virtual StatusCode executeEvent(EventContext &&ctx)
implementation of IEventProcessor::executeEvent(EventContext&& ctx)
tool_stats m_toolInvoke
tool called counter
void setConditionsRun(EventIDBase::number_type conditionsRun)
tool_stats m_toolReject
tool returns StatusCode::FAILURE counter
void setupPreSelectTools(Gaudi::Details::PropertyBase &)
property update handler:sets up the Pre-selection tools
StringProperty m_clearStorePolicy
Helpers for checking error return status codes and reporting errors.
This class provides general information about an event. Event information is provided by the accessor...
ServiceHandle< IChronoStatSvc > m_chronoStatSvc
StatusCode recordAddress(const std::string &skey, IOpaqueAddress *pAddress, bool clearAddressFlag=true)
Create a proxy object using an IOpaqueAddress and a transient key.
const T * tryConstRetrieve() const
An AttributeList represents a logical row of attributes in a metadata table. The name and type of eac...
Class describing the basic event information.
bool m_useSecondaryEventNumber
read event number from secondary input
void setClearStorePolicy(Gaudi::Details::PropertyBase &clearStorePolicy)
property update handler:set the clear-store policy value and check its value.
def time(flags, cells_name, *args, **kw)
unsigned int m_intervalInSeconds
#define ATH_MSG_WARNING(x)
EventID eventIDFromxAOD(const xAOD::EventInfo *xaod)
Create EventID object from xAOD::EventInfo.
This class provides a unique identification for each event, in terms of run/event number and/or a tim...
virtual StatusCode writeHistograms(bool force=false)
Dump out histograms as needed.
tool_store::const_iterator tool_iterator
AthenaEventLoopMgr()
no implementation
void resetTimeout(Timeout &instance)
Reset timeout.
Define macros for attributes used to control the static checker.
EventType eventTypeFromxAOD(const xAOD::EventInfo *xaod)
Create EventType object from xAOD::EventInfo.
virtual StatusCode executeAlgorithms(const EventContext &)
Run the algorithms for the current event.
void setExtendedEventContext(EventContext &ctx, ExtendedEventContext &&ectx)
Move an extended context into a context object.
IDataManagerSvc_t m_histoDataMgrSvc
Reference to the Histogram Data Service.
Abstract interface for seeking for an event selector.
thread_local event_number_t eventIndex