SequentialSchedulerSvc Class Reference

This SchedulerSvc implements the IScheduler interface. More...

#include <src/SequentialSchedulerSvc.h>

Inheritance diagram for SequentialSchedulerSvc:
Collaboration diagram for SequentialSchedulerSvc:

Public Member Functions

 SequentialSchedulerSvc (const std::string &name, ISvcLocator *svc)
 Constructor. More...
 
 ~SequentialSchedulerSvc ()
 Destructor. More...
 
virtual StatusCode initialize ()
 Initialise. More...
 
virtual StatusCode finalize ()
 Finalise. More...
 
virtual StatusCode pushNewEvent (EventContext *eventContext)
 Make an event available to the scheduler. More...
 
virtual StatusCode pushNewEvents (std::vector< EventContext * > &eventContexts)
 
virtual StatusCode popFinishedEvent (EventContext *&eventContext)
 Blocks until an event is availble. More...
 
virtual StatusCode tryPopFinishedEvent (EventContext *&eventContext)
 Try to fetch an event from the scheduler. More...
 
virtual unsigned int freeSlots ()
 Get free slots number. More...
 
- Public Member Functions inherited from extends< BASE, Interfaces >
void * i_cast (const InterfaceID &tid) const override
 Implementation of IInterface::i_cast. More...
 
StatusCode queryInterface (const InterfaceID &ti, void **pp) override
 Implementation of IInterface::queryInterface. More...
 
std::vector< std::string > getInterfaceNames () const override
 Implementation of IInterface::getInterfaceNames. More...
 
 ~extends () override=default
 Virtual destructor. More...
 
void * i_cast (const InterfaceID &tid) const override
 Implementation of IInterface::i_cast. More...
 
StatusCode queryInterface (const InterfaceID &ti, void **pp) override
 Implementation of IInterface::queryInterface. More...
 
std::vector< std::string > getInterfaceNames () const override
 Implementation of IInterface::getInterfaceNames. More...
 
 ~extends () override=default
 Virtual destructor. More...
 
- Public Member Functions inherited from extend_interfaces< Interfaces...>
 ~extend_interfaces () override=default
 Virtual destructor. More...
 
 ~extend_interfaces () override=default
 Virtual destructor. More...
 

Private Attributes

bool m_useTopAlgList
 Decide if the top alglist or its flat version has to be used. More...
 
std::list< IAlgorithm * > m_algList
 Cache the list of algs to be executed. More...
 
EventContextm_eventContext
 The context of the event being processed. More...
 
int m_freeSlots
 The number of free slots (0 or 1) More...
 

Additional Inherited Members

- Public Types inherited from extends< BASE, Interfaces >
using base_class = extends
 Typedef to this class. More...
 
using extend_interfaces_base = extend_interfaces< Interfaces...>
 Typedef to the base of this class. More...
 
using base_class = extends
 Typedef to this class. More...
 
using extend_interfaces_base = extend_interfaces< Interfaces...>
 Typedef to the base of this class. More...
 
- Public Types inherited from extend_interfaces< Interfaces...>
using ext_iids = typename Gaudi::interface_list_cat< typename Interfaces::ext_iids...>::type
 take union of the ext_iids of all Interfaces... More...
 
using ext_iids = typename Gaudi::interface_list_cat< typename Interfaces::ext_iids...>::type
 take union of the ext_iids of all Interfaces... More...
 

Detailed Description

This SchedulerSvc implements the IScheduler interface.

It executes all the algorithms in sequence, pulling them from the AlgResourcePool. No task level parallelism is involved. Given its sequential nature, the scheduler does not run in its own thread. It has therefore to be treated a as a THREAD UNSAFE and NON REENTRANT entity.

Author
Danilo Piparo
Benedikt Hegner
Version
1.1

Definition at line 36 of file SequentialSchedulerSvc.h.

Constructor & Destructor Documentation

SequentialSchedulerSvc::SequentialSchedulerSvc ( const std::string &  name,
ISvcLocator svc 
)

Constructor.

Definition at line 23 of file SequentialSchedulerSvc.cpp.

23  :
24  base_class(name,svcLoc),
25  m_eventContext(nullptr),
26  m_freeSlots(1){
27  declareProperty("UseTopAlgList", m_useTopAlgList=true);
28 }
extends base_class
Typedef to this class.
Definition: extends.h:14
int m_freeSlots
The number of free slots (0 or 1)
bool m_useTopAlgList
Decide if the top alglist or its flat version has to be used.
EventContext * m_eventContext
The context of the event being processed.
SequentialSchedulerSvc::~SequentialSchedulerSvc ( )

Destructor.

Definition at line 31 of file SequentialSchedulerSvc.cpp.

31 {}

Member Function Documentation

StatusCode SequentialSchedulerSvc::finalize ( )
virtual

Finalise.

Definition at line 57 of file SequentialSchedulerSvc.cpp.

57  {
59  if (!sc.isSuccess())
60  warning () << "Base class could not be finalized" << endmsg;
61  return sc;
62 }
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244
StatusCode finalize() override
Definition: Service.cpp:188
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:26
unsigned int SequentialSchedulerSvc::freeSlots ( )
virtual

Get free slots number.

Given that the scheduler is sequential and its methods non reentrant, this is always 1.

Definition at line 173 of file SequentialSchedulerSvc.cpp.

173 {return m_freeSlots;}
int m_freeSlots
The number of free slots (0 or 1)
StatusCode SequentialSchedulerSvc::initialize ( )
virtual

Initialise.

Definition at line 34 of file SequentialSchedulerSvc.cpp.

34  {
35 
36  // Initialise mother class (read properties, ...)
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 }
StatusCode initialize() override
Definition: Service.cpp:63
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244
std::list< IAlgorithm * > m_algList
Cache the list of algs to be executed.
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:26
bool m_useTopAlgList
Decide if the top alglist or its flat version has to be used.
StatusCode SequentialSchedulerSvc::popFinishedEvent ( EventContext *&  eventContext)
virtual

Blocks until an event is availble.

Definition at line 154 of file SequentialSchedulerSvc.cpp.

154  {
155  m_freeSlots++;
156  eventContext = m_eventContext;
157  debug() << "[popFinishedEvent] Free slots are now: " << m_freeSlots << endmsg;
158  return StatusCode::SUCCESS;
159 }
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244
int m_freeSlots
The number of free slots (0 or 1)
EventContext * m_eventContext
The context of the event being processed.
StatusCode SequentialSchedulerSvc::pushNewEvent ( EventContext eventContext)
virtual

Make an event available to the scheduler.

Immediately the algortihms are executed.

Definition at line 69 of file SequentialSchedulerSvc.cpp.

69  {
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",
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
106  try {
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 }
Define general base for Gaudi exception.
Helper class to set the application return code in case of early exit (e.g.
Definition: RetCodeGuard.h:9
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244
std::list< IAlgorithm * > m_algList
Cache the list of algs to be executed.
bool filterPassed() const override
Did this algorithm pass or fail its filter criterion for the last event?
Definition: Algorithm.cpp:948
void setContext(EventContext *context)
set the context
Definition: Algorithm.h:556
const std::string & name() const override
The identifying name of the algorithm object.
Definition: Algorithm.cpp:919
constexpr int UnhandledException
Definition: AppReturnCode.h:27
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:26
void setFail(const bool &b=true)
Definition: EventContext.h:54
virtual const std::string & tag() const
name tag for the exception, or exception type
The IAlgorithm is the interface implemented by the Algorithm base class.
Definition: IAlgorithm.h:23
int m_freeSlots
The number of free slots (0 or 1)
Base class from which all concrete algorithm classes should be derived.
Definition: Algorithm.h:77
#define UNLIKELY(x)
Definition: Kernel.h:126
#define LIKELY(x)
Definition: Kernel.h:125
EventContext * m_eventContext
The context of the event being processed.
StatusCode SequentialSchedulerSvc::pushNewEvents ( std::vector< EventContext * > &  eventContexts)
virtual

Definition at line 143 of file SequentialSchedulerSvc.cpp.

143  {
144  StatusCode sc;
145  for (auto context : eventContexts){
146  sc = pushNewEvent(context);
147  if (sc != StatusCode::SUCCESS) return sc;
148  }
149  return sc;
150 }
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:26
virtual StatusCode pushNewEvent(EventContext *eventContext)
Make an event available to the scheduler.
StatusCode SequentialSchedulerSvc::tryPopFinishedEvent ( EventContext *&  eventContext)
virtual

Try to fetch an event from the scheduler.

The scheduler is sequential.

Therefore pop and try/pop are factually the same.

Definition at line 165 of file SequentialSchedulerSvc.cpp.

165  {
166  return m_freeSlots == 1 ? StatusCode::FAILURE : popFinishedEvent(eventContext);
167 }
int m_freeSlots
The number of free slots (0 or 1)
virtual StatusCode popFinishedEvent(EventContext *&eventContext)
Blocks until an event is availble.

Member Data Documentation

std::list<IAlgorithm*> SequentialSchedulerSvc::m_algList
private

Cache the list of algs to be executed.

Definition at line 72 of file SequentialSchedulerSvc.h.

EventContext* SequentialSchedulerSvc::m_eventContext
private

The context of the event being processed.

Definition at line 75 of file SequentialSchedulerSvc.h.

int SequentialSchedulerSvc::m_freeSlots
private

The number of free slots (0 or 1)

Definition at line 78 of file SequentialSchedulerSvc.h.

bool SequentialSchedulerSvc::m_useTopAlgList
private

Decide if the top alglist or its flat version has to be used.

Definition at line 69 of file SequentialSchedulerSvc.h.


The documentation for this class was generated from the following files: