All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
AlgoExecutionTask.cpp
Go to the documentation of this file.
1 // Framework
2 #include "AlgoExecutionTask.h"
3 #include "GaudiKernel/Algorithm.h"
4 #include "GaudiKernel/IMessageSvc.h"
5 #include "GaudiKernel/IProperty.h"
6 #include "GaudiKernel/ContextSpecificPtr.h"
7 
8 // C++
9 #include <functional>
10 
11 // local includes
12 #include "RetCodeGuard.h"
13 
15 
16  Algorithm* this_algo = dynamic_cast<Algorithm*>(m_algorithm.get());
17  if (!this_algo){
18  throw GaudiException ("Cast to Algorithm failed!","AlgoExecutionTask",StatusCode::FAILURE);
19  }
20 
21  bool eventfailed=false;
22  EventContext* eventContext = this_algo->getContext();
23  // eventContext->m_thread_id = pthread_self();
24  // Gaudi::Hive::setCurrentContextId(eventContext->slot(),eventContext->evt());
25  Gaudi::Hive::setCurrentContextId( eventContext );
26 
27  // Get the IProperty interface of the ApplicationMgr to pass it to RetCodeGuard
29 
31  MsgStream log(messageSvc, "AlgoExecutionTask");
32 
34  try {
36  sc = m_algorithm->sysExecute();
37  if (UNLIKELY(!sc.isSuccess())) {
38  log << MSG::WARNING << "Execution of algorithm " << m_algorithm->name() << " failed" << endmsg;
39  eventfailed = true;
40  }
41  rcg.ignore(); // disarm the guard
42  } catch ( const GaudiException& Exception ) {
43  log << MSG::FATAL << ".executeEvent(): Exception with tag=" << Exception.tag()
44  << " thrown by " << m_algorithm->name() << endmsg;
45  log << MSG::ERROR << Exception << endmsg;
46  } catch ( const std::exception& Exception ) {
47  log << MSG::FATAL << ".executeEvent(): Standard std::exception thrown by "
48  << m_algorithm->name() << endmsg;
49  log << MSG::ERROR << Exception.what() << endmsg;
50  } catch(...) {
51  log << MSG::FATAL << ".executeEvent(): UNKNOWN Exception thrown by "
52  << m_algorithm->name() << endmsg;
53  }
54 
55  // DP it is important to propagate the failure of an event.
56  // We need to stop execution when this happens so that execute run can
57  // then receive the FAILURE
58  eventContext->setFail(eventfailed);
59 
60  // Push in the scheduler queue an action to be performed
61  auto action_promote2Executed = std::bind(&ForwardSchedulerSvc::promoteToExecuted,
62  m_schedSvc,
63  m_algoIndex,
64  eventContext->slot(),
65  m_algorithm);
66 
67  m_schedSvc->m_actionsQueue.push(action_promote2Executed);
68 
70 
71  return nullptr;
72 }
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
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244
bool isSuccess() const
Test for a status code of SUCCESS.
Definition: StatusCode.h:76
SmartIF< ISvcLocator > m_serviceLocator
SmartIF< IAlgorithm > m_algorithm
virtual tbb::task * execute()
This class represents an entry point to all the event specific data.
Definition: EventContext.h:22
GAUDI_API void setCurrentContextId(ContextIdType newId)
Used by the framework to change the value of the current context id.
StatusCode promoteToExecuted(unsigned int iAlgo, int si, IAlgorithm *algo)
The call to this method is triggered only from within the AlgoExecutionTask.
virtual StatusCode sysExecute()=0
System execution. This method invokes the execute() method of a concrete algorithm.
constexpr int UnhandledException
Definition: AppReturnCode.h:27
TYPE * get() const
Get interface pointer.
Definition: SmartIF.h:76
SmartIF< ForwardSchedulerSvc > m_schedSvc
const unsigned int m_algoIndex
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:26
void setFail(const bool &b=true)
Definition: EventContext.h:54
virtual const std::string & tag() const
name tag for the exception, or exception type
tbb::concurrent_bounded_queue< action > m_actionsQueue
Queue where closures are stored and picked for execution.
Base class from which all concrete algorithm classes should be derived.
Definition: Algorithm.h:77
ID_type slot() const
Definition: EventContext.h:38
#define UNLIKELY(x)
Definition: Kernel.h:126
GAUDI_API void setCurrentContextEvt(long int evtN)
void ignore()
Definition: RetCodeGuard.h:13
EventContext * getContext()
get the context
Definition: Algorithm.h:553