The Gaudi Framework  v29r0 (ff2e7097)
Auditor.h
Go to the documentation of this file.
1 #ifndef GAUDIKERNEL_AUDITOR_H
2 #define GAUDIKERNEL_AUDITOR_H
3 
4 // Include files
6 #include "GaudiKernel/IAuditor.h"
8 #include "GaudiKernel/IService.h"
9 #include "GaudiKernel/ISvcLocator.h" /*used by service(..)*/
12 #include <Gaudi/PluginService.h>
13 #include <string>
14 #include <vector>
15 
16 // Forward declarations
17 class IService;
18 class IMessageSvc;
19 class Algorithm;
20 
35 class GAUDI_API Auditor : public PropertyHolder<CommonMessaging<implements<IAuditor, IProperty>>>
36 {
37 public:
38 #ifndef __REFLEX__
40 #endif
41 
45  Auditor( const std::string& name, ISvcLocator* svcloc );
46 
47  Auditor( const Auditor& a ) = delete;
48  Auditor& operator=( const Auditor& rhs ) = delete;
49 
53  StatusCode sysInitialize() override;
57  StatusCode sysFinalize() override;
58 
60 
61  void before( StandardEventType, INamedInterface* ) override;
62  void before( StandardEventType, const std::string& ) override;
63 
64  void before( CustomEventTypeRef, INamedInterface* ) override;
65  void before( CustomEventTypeRef, const std::string& ) override;
66 
67  void after( StandardEventType, INamedInterface*, const StatusCode& ) override;
68  void after( StandardEventType, const std::string&, const StatusCode& ) override;
69 
70  void after( CustomEventTypeRef, INamedInterface*, const StatusCode& ) override;
71  void after( CustomEventTypeRef, const std::string&, const StatusCode& ) override;
72 
73  // Obsolete methods
74 
75  void beforeInitialize( INamedInterface* ) override;
76  void afterInitialize( INamedInterface* ) override;
77 
78  void beforeReinitialize( INamedInterface* ) override;
79  void afterReinitialize( INamedInterface* ) override;
80 
81  void beforeExecute( INamedInterface* ) override;
82  void afterExecute( INamedInterface*, const StatusCode& ) override;
83 
84  void beforeFinalize( INamedInterface* ) override;
85  void afterFinalize( INamedInterface* ) override;
86 
87  void beforeBeginRun( INamedInterface* ) override;
88  void afterBeginRun( INamedInterface* ) override;
89 
90  void beforeEndRun( INamedInterface* ) override;
91  void afterEndRun( INamedInterface* ) override;
92 
93  virtual StatusCode initialize();
94  virtual StatusCode finalize();
95 
96  const std::string& name() const override;
97 
98  bool isEnabled() const override;
99 
104  SmartIF<ISvcLocator>& serviceLocator() const override;
105 
108  template <class T>
109  StatusCode service( const std::string& name, T*& svc, bool createIf = false ) const
110  {
111  auto ptr = serviceLocator()->service<T>( name, createIf );
112  if ( ptr ) {
113  svc = ptr.get();
114  svc->addRef();
115  return StatusCode::SUCCESS;
116  }
117  svc = nullptr;
118  return StatusCode::FAILURE;
119  }
120 
121  template <class T = IService>
122  SmartIF<T> service( const std::string& name, bool createIf = false ) const
123  {
124  return serviceLocator()->service<T>( name, createIf );
125  }
126 
132  StatusCode setProperties();
133 
134 private:
136 
138 
139  Gaudi::Property<int> m_outputLevel{this, "OutputLevel", MSG::NIL, "output level"};
140  Gaudi::Property<bool> m_isEnabled{this, "Enable", true, "should the auditor be used or not"};
141 
142  bool m_isInitialized = false;
143  bool m_isFinalized = false;
144 };
145 
146 #ifndef GAUDI_NEW_PLUGIN_SERVICE
147 template <class T>
149 {
150 public:
151 #ifndef __REFLEX__
152  template <typename S, typename... Args>
153  static typename S::ReturnType create( Args&&... args )
154  {
155  return new T( std::forward<Args>( args )... );
156  }
157 #endif
158 };
159 
160 // Macros to declare component factories
161 #define DECLARE_AUDITOR_FACTORY( x ) DECLARE_FACTORY_WITH_CREATOR( x, AudFactory<x>, Auditor::Factory )
162 #define DECLARE_NAMESPACE_AUDITOR_FACTORY( n, x ) DECLARE_AUDITOR_FACTORY( n::x )
163 
164 #else
165 
166 // macros to declare factories
167 #define DECLARE_AUDITOR_FACTORY( x ) DECLARE_COMPONENT( x )
168 #define DECLARE_NAMESPACE_AUDITOR_FACTORY( n, x ) DECLARE_COMPONENT( n::x )
169 
170 #endif
171 
172 #endif // GAUDIKERNEL_AUDITOR_H
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
Implementation of property with value of concrete type.
Definition: Property.h:319
std::string m_name
Auditor&#39;s name for identification.
Definition: Auditor.h:135
STL class.
SmartIF< ISvcLocator > m_pSvcLocator
Pointer to service locator service.
Definition: Auditor.h:137
Gaudi::PluginService::Factory< IAuditor *, const std::string &, ISvcLocator * > Factory
Definition: Auditor.h:39
General service interface definition.
Definition: IService.h:18
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:28
PropertyHolder & operator=(const PropertyHolder &)=delete
The IMessage is the interface implemented by the message service.
Definition: IMessageSvc.h:38
Base class from which all concrete algorithm classes should be derived.
Definition: Algorithm.h:78
IInterface compliant class extending IInterface with the name() method.
Class wrapping the signature for a factory with any number of arguments.
Definition: PluginService.h:45
Helper class to implement the IProperty interface.
static S::ReturnType create(Args &&...args)
Definition: Auditor.h:153
#define GAUDI_API
Definition: Kernel.h:110
SmartIF< T > service(const std::string &name, bool createIf=false) const
Definition: Auditor.h:122
Base class from which all concrete auditor classes should be derived.
Definition: Auditor.h:35