Loading [MathJax]/extensions/tex2jax.js
The Gaudi Framework  v31r0 (aeb156f0)
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
AlgoExecutionTask.cpp
Go to the documentation of this file.
1 // local includes
2 #include "AlgoExecutionTask.h"
3 #include "RetCodeGuard.h"
4 
5 // Framework
11 #include <Gaudi/Algorithm.h>
12 
13 #include <functional>
14 
15 namespace Gaudi {
16  namespace Concurrency {
17  extern thread_local bool ThreadInitDone;
18  }
19 } // namespace Gaudi
20 
22 
23  IAlgorithm* ialg = m_algorithm.get();
24  Gaudi::Algorithm* this_algo = dynamic_cast<Gaudi::Algorithm*>( ialg );
25  if ( !this_algo ) { throw GaudiException( "Cast to Algorithm failed!", "AlgoExecutionTask", StatusCode::FAILURE ); }
26 
27  bool eventfailed = false;
29 
30  // Get the IProperty interface of the ApplicationMgr to pass it to RetCodeGuard
31  const SmartIF<IProperty> appmgr( m_serviceLocator );
32 
33  SmartIF<IMessageSvc> messageSvc( m_serviceLocator );
34  MsgStream log( messageSvc, "AlgoExecutionTask" );
35 
37  log << MSG::DEBUG << "New thread detected: 0x" << std::hex << pthread_self() << std::dec
38  << ". Doing thread local initialization." << endmsg;
40  tps = m_serviceLocator->service( "ThreadPoolSvc" );
41  if ( !tps.isValid() ) {
42  log << MSG::ERROR << "unable to get the ThreadPoolSvc to trigger thread local initialization" << endmsg;
43  throw GaudiException( "retrieval of ThrePoolSvc failed", "AlgoExecutionTask", StatusCode::FAILURE );
44  }
45 
46  tps->initThisThread();
47  }
48 
49  // select the appropriate store
50  this_algo->whiteboard()->selectStore( m_evtCtx.valid() ? m_evtCtx.slot() : 0 ).ignore();
51 
53  try {
55  sc = m_algorithm->sysExecute( m_evtCtx );
56  if ( UNLIKELY( !sc.isSuccess() ) ) {
57  log << MSG::WARNING << "Execution of algorithm " << m_algorithm->name() << " failed" << endmsg;
58  eventfailed = true;
59  }
60  rcg.ignore(); // disarm the guard
61  } catch ( const GaudiException& Exception ) {
62  log << MSG::FATAL << ".executeEvent(): Exception with tag=" << Exception.tag() << " thrown by "
63  << m_algorithm->name() << endmsg;
64  log << MSG::ERROR << Exception << endmsg;
65  eventfailed = true;
66  } catch ( const std::exception& Exception ) {
67  log << MSG::FATAL << ".executeEvent(): Standard std::exception thrown by " << m_algorithm->name() << endmsg;
68  log << MSG::ERROR << Exception.what() << endmsg;
69  eventfailed = true;
70  } catch ( ... ) {
71  log << MSG::FATAL << ".executeEvent(): UNKNOWN Exception thrown by " << m_algorithm->name() << endmsg;
72  eventfailed = true;
73  }
74 
75  // DP it is important to propagate the failure of an event.
76  // We need to stop execution when this happens so that execute run can
77  // then receive the FAILURE
78  m_aess->updateEventStatus( eventfailed, m_evtCtx );
79 
80  // update scheduler state
81  m_promote2ExecutedClosure();
82 
84 
85  return nullptr;
86 }
#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
bool isSuccess() const
Definition: StatusCode.h:267
SmartIF< IHiveWhiteBoard > & whiteboard() const
Definition: Algorithm.cpp:677
virtual void initThisThread()=0
Do thread local initialization of current thread.
tbb::task * execute() override
constexpr int UnhandledException
Definition: AppReturnCode.h:27
virtual StatusCode selectStore(size_t partitionIndex)=0
Activate an given &#39;slot&#39; for all subsequent calls within the same thread id.
T what(T...args)
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:50
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)
thread_local bool ThreadInitDone
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)
void ignore()
Definition: RetCodeGuard.h:12
Helper functions to set/get the application return code.
Definition: __init__.py:1
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:192