Loading [MathJax]/extensions/tex2jax.js
ATLAS Offline Software
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
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"
16 #include "MultipleEventLoopMgr.h"
17 
18 using std::string;
19 using 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 
32  if (m_pAlgMgr) m_pAlgMgr->release();
33 }
34 
35 IAlgManager*
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 }
71 bool
73  INextPassFilter* pFilter(nextPassFilter());
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 }
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 
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 
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:63
MultipleEventLoopMgr::m_pToolSvc
ServiceHandle< IToolSvc > m_pToolSvc
handle to the ToolSvc
Definition: MultipleEventLoopMgr.h:94
AthenaEventLoopMgr::name
virtual const std::string & name() const
Definition: AthenaEventLoopMgr.h:185
MultipleEventLoopMgr::algMgr
IAlgManager * algMgr()
Definition: MultipleEventLoopMgr.cxx:36
MultipleEventLoopMgr::m_nextPassFilterName
StringProperty m_nextPassFilterName
the name of the INextPassFilter object queried at end of pass
Definition: MultipleEventLoopMgr.h:76
MultipleEventLoopMgr::reInitList
StatusCode reInitList()
called at each end of pass.
Definition: MultipleEventLoopMgr.cxx:79
MultipleEventLoopMgr::nextEvent
virtual StatusCode nextEvent(int maxevt)
Dump out histograms as needed.
Definition: MultipleEventLoopMgr.cxx:90
AthenaEventLoopMgr::m_currentRun
number_type m_currentRun
current run number
Definition: AthenaEventLoopMgr.h:103
AthenaPoolTestRead.sc
sc
Definition: AthenaPoolTestRead.py:27
MultipleEventLoopMgr::~MultipleEventLoopMgr
virtual ~MultipleEventLoopMgr()
Standard Destructor.
Definition: MultipleEventLoopMgr.cxx:31
MultipleEventLoopMgr::nextPassFilter
INextPassFilter * nextPassFilter()
Locate filter.
Definition: MultipleEventLoopMgr.cxx:47
AthenaEventLoopMgr::nextEvent
virtual StatusCode nextEvent(int maxevt)
implementation of IAppMgrUI::nextEvent. maxevt==0 returns immediately
Definition: AthenaEventLoopMgr.cxx:713
MultipleEventLoopMgr::m_pAlgMgr
IAlgManager * m_pAlgMgr
Definition: MultipleEventLoopMgr.h:97
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
AthenaEventLoopMgr::seek
virtual StatusCode seek(int evt)
Seek to a given event.
Definition: AthenaEventLoopMgr.cxx:849
Handler::svc
AthROOTErrorHandlerSvc * svc
Definition: AthROOTErrorHandlerSvc.cxx:10
INextPassFilter.h
MultipleEventLoopMgr::m_toBeReInitializedNames
StringArrayProperty m_toBeReInitializedNames
a list of services to be reinit at the end of the pass
Definition: MultipleEventLoopMgr.h:79
python.CaloCondTools.log
log
Definition: CaloCondTools.py:20
MultipleEventLoopMgr::MultipleEventLoopMgr
MultipleEventLoopMgr()
implementation of IEventProcessor::executeEvent(void* par)
MultipleEventLoopMgr::m_passDone
unsigned int m_passDone
number of passes already completed
Definition: MultipleEventLoopMgr.h:99
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:72