 |
ATLAS Offline Software
|
Go to the documentation of this file.
5 #define GAUDISVC_EVENTLOOPMGR_CPP
24 #include "GaudiKernel/IAlgManager.h"
25 #include "GaudiKernel/IAlgorithm.h"
26 #include "GaudiKernel/SmartIF.h"
27 #include "GaudiKernel/Incident.h"
28 #include "GaudiKernel/DataObject.h"
29 #include "GaudiKernel/IIncidentSvc.h"
30 #include "GaudiKernel/IEvtSelector.h"
31 #include "GaudiKernel/IDataManagerSvc.h"
32 #include "GaudiKernel/IConversionSvc.h"
33 #include "GaudiKernel/GaudiException.h"
34 #include "GaudiKernel/EventContext.h"
35 #include "GaudiKernel/EventIDBase.h"
36 #include "GaudiKernel/ThreadLocalContext.h"
37 #include "GaudiKernel/Algorithm.h"
41 #include "EventInfo/EventInfo.h"
62 : base_class(nam, svcLoc),
64 m_incidentSvc (
"IncidentSvc", nam ),
65 m_eventStore(
"StoreGateSvc", nam ),
66 m_evtSelector(nullptr), m_evtSelCtxt(nullptr),
67 m_histoDataMgrSvc(
"HistogramDataSvc", nam ),
68 m_histoPersSvc (
"HistogramPersistencySvc", nam ),
69 m_evtIdModSvc (
"", nam ),
71 m_currentRun(0), m_firstRun(true), m_tools(this),
72 m_nevt(0), m_writeHists(false),
73 m_nev(0), m_proc(0), m_useTools(false),
74 m_chronoStatSvc(
"ChronoStatSvc", nam ),
75 m_conditionsCleaner(
"Athena::ConditionsCleanerSvc", nam )
77 declareProperty(
"EvtStore",
m_eventStore,
"The StoreGateSvc instance to interact with for event payload" );
79 "Name of Event Selector to use. If empty string (default) "
80 "take value from ApplicationMgr");
82 "Histogram persistency technology to use: ROOT, HBOOK, NONE. "
83 "By default (empty string) get property value from "
86 "histogram write/update interval");
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");
93 "Print event heartbeat printouts every m_eventPrintoutInterval events");
95 "heartbeat time interval is seconds rather than events"
96 "you also get a nice event rate printout then");
97 declareProperty(
"DoLiteLoop",
m_liteLoop=
false,
"Runs the bare minimum during executeEvent");
98 declareProperty(
"UseDetailChronoStat",
m_doChrono=
false);
99 declareProperty(
"ClearStorePolicy",
101 "Configure the policy wrt handling of when the "
102 "'clear-the-event-store' event shall happen: at EndEvent "
103 "(default as it is makes things easier for memory management"
104 ") or at BeginEvent (easier e.g. for interactive use)");
105 declareProperty(
"PreSelectTools",
m_tools,
"AlgTools for event pre-selection")->
108 "Require valid input attribute list to be present");
110 "In case of DoubleEventSelector use event number from secondary input");
112 "ServiceHandle for EvtIdModifierSvc");
114 "List of algorithms/sequences to execute during PreFork");
131 m_autoRetrieveTools =
false;
132 m_checkToolDeps =
false;
135 if ( !
sc.isSuccess() )
137 ATH_MSG_ERROR (
"Failed to initialize base class MinimalEventLoopMgr" );
146 if( !
sc.isSuccess() )
148 ATH_MSG_FATAL (
"Error retrieving pointer to StoreGateSvc" );
157 if( !
sc.isSuccess() )
166 SmartIF<IProperty> prpMgr(serviceLocator());
167 if ( !prpMgr.isValid() )
169 ATH_MSG_FATAL (
"IProperty interface not found in ApplicationMgr." );
170 return StatusCode::FAILURE;
178 if( !
sc.isSuccess() )
185 if ( histPersName.length() == 0 )
190 if ( histPersName !=
"NONE" ) {
195 if( !sc.isSuccess() ) {
196 ATH_MSG_WARNING (
"Histograms cannot not be saved - though required." );
200 if (histPersName ==
"ROOT") {
201 histSvc = serviceLocator()->service(
"RootHistSvc");
202 }
else if ( histPersName ==
"HBOOK" ) {
203 histSvc = serviceLocator()->service(
"HbookHistSvc");
207 ATH_MSG_ERROR (
"could not locate actual Histogram persistency service" );
209 const Gaudi::Details::PropertyBase &prop =
histSvc->getProperty(
"OutputFile");
212 const StringProperty &sprop =
dynamic_cast<const StringProperty&
>( prop );
217 ATH_MSG_VERBOSE (
"could not dcast OutputFile property to a StringProperty."
218 <<
" Need to fix Gaudi." );
220 val = prop.toString();
225 val !=
"UndefinedROOTOutputFileName" &&
226 val !=
"UndefinedHbookOutputFileName" ) {
240 ATH_MSG_DEBUG (
"EventID modifier Service not set. No run number, ... overrides will be applied." );
243 ATH_MSG_INFO (
"Could not find EventID modifier Service. No run number, ... overrides will be applied." );
257 SmartIF<IEvtSelector> theEvtSel{serviceLocator()->service(
selName )};
266 return StatusCode::FAILURE;
269 SmartIF<INamedInterface> named(theEvtSel);
271 ATH_MSG_INFO (
"Setup EventSelector service " << named->name( )
275 }
else if (
sc.isFailure()) {
278 return StatusCode::FAILURE;
288 return StatusCode::FAILURE;
292 m_aess = serviceLocator()->service(
"AlgExecStateSvc");
295 return StatusCode::FAILURE;
319 if ( policyName !=
"BeginEvent" &&
320 policyName !=
"EndEvent" ) {
323 <<
"] for the 'ClearStore-policy !"
325 <<
"Valid values are: BeginEvent, EndEvent"
327 throw GaudiException(
"Can not setup 'ClearStore'-policy",
329 StatusCode::FAILURE);
351 unsigned int toolCtr = 0;
352 for ( ; firstTool != lastTool; ++firstTool )
373 if (
sc.isFailure()) {
378 if (sc2.isFailure()) {
394 unsigned int toolCtr = 0;
395 ATH_MSG_INFO (
"Summary of AthenaEvtLoopPreSelectTool invocation: (invoked/success/failure)" );
396 ATH_MSG_INFO (
"-----------------------------------------------------" );
398 for ( ; firstTool != lastTool; ++firstTool ) {
399 ATH_MSG_INFO ( std::setw(2) << std::setiosflags(std::ios_base::right)
400 << toolCtr+1 <<
".) " << std::resetiosflags(std::ios_base::right)
401 << std::setw(48) << std::setfill(
'.')
402 << std::setiosflags(std::ios_base::left)
403 << (*firstTool)->name() << std::resetiosflags(std::ios_base::left)
406 << std::setw(6) << std::setiosflags(std::ios_base::right)
417 return (
sc.isFailure() || sc2.isFailure() ) ? StatusCode::FAILURE :
430 std::vector<DataObject*>
objects;
432 DataObject*
obj = reg->object();
433 if ( !
obj ||
obj->clID() == CLID_StatisticsFile )
return false;
438 if ( !
sc.isSuccess() ) {
439 ATH_MSG_ERROR (
"Error while traversing Histogram data store" );
447 (writeInterval != 0 &&
m_nevt%writeInterval == 0) ) {
451 IOpaqueAddress* pAddr =
nullptr;
453 if ( iret.isFailure() )
return iret;
454 i->registry()->setAddress( pAddr );
458 IRegistry* reg =
i->registry();
460 return iret.isFailure() ? iret : isc;
462 if ( !
sc.isSuccess() ) {
467 if (
force || (writeInterval != 0 &&
m_nevt%writeInterval == 0) ) {
486 for ( ita = m_topAlgList.begin(); ita != m_topAlgList.end(); ++ita )
499 for (ita = m_outStreamList.begin(); ita != m_outStreamList.end(); ++ita )
502 if(
sc.isFailure() ) {
510 return StatusCode::SUCCESS;
520 ita != m_topAlgList.end();
527 m_aess->algExecState(*ita,ctx).setState(AlgExecState::State::Done,
sc);
528 if ( !
sc.isSuccess() ) {
530 << (*ita)->name() <<
" failed with StatusCode::" <<
sc );
535 return StatusCode::SUCCESS;
546 m_incidentSvc->fireIncident(Incident(
"BeginEvent",IncidentType::BeginEvent));
548 m_incidentSvc->fireIncident(Incident(
"EndEvent",IncidentType::EndEvent));
570 bool toolsPassed=
true;
571 bool eventFailed =
false;
573 unsigned int toolCtr=0;
578 while(toolsPassed && theTool!=lastTool )
580 toolsPassed = (*theTool)->passEvent(ctx.eventID());
589 uint64_t evtNumber = ctx.eventID().event_number();
593 if (doEvtHeartbeat) {
595 ATH_MSG_INFO (
" ===>>> start processing event #" << evtNumber <<
", run #" <<
m_currentRun <<
" " <<
m_nev <<
" events processed so far <<<===" );
604 <<
" events processed so far <<<===" );
614 if ( m_scheduledStop ) {
615 ATH_MSG_ALWAYS (
"A stopRun was requested by an incidentListener. "
616 <<
"Do not process this event." );
617 return (StatusCode::SUCCESS);
625 if(!
sc.isSuccess()) {
627 m_aess->setEventStatus( EventStatus::AlgFail, ctx );
634 <<
"Skipping remaining algorithms." << std::endl
635 <<
"\tNo output will be written for this event, "
636 <<
"but job will continue to next event" );
642 ATH_MSG_INFO (
"Skipping remaining algorithms." << std::endl
643 <<
"\tNo output will be written for this event, "
644 <<
"but job will continue to next event" );
650 m_aess->setEventStatus( EventStatus::Success, ctx );
654 ito != m_outStreamList.end(); ++ito ) {
655 sc = (*ito)->sysExecute(ctx);
656 if( !
sc.isSuccess() ) {
670 if (doEvtHeartbeat) {
674 <<
" " <<
m_nev <<
" events processed so far <<<===");
678 <<
" events processed so far <<<===");
680 std::ofstream
outfile(
"eventLoopHeartBeat.txt");
685 <<
" " <<
m_nev <<
" events read so far <<<===" << std::endl;
694 return eventFailed?StatusCode::FAILURE:StatusCode::SUCCESS;
703 if (!(this->
nextEvent(maxevt)).isSuccess())
return StatusCode::FAILURE;
707 return StatusCode::SUCCESS;
716 if (0 == maxevt)
return StatusCode::SUCCESS;
718 static std::atomic<int> total_nevt = 0;
742 while(maxevt == -1 ||
m_nevt < maxevt) {
748 if ( m_scheduledStop ) {
749 m_scheduledStop =
false;
750 ATH_MSG_ALWAYS (
"A stopRun was requested. Terminating event loop." );
763 if( !
sc.isSuccess() ) {
778 IOpaqueAddress* addr =
nullptr;
782 if ( !
sc.isSuccess() )
786 sc = StatusCode::SUCCESS;
797 if (
nullptr != addr) {
800 if( !
sc.isSuccess() ) {
805 if ((
sc=
eventStore()->loadEventProxies()).isFailure()) {
818 if( !
sc.isSuccess() )
820 ATH_MSG_ERROR (
"Terminating event processing loop due to errors" );
829 if( !
sc.isSuccess() ) {
853 ATH_MSG_ERROR (
"Seek failed; unsupported by event selector" );
854 return StatusCode::FAILURE;
859 ATH_MSG_FATAL (
"Can not create the event selector Context." );
860 return StatusCode::FAILURE;
866 if (
sc.isSuccess()) {
891 ATH_MSG_ERROR (
"Collection size unsupported by event selector" );
897 ATH_MSG_FATAL (
"Can not create the event selector Context." );
911 if(inc.type()!=
"BeforeFork")
915 ATH_MSG_WARNING (
"Skipping BeforeFork handler. Begin run has already passed" );
927 ATH_MSG_WARNING (
"Skipping BeforeFork handler. No event selector is provided" );
932 IOpaqueAddress* addr =
nullptr;
934 if(!
sc.isSuccess()) {
939 if (
sc.isFailure()) {
943 if (
nullptr != addr) {
946 if(!
sc.isSuccess()) {
952 if(
eventStore()->loadEventProxies().isFailure()) {
964 throw std::runtime_error(
"Error installing event context object" );
973 ATH_MSG_ERROR (
"Unable to execute requested algorithms/sequences during PreFork!" );
981 if(!
sc.isSuccess()) {
991 IAlgManager* algMgr = Gaudi::svcLocator()->as<IAlgManager>();
995 SmartIF<IAlgorithm>&
alg = algMgr->algorithm(
name,
false);
998 sc &=
alg->sysExecute(ctx);
1017 std::unique_ptr<EventInfo> eventInfo;
1019 unsigned int conditionsRun = EventIDBase::UNDEFNUM;
1020 bool consume_modifier_stream =
false;
1027 if (pAttrList !=
nullptr && pAttrList->size() > 6) {
1030 unsigned int runNumber = (*pAttrList)[
"RunNumber"].data<
unsigned int>();
1031 unsigned long long eventNumber = (*pAttrList)[
"EventNumber"].data<
unsigned long long>();
1032 unsigned int eventTime = (*pAttrList)[
"EventTime"].data<
unsigned int>();
1033 unsigned int eventTimeNS = (*pAttrList)[
"EventTimeNanoSec"].data<
unsigned int>();
1034 unsigned int lumiBlock = (*pAttrList)[
"LumiBlockN"].data<
unsigned int>();
1035 unsigned int bunchId = (*pAttrList)[
"BunchId"].data<
unsigned int>();
1038 consume_modifier_stream =
true;
1042 unsigned long long eventNumberSecondary{};
1043 if (!(pAttrList->exists(
"hasSecondaryInput") &&
1044 (*pAttrList)[
"hasSecondaryInput"].data<
bool>())) {
1045 ATH_MSG_FATAL(
"Secondary EventNumber requested, but secondary input does not exist!");
1046 return StatusCode::FAILURE;
1048 if (pAttrList->exists(
"EventNumber_secondary")) {
1049 eventNumberSecondary = (*pAttrList)[
"EventNumber_secondary"].data<
unsigned long long>();
1054 if (pEventSecondary) {
1055 eventNumberSecondary = pEventSecondary->
event_ID()->event_number();
1057 ATH_MSG_FATAL(
"Secondary EventNumber requested, but it does not exist!");
1058 return StatusCode::FAILURE;
1061 if (eventNumberSecondary != 0) {
1064 if (doEvtHeartbeat) {
1066 << eventNumberSecondary <<
" instead of #"
1073 eventInfo = std::make_unique<EventInfo>(
1077 eventID = *(eventInfo->
event_ID());
1079 if (!
m_evtIdModSvc.isSet() && pAttrList->exists(
"ConditionsRun")) {
1080 conditionsRun = (*pAttrList)[
"ConditionsRun"].data<
unsigned int>();
1100 ATH_MSG_FATAL(
"Valid input attribute list required but not present!");
1101 return StatusCode::FAILURE;
1115 if (xAODEvent ==
nullptr) {
1116 ATH_MSG_ERROR(
"Failed to get EventID from input. Tried old-style and xAOD::EventInfo");
1117 return StatusCode::FAILURE;
1121 eventInfo = std::make_unique<EventInfo>(
1124 eventID = *(eventInfo->
event_ID());
1126 if (!
sc.isSuccess()) {
1128 return StatusCode::FAILURE;
1135 eventInfo = std::make_unique<EventInfo>(
1136 std::make_unique<EventID>(1,
m_nevt, 0), std::make_unique<EventType>());
1138 eventID = *(eventInfo->
event_ID());
1140 if (!
sc.isSuccess()) {
1142 return (StatusCode::FAILURE);
1146 ctx.setEventID( eventID );
1152 Gaudi::Hive::setCurrentContext( ctx );
1155 if (
eventStore()->record(std::make_unique<EventContext> ( ctx ),
1156 "EventContext").isFailure())
1159 return (StatusCode::FAILURE);
1162 return StatusCode::SUCCESS;
1173 unsigned int oldrunnr=eID.run_number();
1174 unsigned int oldLB=eID.lumi_block();
1175 unsigned int oldTS=eID.time_stamp();
1176 unsigned int oldTSno=eID.time_stamp_ns_offset();
1177 ATH_MSG_DEBUG (
"modifyEventContext: use evtIdModSvc runnr=" << oldrunnr <<
" -> " << new_eID.run_number() );
1178 ATH_MSG_DEBUG (
"modifyEventContext: use evtIdModSvc LB=" << oldLB <<
" -> " << new_eID.lumi_block() );
1179 ATH_MSG_DEBUG (
"modifyEventContext: use evtIdModSvc TimeStamp=" << oldTS <<
" -> " << new_eID.time_stamp() );
1180 ATH_MSG_DEBUG (
"modifyEventContext: use evtIdModSvc TimeStamp ns Offset=" << oldTSno <<
" -> " << new_eID.time_stamp_ns_offset() );
1182 ctx.setEventID( new_eID );
1187 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
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)
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
void setProperty(columnar::PythonToolHandle &self, const std::string &key, nb::object value)
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.
accumulate
Update flags based on parser line args.
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.
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