33#include "GaudiKernel/IAlgorithm.h"
34#include "GaudiKernel/IEvtSelector.h"
35#include "GaudiKernel/IIncidentSvc.h"
36#include "GaudiKernel/Incident.h"
37#include "GaudiKernel/DataIncident.h"
38#include "GaudiKernel/EventContext.h"
39#include "GaudiKernel/ThreadLocalContext.h"
49 : base_class(name, svcLoc)
52 ,
m_evtStore(
"StoreGateSvc/StoreGateSvc", name)
69 ATH_MSG_WARNING (
"AllowSerialAndMPToDiffer=False! This will incur serious performance penalties! But Serial and MP output will be the same." );
90 SmartIF<IProperty> prpMgr(serviceLocator());
91 SmartIF<IEvtSelector> evtSelector;
92 if (prpMgr.isValid()) {
94 evtSelector = serviceLocator()->service(prpMgr->getProperty(
"EvtSel").toString());
95 CHECK(evtSelector.isValid());
98 ATH_MSG_ERROR (
"IProperty interface not found in ApplicationMgr" );
99 return StatusCode::FAILURE;
102 SmartIF<IProperty> prpMgr1(evtSelector);
103 if (prpMgr1.isValid()) {
104 std::string skipEventsStr = prpMgr1->getProperty(
"SkipEvents").toString();
105 m_ncurevt = std::atoi(skipEventsStr.c_str());
108 ATH_MSG_ERROR (
"IProperty interface not found on the event selector" );
109 return StatusCode::FAILURE;
113 m_aess = serviceLocator()->service(
"AlgExecStateSvc");
116 return StatusCode::FAILURE;
123 ATH_MSG_DEBUG (
"EventID modifier Service not set. No run number, ... overrides will be applied." );
126 ATH_MSG_INFO (
"Could not find EventID modifier Service. No run number, ... overrides will be applied." );
133 return MinimalEventLoopMgr::initialize();
144 ToolHandleArray<IBkgStreamsCache>::iterator cacheIterator(
m_caches.begin());
145 ToolHandleArray<IBkgStreamsCache>::iterator endOfCaches(
m_caches.end());
146 while (cacheIterator != endOfCaches) {
154 return MinimalEventLoopMgr::finalize();
175 if (msgLevel(MSG::DEBUG)) {
176 unsigned int oldrunnr=eID.run_number();
177 unsigned int oldLB=eID.lumi_block();
178 unsigned int oldTS=eID.time_stamp();
179 unsigned int oldTSno=eID.time_stamp_ns_offset();
180 ATH_MSG_DEBUG (
"modifyEventContext: use evtIdModSvc runnr=" << oldrunnr <<
" -> " << new_eID.run_number() );
181 ATH_MSG_DEBUG (
"modifyEventContext: use evtIdModSvc LB=" << oldLB <<
" -> " << new_eID.lumi_block() );
182 ATH_MSG_DEBUG (
"modifyEventContext: use evtIdModSvc TimeStamp=" << oldTS <<
" -> " << new_eID.time_stamp() );
183 ATH_MSG_DEBUG (
"modifyEventContext: use evtIdModSvc TimeStamp ns Offset=" << oldTSno <<
" -> " << new_eID.time_stamp_ns_offset() );
185 ctx.setEventID(new_eID);
189 ctx.setEventID( eID );
200 return StatusCode::SUCCESS;
216 ListAlg::iterator ita;
217 for ( ita = m_topAlgList.begin(); ita != m_topAlgList.end(); ++ita ) {
218 if( !((*ita)->sysInitialize()).isSuccess() ) {
221 return StatusCode::FAILURE;
227 for (ita = m_outStreamList.begin(); ita != m_outStreamList.end(); ++ita ) {
228 if( !((*ita)->sysInitialize()).isSuccess() ) {
231 return StatusCode::FAILURE;
239 while( (maxevt == -1 ||
m_nevt < maxevt) &&
242 if ( m_scheduledStop ) {
243 m_scheduledStop =
false;
244 ATH_MSG_ALWAYS (
"A stopRun was requested. Terminating event loop." );
253 auto upOverEvent = std::make_unique<xAOD::EventInfo>();
254 auto upOverEventAux = std::make_unique<xAOD::EventAuxInfo>();
255 upOverEvent->setStore( upOverEventAux.get() );
260 *pOverEvent = *inputEventInfo;
277 <<
") and provided mcChannelNumber (" <<
m_mcChannelNumber.value() <<
") do not match.");
287 return StatusCode::FAILURE;
292 ATH_MSG_ERROR(
"Input mcEventWeights are empty. This should not happen.");
293 return StatusCode::FAILURE;
303 puei->setStore( puaux );
313 bool consume_modifier_stream =
false;
316 if ( pAttrList !=
nullptr && pAttrList->size() > 6 ) {
322 consume_modifier_stream =
true;
328 ctx.eventID().run_number()) );
329 Gaudi::Hive::setCurrentContext( ctx );
332 auto puctx =std::make_unique<EventContext> ( ctx );
333 if (
m_evtStore->record( std::move(puctx) ,
"EventContext").isFailure()) {
335 return StatusCode::FAILURE;
345 ATH_MSG_INFO (
"nextEvent(): overlaying original event " <<
352 m_beamInt->selectT0(ctx.eventID().run_number(), ctx.eventID().event_number());
357 unsigned int t0BCID = pOverEvent->
bcid();
367 bool addpEvent(
true);
369 ATH_MSG_DEBUG(
"inputEventInfo->evtStore()="<<inputEventInfo->evtStore()<<
", pOverEvent->evtStore()=" << pOverEvent->evtStore()<<
", &m_origStream.store()="<<&
m_origStream.store() );
377 ATH_MSG_DEBUG(
"Added inputEventInfo="<<inputEventInfo<<
" as subEvent "<<newEv<<
" to pOverEvent " << pOverEvent );
378 ATH_MSG_DEBUG(
" afterwards: newEv->evtStore()="<<newEv->evtStore()<<
", pOverEvent->evtStore()=" << pOverEvent->evtStore() );
402 ToolHandleArray<IBkgStreamsCache>::iterator cacheIterator(
m_caches.begin());
403 ToolHandleArray<IBkgStreamsCache>::iterator endOfCaches(
m_caches.end());
404 while (cacheIterator != endOfCaches) {
406 (*cacheIterator)->resetEvtsPerXingScaleFactor(sf);
408 (*cacheIterator++)->newEvent();
419 unsigned int currentBCID =
getBCID((t0BinCenter/25), t0BCID);
422 while (cacheIterator != endOfCaches) {
424 if (((*cacheIterator)->addSubEvts(iXing-
m_firstXing, pOverEvent, t0BinCenter,
m_loadProxies, currentBCID)).isFailure()) {
427 ATH_MSG_INFO (
"No more sub events for " << cacheIterator->name() );
428 return StatusCode::SUCCESS;
431 ATH_MSG_FATAL (
"Error adding sub events to " << cacheIterator->name() );
432 return StatusCode::FAILURE;
461 m_incidentSvc->fireIncident(ContextIncident<std::pair<unsigned,unsigned> >(this->name(),
"ReseedIncident",std::pair<unsigned,unsigned>(pOverEvent->
eventNumber(),pOverEvent->
runNumber())));
462 m_incidentSvc->fireIncident(Incident(this->name(),
"AfterReseedIncident"));
467 ATH_MSG_ERROR (
"Terminating event processing loop due to errors" );
468 return StatusCode::FAILURE;
490 return StatusCode::SUCCESS;
499 " nevtsToAdvance=" << nevtsToAdvance );
502 for (
int i=0; i<nevtsToAdvance; ++i) {
506 if (this->
nextEvent(nParam).isFailure()) {
508 return StatusCode::FAILURE;
512 return StatusCode::SUCCESS;
533 return StatusCode::FAILURE;
540 ToolHandleArray<IBkgStreamsCache>::iterator cacheIterator(
m_caches.begin());
541 ToolHandleArray<IBkgStreamsCache>::iterator endOfCaches(
m_caches.end());
543 unsigned int firstStore(0);
544 StatusCode
sc(StatusCode::SUCCESS);
545 while ((cacheIterator != endOfCaches) &&
sc.isSuccess()) {
547 firstStore += (*cacheIterator)->nStores() ;
559 for ( ListAlg::iterator ita = m_topAlgList.begin();
560 ita != m_topAlgList.end();
562 StatusCode
sc = (*ita)->sysExecute( ctx );
566 m_aess->algExecState(*ita, ctx ).setState(AlgExecState::State::Done,
sc);
567 if ( !
sc.isSuccess() ) {
569 (*ita)->name() <<
" failed with StatusCode::" <<
sc );
574 return StatusCode::SUCCESS;
587 m_incidentSvc->fireIncident(Incident(this->name(),IncidentType::EndRun));
595 m_incidentSvc->fireIncident(Incident(this->name(),IncidentType::BeginRun,ctx));
598 bool eventFailed(
false);
602 if (!
sc.isSuccess()) {
604 m_aess->setEventStatus( EventStatus::AlgFail, ctx );
611 "Skipping remaining algorithms." << std::endl <<
612 "\tNo output will be written for this event, " <<
613 "but job will continue to next event" );
619 ATH_MSG_INFO (
"Skipping remaining algorithms." << std::endl <<
620 "\tNo output will be written for this event, " <<
621 "but job will continue to next event" );
626 m_aess->setEventStatus( EventStatus::Success, ctx );
629 for (ListAlg::iterator ito = m_outStreamList.begin();
630 ito != m_outStreamList.end(); ++ito ) {
631 sc = (*ito)->sysExecute( ctx );
632 if ( !
sc.isSuccess() ) {
641 return eventFailed?StatusCode::FAILURE:StatusCode::SUCCESS;
#define ATH_MSG_VERBOSE(x)
#define ATH_MSG_ALWAYS(x)
#define ATH_MSG_WARNING(x)
Helpers for checking error return status codes and reporting errors.
#define CHECK(...)
Evaluate an expression and check for errors.
Assign a CLID to EventContext.
EventID eventIDFromxAOD(const xAOD::EventInfo *xaod)
Create EventID object from xAOD::EventInfo.
provides the relative beam intensity as a function of the bunch xing.
provides the relative beam luminosity as a function of the bunch xing.
Interface to in-memory cache for pileup events.
An AttributeList represents a logical row of attributes in a metadata table.
The ATLAS event loop for pile-up applications.
A helper class to compute a hash of pile-up events.
the preferred mechanism to access information from the different event stores in a pileup job.
xAOD::EventInfo * addSubEvent(xAOD::EventInfo *targetEv, const xAOD::EventInfo::SubEvent &subev, xAOD::EventInfoContainer *eiContainer, const std::string &eiContKey, StoreGateSvc *subev_store=nullptr)
AthMessaging(IMessageSvc *msgSvc, const std::string &name)
Constructor.
An AttributeList represents a logical row of attributes in a metadata table.
This class provides a unique identification for each event, in terms of run/event number and/or a tim...
ServiceHandle< StoreGateSvc > m_evtStore
output store
Gaudi::Property< bool > m_xingByXing
virtual StatusCode initialize() override
Gaudi::Property< float > m_xingFreq
virtual StatusCode nextEvent(int maxevt) override
ServiceHandle< IEvtIdModifierSvc > m_evtIdModSvc
Gaudi::Property< uint32_t > m_mcChannelNumber
Gaudi::Property< float > m_maxCollPerXing
Gaudi::Property< bool > m_allowSerialAndMPToDiffer
void modifyEventContext(EventContext &ctx, const EventID &eID, bool consume_modifier_stream)
PileUpStream m_origStream
Input Stream.
virtual StatusCode seek(int evt) override
ServiceHandle< IIncidentSvc > m_incidentSvc
Incident Service.
virtual ~PileUpEventLoopMgr()
Standard Destructor.
virtual int curEvent() const override
Gaudi::Property< std::string > m_evinfName
Gaudi::Property< int > m_firstXing
Gaudi::Property< int > m_failureMode
SmartIF< IAlgExecStateSvc > m_aess
Reference to the Algorithm Execution State Svc.
ServiceHandle< IEvtSelector > m_origSel
unsigned int getBCID(int bunchXing, unsigned int centralBCID) const
return the 'fake BCID' corresponding to bunchXing
virtual StatusCode executeEvent(EventContext &&ctx) override
Gaudi::Property< int > m_lastXing
ServiceHandle< IBeamLuminosity > m_beamLumi
ToolHandleArray< IBkgStreamsCache > m_caches
ServiceHandle< IBeamIntensity > m_beamInt
ServiceHandle< PileUpMergeSvc > m_mergeSvc
PileUpEventLoopMgr(const std::string &nam, ISvcLocator *svcLoc)
Standard Constructor.
virtual StatusCode finalize() override
Gaudi::Property< bool > m_allowSubEvtsEOF
virtual StatusCode executeAlgorithms(const EventContext &ctx)
Run the algorithms for the current event.
uint32_t m_currentRun
current run number
Gaudi::Property< std::string > m_evinfContName
StatusCode setupStreams()
setup input and overlay selectors and iters
std::string hashSource() const
Get the current hash base.
void addToHashSource(const std::string &string)
Add a plain string to the stream.
void calculateHash(uuid_t &hash) const
Calculate the hash.
static xAOD::EventInfo::PileUpMixtureID uuidToPileUpMixtureId(const uuid_t &hash)
Convert uuid_t to xAOD::EventInfo::PileUpMixtureID.
a triple selector/context/store defines a stream
uint64_t mcEventNumber() const
The MC generator's event number.
const std::vector< float > & mcEventWeights() const
The weights of all the MC events used in the simulation.
void setAverageInteractionsPerCrossing(float value)
Set average interactions per crossing for all BCIDs.
void setBCID(uint32_t value)
Set the bunch crossing ID of the event.
uint32_t lumiBlock() const
The current event's luminosity block number.
void setMCEventNumber(uint64_t value)
Set the MC generator's event number.
uint32_t eventTypeBitmask() const
The event type bitmask.
uint32_t bcid() const
The bunch crossing ID of the event.
void setTimeStamp(uint32_t value)
Set the POSIX time of the event.
void clearSubEvents()
Clear all the currently held sub-events.
void setEventNumber(uint64_t value)
Set the current event's event number.
float averageInteractionsPerCrossing() const
Average interactions per crossing for all BCIDs - for out-of-time pile-up.
PileUpMixtureID pileUpMixtureID() const
Unique pile-up mixture identifier.
float actualInteractionsPerCrossing() const
Average interactions per crossing for the current BCID - for in-time pile-up.
void setPileUpMixtureID(const PileUpMixtureID &value)
Set unique pile-up mixture identifier.
void setEventTypeBitmask(uint32_t value)
Set the event type bitmask.
void setMCChannelNumber(uint32_t value)
Set the MC generator's channel number.
const std::vector< SubEvent > & subEvents() const
Get the pileup events that were used in the simulation.
void setMCEventWeights(const std::vector< float > &value)
Set the weights of all the MC events used in the simulation.
void setRunNumber(uint32_t value)
Set the current event's run number.
void setEvtStore(StoreGateSvc *svc)
Set the pointer to the event store associated with this event.
@ Signal
The signal event.
@ IS_SIMULATION
true: simulation, false: data
uint32_t runNumber() const
The current event's run number.
uint32_t mcChannelNumber() const
The MC generator's channel number.
uint64_t eventNumber() const
The current event's event number.
void setLumiBlock(uint32_t value)
Set the current event's luminosity block number.
void setActualInteractionsPerCrossing(float value)
Set average interactions per crossing for the current BCID.
static std::string release
EventInfoContainer_v1 EventInfoContainer
Define the latest version of the container.
EventInfo_v1 EventInfo
Definition of the latest event info version.
EventInfoAuxContainer_v1 EventInfoAuxContainer
Define the latest version of the auxiliary container.