| The Gaudi Framework v27r1

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

SequentialSchedulerSvc.cpp
Go to the documentation of this file.
1 // Framework includes
2 #include "GaudiKernel/SvcFactory.h"
3 #include "GaudiKernel/IAlgorithm.h"
4 #include "GaudiKernel/Algorithm.h" // will be IAlgorithm if context getter promoted to interface
5 #include "GaudiKernel/IProperty.h"
6 #include "GaudiKernel/AppReturnCode.h"
7
8 // C++
9 #include <list>
10 #include <thread>
11
12 // Local
13 #include "SequentialSchedulerSvc.h"
14 #include "AlgResourcePool.h"
15 #include "RetCodeGuard.h"
16
17 // Instantiation of a static factory class used by clients to create instances of this service
18 DECLARE_SERVICE_FACTORY(SequentialSchedulerSvc)
19
20 //===========================================================================
21 // Infrastructure methods
22
23 SequentialSchedulerSvc::SequentialSchedulerSvc( const std::string& name, ISvcLocator* svcLoc ):
24 base_class(name,svcLoc),
25 m_eventContext(nullptr),
26 m_freeSlots(1){
27 declareProperty("UseTopAlgList", m_useTopAlgList=true);
28 }
29
30 //---------------------------------------------------------------------------
31 SequentialSchedulerSvc::~SequentialSchedulerSvc(){}
32 //---------------------------------------------------------------------------
33
34 StatusCode SequentialSchedulerSvc::initialize(){
35
36 // Initialise mother class (read properties, ...)
37 StatusCode sc(Service::initialize());
38 if (!sc.isSuccess())
39 warning () << "Base class could not be initialized" << endmsg;
40
41 // Get the algo resource pool
42 SmartIF<IAlgResourcePool> algResourcePool (serviceLocator()->service("AlgResourcePool"));
43 if (!algResourcePool.isValid()){
44 error() << "Error retrieving AlgResourcePool" << endmsg;
45 return StatusCode::FAILURE;
46 }
47
48 // Get the list of algorithms
49 m_algList = m_useTopAlgList ? algResourcePool->getTopAlgList() : algResourcePool->getFlatAlgList();
50 info() << "Found " << m_algList.size() << " algorithms" << endmsg;
51
52 return StatusCode::SUCCESS;
53
54 }
55 //---------------------------------------------------------------------------
56
57 StatusCode SequentialSchedulerSvc::finalize(){
58 StatusCode sc(Service::finalize());
59 if (!sc.isSuccess())
60 warning () << "Base class could not be finalized" << endmsg;
61 return sc;
62 }
63
64 //---------------------------------------------------------------------------
65
69 StatusCode SequentialSchedulerSvc::pushNewEvent(EventContext* eventContext){
70
71 m_freeSlots--;
72
73 debug() << "[pushNewEvent] Free slots are now: " << m_freeSlots << endmsg;
74
75 // Call the resetExecuted() method of ALL "known" algorithms
76 // (From the MinimalEventLoopMgr)
77 SmartIF<IAlgManager> algMan(serviceLocator());
78 if (LIKELY(algMan.isValid())) {
79 for( IAlgorithm* ialg : algMan->getAlgorithms() ) {
80 if (LIKELY(nullptr != ialg)) ialg->resetExecuted();
81 }
82 }
83
84 m_eventContext= eventContext;
85 bool eventfailed=false;
86
87 for (IAlgorithm* ialgorithm : m_algList){
88
89 Algorithm* this_algo = dynamic_cast<Algorithm*>(ialgorithm);
90 if (!this_algo){
91 throw GaudiException ("Cast to Algorithm failed!",
92 "SequentialSchedulerSvc",
93 StatusCode::FAILURE);
94 }
95
96 debug() << "Running algorithm " << this_algo->name() << endmsg;
97
98 // m_eventContext->m_thread_id = pthread_self();
99 this_algo->setContext(m_eventContext);
100
101 // Get the IProperty interface of the ApplicationMgr to pass it to RetCodeGuard
102 const SmartIF<IProperty> appmgr(serviceLocator());
103
104 // Call the execute() method of all top algorithms
105 StatusCode sc(StatusCode::FAILURE);
106 try {
107 RetCodeGuard rcg(appmgr, Gaudi::ReturnCode::UnhandledException);
108 sc = ialgorithm->sysExecute();
109 if (UNLIKELY(!sc.isSuccess())) {
110 warning() << "Execution of algorithm " << ialgorithm->name() << " failed" << endmsg;
111 eventfailed = true;
112 }
113 rcg.ignore(); // disarm the guard
114 } catch ( const GaudiException& Exception ) {
115 error() << ".executeEvent(): Exception with tag=" << Exception.tag()
116 << " thrown by " << ialgorithm->name() << endmsg;
117 error() << Exception << endmsg;
118 } catch ( const std::exception& Exception ) {
119 fatal() << ".executeEvent(): Standard std::exception thrown by "
120 << ialgorithm->name() << endmsg;
121 error() << Exception.what() << endmsg;
122 } catch(...) {
123 fatal() << ".executeEvent(): UNKNOWN Exception thrown by "
124 << ialgorithm->name() << endmsg;
125 }
126
127 debug() << "Algorithm " << this_algo->name() << (eventfailed ? " failed" : " succeeded") << endmsg;
128 debug() << "Algorithm " << this_algo->name() << (this_algo->filterPassed() ? " passed" : " rejected") << endmsg;
129
130 // DP it is important to propagate the failure of an event.
131 // We need to stop execution when this happens so that execute run can
132 // then receive the FAILURE
133 m_eventContext->setFail(eventfailed);
134
135 if (eventfailed)
136 return StatusCode::FAILURE;
137 }
138 return StatusCode::SUCCESS;
139
140 }
141
142 //---------------------------------------------------------------------------
143 StatusCode SequentialSchedulerSvc::pushNewEvents(std::vector<EventContext*>& eventContexts){
144 StatusCode sc;
145 for (auto context : eventContexts){
146 sc = pushNewEvent(context);
147 if (sc != StatusCode::SUCCESS) return sc;
148 }
149 return sc;
150 }
151
152 //---------------------------------------------------------------------------
154 StatusCode SequentialSchedulerSvc::popFinishedEvent(EventContext*& eventContext){
155 m_freeSlots++;
156 eventContext = m_eventContext;
157 debug() << "[popFinishedEvent] Free slots are now: " << m_freeSlots << endmsg;
158 return StatusCode::SUCCESS;
159 }
160
161 //---------------------------------------------------------------------------
165 StatusCode SequentialSchedulerSvc::tryPopFinishedEvent(EventContext*& eventContext){
166 return m_freeSlots == 1 ? StatusCode::FAILURE : popFinishedEvent(eventContext);
167 }
168 //---------------------------------------------------------------------------
169
173 unsigned int SequentialSchedulerSvc::freeSlots(){return m_freeSlots;}
174
175 //---------------------------------------------------------------------------
UNLIKELY
#define UNLIKELY(x)
Definition: Kernel.h:126
Service::initialize
StatusCode initialize() override
Definition: Service.cpp:68
Algorithm.h
SmartIF< IAlgResourcePool >
Service::serviceLocator
SmartIF< ISvcLocator > & serviceLocator() const override
Retrieve pointer to service locator.
Definition: Service.cpp:324
GaudiException
Define general base for Gaudi exception.
Definition: GaudiException.h:23
RetCodeGuard
Helper class to set the application return code in case of early exit (e.g.
Definition: RetCodeGuard.h:9
ISvcLocator
The ISvcLocator is the interface implemented by the Service Factory in the Application Manager to loc...
Definition: ISvcLocator.h:25
gaudiComponentHelp.name
name
Definition: gaudiComponentHelp.py:28
Service::finalize
StatusCode finalize() override
Definition: Service.cpp:193
SequentialSchedulerSvc::m_algList
std::list< IAlgorithm * > m_algList
Cache the list of algs to be executed.
Definition: SequentialSchedulerSvc.h:73
CommonMessagingBase::info
MsgStream & info() const
shortcut for the method msgStream(MSG::INFO)
Definition: CommonMessaging.h:124
IAlgorithm.h
StatusCode::isSuccess
bool isSuccess() const
Test for a status code of SUCCESS.
Definition: StatusCode.h:76
SequentialSchedulerSvc.h
std
STL namespace.
SequentialSchedulerSvc::tryPopFinishedEvent
virtual StatusCode tryPopFinishedEvent(EventContext *&eventContext)
Try to fetch an event from the scheduler.
Definition: SequentialSchedulerSvc.cpp:165
SequentialSchedulerSvc::pushNewEvents
virtual StatusCode pushNewEvents(std::vector< EventContext * > &eventContexts)
Definition: SequentialSchedulerSvc.cpp:143
Algorithm::filterPassed
bool filterPassed() const override
Did this algorithm pass or fail its filter criterion for the last event?
Definition: Algorithm.cpp:857
IAlgManager::getAlgorithms
virtual const std::vector< IAlgorithm * > & getAlgorithms() const =0
Return the list of Algorithms.
SequentialSchedulerSvc::finalize
virtual StatusCode finalize()
Finalise.
Definition: SequentialSchedulerSvc.cpp:57
IAlgResourcePool::getFlatAlgList
virtual std::list< IAlgorithm * > getFlatAlgList()=0
Get the flat list of algorithms.
SequentialSchedulerSvc::freeSlots
virtual unsigned int freeSlots()
Get free slots number.
Definition: SequentialSchedulerSvc.cpp:173
merge_files.sc
int sc
Definition: merge_files.py:167
EventContext
This class represents an entry point to all the event specific data.
Definition: EventContext.h:25
Algorithm::setContext
void setContext(EventContext *context)
set the context
Definition: Algorithm.h:574
Algorithm::name
const std::string & name() const override
The identifying name of the algorithm object.
Definition: Algorithm.cpp:820
Gaudi::ReturnCode::UnhandledException
constexpr int UnhandledException
Definition: AppReturnCode.h:27
CommonMessagingBase::error
MsgStream & error() const
shortcut for the method msgStream(MSG::ERROR)
Definition: CommonMessaging.h:118
SvcFactory.h
SequentialSchedulerSvc::~SequentialSchedulerSvc
~SequentialSchedulerSvc()
Destructor.
Definition: SequentialSchedulerSvc.cpp:31
IAlgResourcePool::getTopAlgList
virtual std::list< IAlgorithm * > getTopAlgList()=0
Get top list of algorithms.
CommonMessagingBase::warning
MsgStream & warning() const
shortcut for the method msgStream(MSG::WARNING)
Definition: CommonMessaging.h:121
StatusCode::FAILURE
Definition: StatusCode.h:29
std::exception::what
T what(T...args)
StatusCode::SUCCESS
Definition: StatusCode.h:30
StatusCode
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:26
EventContext::setFail
void setFail(const bool &b=true)
Definition: EventContext.h:65
GaudiException::tag
virtual const std::string & tag() const
name tag for the exception, or exception type
Definition: GaudiException.h:119
DECLARE_SERVICE_FACTORY
#define DECLARE_SERVICE_FACTORY(x)
Definition: Service.h:361
std::exception
STL class.
IAlgorithm
The IAlgorithm is the interface implemented by the Algorithm base class.
Definition: IAlgorithm.h:25
LIKELY
#define LIKELY(x)
Definition: Kernel.h:125
SequentialSchedulerSvc::pushNewEvent
virtual StatusCode pushNewEvent(EventContext *eventContext)
Make an event available to the scheduler.
Definition: SequentialSchedulerSvc.cpp:69
AppReturnCode.h
SequentialSchedulerSvc::m_freeSlots
int m_freeSlots
The number of free slots (0 or 1)
Definition: SequentialSchedulerSvc.h:79
Algorithm
Base class from which all concrete algorithm classes should be derived.
Definition: Algorithm.h:74
std::list::size
T size(T...args)
IProperty.h
SequentialSchedulerSvc::initialize
virtual StatusCode initialize()
Initialise.
Definition: SequentialSchedulerSvc.cpp:34
RetCodeGuard.h
std::vector< EventContext * >
CommonMessagingBase::debug
MsgStream & debug() const
shortcut for the method msgStream(MSG::DEBUG)
Definition: CommonMessaging.h:127
SmartIF::isValid
bool isValid() const
Allow for check if smart pointer is valid.
Definition: SmartIF.h:62
CommonMessaging
Definition: CommonMessaging.h:58
Service::service
StatusCode service(const std::string &name, const T *&psvc, bool createIf=true) const
Access a service by name, creating it if it doesn't already exist.
Definition: Service.h:144
RetCodeGuard::ignore
void ignore()
Definition: RetCodeGuard.h:13
AlgResourcePool.h
CommonMessagingBase::fatal
MsgStream & fatal() const
shortcut for the method msgStream(MSG::FATAL)
Definition: CommonMessaging.h:112
SequentialSchedulerSvc::popFinishedEvent
virtual StatusCode popFinishedEvent(EventContext *&eventContext)
Blocks until an event is availble.
Definition: SequentialSchedulerSvc.cpp:154
SequentialSchedulerSvc::m_useTopAlgList
bool m_useTopAlgList
Decide if the top alglist or its flat version has to be used.
Definition: SequentialSchedulerSvc.h:70
endmsg
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244
SequentialSchedulerSvc
This SchedulerSvc implements the IScheduler interface.
Definition: SequentialSchedulerSvc.h:36
SequentialSchedulerSvc::m_eventContext
EventContext * m_eventContext
The context of the event being processed.
Definition: SequentialSchedulerSvc.h:76