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 {
27  inline IAlgorithm* toAlg ( IInterface* ni )
28  {
29  if ( 0 == ni ) { return 0 ; }
30  SmartIF<IAlgorithm> alg ( ni ) ;
31  return alg ;
32  }
33 }
34 // ============================================================================
35 // mandatory auditor factory, needed for instantiation
36 // ============================================================================
38 // ============================================================================
39 // standard constructor @see Auditor
40 // ============================================================================
42 ( const std::string& name ,
43  ISvcLocator* pSvc )
44  : Auditor( name , pSvc )
45 {}
46 // ============================================================================
47 // standard initialization, see @IAuditor
48 // ============================================================================
50 {
51  // initialize the base class
53  if ( sc.isFailure() ) { return sc ; } // RETURN
54  m_svc = service( "AlgContextSvc" , true ) ;
55  if ( !m_svc ) {
56  MsgStream log ( msgSvc() , name() ) ;
57  log << MSG::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 {
67  m_svc.reset();
68  // finalize the base class
69  return Auditor::finalize () ;
70 }
71 // ============================================================================
73  if ( m_svc ) {
74  IAlgorithm* alg = toAlg(a);
75  if (alg) m_svc -> setCurrentAlg ( alg ).ignore() ;
76  }
77 }
78 // ============================================================================
80  if ( m_svc ) {
81  IAlgorithm* alg = toAlg(a);
82  if (alg) m_svc -> unSetCurrentAlg ( alg ).ignore() ;
83  }
84 }
85 // ============================================================================
87  if ( m_svc ) {
88  IAlgorithm* alg = toAlg(a);
89  if (alg) m_svc -> setCurrentAlg ( alg ).ignore() ;
90  }
91 }
92 // ============================================================================
94  if ( m_svc ) {
95  IAlgorithm* alg = toAlg(a);
96  if (alg) m_svc -> unSetCurrentAlg ( alg ).ignore() ;
97  }
98 }
99 // ============================================================================
101  if ( m_svc ) {
102  IAlgorithm* alg = toAlg(a);
103  if (alg) m_svc -> setCurrentAlg ( alg ).ignore() ;
104  }
105 }
106 // ============================================================================
108  const StatusCode& /* s */ ) {
109  if ( m_svc ) {
110  IAlgorithm* alg = toAlg(a);
111  if (alg) m_svc -> unSetCurrentAlg ( alg ).ignore() ;
112  }
113 }
114 // ============================================================================
115 
116 // ============================================================================
117 // The END
118 // ============================================================================
119 
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
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
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244
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:36
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:26
Definition of the basic interface.
Definition: IInterface.h:234
The IAlgorithm is the interface implemented by the Algorithm base class.
Definition: IAlgorithm.h:19
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
const std::string & name() const override
Definition: Auditor.cpp:212
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