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"
7 #include "GaudiKernel/IService.h"
8 #include "GaudiKernel/ISvcLocator.h" /*used by service(..)*/
11 #include <Gaudi/PluginService.h>
12 #include <string>
13 #include <vector>
14 
15 // Forward declarations
16 class IService;
17 class IMessageSvc;
18 class Property;
19 class Algorithm;
20 
35 class GAUDI_API Auditor : public CommonMessaging<implements<IAuditor,
36  IProperty>> {
37 public:
38 #ifndef __REFLEX__
40  const std::string&,
42 #endif
43 
47  Auditor( const std::string& name, ISvcLocator *svcloc );
49  ~Auditor() override = default;
50 
54  StatusCode sysInitialize() override;
58  StatusCode sysFinalize() override;
59 
61 
62  void before(StandardEventType, INamedInterface*) override;
63  void before(StandardEventType, const std::string&) override;
64 
65  void before(CustomEventTypeRef, INamedInterface*) override;
66  void before(CustomEventTypeRef, const std::string&) override;
67 
68  void after(StandardEventType, INamedInterface*, const StatusCode&) override;
69  void after(StandardEventType, const std::string&, const StatusCode&) override;
70 
71  void after(CustomEventTypeRef, INamedInterface*, const StatusCode&) override;
72  void after(CustomEventTypeRef, const std::string&, const StatusCode&) override;
73 
74  // Obsolete methods
75 
76  void beforeInitialize(INamedInterface* ) override;
77  void afterInitialize(INamedInterface* ) override;
78 
79  void beforeReinitialize(INamedInterface* ) override;
80  void afterReinitialize(INamedInterface* ) override;
81 
82  void beforeExecute(INamedInterface* ) override;
83  void afterExecute(INamedInterface*, const StatusCode& ) override;
84 
85  void beforeFinalize(INamedInterface* ) override;
86  void afterFinalize(INamedInterface* ) override;
87 
88  void beforeBeginRun(INamedInterface* ) override;
89  void afterBeginRun(INamedInterface* ) override;
90 
91  void beforeEndRun(INamedInterface* ) override;
92  void afterEndRun(INamedInterface* ) override;
93 
94  virtual StatusCode initialize();
95  virtual StatusCode finalize();
96 
97  const std::string& name() const override;
98 
99  bool isEnabled() const override;
100 
105  SmartIF<ISvcLocator>& serviceLocator() const;
106 
109  template <class T>
110  StatusCode service( const std::string& name, T*& svc, bool createIf = false ) const {
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  return serviceLocator()->service<T>(name, createIf);
124  }
125 
127  StatusCode setProperty(const Property& p) override;
128 
130  StatusCode setProperty( const std::string& s ) override;
131 
133  StatusCode setProperty( const std::string& n, const std::string& v) override;
134 
136  StatusCode getProperty(Property* p) const override;
137 
139  const Property& getProperty( const std::string& name) const override;
140 
142  StatusCode getProperty( const std::string& n, std::string& v ) const override;
143 
145  const std::vector<Property*>& getProperties( ) const override;
146 
148  bool hasProperty(const std::string& name) const override;
149 
190  template <class TYPE>
192  ( const std::string& name ,
193  const TYPE& value )
194  { return Gaudi::Utils::setProperty ( m_PropertyMgr.get() , name , value ) ; }
195 
201  StatusCode setProperties();
202 
203  // ==========================================================================
231  template <class T>
232  Property* declareProperty( const std::string& name, T& property,
233  const std::string& doc = "none") const {
234  return m_PropertyMgr->declareProperty(name, property, doc);
235  }
236 
237  private:
238 
239  std::string m_name;
240 
244  bool m_isEnabled;
247 
248  // Private Copy constructor: NO COPY ALLOWED
249  Auditor(const Auditor& a);
250 
251  // Private assignment operator: NO ASSIGNMENT ALLOWED
252  Auditor& operator=(const Auditor& rhs);
253 };
254 
255 #ifndef GAUDI_NEW_PLUGIN_SERVICE
256 template <class T>
257 class AudFactory {
258 public:
259 #ifndef __REFLEX__
260  template <typename S, typename... Args>
261  static typename S::ReturnType create(Args&&... args) {
262  return new T(std::forward<Args>(args)...);
263  }
264 #endif
265 };
266 
267 // Macros to declare component factories
268 #define DECLARE_AUDITOR_FACTORY(x) \
269  DECLARE_FACTORY_WITH_CREATOR(x, AudFactory< x >, Auditor::Factory)
270 #define DECLARE_NAMESPACE_AUDITOR_FACTORY(n, x) \
271  DECLARE_AUDITOR_FACTORY(n::x)
272 
273 #else
274 
275 // macros to declare factories
276 #define DECLARE_AUDITOR_FACTORY(x) DECLARE_COMPONENT(x)
277 #define DECLARE_NAMESPACE_AUDITOR_FACTORY(n, x) DECLARE_COMPONENT(n::x)
278 
279 #endif
280 
281 #endif //GAUDIKERNEL_AUDITOR_H
282 
StatusCode setProperty(IProperty *component, const std::string &name, const TYPE &value, const std::string &doc)
simple function to set the property of the given object from the value
Definition: Property.h:1187
bool m_isEnabled
Auditor is enabled flag.
Definition: Auditor.h:244
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:110
def initialize()
Definition: AnalysisTest.py:12
The ISvcLocator is the interface implemented by the Service Factory in the Application Manager to loc...
Definition: ISvcLocator.h:25
GAUDI_API bool hasProperty(const IProperty *p, const std::string &name)
simple function which check the existence of the property with the given name.
Definition: Property.cpp:159
const char *PyHelper() getProperty(IInterface *p, char *name)
Definition: Bootstrap.cpp:258
std::string m_name
Auditor's name for identification.
Definition: Auditor.h:239
STL class.
Property * declareProperty(const std::string &name, T &property, const std::string &doc="none") const
Declare the named property.
Definition: Auditor.h:232
bool m_isInitialized
Auditor has been initialized flag.
Definition: Auditor.h:245
SmartIF< ISvcLocator > m_pSvcLocator
Pointer to service locator service.
Definition: Auditor.h:241
Gaudi::PluginService::Factory< IAuditor *, const std::string &, ISvcLocator * > Factory
Definition: Auditor.h:41
General service interface definition.
Definition: IService.h:18
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:26
The IMessage is the interface implemented by the message service.
Definition: IMessageSvc.h:57
bool PyHelper() setProperty(IInterface *p, char *name, char *value)
Definition: Bootstrap.cpp:254
Base class from which all concrete algorithm classes should be derived.
Definition: Algorithm.h:74
IInterface compliant class extending IInterface with the name() method.
Property base class allowing Property* collections to be "homogeneous".
Definition: Property.h:38
list args
Definition: gaudirun.py:290
Class wrapping the signature for a factory with any number of arguments.
Definition: PluginService.h:47
SmartIF< PropertyMgr > m_PropertyMgr
For management of properties.
Definition: Auditor.h:242
string s
Definition: gaudirun.py:245
static S::ReturnType create(Args &&...args)
Definition: Auditor.h:261
#define GAUDI_API
Definition: Kernel.h:107
The IAuditor is the interface implmented by the AlgAuditor base class.
Definition: IAuditor.h:18
SmartIF< T > service(const std::string &name, bool createIf=false) const
Definition: Auditor.h:122
int m_outputLevel
Auditor output level.
Definition: Auditor.h:243
Base class from which all concrete auditor classes should be derived.
Definition: Auditor.h:35
bool m_isFinalized
Auditor has been finalized flag.
Definition: Auditor.h:246