The Gaudi Framework  v33r2 (a6f0ec87)
AlgTask< T > Class Template Reference

#include <src/AlgTask.h>

Inheritance diagram for AlgTask< T >:
Collaboration diagram for AlgTask< T >:

Public Member Functions

 AlgTask (AvalancheSchedulerSvc *scheduler, ISvcLocator *svcLocator, IAlgExecStateSvc *aem)
 
 AlgTask (AvalancheSchedulerSvc::TaskSpec &&ts, AvalancheSchedulerSvc *scheduler, ISvcLocator *svcLocator, IAlgExecStateSvc *aem)
 
T * execute () override
 
void operator() ()
 

Private Attributes

AvalancheSchedulerSvc::TaskSpec m_ts
 
AvalancheSchedulerSvcm_scheduler
 
IAlgExecStateSvcm_aess
 
SmartIF< ISvcLocatorm_serviceLocator
 

Detailed Description

template<class T>
class AlgTask< T >

Definition at line 37 of file AlgTask.h.

Constructor & Destructor Documentation

◆ AlgTask() [1/2]

template<class T>
AlgTask< T >::AlgTask ( AvalancheSchedulerSvc scheduler,
ISvcLocator svcLocator,
IAlgExecStateSvc aem 
)
inline

Definition at line 39 of file AlgTask.h.

IAlgExecStateSvc * m_aess
Definition: AlgTask.h:125
AvalancheSchedulerSvc * m_scheduler
Definition: AlgTask.h:124
GAUDI_API ISvcLocator * svcLocator()
SmartIF< ISvcLocator > m_serviceLocator
Definition: AlgTask.h:126

◆ AlgTask() [2/2]

template<class T>
AlgTask< T >::AlgTask ( AvalancheSchedulerSvc::TaskSpec &&  ts,
AvalancheSchedulerSvc scheduler,
ISvcLocator svcLocator,
IAlgExecStateSvc aem 
)
inline

Definition at line 42 of file AlgTask.h.

IAlgExecStateSvc * m_aess
Definition: AlgTask.h:125
AvalancheSchedulerSvc * m_scheduler
Definition: AlgTask.h:124
GAUDI_API ISvcLocator * svcLocator()
AvalancheSchedulerSvc::TaskSpec m_ts
Definition: AlgTask.h:120
T move(T... args)
SmartIF< ISvcLocator > m_serviceLocator
Definition: AlgTask.h:126

Member Function Documentation

◆ execute()

template<class T>
T* AlgTask< T >::execute ( )
inlineoverride

Definition at line 46 of file AlgTask.h.

46  {
47 
49  MsgStream log( messageSvc, "AlgTask" );
50 
51  // Get task specification dynamically if it was not provided statically
52  if ( !m_ts.algPtr )
53  if ( !m_scheduler->m_scheduledQueue.try_pop( m_ts ) ) {
54  log << MSG::WARNING << "Specification not complete or void while task is running" << endmsg;
55  return nullptr;
56  }
57 
58  EventContext& evtCtx = *( m_ts.contextPtr );
59  IAlgorithm*& iAlgoPtr = m_ts.algPtr;
60 
61  Gaudi::Algorithm* this_algo = dynamic_cast<Gaudi::Algorithm*>( iAlgoPtr );
62  if ( !this_algo ) { throw GaudiException( "Cast to Algorithm failed!", "AlgTask", StatusCode::FAILURE ); }
63 
64  bool eventfailed = false;
66 
67  // Get the IProperty interface of the ApplicationMgr to pass it to RetCodeGuard
68  const SmartIF<IProperty> appmgr( m_serviceLocator );
69 
71  log << MSG::DEBUG << "New thread detected: 0x" << std::hex << pthread_self() << std::dec
72  << ". Doing thread local initialization." << endmsg;
73  if ( SmartIF<IThreadPoolSvc> tps{m_serviceLocator->service( "ThreadPoolSvc" )} ) {
74  tps->initThisThread();
75  } else {
76  log << MSG::ERROR << "Unable to get the ThreadPoolSvc to trigger thread local initialization" << endmsg;
77  throw GaudiException( "Retrieval of ThreadPoolSvc failed", "AlgTask", StatusCode::FAILURE );
78  }
79  }
80 
81  // select the appropriate store
82  this_algo->whiteboard()->selectStore( evtCtx.valid() ? evtCtx.slot() : 0 ).ignore();
83  try {
85 
86  if ( UNLIKELY( iAlgoPtr->sysExecute( evtCtx ).isFailure() ) ) {
87  log << MSG::WARNING << "Execution of algorithm " << m_ts.algName << " failed" << endmsg;
88  eventfailed = true;
89  }
90  rcg.ignore(); // disarm the guard
91  } catch ( const GaudiException& Exception ) {
92  log << MSG::FATAL << ".executeEvent(): Exception with tag=" << Exception.tag() << " thrown by " << m_ts.algName
93  << endmsg;
94  log << MSG::ERROR << Exception << endmsg;
95  eventfailed = true;
96  } catch ( const std::exception& Exception ) {
97  log << MSG::FATAL << ".executeEvent(): Standard std::exception thrown by " << m_ts.algName << endmsg;
98  log << MSG::ERROR << Exception.what() << endmsg;
99  eventfailed = true;
100  } catch ( ... ) {
101  log << MSG::FATAL << ".executeEvent(): UNKNOWN Exception thrown by " << m_ts.algName << endmsg;
102  eventfailed = true;
103  }
104 
105  // A FAILURE in algorithm execution must be communicated to the framework
106  m_aess->updateEventStatus( eventfailed, evtCtx );
107 
108  // Release algorithm
110 
111  // schedule a sign-off of the Algorithm execution
113  [schdlr = this->m_scheduler, ts = std::move( this->m_ts )]() { return schdlr->signoff( ts ); } );
114 
116 
117  return nullptr;
118  }
#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
IAlgExecStateSvc * m_aess
Definition: AlgTask.h:125
SmartIF< IHiveWhiteBoard > & whiteboard() const
Definition: Algorithm.cpp:591
virtual const std::string & tag() const
name tag for the exception, or exception type
AvalancheSchedulerSvc * m_scheduler
Definition: AlgTask.h:124
This class represents an entry point to all the event specific data.
Definition: EventContext.h:34
bool valid() const
Definition: EventContext.h:54
constexpr int UnhandledException
Definition: AppReturnCode.h:37
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)
virtual StatusCode sysExecute(const EventContext &)=0
System execution. This method invokes the execute() method of a concrete algorithm.
AvalancheSchedulerSvc::TaskSpec m_ts
Definition: AlgTask.h:120
STL class.
The IAlgorithm is the interface implemented by the Algorithm base class.
Definition: IAlgorithm.h:38
GAUDI_API void setCurrentContext(const EventContext *ctx)
T move(T... args)
virtual void updateEventStatus(const bool &b, const EventContext &ctx)=0
const StatusCode & ignore() const
Ignore/check StatusCode.
Definition: StatusCode.h:168
thread_local bool ThreadInitDone
tbb::concurrent_priority_queue< TaskSpec, AlgQueueSort > m_scheduledQueue
Queues for scheduled algorithms.
Base class from which all concrete algorithm classes should be derived.
Definition: Algorithm.h:89
constexpr static const auto FAILURE
Definition: StatusCode.h:101
GAUDI_API void setCurrentContextEvt(long int evtN)
T hex(T... args)
bool isFailure() const
Definition: StatusCode.h:145
SmartIF< ISvcLocator > m_serviceLocator
Definition: AlgTask.h:126
virtual StatusCode releaseAlgorithm(std::string_view 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.

◆ operator()()

template<class T>
void AlgTask< T >::operator() ( )
inline

Definition at line 120 of file AlgTask.h.

120 { execute(); };
T * execute() override
Definition: AlgTask.h:46

Member Data Documentation

◆ m_aess

template<class T>
IAlgExecStateSvc* AlgTask< T >::m_aess
private

Definition at line 125 of file AlgTask.h.

◆ m_scheduler

template<class T>
AvalancheSchedulerSvc* AlgTask< T >::m_scheduler
private

Definition at line 124 of file AlgTask.h.

◆ m_serviceLocator

template<class T>
SmartIF<ISvcLocator> AlgTask< T >::m_serviceLocator
private

Definition at line 126 of file AlgTask.h.

◆ m_ts

template<class T>
AvalancheSchedulerSvc::TaskSpec AlgTask< T >::m_ts
private

Definition at line 120 of file AlgTask.h.


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