The Gaudi Framework  v29r0 (ff2e7097)
AlgContextAuditor.cpp
Go to the documentation of this file.
1 #include <cassert>
2 
6 #include "GaudiKernel/SmartIF.h"
7 
8 #include "AlgContextAuditor.h"
9 
10 // ============================================================================
16 // ============================================================================
17 namespace
18 {
19  template <StatusCode ( IAlgContextSvc::*fun )( IAlgorithm* )>
20  void call( IAlgContextSvc* ctx, INamedInterface* a )
21  {
22  if ( ctx ) {
23  // make a safe cast using "smart interface"
24  SmartIF<IAlgorithm> alg{a};
25  if ( alg ) ( ctx->*fun )( alg.get() ).ignore();
26  }
27  }
28 }
29 // ============================================================================
30 // mandatory auditor factory, needed for instantiation
31 // ============================================================================
33 // ============================================================================
34 // standard constructor @see Auditor
35 // ============================================================================
36 AlgContextAuditor::AlgContextAuditor( const std::string& name, ISvcLocator* pSvc ) : Auditor( name, pSvc ) {}
37 // ============================================================================
38 // standard initialization, see @IAuditor
39 // ============================================================================
41 {
42  // initialize the base class
44  if ( sc.isFailure() ) {
45  return sc;
46  } // RETURN
47  m_svc = service( "AlgContextSvc", true );
48  if ( !m_svc ) {
49  error() << "Invalid pointer to IAlgContextSvc" << endmsg;
50  return StatusCode::FAILURE; // RETURN
51  }
52  return StatusCode::SUCCESS;
53 }
54 // ============================================================================
55 // standard finalization, see @IAuditor
56 // ============================================================================
58 {
59  m_svc.reset();
60  // finalize the base class
61  return Auditor::finalize();
62 }
63 // ============================================================================
64 void AlgContextAuditor::beforeInitialize( INamedInterface* a ) { call<&IAlgContextSvc::setCurrentAlg>( m_svc, a ); }
65 // ============================================================================
66 void AlgContextAuditor::afterInitialize( INamedInterface* a ) { call<&IAlgContextSvc::unSetCurrentAlg>( m_svc, a ); }
67 // ============================================================================
68 void AlgContextAuditor::beforeFinalize( INamedInterface* a ) { call<&IAlgContextSvc::setCurrentAlg>( m_svc, a ); }
69 // ============================================================================
70 void AlgContextAuditor::afterFinalize( INamedInterface* a ) { call<&IAlgContextSvc::unSetCurrentAlg>( m_svc, a ); }
71 // ============================================================================
72 void AlgContextAuditor::beforeExecute( INamedInterface* a ) { call<&IAlgContextSvc::setCurrentAlg>( m_svc, a ); }
73 // ============================================================================
75 {
76  call<&IAlgContextSvc::unSetCurrentAlg>( m_svc, a );
77 }
78 // ============================================================================
79 
80 // ============================================================================
81 // The END
82 // ============================================================================
StatusCode initialize() override
standard initialization,
virtual StatusCode finalize()
Definition: Auditor.cpp:200
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:109
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
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
#define DECLARE_COMPONENT(type)
Definition: PluginService.h:33
MsgStream & error() const
shortcut for the method msgStream(MSG::ERROR)
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:28
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
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:92
virtual StatusCode initialize()
Definition: Auditor.cpp:70
void beforeExecute(INamedInterface *a) override
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:209
Base class from which all concrete auditor classes should be derived.
Definition: Auditor.h:35