ATLAS Offline Software
MultipleEventLoopMgr.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3 */
4 
6 ATLAS_NO_CHECK_FILE_THREAD_SAFETY; // non-MT EventLoopMgr
7 
8 #include <string>
9 #include <vector>
10 #include "GaudiKernel/GaudiException.h"
11 #include "GaudiKernel/ListItem.h"
12 #include "GaudiKernel/IAlgorithm.h"
13 #include "GaudiKernel/IAlgTool.h"
14 #include "GaudiKernel/IAlgManager.h"
15 #include "GaudiKernel/IToolSvc.h"
16 #include "GaudiKernel/MsgStream.h"
17 #include "GaudiKernel/SmartIF.h"
19 #include "MultipleEventLoopMgr.h"
20 
21 using std::string;
22 using std::vector;
23 
25  ISvcLocator* svcLoc) :
26  AthenaEventLoopMgr(nam, svcLoc),
27  m_pToolSvc( "ToolSvc", nam ),
28  m_pAlgMgr(nullptr), m_passDone(0)
29 {
30  declareProperty("NextPassFilter", m_nextPassFilterName);
31  declareProperty("ToBeReinitialized", m_toBeReInitializedNames);
32 }
33 
35  if (m_pAlgMgr) m_pAlgMgr->release();
36 }
37 
38 IAlgManager*
40  if ( nullptr == m_pAlgMgr ) {
41  SmartIF<IAlgManager> algMan(serviceLocator());
42  if( algMan.isValid() ) m_pAlgMgr=&*algMan;
43  else throw GaudiException("IAlgManager not found", name(), StatusCode::FAILURE);
44  m_pAlgMgr->addRef();
45  }
46  return m_pAlgMgr;
47 }
48 
51  INextPassFilter* pFilter(nullptr);
52  const string& filterName(m_nextPassFilterName.value());
53  if (!(filterName.empty())) {
54  ListItem theFilter(filterName);
55  IAlgTool* pHoldTool(nullptr);
56  if ( (m_pToolSvc->retrieveTool(theFilter.type(), theFilter.name(),
57  pHoldTool)).isSuccess() ) {
58  pFilter=dynamic_cast<INextPassFilter*>(pHoldTool);
59  }
60  IAlgorithm* pHoldAlg(nullptr);
61  if (nullptr == pFilter &&
62  (algMgr()->getAlgorithm(theFilter.name(), pHoldAlg)).isSuccess() ) {
63  pFilter=dynamic_cast<INextPassFilter*>(pHoldAlg);
64  }
65  }
66  if (nullptr == pFilter) {
67  ListItem theFilter(filterName);
68  MsgStream log(msgSvc(), name());
69  log << MSG::WARNING << "Could not locate filter "
70  << theFilter.type() << '/' << theFilter.name() << endmsg;
71  }
72  return pFilter;
73 }
74 bool
76  INextPassFilter* pFilter(nextPassFilter());
77  //if no tool found or tool not an INextPassFilter we return false
78  //and terminate the multiple pass iteration
79  return ( nullptr != pFilter && pFilter->doNextPass() );
80 }
83  StatusCode sc(StatusCode::SUCCESS);
84  const vector<string>& theNames(m_toBeReInitializedNames.value());
85  vector<string>::const_iterator iN(theNames.begin());
86  vector<string>::const_iterator iEnd(theNames.end());
87  while ( sc.isSuccess() && (iN != iEnd) ) {
88  ListItem theSvc(*iN++); //not really needed but safer...
89  IService* pSvc(nullptr);
90  sc = serviceLocator()->getService(theSvc.name(), pSvc);
91  if (sc.isSuccess()) sc = pSvc->reinitialize();
92  }
93  return sc;
94 }
95 
98  StatusCode sc;
99  do {
100  MsgStream log(msgSvc(), name());
101  log << MSG::INFO << "nextEvent: starting pass #" << m_passDone << endmsg;
102  // Reset run number to assure BeginRun each rewind
103  m_currentRun = 0;
105  log << MSG::INFO << "nextEvent: finished pass #" << m_passDone << endmsg;
106  m_passDone++;
107  } while ( sc.isSuccess() && //pass ok
108  doNextPass() && //another one?
109  (sc = reInitList()).isSuccess() && //then reinit svcs
110  (sc = seek(0)).isSuccess() ); //and rewind selector
111  return sc;
112 }
113 
INextPassFilter
interface to a tool (typically) that decides whether the event loop mgr (typically) need to do anothe...
Definition: INextPassFilter.h:15
AthenaEventLoopMgr
The default ATLAS batch event loop manager.
Definition: AthenaEventLoopMgr.h:69
MultipleEventLoopMgr::m_pToolSvc
ServiceHandle< IToolSvc > m_pToolSvc
handle to the ToolSvc
Definition: MultipleEventLoopMgr.h:108
AthenaEventLoopMgr::name
virtual const std::string & name() const
Definition: AthenaEventLoopMgr.h:195
MultipleEventLoopMgr::algMgr
IAlgManager * algMgr()
Definition: MultipleEventLoopMgr.cxx:39
MultipleEventLoopMgr::m_nextPassFilterName
StringProperty m_nextPassFilterName
the name of the INextPassFilter object queried at end of pass
Definition: MultipleEventLoopMgr.h:90
MultipleEventLoopMgr::reInitList
StatusCode reInitList()
called at each end of pass.
Definition: MultipleEventLoopMgr.cxx:82
MultipleEventLoopMgr::nextEvent
virtual StatusCode nextEvent(int maxevt)
Dump out histograms as needed.
Definition: MultipleEventLoopMgr.cxx:97
AthenaEventLoopMgr::m_currentRun
number_type m_currentRun
current run number
Definition: AthenaEventLoopMgr.h:109
AthenaPoolTestRead.sc
sc
Definition: AthenaPoolTestRead.py:27
MultipleEventLoopMgr::~MultipleEventLoopMgr
virtual ~MultipleEventLoopMgr()
Standard Destructor.
Definition: MultipleEventLoopMgr.cxx:34
MultipleEventLoopMgr::nextPassFilter
INextPassFilter * nextPassFilter()
Locate filter.
Definition: MultipleEventLoopMgr.cxx:50
AthenaEventLoopMgr::nextEvent
virtual StatusCode nextEvent(int maxevt)
implementation of IAppMgrUI::nextEvent. maxevt==0 returns immediately
Definition: AthenaEventLoopMgr.cxx:726
MultipleEventLoopMgr::m_pAlgMgr
IAlgManager * m_pAlgMgr
Definition: MultipleEventLoopMgr.h:111
MultipleEventLoopMgr.h
A specialize AthenaEventLoopMgr that allows multiple passes over an event collection.
StdJOSetup.msgSvc
msgSvc
Provide convenience handles for various services.
Definition: StdJOSetup.py:36
endmsg
#define endmsg
Definition: AnalysisConfig_Ntuple.cxx:63
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
vector< string >
AthenaEventLoopMgr::seek
virtual StatusCode seek(int evt)
Seek to a given event.
Definition: AthenaEventLoopMgr.cxx:862
INextPassFilter.h
ATLAS_NO_CHECK_FILE_THREAD_SAFETY
ATLAS_NO_CHECK_FILE_THREAD_SAFETY
Definition: MultipleEventLoopMgr.cxx:6
MultipleEventLoopMgr::m_toBeReInitializedNames
StringArrayProperty m_toBeReInitializedNames
a list of services to be reinit at the end of the pass
Definition: MultipleEventLoopMgr.h:93
python.CaloCondTools.log
log
Definition: CaloCondTools.py:20
MultipleEventLoopMgr::MultipleEventLoopMgr
MultipleEventLoopMgr()
implementation of IEventProcessor::executeEvent(void* par)
declareProperty
#define declareProperty(n, p, h)
Definition: BaseFakeBkgTool.cxx:15
MultipleEventLoopMgr::m_passDone
unsigned int m_passDone
number of passes already completed
Definition: MultipleEventLoopMgr.h:113
checker_macros.h
Define macros for attributes used to control the static checker.
INextPassFilter::doNextPass
virtual bool doNextPass()=0
decide whether we need another iteration
MultipleEventLoopMgr::doNextPass
bool doNextPass()
called at end of pass. Calls nextPassFilter
Definition: MultipleEventLoopMgr.cxx:75