AlgContextAuditor.cpp
Go to the documentation of this file.
1 #include <cassert>
2 
3 #include "GaudiKernel/IAlgContextSvc.h"
4 #include "GaudiKernel/IAlgorithm.h"
5 #include "GaudiKernel/SmartIF.h"
6 #include "GaudiKernel/MsgStream.h"
7 
8 #include "AlgContextAuditor.h"
9 
10 // ============================================================================
16 // ============================================================================
17 namespace {
18  template <StatusCode(IAlgContextSvc::*fun)(IAlgorithm*)>
19  void call(IAlgContextSvc* ctx,INamedInterface* a) {
20  if ( ctx ) {
21  // make a safe cast using "smart interface"
22  SmartIF<IAlgorithm> alg{ a };
23  if (alg) (ctx->*fun)( alg.get() ).ignore() ;
24  }
25  }
26 }
27 // ============================================================================
28 // mandatory auditor factory, needed for instantiation
29 // ============================================================================
31 // ============================================================================
32 // standard constructor @see Auditor
33 // ============================================================================
35  : Auditor( name , pSvc )
36 {}
37 // ============================================================================
38 // standard initialization, see @IAuditor
39 // ============================================================================
41 {
42  // initialize the base class
44  if ( sc.isFailure() ) { return sc ; } // RETURN
45  m_svc = service( "AlgContextSvc" , true ) ;
46  if ( !m_svc ) {
47  MsgStream log ( msgSvc() , name() ) ;
48  log << MSG::ERROR << "Invalid pointer to IAlgContextSvc" << endmsg ;
49  return StatusCode::FAILURE ; // RETURN
50  }
51  return StatusCode::SUCCESS ;
52 }
53 // ============================================================================
54 // standard finalization, see @IAuditor
55 // ============================================================================
57 {
58  m_svc.reset();
59  // finalize the base class
60  return Auditor::finalize () ;
61 }
62 // ============================================================================
64  call<&IAlgContextSvc::setCurrentAlg>(m_svc,a);
65 }
66 // ============================================================================
68  call<&IAlgContextSvc::unSetCurrentAlg>(m_svc,a);
69 }
70 // ============================================================================
72  call<&IAlgContextSvc::setCurrentAlg>(m_svc,a);
73 }
74 // ============================================================================
76  call<&IAlgContextSvc::unSetCurrentAlg>(m_svc,a);
77 }
78 // ============================================================================
80  call<&IAlgContextSvc::setCurrentAlg>(m_svc,a);
81 }
82 // ============================================================================
84  const StatusCode& /* s */ ) {
85  call<&IAlgContextSvc::unSetCurrentAlg>(m_svc,a);
86 }
87 // ============================================================================
88 
89 // ============================================================================
90 // The END
91 // ============================================================================
92 
StatusCode initialize() override
standard initialization,
Definition of the MsgStream class used to transmit messages.
Definition: MsgStream.h:24
virtual StatusCode finalize()
Definition: Auditor.cpp:207
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:119
The ISvcLocator is the interface implemented by the Service Factory in the Application Manager to loc...
Definition: ISvcLocator.h:25
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244
Description: Register/Unregister the AlgContext of each algorithm before entering the algorithm and a...
SmartIF< IMessageSvc > & msgSvc() const
The standard message service.
Definition: Auditor.cpp:220
void afterFinalize(INamedInterface *a) override
STL namespace.
SmartIF< IAlgContextSvc > m_svc
the pointer to Algorithm Context Service
void beforeInitialize(INamedInterface *a) override
void afterInitialize(INamedInterface *a) override
bool isFailure() const
Test for a status code of FAILURE.
Definition: StatusCode.h:86
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:26
#define DECLARE_COMPONENT(type)
Definition: PluginService.h:36
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
const std::string & name() const override
Definition: Auditor.cpp:212
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:88
virtual StatusCode initialize()
Definition: Auditor.cpp:91
void beforeExecute(INamedInterface *a) override
Base class from which all concrete auditor classes should be derived.
Definition: Auditor.h:34