| The Gaudi Framework v32r1 (f65d50dc)

IOBoundAlgTask.cpp
Go to the documentation of this file.
1 // local includes
2 #include "IOBoundAlgTask.h"
3 #include "RetCodeGuard.h"
4
5 // Framework
6 #include "GaudiKernel/Algorithm.h"
7 #include "GaudiKernel/ContextSpecificPtr.h"
8 #include "GaudiKernel/IMessageSvc.h"
9 #include "GaudiKernel/IProperty.h"
10
11 StatusCode IOBoundAlgTask::execute() {
12
13 IAlgorithm* ialg = m_algorithm.get();
14 Algorithm* this_algo = dynamic_cast<Algorithm*>( ialg );
15 if ( !this_algo ) { throw GaudiException( "Cast to Algorithm failed!", "AlgoExecutionTask", StatusCode::FAILURE ); }
16
17 bool eventfailed = false;
18 Gaudi::Hive::setCurrentContext( m_evtCtx );
19
20 // Get the IProperty interface of the ApplicationMgr to pass it to RetCodeGuard
21 const SmartIF<IProperty> appmgr( m_serviceLocator );
22
23 SmartIF<IMessageSvc> messageSvc( m_serviceLocator );
24 MsgStream log( messageSvc, "AccelAlgoExecutionTask" );
25
26 // select the appropriate store
27 this_algo->whiteboard()->selectStore( m_evtCtx.valid() ? m_evtCtx.slot() : 0 ).ignore();
28
29 StatusCode sc( StatusCode::FAILURE );
30 try {
31 RetCodeGuard rcg( appmgr, Gaudi::ReturnCode::UnhandledException );
32 log << MSG::DEBUG << "Starting execution of algorithm " << m_algorithm->name() << endmsg;
33 sc = m_algorithm->sysExecute( m_evtCtx );
34 if ( UNLIKELY( !sc.isSuccess() ) ) {
35 log << MSG::WARNING << "Execution of algorithm " << m_algorithm->name() << " failed" << endmsg;
36 eventfailed = true;
37 }
38 log << MSG::DEBUG << "Stopped execution of algorithm " << m_algorithm->name() << endmsg;
39 rcg.ignore(); // disarm the guard
40 } catch ( const GaudiException& Exception ) {
41 log << MSG::FATAL << ".executeEvent(): Exception with tag=" << Exception.tag() << " thrown by "
42 << m_algorithm->name() << endmsg;
43 log << MSG::ERROR << Exception << endmsg;
44 eventfailed = true;
45 } catch ( const std::exception& Exception ) {
46 log << MSG::FATAL << ".executeEvent(): Standard std::exception thrown by " << m_algorithm->name() << endmsg;
47 log << MSG::ERROR << Exception.what() << endmsg;
48 eventfailed = true;
49 } catch ( ... ) {
50 log << MSG::FATAL << ".executeEvent(): UNKNOWN Exception thrown by " << m_algorithm->name() << endmsg;
51 eventfailed = true;
52 }
53
54 // DP it is important to propagate the failure of an event.
55 // We need to stop execution when this happens so that execute run can
56 // then receive the FAILURE
57 m_aess->updateEventStatus( eventfailed, m_evtCtx );
58
59 // update scheduler state
60 sc = m_promote2ExecutedClosure();
61 if ( UNLIKELY( sc.isFailure() ) ) {
62 log << MSG::WARNING << "Cannot schedule update of algorithm state for " << m_algorithm->name() << endmsg;
63 }
64
65 Gaudi::Hive::setCurrentContextEvt( -1 );
66
67 return sc;
68 }
UNLIKELY
#define UNLIKELY(x)
Definition: Kernel.h:96
MsgStream
Definition of the MsgStream class used to transmit messages.
Definition: MsgStream.h:24
Algorithm.h
SmartIF< IProperty >
EventContext::slot
ContextID_t slot() const
Definition: EventContext.h:41
GaudiException
Define general base for Gaudi exception.
Definition: GaudiException.h:21
IOBoundAlgTask::m_algorithm
SmartIF< IAlgorithm > m_algorithm
Definition: IOBoundAlgTask.h:36
RetCodeGuard
Helper class to set the application return code in case of early exit (e.g.
Definition: RetCodeGuard.h:9
Gaudi::Algorithm::whiteboard
SmartIF< IHiveWhiteBoard > & whiteboard() const
Definition: Algorithm.cpp:687
IOBoundAlgTask::execute
StatusCode execute() override final
Definition: IOBoundAlgTask.cpp:11
MSG::DEBUG
Definition: IMessageSvc.h:15
GaudiException::tag
virtual const std::string & tag() const
name tag for the exception, or exception type
Definition: GaudiException.h:67
IOBoundAlgTask.h
SmartIF::get
TYPE * get() const
Get interface pointer.
Definition: SmartIF.h:76
EventContext::valid
bool valid() const
Definition: EventContext.h:44
Gaudi::ReturnCode::UnhandledException
constexpr int UnhandledException
Definition: AppReturnCode.h:27
MSG::FATAL
Definition: IMessageSvc.h:15
IHiveWhiteBoard::selectStore
virtual StatusCode selectStore(size_t partitionIndex)=0
Activate an given 'slot' 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:50
IOBoundAlgTask::m_evtCtx
const EventContext & m_evtCtx
Definition: IOBoundAlgTask.h:37
ContextSpecificPtr.h
IAlgorithm::sysExecute
virtual StatusCode sysExecute(const EventContext &)=0
System execution. This method invokes the execute() method of a concrete algorithm.
IOBoundAlgTask::m_serviceLocator
SmartIF< ISvcLocator > m_serviceLocator
Definition: IOBoundAlgTask.h:39
IMessageSvc.h
StatusCode::isSuccess
bool isSuccess() const
Definition: StatusCode.h:267
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:31
IAlgExecStateSvc::updateEventStatus
virtual void updateEventStatus(const bool &b, const EventContext &ctx)=0
IOBoundAlgTask::m_aess
IAlgExecStateSvc * m_aess
Definition: IOBoundAlgTask.h:38
Algorithm
Alias for backward compatibility.
Definition: Algorithm.h:56
IProperty.h
RetCodeGuard.h
StatusCode::FAILURE
constexpr static const auto FAILURE
Definition: StatusCode.h:86
Gaudi::Hive::setCurrentContextEvt
GAUDI_API void setCurrentContextEvt(long int evtN)
Definition: ThreadLocalContext.cpp:22
IOBoundAlgTask::m_promote2ExecutedClosure
std::function< StatusCode()> m_promote2ExecutedClosure
Definition: IOBoundAlgTask.h:40
MSG::ERROR
Definition: IMessageSvc.h:15
RetCodeGuard::ignore
void ignore()
Definition: RetCodeGuard.h:12
MSG::WARNING
Definition: IMessageSvc.h:15
StatusCode::isFailure
bool isFailure() const
Definition: StatusCode.h:130
endmsg
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:192
Gaudi.Configuration.log
log
Definition: Configuration.py:13