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< Service, IScheduler >
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::stringgetInterfaceNames () const override
 Implementation of IInterface::getInterfaceNames. More...
 
 ~extends () override=default
 Virtual destructor. More...
 
- Public Member Functions inherited from Service
const std::stringname () const override
 Retrieve name of the service. More...
 
StatusCode configure () override
 
StatusCode initialize () override
 
StatusCode start () override
 
StatusCode stop () override
 
StatusCode finalize () override
 
StatusCode terminate () override
 
Gaudi::StateMachine::State FSMState () const override
 
Gaudi::StateMachine::State targetFSMState () const override
 
StatusCode reinitialize () override
 
StatusCode restart () override
 
StatusCode sysInitialize () override
 Initialize Service. More...
 
StatusCode sysStart () override
 Initialize Service. More...
 
StatusCode sysStop () override
 Initialize Service. More...
 
StatusCode sysFinalize () override
 Finalize Service. More...
 
StatusCode sysReinitialize () override
 Re-initialize the Service. More...
 
StatusCode sysRestart () override
 Re-initialize the Service. More...
 
StatusCode setProperty (const Property &p) override
 
StatusCode setProperty (const std::string &s) override
 
StatusCode setProperty (const std::string &n, const std::string &v) override
 
StatusCode getProperty (Property *p) const override
 
const PropertygetProperty (const std::string &name) const override
 
StatusCode getProperty (const std::string &n, std::string &v) const override
 
const std::vector< Property * > & getProperties () const override
 
bool hasProperty (const std::string &name) const override
 
template<class TYPE >
StatusCode setProperty (const std::string &name, const TYPE &value)
 set the property form the value More...
 
 Service (std::string name, ISvcLocator *svcloc)
 Standard Constructor. More...
 
SmartIF< ISvcLocator > & serviceLocator () const override
 Retrieve pointer to service locator. More...
 
StatusCode setProperties ()
 Method for setting declared properties to the values specified for the job. More...
 
template<class T >
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. More...
 
template<class T >
StatusCode service (const std::string &name, T *&psvc, bool createIf=true) const
 
template<typename IFace = IService>
SmartIF< IFace > service (const std::string &name, bool createIf=true) const
 
template<class T >
StatusCode service (const std::string &svcType, const std::string &svcName, T *&psvc) const
 Access a service by name and type, creating it if it doesn't already exist. More...
 
template<class T >
PropertydeclareProperty (const std::string &name, T &property, const std::string &doc="none") const
 Declare the named property. More...
 
PropertydeclareRemoteProperty (const std::string &name, IProperty *rsvc, const std::string &rname="") const
 Declare remote named properties. More...
 
template<class T >
StatusCode declarePrivateTool (ToolHandle< T > &handle, std::string toolTypeAndName="", bool createIf=true)
 Declare used Private tool. More...
 
template<class T >
StatusCode declarePublicTool (ToolHandle< T > &handle, std::string toolTypeAndName="", bool createIf=true)
 Declare used Public tool. More...
 
SmartIF< IAuditorSvc > & auditorSvc () const
 The standard auditor service.May not be invoked before sysInitialize() has been invoked. More...
 
- Public Member Functions inherited from CommonMessagingBase
virtual ~CommonMessagingBase ()=default
 Virtual destructor. More...
 
SmartIF< IMessageSvc > & msgSvc () const
 The standard message service. More...
 
MsgStreammsgStream () const
 Return an uninitialized MsgStream. More...
 
MsgStreammsgStream (const MSG::Level level) const
 Predefined configurable message stream for the efficient printouts. More...
 
MsgStreamalways () const
 shortcut for the method msgStream(MSG::ALWAYS) More...
 
MsgStreamfatal () const
 shortcut for the method msgStream(MSG::FATAL) More...
 
MsgStreamerr () const
 shortcut for the method msgStream(MSG::ERROR) More...
 
MsgStreamerror () const
 shortcut for the method msgStream(MSG::ERROR) More...
 
MsgStreamwarning () const
 shortcut for the method msgStream(MSG::WARNING) More...
 
MsgStreaminfo () const
 shortcut for the method msgStream(MSG::INFO) More...
 
MsgStreamdebug () const
 shortcut for the method msgStream(MSG::DEBUG) More...
 
MsgStreamverbose () const
 shortcut for the method msgStream(MSG::VERBOSE) More...
 
MsgStreammsg () const
 shortcut for the method msgStream(MSG::INFO) More...
 
MSG::Level msgLevel () const
 get the output level from the embedded MsgStream More...
 
MSG::Level outputLevel () const __attribute__((deprecated))
 Backward compatibility function for getting the output level. More...
 
bool msgLevel (MSG::Level lvl) const
 get the output level from the embedded MsgStream More...
 
- Public Member Functions inherited from extend_interfaces< Interfaces...>
 ~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< Service, IScheduler >
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 Service
typedef Gaudi::PluginService::Factory< IService *, const std::string &, ISvcLocator * > Factory
 
- Public Types inherited from CommonMessaging< implements< IService, IProperty, IStateful > >
using base_class = CommonMessaging
 
- 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...
 
- Protected Member Functions inherited from Service
 ~Service () override
 Standard Destructor. More...
 
int outputLevel () const
 get the Service's output level More...
 
- Protected Member Functions inherited from CommonMessaging< implements< IService, IProperty, IStateful > >
void updateMsgStreamOutputLevel (int level)
 Update the output level of the cached MsgStream. More...
 
- Protected Attributes inherited from Service
IntegerProperty m_outputLevel = MSG::NIL
 Service output level. More...
 
Gaudi::StateMachine::State m_state = Gaudi::StateMachine::OFFLINE
 Service state. More...
 
Gaudi::StateMachine::State m_targetState = Gaudi::StateMachine::OFFLINE
 Service state. 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)
Property * declareProperty(const std::string &name, T &property, const std::string &doc="none") const
Declare the named property.
Definition: Service.h:215
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 }
StatusCode finalize() override
Definition: Service.cpp:193
MsgStream & warning() const
shortcut for the method msgStream(MSG::WARNING)
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:26
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244
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:68
SmartIF< ISvcLocator > & serviceLocator() const override
Retrieve pointer to service locator.
Definition: Service.cpp:324
std::list< IAlgorithm * > m_algList
Cache the list of algs to be executed.
MsgStream & info() const
shortcut for the method msgStream(MSG::INFO)
MsgStream & error() const
shortcut for the method msgStream(MSG::ERROR)
MsgStream & warning() const
shortcut for the method msgStream(MSG::WARNING)
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:26
T size(T...args)
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
bool m_useTopAlgList
Decide if the top alglist or its flat version has to be used.
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244
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 }
int m_freeSlots
The number of free slots (0 or 1)
MsgStream & debug() const
shortcut for the method msgStream(MSG::DEBUG)
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244
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)
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 UNLIKELY(x)
Definition: Kernel.h:126
SmartIF< ISvcLocator > & serviceLocator() const override
Retrieve pointer to service locator.
Definition: Service.cpp:324
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
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:857
void setContext(EventContext *context)
set the context
Definition: Algorithm.h:574
const std::string & name() const override
The identifying name of the algorithm object.
Definition: Algorithm.cpp:820
constexpr int UnhandledException
Definition: AppReturnCode.h:27
MsgStream & error() const
shortcut for the method msgStream(MSG::ERROR)
MsgStream & warning() const
shortcut for the method msgStream(MSG::WARNING)
T what(T...args)
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:26
void setFail(const bool &b=true)
Definition: EventContext.h:65
virtual const std::string & tag() const
name tag for the exception, or exception type
STL class.
The IAlgorithm is the interface implemented by the Algorithm base class.
Definition: IAlgorithm.h:25
#define LIKELY(x)
Definition: Kernel.h:125
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:74
MsgStream & debug() const
shortcut for the method msgStream(MSG::DEBUG)
MsgStream & fatal() const
shortcut for the method msgStream(MSG::FATAL)
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244
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 73 of file SequentialSchedulerSvc.h.

EventContext* SequentialSchedulerSvc::m_eventContext
private

The context of the event being processed.

Definition at line 76 of file SequentialSchedulerSvc.h.

int SequentialSchedulerSvc::m_freeSlots
private

The number of free slots (0 or 1)

Definition at line 79 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 70 of file SequentialSchedulerSvc.h.


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