The Gaudi Framework  v32r0 (3325bb39)
AlgoExecutionTask Class Reference

#include <src/AlgoExecutionTask.h>

Inheritance diagram for AlgoExecutionTask:
Collaboration diagram for AlgoExecutionTask:

Public Member Functions

 AlgoExecutionTask (AvalancheSchedulerSvc *scheduler, ISvcLocator *svcLocator, IAlgExecStateSvc *aem)
 
tbb::task * execute () override
 

Private Attributes

AvalancheSchedulerSvcm_scheduler
 
IAlgExecStateSvcm_aess
 
SmartIF< ISvcLocatorm_serviceLocator
 

Detailed Description

Definition at line 16 of file AlgoExecutionTask.h.

Constructor & Destructor Documentation

AlgoExecutionTask::AlgoExecutionTask ( AvalancheSchedulerSvc scheduler,
ISvcLocator svcLocator,
IAlgExecStateSvc aem 
)
inline

Definition at line 18 of file AlgoExecutionTask.h.

19  : m_scheduler( scheduler ), m_aess( aem ), m_serviceLocator( svcLocator ){};
IAlgExecStateSvc * m_aess
SmartIF< ISvcLocator > m_serviceLocator
AvalancheSchedulerSvc * m_scheduler

Member Function Documentation

tbb::task * AlgoExecutionTask::execute ( )
override

Definition at line 21 of file AlgoExecutionTask.cpp.

21  {
22 
23  // Get queue data
25  if ( !m_scheduler->m_scheduledQueue.try_pop( queuePop ) ) return nullptr;
26 
27  std::string algName = m_scheduler->index2algname( queuePop.algIndex );
28  EventContext& evtCtx = *queuePop.contextPtr;
29  IAlgorithm* iAlgoPtr = queuePop.algPtr;
30 
31  Gaudi::Algorithm* this_algo = dynamic_cast<Gaudi::Algorithm*>( iAlgoPtr );
32  if ( !this_algo ) { throw GaudiException( "Cast to Algorithm failed!", "AlgoExecutionTask", StatusCode::FAILURE ); }
33 
34  bool eventfailed = false;
36 
37  // Get the IProperty interface of the ApplicationMgr to pass it to RetCodeGuard
38  const SmartIF<IProperty> appmgr( m_serviceLocator );
39 
41  MsgStream log( messageSvc, "AlgoExecutionTask" );
42 
44  log << MSG::DEBUG << "New thread detected: 0x" << std::hex << pthread_self() << std::dec
45  << ". Doing thread local initialization." << endmsg;
47  tps = m_serviceLocator->service( "ThreadPoolSvc" );
48  if ( !tps.isValid() ) {
49  log << MSG::ERROR << "unable to get the ThreadPoolSvc to trigger thread local initialization" << endmsg;
50  throw GaudiException( "retrieval of ThrePoolSvc failed", "AlgoExecutionTask", StatusCode::FAILURE );
51  }
52 
53  tps->initThisThread();
54  }
55 
56  // select the appropriate store
57  this_algo->whiteboard()->selectStore( evtCtx.valid() ? evtCtx.slot() : 0 ).ignore();
59  try {
61  sc = iAlgoPtr->sysExecute( evtCtx );
62  if ( UNLIKELY( !sc.isSuccess() ) ) {
63  log << MSG::WARNING << "Execution of algorithm " << algName << " failed" << endmsg;
64  eventfailed = true;
65  }
66  rcg.ignore(); // disarm the guard
67  } catch ( const GaudiException& Exception ) {
68  log << MSG::FATAL << ".executeEvent(): Exception with tag=" << Exception.tag() << " thrown by " << algName
69  << endmsg;
70  log << MSG::ERROR << Exception << endmsg;
71  eventfailed = true;
72  } catch ( const std::exception& Exception ) {
73  log << MSG::FATAL << ".executeEvent(): Standard std::exception thrown by " << algName << endmsg;
74  log << MSG::ERROR << Exception.what() << endmsg;
75  eventfailed = true;
76  } catch ( ... ) {
77  log << MSG::FATAL << ".executeEvent(): UNKNOWN Exception thrown by " << algName << endmsg;
78  eventfailed = true;
79  }
80 
81  // DP it is important to propagate the failure of an event.
82  // We need to stop execution when this happens so that execute run can
83  // then receive the FAILURE
84  m_aess->updateEventStatus( eventfailed, evtCtx );
85 
86  // Release algorithm
87  StatusCode releaseAlgSC = m_scheduler->m_algResourcePool->releaseAlgorithm( algName, iAlgoPtr );
88  if ( !releaseAlgSC.isSuccess() ) {
89  log << MSG::ERROR << "[Event " << evtCtx.evt() << ", Slot " << evtCtx.slot() << "] "
90  << "Instance of algorithm " << algName << " could not be properly put back." << endmsg;
91  }
92 
93  // Create a lambda to update scheduler state
94  m_scheduler->m_actionsQueue.push( [this, queuePop]() -> StatusCode {
95  return this->m_scheduler->promoteToExecuted( queuePop.algIndex, queuePop.slotIndex, queuePop.contextPtr );
96  } );
97 
99 
100  return nullptr;
101 }
#define UNLIKELY(x)
Definition: Kernel.h:89
Definition of the MsgStream class used to transmit messages.
Definition: MsgStream.h:24
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
unsigned int algIndex
ContextID_t slot() const
Definition: EventContext.h:41
const std::string & index2algname(unsigned int index)
Convert an integer to a name.
int slotIndex
IAlgExecStateSvc * m_aess
bool isSuccess() const
Definition: StatusCode.h:267
SmartIF< ISvcLocator > m_serviceLocator
SmartIF< IHiveWhiteBoard > & whiteboard() const
Definition: Algorithm.cpp:685
virtual void initThisThread()=0
Do thread local initialization of current thread.
EventContext * contextPtr
Struct to hold entries in the alg queues.
This class represents an entry point to all the event specific data.
Definition: EventContext.h:24
ContextEvt_t evt() const
Definition: EventContext.h:40
STL class.
constexpr int UnhandledException
Definition: AppReturnCode.h:27
AvalancheSchedulerSvc * m_scheduler
StatusCode service(const Gaudi::Utils::TypeNameString &name, T *&svc, bool createIf=true)
Templated method to access a service by name.
Definition: ISvcLocator.h:76
virtual StatusCode selectStore(size_t partitionIndex)=0
Activate an given &#39;slot&#39; for all subsequent calls within the same thread id.
SmartIF< IAlgResourcePool > m_algResourcePool
Cache for the algorithm resource pool.
T what(T...args)
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:50
virtual StatusCode sysExecute(const EventContext &)=0
System execution. This method invokes the execute() method of a concrete algorithm.
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:28
GAUDI_API void setCurrentContext(const EventContext *ctx)
virtual void updateEventStatus(const bool &b, const EventContext &ctx)=0
thread_local bool ThreadInitDone
IAlgorithm * algPtr
bool isValid() const
Allow for check if smart pointer is valid.
Definition: SmartIF.h:62
Base class from which all concrete algorithm classes should be derived.
Definition: Algorithm.h:79
constexpr static const auto FAILURE
Definition: StatusCode.h:86
GAUDI_API void setCurrentContextEvt(long int evtN)
T hex(T...args)
virtual StatusCode releaseAlgorithm(const std::string &name, IAlgorithm *&algo)=0
Release a certain algorithm.
tbb::concurrent_priority_queue< algQueueEntry, algQueueSort > m_scheduledQueue
Queues for scheduled algorithms.
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:192
tbb::concurrent_bounded_queue< action > m_actionsQueue
Queue where closures are stored and picked for execution.
StatusCode promoteToExecuted(unsigned int iAlgo, int si, EventContext *)
The call to this method is triggered only from within the AlgoExecutionTask.
bool valid() const
Definition: EventContext.h:44

Member Data Documentation

IAlgExecStateSvc* AlgoExecutionTask::m_aess
private

Definition at line 24 of file AlgoExecutionTask.h.

AvalancheSchedulerSvc* AlgoExecutionTask::m_scheduler
private

Definition at line 23 of file AlgoExecutionTask.h.

SmartIF<ISvcLocator> AlgoExecutionTask::m_serviceLocator
private

Definition at line 25 of file AlgoExecutionTask.h.


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