| The Gaudi Framework v30r0 (c919700c)

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

- File List
- File Members

AlgoExecutionTask.cpp
Go to the documentation of this file.
1 // local includes
2 #include "AlgoExecutionTask.h"
3 #include "RetCodeGuard.h"
4
5 // Framework
6 #include "GaudiKernel/Algorithm.h"
7 #include "GaudiKernel/IAlgExecStateSvc.h"
8 #include "GaudiKernel/IMessageSvc.h"
9 #include "GaudiKernel/IProperty.h"
10 #include "GaudiKernel/ThreadLocalContext.h"
11
12 #include <functional>
13
14 tbb::task* AlgoExecutionTask::execute()
15 {
16
17 IAlgorithm* ialg = m_algorithm.get();
18 Algorithm* this_algo = dynamic_cast<Algorithm*>( ialg );
19 if ( !this_algo ) {
20 throw GaudiException( "Cast to Algorithm failed!", "AlgoExecutionTask", StatusCode::FAILURE );
21 }
22
23 bool eventfailed = false;
24 Gaudi::Hive::setCurrentContext( m_evtCtx );
25
26 // TODO reproduce the commented out functionality in a different service
27 // m_schedSvc->addAlg(this_algo, m_evtCtx, pthread_self());
28
29 // Get the IProperty interface of the ApplicationMgr to pass it to RetCodeGuard
30 const SmartIF<IProperty> appmgr( m_serviceLocator );
31
32 SmartIF<IMessageSvc> messageSvc( m_serviceLocator );
33 MsgStream log( messageSvc, "AlgoExecutionTask" );
34
35 // select the appropriate store
36 this_algo->whiteboard()->selectStore( m_evtCtx->valid() ? m_evtCtx->slot() : 0 ).ignore();
37
38 StatusCode sc( StatusCode::FAILURE );
39 try {
40 RetCodeGuard rcg( appmgr, Gaudi::ReturnCode::UnhandledException );
41 m_aess->algExecState( ialg, *m_evtCtx ).setState( AlgExecState::State::Executing );
42 sc = m_algorithm->sysExecute( *m_evtCtx );
43 if ( UNLIKELY( !sc.isSuccess() ) ) {
44 log << MSG::WARNING << "Execution of algorithm " << m_algorithm->name() << " failed" << endmsg;
45 eventfailed = true;
46 }
47 rcg.ignore(); // disarm the guard
48 } catch ( const GaudiException& Exception ) {
49 log << MSG::FATAL << ".executeEvent(): Exception with tag=" << Exception.tag() << " thrown by "
50 << m_algorithm->name() << endmsg;
51 log << MSG::ERROR << Exception << endmsg;
52 eventfailed = true;
53 } catch ( const std::exception& Exception ) {
54 log << MSG::FATAL << ".executeEvent(): Standard std::exception thrown by " << m_algorithm->name() << endmsg;
55 log << MSG::ERROR << Exception.what() << endmsg;
56 eventfailed = true;
57 } catch ( ... ) {
58 log << MSG::FATAL << ".executeEvent(): UNKNOWN Exception thrown by " << m_algorithm->name() << endmsg;
59 eventfailed = true;
60 }
61
62 // Commit all DataHandles
63 this_algo->commitHandles();
64
65 // DP it is important to propagate the failure of an event.
66 // We need to stop execution when this happens so that execute run can
67 // then receive the FAILURE
68 m_aess->algExecState( ialg, *m_evtCtx ).setState( AlgExecState::State::Done, sc );
69 m_aess->updateEventStatus( eventfailed, *m_evtCtx );
70
71 // TODO reproduce the commented out functionality in a different service
72 // m_schedSvc->delAlg(this_algo);
73
74 // update scheduler state
75 m_promote2ExecutedClosure();
76
77 Gaudi::Hive::setCurrentContextEvt( -1 );
78
79 return nullptr;
80 }
UNLIKELY
#define UNLIKELY(x)
Definition: Kernel.h:128
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:22
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:971
IAlgExecStateSvc.h
EventContext::slot
ContextID_t slot() const
Definition: EventContext.h:40
AlgoExecutionTask::m_aess
IAlgExecStateSvc * m_aess
Definition: AlgoExecutionTask.h:29
StatusCode::isSuccess
bool isSuccess() const
Test for a status code of SUCCESS.
Definition: StatusCode.h:50
ThreadLocalContext.h
AlgoExecutionTask::m_serviceLocator
SmartIF< ISvcLocator > m_serviceLocator
Definition: AlgoExecutionTask.h:30
AlgoExecutionTask::m_algorithm
SmartIF< IAlgorithm > m_algorithm
Definition: AlgoExecutionTask.h:27
AlgExecState::setState
void setState(State s)
Definition: IAlgExecStateSvc.h:37
AlgoExecutionTask::execute
tbb::task * execute() override
Definition: AlgoExecutionTask.cpp:14
Gaudi::ReturnCode::UnhandledException
constexpr int UnhandledException
Definition: AppReturnCode.h:29
SmartIF::get
TYPE * get() const
Get interface pointer.
Definition: SmartIF.h:82
MSG::FATAL
Definition: IMessageSvc.h:16
IHiveWhiteBoard::selectStore
virtual StatusCode selectStore(size_t partitionIndex)=0
Activate an given &#39;slot&#39; for all subsequent calls within the same thread id.
std::exception::what
T what(T...args)
StatusCode
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:26
IAlgExecStateSvc::algExecState
virtual const AlgExecState & algExecState(const Gaudi::StringKey &algName, const EventContext &ctx) const =0
IAlgorithm::sysExecute
virtual StatusCode sysExecute(const EventContext &)=0
System execution. This method invokes the execute() method of a concrete algorithm.
GaudiException::tag
virtual const std::string & tag() const
name tag for the exception, or exception type
Definition: GaudiException.h:109
IMessageSvc.h
std::exception
STL class.
IAlgorithm
The IAlgorithm is the interface implemented by the Algorithm base class.
Definition: IAlgorithm.h:28
Gaudi::Hive::setCurrentContext
GAUDI_API void setCurrentContext(const EventContext *ctx)
Definition: ThreadLocalContext.cpp:35
IAlgExecStateSvc::updateEventStatus
virtual void updateEventStatus(const bool &b, const EventContext &ctx)=0
Algorithm::whiteboard
SmartIF< IHiveWhiteBoard > & whiteboard() const
Definition: Algorithm.cpp:813
Algorithm
Base class from which all concrete algorithm classes should be derived.
Definition: Algorithm.h:79
IProperty.h
RetCodeGuard.h
Gaudi::Hive::setCurrentContextEvt
GAUDI_API void setCurrentContextEvt(long int evtN)
Definition: ThreadLocalContext.cpp:26
MSG::ERROR
Definition: IMessageSvc.h:16
AlgoExecutionTask::m_evtCtx
EventContext * m_evtCtx
Definition: AlgoExecutionTask.h:28
RetCodeGuard::ignore
void ignore()
Definition: RetCodeGuard.h:13
MSG::WARNING
Definition: IMessageSvc.h:16
StatusCode::FAILURE
Definition: StatusCode.h:29
AlgoExecutionTask::m_promote2ExecutedClosure
std::function< StatusCode()> m_promote2ExecutedClosure
Definition: AlgoExecutionTask.h:31
endmsg
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:209
AlgoExecutionTask.h
Gaudi.Configuration.log
log
Definition: Configuration.py:13
EventContext::valid
bool valid() const
Definition: EventContext.h:41