The Gaudi Framework
master (bdbe7744)
Toggle main menu visibility
Loading...
Searching...
No Matches
AlgTask.h
Go to the documentation of this file.
1
/***********************************************************************************\
2
* (c) Copyright 1998-2025 CERN for the benefit of the LHCb and ATLAS collaborations *
3
* *
4
* This software is distributed under the terms of the Apache version 2 licence, *
5
* copied verbatim in the file "LICENSE". *
6
* *
7
* In applying this licence, CERN does not waive the privileges and immunities *
8
* granted to it by virtue of its status as an Intergovernmental Organization *
9
* or submit itself to any jurisdiction. *
10
\***********************************************************************************/
11
#pragma once
12
13
#include "
AvalancheSchedulerSvc.h
"
14
#include "
RetCodeGuard.h
"
15
16
// Framework include files
17
#include <
Gaudi/Algorithm.h
>
18
#include <
GaudiKernel/EventContext.h
>
19
#include <
GaudiKernel/IAlgExecStateSvc.h
>
20
#include <
GaudiKernel/IMessageSvc.h
>
21
#include <
GaudiKernel/IProperty.h
>
22
#include <
GaudiKernel/ISvcLocator.h
>
23
#include <
GaudiKernel/IThreadPoolSvc.h
>
24
#include <
GaudiKernel/SmartIF.h
>
25
#include <
GaudiKernel/ThreadLocalContext.h
>
26
27
#include <functional>
28
29
namespace
Gaudi
{
30
namespace
Concurrency
{
31
extern
thread_local
bool
ThreadInitDone
;
32
}
33
}
// namespace Gaudi
34
35
class
AlgTask
{
36
public
:
37
AlgTask
(
AvalancheSchedulerSvc
* scheduler,
ISvcLocator
* svcLocator,
IAlgExecStateSvc
* aem,
bool
asynchronous )
38
:
m_scheduler
( scheduler ),
m_aess
( aem ),
m_serviceLocator
( svcLocator ),
m_asynchronous
( asynchronous ) {}
39
40
void
operator()
()
const
{
41
42
SmartIF<IMessageSvc>
messageSvc(
m_serviceLocator
);
43
MsgStream
log( messageSvc,
"AlgTask"
);
44
45
// Get task specification dynamically if it was not provided statically
46
AvalancheSchedulerSvc::TaskSpec
ts;
47
log <<
MSG::DEBUG
<<
"Getting taskspec for "
<< (
m_asynchronous
?
"asynchronous"
:
"standard"
) <<
" algorithm"
48
<<
endmsg
;
49
if
( !
m_scheduler
->next( ts,
m_asynchronous
) ) {
50
log <<
MSG::WARNING
<<
"Missing specification while task is running"
<<
endmsg
;
51
return
;
52
}
53
54
EventContext
& evtCtx = *( ts.contextPtr );
55
IAlgorithm
*& iAlgoPtr = ts.algPtr;
56
57
Gaudi::Algorithm
* this_algo =
dynamic_cast<
Gaudi::Algorithm
*
>
( iAlgoPtr );
58
if
( !this_algo ) {
throw
GaudiException
(
"Cast to Algorithm failed!"
,
"AlgTask"
,
StatusCode::FAILURE
); }
59
60
bool
eventfailed =
false
;
61
Gaudi::Hive::setCurrentContext
( evtCtx );
62
63
// Get the IProperty interface of the ApplicationMgr to pass it to RetCodeGuard
64
const
SmartIF<IProperty>
appmgr(
m_serviceLocator
);
65
66
if
( !
Gaudi::Concurrency::ThreadInitDone
) {
67
log <<
MSG::DEBUG
<<
"New thread detected: 0x"
<< std::hex << pthread_self() << std::dec
68
<<
". Doing thread local initialization."
<<
endmsg
;
69
if
(
SmartIF<IThreadPoolSvc>
tps{
m_serviceLocator
->service(
"ThreadPoolSvc"
) } ) {
70
tps->initThisThread();
71
}
else
{
72
log <<
MSG::ERROR
<<
"Unable to get the ThreadPoolSvc to trigger thread local initialization"
<<
endmsg
;
73
throw
GaudiException
(
"Retrieval of ThreadPoolSvc failed"
,
"AlgTask"
,
StatusCode::FAILURE
);
74
}
75
}
76
77
// select the appropriate store
78
this_algo->
whiteboard
()->
selectStore
( evtCtx.
valid
() ? evtCtx.
slot
() : 0 ).
ignore
();
79
try
{
80
RetCodeGuard
rcg( appmgr,
Gaudi::ReturnCode::UnhandledException
);
81
82
if
( iAlgoPtr->
sysExecute
( evtCtx ).
isFailure
() ) {
83
log <<
MSG::WARNING
<<
"Execution of algorithm "
<< ts.algName <<
" failed"
<<
endmsg
;
84
eventfailed =
true
;
85
}
86
rcg.
ignore
();
// disarm the guard
87
}
catch
(
const
GaudiException
& Exception ) {
88
log <<
MSG::FATAL
<<
".executeEvent(): Exception with tag="
<< Exception.tag() <<
" thrown by "
<< ts.algName
89
<<
endmsg
;
90
log <<
MSG::ERROR
<< Exception <<
endmsg
;
91
eventfailed =
true
;
92
}
catch
(
const
std::exception& Exception ) {
93
log <<
MSG::FATAL
<<
".executeEvent(): Standard std::exception thrown by "
<< ts.algName <<
endmsg
;
94
log <<
MSG::ERROR
<< Exception.what() <<
endmsg
;
95
eventfailed =
true
;
96
}
catch
( ... ) {
97
log <<
MSG::FATAL
<<
".executeEvent(): UNKNOWN Exception thrown by "
<< ts.algName <<
endmsg
;
98
eventfailed =
true
;
99
}
100
101
// A FAILURE in algorithm execution must be communicated to the framework
102
m_aess
->updateEventStatus( eventfailed, evtCtx );
103
104
// Release algorithm
105
m_scheduler
->m_algResourcePool->releaseAlgorithm( ts.algName, iAlgoPtr ).ignore();
106
107
// schedule a sign-off of the Algorithm execution
108
m_scheduler
->m_actionsQueue.push(
109
[schdlr = this->
m_scheduler
, ts = std::move( ts )]() {
return
schdlr->signoff( ts ); } );
110
111
Gaudi::Hive::setCurrentContextEvt
( -1 );
112
}
113
114
private
:
115
// Shortcuts to services
116
AvalancheSchedulerSvc
*
m_scheduler
;
117
IAlgExecStateSvc
*
m_aess
;
118
SmartIF<ISvcLocator>
m_serviceLocator
;
119
// Marks the task as asynchronous or not
120
bool
m_asynchronous
{
false
};
121
};
AvalancheSchedulerSvc.h
EventContext.h
Algorithm.h
IAlgExecStateSvc.h
IMessageSvc.h
IProperty.h
ISvcLocator.h
IThreadPoolSvc.h
endmsg
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition
MsgStream.h:198
RetCodeGuard.h
SmartIF.h
ThreadLocalContext.h
AlgTask::m_scheduler
AvalancheSchedulerSvc * m_scheduler
Definition
AlgTask.h:116
AlgTask::m_aess
IAlgExecStateSvc * m_aess
Definition
AlgTask.h:117
AlgTask::m_serviceLocator
SmartIF< ISvcLocator > m_serviceLocator
Definition
AlgTask.h:118
AlgTask::m_asynchronous
bool m_asynchronous
Definition
AlgTask.h:120
AlgTask::operator()
void operator()() const
Definition
AlgTask.h:40
AlgTask::AlgTask
AlgTask(AvalancheSchedulerSvc *scheduler, ISvcLocator *svcLocator, IAlgExecStateSvc *aem, bool asynchronous)
Definition
AlgTask.h:37
AvalancheSchedulerSvc
Definition
AvalancheSchedulerSvc.h:114
EventContext
This class represents an entry point to all the event specific data.
Definition
EventContext.h:35
EventContext::slot
ContextID_t slot() const
Definition
EventContext.h:52
EventContext::valid
bool valid() const
Definition
EventContext.h:55
Gaudi::Algorithm
Base class from which all concrete algorithm classes should be derived.
Definition
Algorithm.h:87
Gaudi::Algorithm::whiteboard
SmartIF< IHiveWhiteBoard > & whiteboard() const
Definition
Algorithm.cpp:560
GaudiException
Define general base for Gaudi exception.
Definition
GaudiException.h:29
IAlgExecStateSvc
Abstract interface for a service that manages the Algorithm execution states.
Definition
IAlgExecStateSvc.h:94
IAlgorithm
The IAlgorithm is the interface implemented by the Algorithm base class.
Definition
IAlgorithm.h:37
IAlgorithm::sysExecute
virtual StatusCode sysExecute(const EventContext &)=0
System execution. This method invokes the execute() method of a concrete algorithm.
IHiveWhiteBoard::selectStore
virtual StatusCode selectStore(size_t partitionIndex)=0
Activate an given 'slot' for all subsequent calls within the same thread id.
ISvcLocator
The ISvcLocator is the interface implemented by the Service Factory in the Application Manager to loc...
Definition
ISvcLocator.h:42
MsgStream
Definition of the MsgStream class used to transmit messages.
Definition
MsgStream.h:29
RetCodeGuard
Helper class to set the application return code in case of early exit (e.g.
Definition
RetCodeGuard.h:18
RetCodeGuard::ignore
void ignore()
Definition
RetCodeGuard.h:21
SmartIF
Small smart pointer class with automatic reference counting for IInterface.
Definition
SmartIF.h:28
StatusCode::isFailure
bool isFailure() const
Definition
StatusCode.h:118
StatusCode::ignore
void ignore() const
Allow discarding a StatusCode without warning.
Definition
StatusCode.h:128
StatusCode::FAILURE
constexpr static const auto FAILURE
Definition
StatusCode.h:100
Gaudi::ReturnCode::UnhandledException
constexpr int UnhandledException
Definition
AppReturnCode.h:36
Gaudi::Concurrency
Definition
AlgTask.h:30
Gaudi::Concurrency::ThreadInitDone
bool ThreadInitDone
Definition
ThreadInitTask.cpp:22
Gaudi::Hive::setCurrentContextEvt
GAUDI_API void setCurrentContextEvt(long int evtN)
Definition
ThreadLocalContext.cpp:32
Gaudi::Hive::setCurrentContext
GAUDI_API void setCurrentContext(const EventContext *ctx)
Definition
ThreadLocalContext.cpp:41
Gaudi
This file provides a Grammar for the type Gaudi::Accumulators::Axis It allows to use that type from p...
Definition
__init__.py:1
MSG::WARNING
@ WARNING
Definition
IMessageSvc.h:22
MSG::FATAL
@ FATAL
Definition
IMessageSvc.h:22
MSG::DEBUG
@ DEBUG
Definition
IMessageSvc.h:22
MSG::ERROR
@ ERROR
Definition
IMessageSvc.h:22
AvalancheSchedulerSvc::TaskSpec
Struct to hold entries in the alg queues.
Definition
AvalancheSchedulerSvc.h:314
GaudiHive
src
AlgTask.h
Generated on
for The Gaudi Framework by
1.17.0