The Gaudi Framework  v33r1 (b1225454)
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 26 of file AlgoExecutionTask.h.

Constructor & Destructor Documentation

◆ AlgoExecutionTask()

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

Definition at line 28 of file AlgoExecutionTask.h.

IAlgExecStateSvc * m_aess
SmartIF< ISvcLocator > m_serviceLocator
AvalancheSchedulerSvc * m_scheduler
GAUDI_API ISvcLocator * svcLocator()

Member Function Documentation

◆ execute()

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

Definition at line 31 of file AlgoExecutionTask.cpp.

31  {
32 
33  // Get queue data
35  if ( !m_scheduler->m_scheduledQueue.try_pop( queuePop ) ) return nullptr;
36 
37  std::string algName = m_scheduler->index2algname( queuePop.algIndex );
38  EventContext& evtCtx = *queuePop.contextPtr;
39  IAlgorithm* iAlgoPtr = queuePop.algPtr;
40 
41  Gaudi::Algorithm* this_algo = dynamic_cast<Gaudi::Algorithm*>( iAlgoPtr );
42  if ( !this_algo ) { throw GaudiException( "Cast to Algorithm failed!", "AlgoExecutionTask", StatusCode::FAILURE ); }
43 
44  bool eventfailed = false;
46 
47  // Get the IProperty interface of the ApplicationMgr to pass it to RetCodeGuard
48  const SmartIF<IProperty> appmgr( m_serviceLocator );
49 
51  MsgStream log( messageSvc, "AlgoExecutionTask" );
52 
54  log << MSG::DEBUG << "New thread detected: 0x" << std::hex << pthread_self() << std::dec
55  << ". Doing thread local initialization." << endmsg;
57  tps = m_serviceLocator->service( "ThreadPoolSvc" );
58  if ( !tps.isValid() ) {
59  log << MSG::ERROR << "unable to get the ThreadPoolSvc to trigger thread local initialization" << endmsg;
60  throw GaudiException( "retrieval of ThrePoolSvc failed", "AlgoExecutionTask", StatusCode::FAILURE );
61  }
62 
63  tps->initThisThread();
64  }
65 
66  // select the appropriate store
67  this_algo->whiteboard()->selectStore( evtCtx.valid() ? evtCtx.slot() : 0 ).ignore();
69  try {
71  sc = iAlgoPtr->sysExecute( evtCtx );
72  if ( UNLIKELY( !sc.isSuccess() ) ) {
73  log << MSG::WARNING << "Execution of algorithm " << algName << " failed" << endmsg;
74  eventfailed = true;
75  }
76  rcg.ignore(); // disarm the guard
77  } catch ( const GaudiException& Exception ) {
78  log << MSG::FATAL << ".executeEvent(): Exception with tag=" << Exception.tag() << " thrown by " << algName
79  << endmsg;
80  log << MSG::ERROR << Exception << endmsg;
81  eventfailed = true;
82  } catch ( const std::exception& Exception ) {
83  log << MSG::FATAL << ".executeEvent(): Standard std::exception thrown by " << algName << endmsg;
84  log << MSG::ERROR << Exception.what() << endmsg;
85  eventfailed = true;
86  } catch ( ... ) {
87  log << MSG::FATAL << ".executeEvent(): UNKNOWN Exception thrown by " << algName << endmsg;
88  eventfailed = true;
89  }
90 
91  // DP it is important to propagate the failure of an event.
92  // We need to stop execution when this happens so that execute run can
93  // then receive the FAILURE
94  m_aess->updateEventStatus( eventfailed, evtCtx );
95 
96  // Release algorithm
97  StatusCode releaseAlgSC = m_scheduler->m_algResourcePool->releaseAlgorithm( algName, iAlgoPtr );
98  if ( !releaseAlgSC.isSuccess() ) {
99  log << MSG::ERROR << "[Event " << evtCtx.evt() << ", Slot " << evtCtx.slot() << "] "
100  << "Instance of algorithm " << algName << " could not be properly put back." << endmsg;
101  }
102 
103  // Create a lambda to update scheduler state
104  auto schedulerPtr = m_scheduler; // can't capture m_scheduler directly for some reason (implied this* ?)
105  m_scheduler->m_actionsQueue.push( [schedulerPtr, queuePop]() -> StatusCode {
106  return schedulerPtr->promoteToExecuted( queuePop.algIndex, queuePop.slotIndex, queuePop.contextPtr );
107  } );
108 
110 
111  return nullptr;
112 }
EventContext * contextPtr
#define UNLIKELY(x)
Definition: Kernel.h:106
Definition of the MsgStream class used to transmit messages.
Definition: MsgStream.h:34
ContextID_t slot() const
Definition: EventContext.h:51
Define general base for Gaudi exception.
Helper class to set the application return code in case of early exit (e.g.
Definition: RetCodeGuard.h:19
ContextEvt_t evt() const
Definition: EventContext.h:50
const std::string & index2algname(unsigned int index)
Convert an integer to a name.
IAlgExecStateSvc * m_aess
SmartIF< IHiveWhiteBoard > & whiteboard() const
Definition: Algorithm.cpp:591
SmartIF< ISvcLocator > m_serviceLocator
virtual const std::string & tag() const
name tag for the exception, or exception type
bool isValid() const
Allow for check if smart pointer is valid.
Definition: SmartIF.h:72
virtual void initThisThread()=0
Do thread local initialization of current thread.
Struct to hold entries in the alg queues.
This class represents an entry point to all the event specific data.
Definition: EventContext.h:34
bool valid() const
Definition: EventContext.h:54
unsigned int algIndex
STL class.
constexpr int UnhandledException
Definition: AppReturnCode.h:37
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:86
virtual StatusCode selectStore(size_t partitionIndex)=0
Activate an given 'slot' 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:61
virtual StatusCode sysExecute(const EventContext &)=0
System execution. This method invokes the execute() method of a concrete algorithm.
bool isSuccess() const
Definition: StatusCode.h:365
STL class.
The IAlgorithm is the interface implemented by the Algorithm base class.
Definition: IAlgorithm.h:38
GAUDI_API void setCurrentContext(const EventContext *ctx)
virtual void updateEventStatus(const bool &b, const EventContext &ctx)=0
thread_local bool ThreadInitDone
int slotIndex
Base class from which all concrete algorithm classes should be derived.
Definition: Algorithm.h:89
IAlgorithm * algPtr
constexpr static const auto FAILURE
Definition: StatusCode.h:101
GAUDI_API void setCurrentContextEvt(long int evtN)
T hex(T... args)
tbb::concurrent_priority_queue< AlgQueueEntry, AlgQueueSort > m_scheduledQueue
Queues for scheduled algorithms.
virtual StatusCode releaseAlgorithm(const std::string &name, IAlgorithm *&algo)=0
Release a certain algorithm.
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:202
tbb::concurrent_bounded_queue< action > m_actionsQueue
Queue where closures are stored and picked for execution.

Member Data Documentation

◆ m_aess

IAlgExecStateSvc* AlgoExecutionTask::m_aess
private

Definition at line 34 of file AlgoExecutionTask.h.

◆ m_scheduler

AvalancheSchedulerSvc* AlgoExecutionTask::m_scheduler
private

Definition at line 33 of file AlgoExecutionTask.h.

◆ m_serviceLocator

SmartIF<ISvcLocator> AlgoExecutionTask::m_serviceLocator
private

Definition at line 35 of file AlgoExecutionTask.h.


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