ATLAS Offline Software
Loading...
Searching...
No Matches
MultipleEventLoopMgr.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3*/
4
5#include <string>
6#include <vector>
7#include "GaudiKernel/GaudiException.h"
8#include "GaudiKernel/TypeNameString.h"
9#include "GaudiKernel/IAlgorithm.h"
10#include "GaudiKernel/IAlgTool.h"
11#include "GaudiKernel/IAlgManager.h"
12#include "GaudiKernel/IToolSvc.h"
13#include "GaudiKernel/MsgStream.h"
14#include "GaudiKernel/SmartIF.h"
17
18using std::string;
19using std::vector;
20
22 ISvcLocator* svcLoc) :
23 AthenaEventLoopMgr(nam, svcLoc),
24 m_pToolSvc( "ToolSvc", nam ),
25 m_pAlgMgr(nullptr), m_passDone(0)
26{
27 declareProperty("NextPassFilter", m_nextPassFilterName);
28 declareProperty("ToBeReinitialized", m_toBeReInitializedNames);
29}
30
34
35IAlgManager*
37 if ( nullptr == m_pAlgMgr ) {
38 SmartIF<IAlgManager> algMan(serviceLocator());
39 if( algMan.isValid() ) m_pAlgMgr=&*algMan;
40 else throw GaudiException("IAlgManager not found", name(), StatusCode::FAILURE);
41 m_pAlgMgr->addRef();
42 }
43 return m_pAlgMgr;
44}
45
48 INextPassFilter* pFilter(nullptr);
49 const string& filterName(m_nextPassFilterName.value());
50 if (!(filterName.empty())) {
51 Gaudi::Utils::TypeNameString theFilter(filterName);
52 IAlgTool* pHoldTool(nullptr);
53 if ( (m_pToolSvc->retrieveTool(theFilter.type(), theFilter.name(),
54 pHoldTool)).isSuccess() ) {
55 pFilter=dynamic_cast<INextPassFilter*>(pHoldTool);
56 }
57
58 SmartIF<IAlgorithm>& pHoldAlg = algMgr()->algorithm(theFilter, /*createIf*/false);
59 if (nullptr == pFilter && pHoldAlg) {
60 pFilter=dynamic_cast<INextPassFilter*>(pHoldAlg.get());
61 }
62 }
63 if (nullptr == pFilter) {
64 Gaudi::Utils::TypeNameString theFilter(filterName);
65 MsgStream log(msgSvc(), name());
66 log << MSG::WARNING << "Could not locate filter "
67 << theFilter.type() << '/' << theFilter.name() << endmsg;
68 }
69 return pFilter;
70}
71bool
74 //if no tool found or tool not an INextPassFilter we return false
75 //and terminate the multiple pass iteration
76 return ( nullptr != pFilter && pFilter->doNextPass() );
77}
78StatusCode
80 StatusCode sc;
81 for (const std::string& name : m_toBeReInitializedNames.value()) {
82 SmartIF<IService>& svc = serviceLocator()->service(name, /*createIf*/false);
83 if (svc) sc = svc->reinitialize();
84 if (!sc.isSuccess()) return sc;
85 }
86 return sc;
87}
88
89StatusCode
91 StatusCode sc;
92 do {
93 MsgStream log(msgSvc(), name());
94 log << MSG::INFO << "nextEvent: starting pass #" << m_passDone << endmsg;
95 // Reset run number to assure BeginRun each rewind
96 m_currentRun = 0;
98 log << MSG::INFO << "nextEvent: finished pass #" << m_passDone << endmsg;
99 m_passDone++;
100 } while ( sc.isSuccess() && //pass ok
101 doNextPass() && //another one?
102 (sc = reInitList()).isSuccess() && //then reinit svcs
103 (sc = seek(0)).isSuccess() ); //and rewind selector
104 return sc;
105}
106
#define endmsg
static Double_t sc
A specialize AthenaEventLoopMgr that allows multiple passes over an event collection.
virtual StatusCode seek(int evt) override
Seek to a given event.
virtual const std::string & name() const override
AthenaEventLoopMgr(const std::string &nam, ISvcLocator *svcLoc)
Standard Constructor.
number_type m_currentRun
current run number
virtual StatusCode nextEvent(int maxevt) override
implementation of IAppMgrUI::nextEvent. maxevt==0 returns immediately
interface to a tool (typically) that decides whether the event loop mgr (typically) need to do anothe...
virtual bool doNextPass()=0
decide whether we need another iteration
MultipleEventLoopMgr()
implementation of IEventProcessor::executeEvent(void* par)
bool doNextPass()
called at end of pass. Calls nextPassFilter
StatusCode reInitList()
called at each end of pass.
StringProperty m_nextPassFilterName
the name of the INextPassFilter object queried at end of pass
virtual StatusCode nextEvent(int maxevt)
Dump out histograms as needed.
ServiceHandle< IToolSvc > m_pToolSvc
handle to the ToolSvc
StringArrayProperty m_toBeReInitializedNames
a list of services to be reinit at the end of the pass
virtual ~MultipleEventLoopMgr()
Standard Destructor.
unsigned int m_passDone
number of passes already completed
INextPassFilter * nextPassFilter()
Locate filter.