|
ATLAS Offline Software
|
Go to the documentation of this file.
5 #define GAUDISVC_EVENTLOOPMGR_CPP
26 #include "GaudiKernel/IAlgManager.h"
27 #include "GaudiKernel/IAlgorithm.h"
28 #include "GaudiKernel/SmartIF.h"
29 #include "GaudiKernel/Incident.h"
30 #include "GaudiKernel/DataObject.h"
31 #include "GaudiKernel/IIncidentSvc.h"
32 #include "GaudiKernel/IEvtSelector.h"
33 #include "GaudiKernel/IDataManagerSvc.h"
34 #include "GaudiKernel/IConversionSvc.h"
35 #include "GaudiKernel/GaudiException.h"
36 #include "GaudiKernel/EventContext.h"
37 #include "GaudiKernel/EventIDBase.h"
38 #include "GaudiKernel/ThreadLocalContext.h"
39 #include "GaudiKernel/Algorithm.h"
43 #include "EventInfo/EventInfo.h"
64 : MinimalEventLoopMgr(nam, svcLoc),
66 m_incidentSvc (
"IncidentSvc", nam ),
67 m_eventStore(
"StoreGateSvc", nam ),
68 m_evtSelector(nullptr), m_evtSelCtxt(nullptr),
69 m_histoDataMgrSvc(
"HistogramDataSvc", nam ),
70 m_histoPersSvc (
"HistogramPersistencySvc", nam ),
71 m_evtIdModSvc (
"", nam ),
73 m_currentRun(0), m_firstRun(true), m_tools(this),
74 m_nevt(0), m_writeHists(false),
75 m_nev(0), m_proc(0), m_useTools(false),
76 m_chronoStatSvc(
"ChronoStatSvc", nam ),
77 m_conditionsCleaner(
"Athena::ConditionsCleanerSvc", nam )
81 "Name of Event Selector to use. If empty string (default) "
82 "take value from ApplicationMgr");
84 "Histogram persistency technology to use: ROOT, HBOOK, NONE. "
85 "By default (empty string) get property value from "
88 "histogram write/update interval");
90 "Controls behaviour of event loop depending on return code of"
91 " Algorithms. 0: all non-SUCCESSes terminate job. "
92 "1: RECOVERABLE skips to next event, FAILURE terminates job "
93 "(DEFAULT). 2: RECOVERABLE and FAILURE skip to next events");
95 "Print event heartbeat printouts every m_eventPrintoutInterval events");
97 "heartbeat time interval is seconds rather than events"
98 "you also get a nice event rate printout then");
103 "Configure the policy wrt handling of when the "
104 "'clear-the-event-store' event shall happen: at EndEvent "
105 "(default as it is makes things easier for memory management"
106 ") or at BeginEvent (easier e.g. for interactive use)");
110 "Require valid input attribute list to be present");
112 "In case of DoubleEventSelector use event number from secondary input");
114 "ServiceHandle for EvtIdModifierSvc");
116 "List of algorithms/sequences to execute during PreFork");
133 m_autoRetrieveTools =
false;
134 m_checkToolDeps =
false;
137 if ( !
sc.isSuccess() )
139 ATH_MSG_ERROR (
"Failed to initialize base class MinimalEventLoopMgr" );
148 if( !
sc.isSuccess() )
150 ATH_MSG_FATAL (
"Error retrieving pointer to StoreGateSvc" );
159 if( !
sc.isSuccess() )
168 SmartIF<IProperty> prpMgr(serviceLocator());
169 if ( !prpMgr.isValid() )
171 ATH_MSG_FATAL (
"IProperty interface not found in ApplicationMgr." );
172 return StatusCode::FAILURE;
180 if( !
sc.isSuccess() )
187 if ( histPersName.length() == 0 )
189 CHECK(setProperty(prpMgr->getProperty(
"HistogramPersistency")));
192 if ( histPersName !=
"NONE" ) {
197 if( !sc.isSuccess() ) {
198 ATH_MSG_WARNING (
"Histograms cannot not be saved - though required." );
201 IService *is =
nullptr;
202 if (histPersName ==
"ROOT") {
203 sc = serviceLocator()->service(
"RootHistSvc", is);
204 }
else if ( histPersName ==
"HBOOK" ) {
205 sc = serviceLocator()->service(
"HbookHistSvc", is);
208 if (
sc.isFailure()) {
209 ATH_MSG_ERROR (
"could not locate actual Histogram persistency service" );
213 ATH_MSG_ERROR (
"Could not dcast HistPersSvc to a Service" );
215 const Gaudi::Details::PropertyBase &prop =
s->getProperty(
"OutputFile");
218 const StringProperty &sprop =
dynamic_cast<const StringProperty&
>( prop );
223 ATH_MSG_VERBOSE (
"could not dcast OutputFile property to a StringProperty."
224 <<
" Need to fix Gaudi." );
226 val = prop.toString();
234 val !=
"UndefinedROOTOutputFileName" &&
235 val !=
"UndefinedHbookOutputFileName" ) {
252 ATH_MSG_DEBUG (
"EventID modifier Service not set. No run number, ... overrides will be applied." );
255 ATH_MSG_INFO (
"Could not find EventID modifier Service. No run number, ... overrides will be applied." );
264 sc = setProperty(prpMgr->getProperty(
"EvtSel"));
269 IEvtSelector* theEvtSel(
nullptr);
279 return StatusCode::FAILURE;
281 if (msgLevel(MSG::INFO)) {
282 INamedInterface* named (
dynamic_cast< INamedInterface*
>(theEvtSel));
283 if (
nullptr != named) {
284 ATH_MSG_INFO (
"Setup EventSelector service " << named->name( )
288 }
else if (
sc.isFailure()) {
291 return StatusCode::FAILURE;
301 return StatusCode::FAILURE;
305 m_aess = serviceLocator()->service(
"AlgExecStateSvc");
308 return StatusCode::FAILURE;
332 if ( policyName !=
"BeginEvent" &&
333 policyName !=
"EndEvent" ) {
336 <<
"] for the 'ClearStore-policy !"
338 <<
"Valid values are: BeginEvent, EndEvent"
340 throw GaudiException(
"Can not setup 'ClearStore'-policy",
342 StatusCode::FAILURE);
364 unsigned int toolCtr = 0;
365 for ( ; firstTool != lastTool; ++firstTool )
386 if (
sc.isFailure()) {
391 if (sc2.isFailure()) {
407 unsigned int toolCtr = 0;
408 ATH_MSG_INFO (
"Summary of AthenaEvtLoopPreSelectTool invocation: (invoked/success/failure)" );
409 ATH_MSG_INFO (
"-----------------------------------------------------" );
411 for ( ; firstTool != lastTool; ++firstTool ) {
412 ATH_MSG_INFO ( std::setw(2) << std::setiosflags(std::ios_base::right)
413 << toolCtr+1 <<
".) " << std::resetiosflags(std::ios_base::right)
414 << std::setw(48) << std::setfill(
'.')
415 << std::setiosflags(std::ios_base::left)
416 << (*firstTool)->name() << std::resetiosflags(std::ios_base::left)
419 << std::setw(6) << std::setiosflags(std::ios_base::right)
430 return (
sc.isFailure() || sc2.isFailure() ) ? StatusCode::FAILURE :
443 std::vector<DataObject*>
objects;
445 DataObject*
obj =
reg->object();
446 if ( !
obj ||
obj->clID() == CLID_StatisticsFile )
return false;
451 if ( !
sc.isSuccess() ) {
452 ATH_MSG_ERROR (
"Error while traversing Histogram data store" );
460 (writeInterval != 0 &&
m_nevt%writeInterval == 0) ) {
464 IOpaqueAddress* pAddr =
nullptr;
466 if ( iret.isFailure() )
return iret;
467 i->registry()->setAddress( pAddr );
471 IRegistry*
reg =
i->registry();
473 return iret.isFailure() ? iret : isc;
475 if ( !
sc.isSuccess() ) {
480 if (
force || (writeInterval != 0 &&
m_nevt%writeInterval == 0) ) {
499 for ( ita = m_topAlgList.begin(); ita != m_topAlgList.end(); ++ita )
512 for (ita = m_outStreamList.begin(); ita != m_outStreamList.end(); ++ita )
515 if(
sc.isFailure() ) {
523 return StatusCode::SUCCESS;
533 ita != m_topAlgList.end();
540 m_aess->algExecState(*ita,ctx).setState(AlgExecState::State::Done,
sc);
541 if ( !
sc.isSuccess() ) {
543 << (*ita)->name() <<
" failed with StatusCode::" <<
sc );
548 return StatusCode::SUCCESS;
559 m_incidentSvc->fireIncident(Incident(
"BeginEvent",IncidentType::BeginEvent));
561 m_incidentSvc->fireIncident(Incident(
"EndEvent",IncidentType::EndEvent));
583 bool toolsPassed=
true;
584 bool eventFailed =
false;
586 unsigned int toolCtr=0;
591 while(toolsPassed && theTool!=lastTool )
593 toolsPassed = (*theTool)->passEvent(ctx.eventID());
602 uint64_t evtNumber = ctx.eventID().event_number();
606 if (doEvtHeartbeat) {
608 ATH_MSG_INFO (
" ===>>> start processing event #" << evtNumber <<
", run #" <<
m_currentRun <<
" " <<
m_nev <<
" events processed so far <<<===" );
617 <<
" events processed so far <<<===" );
627 if ( m_scheduledStop ) {
628 ATH_MSG_ALWAYS (
"A stopRun was requested by an incidentListener. "
629 <<
"Do not process this event." );
630 return (StatusCode::SUCCESS);
638 if(!
sc.isSuccess()) {
640 m_aess->setEventStatus( EventStatus::AlgFail, ctx );
647 <<
"Skipping remaining algorithms." << std::endl
648 <<
"\tNo output will be written for this event, "
649 <<
"but job will continue to next event" );
655 ATH_MSG_INFO (
"Skipping remaining algorithms." << std::endl
656 <<
"\tNo output will be written for this event, "
657 <<
"but job will continue to next event" );
663 m_aess->setEventStatus( EventStatus::Success, ctx );
667 ito != m_outStreamList.end(); ++ito ) {
668 sc = (*ito)->sysExecute(ctx);
669 if( !
sc.isSuccess() ) {
683 if (doEvtHeartbeat) {
687 <<
" " <<
m_nev <<
" events processed so far <<<===");
691 <<
" events processed so far <<<===");
693 std::ofstream
outfile(
"eventLoopHeartBeat.txt");
698 <<
" " <<
m_nev <<
" events read so far <<<===" << std::endl;
707 return eventFailed?StatusCode::FAILURE:StatusCode::SUCCESS;
716 if (!(this->
nextEvent(maxevt)).isSuccess())
return StatusCode::FAILURE;
720 return StatusCode::SUCCESS;
729 if (0 == maxevt)
return StatusCode::SUCCESS;
731 static int total_nevt = 0;
755 while(maxevt == -1 ||
m_nevt < maxevt) {
761 if ( m_scheduledStop ) {
762 m_scheduledStop =
false;
763 ATH_MSG_ALWAYS (
"A stopRun was requested. Terminating event loop." );
776 if( !
sc.isSuccess() ) {
791 IOpaqueAddress* addr =
nullptr;
795 if ( !
sc.isSuccess() )
799 sc = StatusCode::SUCCESS;
810 if (
nullptr != addr) {
813 if( !
sc.isSuccess() ) {
818 if ((
sc=
eventStore()->loadEventProxies()).isFailure()) {
831 if( !
sc.isSuccess() )
833 ATH_MSG_ERROR (
"Terminating event processing loop due to errors" );
842 if( !
sc.isSuccess() ) {
866 ATH_MSG_ERROR (
"Seek failed; unsupported by event selector" );
867 return StatusCode::FAILURE;
872 ATH_MSG_FATAL (
"Can not create the event selector Context." );
873 return StatusCode::FAILURE;
879 if (
sc.isSuccess()) {
904 ATH_MSG_ERROR (
"Collection size unsupported by event selector" );
910 ATH_MSG_FATAL (
"Can not create the event selector Context." );
924 if(inc.type()!=
"BeforeFork")
928 ATH_MSG_WARNING (
"Skipping BeforeFork handler. Begin run has already passed" );
940 ATH_MSG_WARNING (
"Skipping BeforeFork handler. No event selector is provided" );
945 IOpaqueAddress* addr =
nullptr;
947 if(!
sc.isSuccess()) {
952 if (
sc.isFailure()) {
956 if (
nullptr != addr) {
959 if(!
sc.isSuccess()) {
965 if(
eventStore()->loadEventProxies().isFailure()) {
977 throw std::runtime_error(
"Error installing event context object" );
986 ATH_MSG_ERROR (
"Unable to execute requested algorithms/sequences during PreFork!" );
994 if(!
sc.isSuccess()) {
1004 const IAlgManager* algMgr = Gaudi::svcLocator()->as<IAlgManager>();
1005 IAlgorithm*
alg{
nullptr};
1009 if ( algMgr->getAlgorithm(
name,
alg) ) {
1011 sc &=
alg->sysExecute(ctx);
1027 void** ppvInterface)
1029 if ( IEventSeek::interfaceID().versionMatch(riid) ) {
1030 *ppvInterface =
dynamic_cast<IEventSeek*
>(
this);
1036 return MinimalEventLoopMgr::queryInterface(riid, ppvInterface);
1039 return StatusCode::SUCCESS;
1052 std::unique_ptr<EventInfo> eventInfo;
1054 unsigned int conditionsRun = EventIDBase::UNDEFNUM;
1055 bool consume_modifier_stream =
false;
1062 if (pAttrList !=
nullptr && pAttrList->size() > 6) {
1065 unsigned int runNumber = (*pAttrList)[
"RunNumber"].data<
unsigned int>();
1066 unsigned long long eventNumber = (*pAttrList)[
"EventNumber"].data<
unsigned long long>();
1067 unsigned int eventTime = (*pAttrList)[
"EventTime"].data<
unsigned int>();
1068 unsigned int eventTimeNS = (*pAttrList)[
"EventTimeNanoSec"].data<
unsigned int>();
1069 unsigned int lumiBlock = (*pAttrList)[
"LumiBlockN"].data<
unsigned int>();
1070 unsigned int bunchId = (*pAttrList)[
"BunchId"].data<
unsigned int>();
1073 consume_modifier_stream =
true;
1077 unsigned long long eventNumberSecondary{};
1078 if (!(pAttrList->exists(
"hasSecondaryInput") &&
1079 (*pAttrList)[
"hasSecondaryInput"].data<
bool>())) {
1080 ATH_MSG_FATAL(
"Secondary EventNumber requested, but secondary input does not exist!");
1081 return StatusCode::FAILURE;
1083 if (pAttrList->exists(
"EventNumber_secondary")) {
1084 eventNumberSecondary = (*pAttrList)[
"EventNumber_secondary"].data<
unsigned long long>();
1089 if (pEventSecondary) {
1090 eventNumberSecondary = pEventSecondary->
event_ID()->event_number();
1092 ATH_MSG_FATAL(
"Secondary EventNumber requested, but it does not exist!");
1093 return StatusCode::FAILURE;
1096 if (eventNumberSecondary != 0) {
1099 if (doEvtHeartbeat) {
1101 << eventNumberSecondary <<
" instead of #"
1108 eventInfo = std::make_unique<EventInfo>(
1111 eventID = *(eventInfo->
event_ID());
1113 if (!
m_evtIdModSvc.isSet() && pAttrList->exists(
"ConditionsRun")) {
1114 conditionsRun = (*pAttrList)[
"ConditionsRun"].data<
unsigned int>();
1134 ATH_MSG_FATAL(
"Valid input attribute list required but not present!");
1135 return StatusCode::FAILURE;
1149 if (xAODEvent ==
nullptr) {
1150 ATH_MSG_ERROR(
"Failed to get EventID from input. Tried old-style and xAOD::EventInfo");
1151 return StatusCode::FAILURE;
1155 eventInfo = std::make_unique<EventInfo>(
1158 eventID = *(eventInfo->
event_ID());
1160 if (!
sc.isSuccess()) {
1162 return StatusCode::FAILURE;
1171 eventID = *(eventInfo->
event_ID());
1173 if (!
sc.isSuccess()) {
1175 return (StatusCode::FAILURE);
1179 ctx.setEventID( eventID );
1185 Gaudi::Hive::setCurrentContext( ctx );
1188 if (
eventStore()->record(std::make_unique<EventContext> ( ctx ),
1189 "EventContext").isFailure())
1192 return (StatusCode::FAILURE);
1195 return StatusCode::SUCCESS;
1206 unsigned int oldrunnr=eID.run_number();
1207 unsigned int oldLB=eID.lumi_block();
1208 unsigned int oldTS=eID.time_stamp();
1209 unsigned int oldTSno=eID.time_stamp_ns_offset();
1210 ATH_MSG_DEBUG (
"modifyEventContext: use evtIdModSvc runnr=" << oldrunnr <<
" -> " << new_eID.run_number() );
1211 ATH_MSG_DEBUG (
"modifyEventContext: use evtIdModSvc LB=" << oldLB <<
" -> " << new_eID.lumi_block() );
1212 ATH_MSG_DEBUG (
"modifyEventContext: use evtIdModSvc TimeStamp=" << oldTS <<
" -> " << new_eID.time_stamp() );
1213 ATH_MSG_DEBUG (
"modifyEventContext: use evtIdModSvc TimeStamp ns Offset=" << oldTSno <<
" -> " << new_eID.time_stamp_ns_offset() );
1215 ctx.setEventID( new_eID );
1220 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.
This class represents the "type of event" where the type is given by one or more "characteristics".
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.
reg
globals -----------------------------------------------------------------—
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
static const InterfaceID & interfaceID()
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)
Abstract interface for finding the size of an event collection.
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...
virtual StatusCode queryInterface(const InterfaceID &riid, void **ppvInterface)
interface dispatcher
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
Abstract interface for seeking within an event stream.
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