The Gaudi Framework  master (37c0b60a)
AlgContextAuditor.cpp
Go to the documentation of this file.
1 /***********************************************************************************\
2 * (c) Copyright 1998-2024 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 #include "AlgContextAuditor.h"
12 
15 #include <GaudiKernel/IAlgorithm.h>
16 #include <GaudiKernel/MsgStream.h>
17 #include <GaudiKernel/SmartIF.h>
19 
20 #include <cassert>
21 
22 // ============================================================================
28 // ============================================================================
29 namespace {
30  template <StatusCode ( IAlgContextSvc::*fun )( IAlgorithm*, const EventContext& )>
31  void call( IAlgContextSvc* ctx, INamedInterface* a ) {
32  if ( ctx ) {
33  // make a safe cast using "smart interface"
36  if ( alg ) ( ctx->*fun )( alg.get(), ectx ).ignore();
37  }
38  }
39 } // namespace
40 // ============================================================================
41 // mandatory auditor factory, needed for instantiation
42 // ============================================================================
44 // ============================================================================
45 // standard constructor @see Auditor
46 // ============================================================================
47 AlgContextAuditor::AlgContextAuditor( const std::string& name, ISvcLocator* pSvc ) : Auditor( name, pSvc ) {}
48 // ============================================================================
49 // standard initialization, see @IAuditor
50 // ============================================================================
52  // initialize the base class
54  if ( sc.isFailure() ) { return sc; } // RETURN
55  m_svc = service( "AlgContextSvc", true );
56  if ( !m_svc ) {
57  error() << "Invalid pointer to IAlgContextSvc" << endmsg;
58  return StatusCode::FAILURE; // RETURN
59  }
60  return StatusCode::SUCCESS;
61 }
62 // ============================================================================
63 // standard finalization, see @IAuditor
64 // ============================================================================
66  m_svc.reset();
67  // finalize the base class
68  return Auditor::finalize();
69 }
70 // ============================================================================
71 void AlgContextAuditor::beforeInitialize( INamedInterface* a ) { call<&IAlgContextSvc::setCurrentAlg>( m_svc, a ); }
72 // ============================================================================
73 void AlgContextAuditor::afterInitialize( INamedInterface* a ) { call<&IAlgContextSvc::unSetCurrentAlg>( m_svc, a ); }
74 // ============================================================================
75 void AlgContextAuditor::beforeFinalize( INamedInterface* a ) { call<&IAlgContextSvc::setCurrentAlg>( m_svc, a ); }
76 // ============================================================================
77 void AlgContextAuditor::afterFinalize( INamedInterface* a ) { call<&IAlgContextSvc::unSetCurrentAlg>( m_svc, a ); }
78 // ============================================================================
79 void AlgContextAuditor::beforeExecute( INamedInterface* a ) { call<&IAlgContextSvc::setCurrentAlg>( m_svc, a ); }
80 // ============================================================================
82  call<&IAlgContextSvc::unSetCurrentAlg>( m_svc, a );
83 }
84 // ============================================================================
85 
86 // ============================================================================
87 // The END
88 // ============================================================================
Gaudi::Hive::currentContext
GAUDI_API const EventContext & currentContext()
Definition: ThreadLocalContext.cpp:30
SmartIF::reset
void reset(TYPE *ptr=nullptr)
Set the internal pointer to the passed one disposing of the old one.
Definition: SmartIF.h:96
ISvcLocator
Definition: ISvcLocator.h:46
AlgContextAuditor.h
Auditor::finalize
virtual StatusCode finalize()
Definition: Auditor.cpp:190
AlgContextAuditor::finalize
StatusCode finalize() override
standard finalization,
Definition: AlgContextAuditor.cpp:65
Auditor::initialize
virtual StatusCode initialize()
Definition: Auditor.cpp:79
ManySmallAlgs.alg
alg
Definition: ManySmallAlgs.py:81
SmartIF.h
Auditor
Definition: Auditor.h:43
GaudiPython.Pythonizations.ctx
ctx
Definition: Pythonizations.py:578
StatusCode
Definition: StatusCode.h:65
AlgContextAuditor::beforeExecute
void beforeExecute(INamedInterface *a) override
Definition: AlgContextAuditor.cpp:79
AlgContextAuditor::initialize
StatusCode initialize() override
standard initialization,
Definition: AlgContextAuditor.cpp:51
SmartIF< IAlgorithm >
endmsg
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:202
StatusCode::isFailure
bool isFailure() const
Definition: StatusCode.h:129
ThreadLocalContext.h
INamedInterface
Definition: INamedInterface.h:25
StatusCode::SUCCESS
constexpr static const auto SUCCESS
Definition: StatusCode.h:100
ConditionsStallTest.name
name
Definition: ConditionsStallTest.py:77
IAlgContextSvc.h
AlgContextAuditor::m_svc
SmartIF< IAlgContextSvc > m_svc
the pointer to Algorithm Context Service
Definition: AlgContextAuditor.h:59
EventContext.h
std
STL namespace.
DECLARE_COMPONENT
#define DECLARE_COMPONENT(type)
Definition: PluginServiceV1.h:46
EventContext
Definition: EventContext.h:34
IAlgContextSvc
Definition: IAlgContextSvc.h:33
AlgContextAuditor::afterInitialize
void afterInitialize(INamedInterface *a) override
Definition: AlgContextAuditor.cpp:73
AlgContextAuditor::beforeFinalize
void beforeFinalize(INamedInterface *a) override
Definition: AlgContextAuditor.cpp:75
IAlgorithm.h
StatusCode::FAILURE
constexpr static const auto FAILURE
Definition: StatusCode.h:101
Auditor::service
StatusCode service(std::string_view name, T *&svc, bool createIf=false) const
Access a service by name, creating it if it doesn't already exist.
Definition: Auditor.h:108
AlgContextAuditor
Definition: AlgContextAuditor.h:31
AlgContextAuditor::beforeInitialize
void beforeInitialize(INamedInterface *a) override
Definition: AlgContextAuditor.cpp:71
AlgContextAuditor::afterExecute
void afterExecute(INamedInterface *a, const StatusCode &s) override
Definition: AlgContextAuditor.cpp:81
AlgContextAuditor::afterFinalize
void afterFinalize(INamedInterface *a) override
Definition: AlgContextAuditor.cpp:77
MsgStream.h