Loading [MathJax]/extensions/tex2jax.js
The Gaudi Framework  v31r0 (aeb156f0)
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
AlgContextAuditor.cpp
Go to the documentation of this file.
1 #include "AlgContextAuditor.h"
2 
7 #include "GaudiKernel/SmartIF.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};
26  if ( alg ) ( ctx->*fun )( alg.get(), ectx ).ignore();
27  }
28  }
29 } // namespace
30 // ============================================================================
31 // mandatory auditor factory, needed for instantiation
32 // ============================================================================
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 // ============================================================================
42  // initialize the base class
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 // ============================================================================
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 // ============================================================================
72  call<&IAlgContextSvc::unSetCurrentAlg>( m_svc, a );
73 }
74 // ============================================================================
75 
76 // ============================================================================
77 // The END
78 // ============================================================================
StatusCode initialize() override
standard initialization,
virtual StatusCode finalize()
Definition: Auditor.cpp:191
StatusCode service(const std::string &name, T *&svc, bool createIf=false) const
Access a service by name, creating it if it doesn&#39;t already exist.
Definition: Auditor.h:105
The ISvcLocator is the interface implemented by the Service Factory in the Application Manager to loc...
Definition: ISvcLocator.h:25
Description: Register/Unregister the AlgContext of each algorithm before entering the algorithm and a...
void afterFinalize(INamedInterface *a) override
constexpr static const auto SUCCESS
Definition: StatusCode.h:85
STL namespace.
SmartIF< IAlgContextSvc > m_svc
the pointer to Algorithm Context Service
void beforeInitialize(INamedInterface *a) override
void afterInitialize(INamedInterface *a) override
This class represents an entry point to all the event specific data.
Definition: EventContext.h:31
bool isFailure() const
Definition: StatusCode.h:130
#define DECLARE_COMPONENT(type)
MsgStream & error() const
shortcut for the method msgStream(MSG::ERROR)
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:50
GAUDI_API const EventContext & currentContext()
StatusCode finalize() override
standard finalization,
IInterface compliant class extending IInterface with the name() method.
void beforeFinalize(INamedInterface *a) override
void afterExecute(INamedInterface *a, const StatusCode &s) override
double fun(const std::vector< double > &x)
Definition: PFuncTest.cpp:26
constexpr static const auto FAILURE
Definition: StatusCode.h:86
An abstract interface for Algorithm Context Service.
void reset(TYPE *ptr=nullptr)
Set the internal pointer to the passed one disposing of the old one.
Definition: SmartIF.h:86
virtual StatusCode initialize()
Definition: Auditor.cpp:64
void beforeExecute(INamedInterface *a) override
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:192
Base class from which all concrete auditor classes should be derived.
Definition: Auditor.h:34