| The Gaudi Framework v27r1

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

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/ThreadLocalContext.h"
7
8 // C++
9 #include <functional>
10
11 // local includes
12 #include "RetCodeGuard.h"
13
14 tbb::task* AlgoExecutionTask::execute() {
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::setCurrentContext( eventContext );
25
26 m_schedSvc->addAlg(this_algo, eventContext, pthread_self());
27
28 // Get the IProperty interface of the ApplicationMgr to pass it to RetCodeGuard
29 const SmartIF<IProperty> appmgr(m_serviceLocator);
30
31 SmartIF<IMessageSvc> messageSvc (m_serviceLocator);
32 MsgStream log(messageSvc, "AlgoExecutionTask");
33
34 StatusCode sc(StatusCode::FAILURE);
35 try {
36 RetCodeGuard rcg(appmgr, Gaudi::ReturnCode::UnhandledException);
37 sc = m_algorithm->sysExecute();
38 if (UNLIKELY(!sc.isSuccess())) {
39 log << MSG::WARNING << "Execution of algorithm " << m_algorithm->name() << " failed" << endmsg;
40 eventfailed = true;
41 }
42 rcg.ignore(); // disarm the guard
43 } catch ( const GaudiException& Exception ) {
44 log << MSG::FATAL << ".executeEvent(): Exception with tag=" << Exception.tag()
45 << " thrown by " << m_algorithm->name() << endmsg;
46 log << MSG::ERROR << Exception << endmsg;
47 } catch ( const std::exception& Exception ) {
48 log << MSG::FATAL << ".executeEvent(): Standard std::exception thrown by "
49 << m_algorithm->name() << endmsg;
50 log << MSG::ERROR << Exception.what() << endmsg;
51 } catch(...) {
52 log << MSG::FATAL << ".executeEvent(): UNKNOWN Exception thrown by "
53 << m_algorithm->name() << endmsg;
54 }
55
56 // Commit all DataHandles
57 this_algo->commitHandles();
58
59 // DP it is important to propagate the failure of an event.
60 // We need to stop execution when this happens so that execute run can
61 // then receive the FAILURE
62 eventContext->setFail(eventfailed);
63
64 // Push in the scheduler queue an action to be performed
65 auto action_promote2Executed = std::bind(&ForwardSchedulerSvc::promoteToExecuted,
66 m_schedSvc,
67 m_algoIndex,
68 eventContext->slot(),
69 m_algorithm);
70
71 m_schedSvc->m_actionsQueue.push(action_promote2Executed);
72
73 m_schedSvc->delAlg(this_algo);
74
75 Gaudi::Hive::setCurrentContextEvt(-1);
76
77 return nullptr;
78 }
UNLIKELY
#define UNLIKELY(x)
Definition: Kernel.h:126
MsgStream
Definition of the MsgStream class used to transmit messages.
Definition: MsgStream.h:24
Algorithm.h
SmartIF< IProperty >
GaudiException
Define general base for Gaudi exception.
Definition: GaudiException.h:23
RetCodeGuard
Helper class to set the application return code in case of early exit (e.g.
Definition: RetCodeGuard.h:9
Algorithm::commitHandles
void commitHandles() override
Definition: Algorithm.cpp:1097
EventContext::slot
ContextID_t slot() const
Definition: EventContext.h:41
Gaudi.Configuration.log
tuple log
Definition: Configuration.py:13
StatusCode::isSuccess
bool isSuccess() const
Test for a status code of SUCCESS.
Definition: StatusCode.h:76
ThreadLocalContext.h
AlgoExecutionTask::m_serviceLocator
SmartIF< ISvcLocator > m_serviceLocator
Definition: AlgoExecutionTask.h:30
AlgoExecutionTask::m_algorithm
SmartIF< IAlgorithm > m_algorithm
Definition: AlgoExecutionTask.h:26
AlgoExecutionTask::execute
virtual tbb::task * execute()
Definition: AlgoExecutionTask.cpp:14
Algorithm::getContext
EventContext * getContext() const
get the context
Definition: Algorithm.h:571
merge_files.sc
int sc
Definition: merge_files.py:167
EventContext
This class represents an entry point to all the event specific data.
Definition: EventContext.h:25
ForwardSchedulerSvc::promoteToExecuted
StatusCode promoteToExecuted(unsigned int iAlgo, int si, IAlgorithm *algo)
The call to this method is triggered only from within the AlgoExecutionTask.
Definition: ForwardSchedulerSvc.cpp:928
IAlgorithm::sysExecute
virtual StatusCode sysExecute()=0
System execution. This method invokes the execute() method of a concrete algorithm.
Gaudi::ReturnCode::UnhandledException
constexpr int UnhandledException
Definition: AppReturnCode.h:27
SmartIF::get
TYPE * get() const
Get interface pointer.
Definition: SmartIF.h:76
MSG::FATAL
Definition: IMessageSvc.h:22
ForwardSchedulerSvc::addAlg
void addAlg(Algorithm *, EventContext *, pthread_t)
Definition: ForwardSchedulerSvc.cpp:1002
AlgoExecutionTask::m_schedSvc
SmartIF< ForwardSchedulerSvc > m_schedSvc
Definition: AlgoExecutionTask.h:29
AlgoExecutionTask::m_algoIndex
const unsigned int m_algoIndex
Definition: AlgoExecutionTask.h:27
StatusCode::FAILURE
Definition: StatusCode.h:29
std::exception::what
T what(T...args)
StatusCode
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:26
EventContext::setFail
void setFail(const bool &b=true)
Definition: EventContext.h:65
GaudiException::tag
virtual const std::string & tag() const
name tag for the exception, or exception type
Definition: GaudiException.h:119
std::bind
T bind(T...args)
IMessageSvc.h
std::exception
STL class.
Gaudi::Hive::setCurrentContext
GAUDI_API void setCurrentContext(const EventContext *ctx)
Definition: ThreadLocalContext.cpp:35
ForwardSchedulerSvc::m_actionsQueue
tbb::concurrent_bounded_queue< action > m_actionsQueue
Queue where closures are stored and picked for execution.
Definition: ForwardSchedulerSvc.h:206
Algorithm
Base class from which all concrete algorithm classes should be derived.
Definition: Algorithm.h:74
IProperty.h
RetCodeGuard.h
Gaudi::Hive::setCurrentContextEvt
GAUDI_API void setCurrentContextEvt(long int evtN)
Definition: ThreadLocalContext.cpp:18
MSG::ERROR
Definition: IMessageSvc.h:21
ForwardSchedulerSvc::delAlg
bool delAlg(Algorithm *)
Definition: ForwardSchedulerSvc.cpp:1011
RetCodeGuard::ignore
void ignore()
Definition: RetCodeGuard.h:13
MSG::WARNING
Definition: IMessageSvc.h:20
endmsg
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244
AlgoExecutionTask.h