| The Gaudi Framework v32r1 (f65d50dc)

AlgContextAuditor.cpp
Go to the documentation of this file.
1 #include "AlgContextAuditor.h"
2
3 #include "GaudiKernel/EventContext.h"
4 #include "GaudiKernel/IAlgContextSvc.h"
5 #include "GaudiKernel/IAlgorithm.h"
6 #include "GaudiKernel/MsgStream.h"
7 #include "GaudiKernel/SmartIF.h"
8 #include "GaudiKernel/ThreadLocalContext.h"
9
10 #include <cassert>
11
12 // ============================================================================
18 // ============================================================================
19 namespace {
20 template <StatusCode ( IAlgContextSvc::*fun )( IAlgorithm*, const EventContext& )>
21 void call( IAlgContextSvc* ctx, INamedInterface* a ) {
22 if ( ctx ) {
23 // make a safe cast using "smart interface"
24 SmartIF<IAlgorithm> alg{a};
25 const EventContext& ectx = Gaudi::Hive::currentContext();
26 if ( alg ) ( ctx->*fun )( alg.get(), ectx ).ignore();
27 }
28 }
29 } // namespace
30 // ============================================================================
31 // mandatory auditor factory, needed for instantiation
32 // ============================================================================
33 DECLARE_COMPONENT( AlgContextAuditor )
34 // ============================================================================
35 // standard constructor @see Auditor
36 // ============================================================================
37 AlgContextAuditor::AlgContextAuditor( const std::string& name, ISvcLocator* pSvc ) : Auditor( name, pSvc ) {}
38 // ============================================================================
39 // standard initialization, see @IAuditor
40 // ============================================================================
41 StatusCode AlgContextAuditor::initialize() {
42 // initialize the base class
43 StatusCode sc = Auditor::initialize();
44 if ( sc.isFailure() ) { return sc; } // RETURN
45 m_svc = service( "AlgContextSvc", true );
46 if ( !m_svc ) {
47 error() << "Invalid pointer to IAlgContextSvc" << endmsg;
48 return StatusCode::FAILURE; // RETURN
49 }
50 return StatusCode::SUCCESS;
51 }
52 // ============================================================================
53 // standard finalization, see @IAuditor
54 // ============================================================================
55 StatusCode AlgContextAuditor::finalize() {
56 m_svc.reset();
57 // finalize the base class
58 return Auditor::finalize();
59 }
60 // ============================================================================
61 void AlgContextAuditor::beforeInitialize( INamedInterface* a ) { call<&IAlgContextSvc::setCurrentAlg>( m_svc, a ); }
62 // ============================================================================
63 void AlgContextAuditor::afterInitialize( INamedInterface* a ) { call<&IAlgContextSvc::unSetCurrentAlg>( m_svc, a ); }
64 // ============================================================================
65 void AlgContextAuditor::beforeFinalize( INamedInterface* a ) { call<&IAlgContextSvc::setCurrentAlg>( m_svc, a ); }
66 // ============================================================================
67 void AlgContextAuditor::afterFinalize( INamedInterface* a ) { call<&IAlgContextSvc::unSetCurrentAlg>( m_svc, a ); }
68 // ============================================================================
69 void AlgContextAuditor::beforeExecute( INamedInterface* a ) { call<&IAlgContextSvc::setCurrentAlg>( m_svc, a ); }
70 // ============================================================================
71 void AlgContextAuditor::afterExecute( INamedInterface* a, const StatusCode& /* s */ ) {
72 call<&IAlgContextSvc::unSetCurrentAlg>( m_svc, a );
73 }
74 // ============================================================================
75
76 // ============================================================================
77 // The END
78 // ============================================================================
AlgContextAuditor::initialize
StatusCode initialize() override
standard initialization,
Definition: AlgContextAuditor.cpp:41
SmartIF< IAlgorithm >
Auditor::finalize
virtual StatusCode finalize()
Definition: Auditor.cpp:191
ISvcLocator
The ISvcLocator is the interface implemented by the Service Factory in the Application Manager to loc...
Definition: ISvcLocator.h:25
ManySmallAlgs.alg
alg
Definition: ManySmallAlgs.py:69
gaudiComponentHelp.name
name
Definition: gaudiComponentHelp.py:41
AlgContextAuditor
Description: Register/Unregister the AlgContext of each algorithm before entering the algorithm and a...
Definition: AlgContextAuditor.h:21
AlgContextAuditor::afterFinalize
void afterFinalize(INamedInterface *a) override
Definition: AlgContextAuditor.cpp:67
MsgStream.h
Auditor::service
StatusCode service(const std::string &name, T *&svc, bool createIf=false) const
Access a service by name, creating it if it doesn't already exist.
Definition: Auditor.h:105
IAlgorithm.h
ThreadLocalContext.h
StatusCode::SUCCESS
constexpr static const auto SUCCESS
Definition: StatusCode.h:85
EventContext.h
std
STL namespace.
AlgContextAuditor::m_svc
SmartIF< IAlgContextSvc > m_svc
the pointer to Algorithm Context Service
Definition: AlgContextAuditor.h:49
AlgContextAuditor::beforeInitialize
void beforeInitialize(INamedInterface *a) override
Definition: AlgContextAuditor.cpp:61
AlgContextAuditor::afterInitialize
void afterInitialize(INamedInterface *a) override
Definition: AlgContextAuditor.cpp:63
EventContext
This class represents an entry point to all the event specific data.
Definition: EventContext.h:24
DECLARE_COMPONENT
#define DECLARE_COMPONENT(type)
Definition: PluginServiceV1.h:46
CommonMessagingBase::error
MsgStream & error() const
shortcut for the method msgStream(MSG::ERROR)
Definition: CommonMessaging.h:98
StatusCode
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:50
SmartIF.h
Gaudi::Hive::currentContext
GAUDI_API const EventContext & currentContext()
Definition: ThreadLocalContext.cpp:20
AlgContextAuditor::finalize
StatusCode finalize() override
standard finalization,
Definition: AlgContextAuditor.cpp:55
IAlgContextSvc.h
INamedInterface
IInterface compliant class extending IInterface with the name() method.
Definition: INamedInterface.h:15
AlgContextAuditor::beforeFinalize
void beforeFinalize(INamedInterface *a) override
Definition: AlgContextAuditor.cpp:65
AlgContextAuditor::afterExecute
void afterExecute(INamedInterface *a, const StatusCode &s) override
Definition: AlgContextAuditor.cpp:71
StatusCode::FAILURE
constexpr static const auto FAILURE
Definition: StatusCode.h:86
AlgContextAuditor.h
IAlgContextSvc
An abstract interface for Algorithm Context Service.
Definition: IAlgContextSvc.h:23
SmartIF::reset
void reset(TYPE *ptr=nullptr)
Set the internal pointer to the passed one disposing of the old one.
Definition: SmartIF.h:86
Auditor::initialize
virtual StatusCode initialize()
Definition: Auditor.cpp:64
StatusCode::isFailure
bool isFailure() const
Definition: StatusCode.h:130
AlgContextAuditor::beforeExecute
void beforeExecute(INamedInterface *a) override
Definition: AlgContextAuditor.cpp:69
endmsg
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:192
Auditor
Base class from which all concrete auditor classes should be derived.
Definition: Auditor.h:34