Auditor.h
Go to the documentation of this file.
1 #ifndef GAUDIKERNEL_AUDITOR_H
2 #define GAUDIKERNEL_AUDITOR_H
3 
4 // Include files
5 #include "GaudiKernel/IProperty.h"
6 #include "GaudiKernel/IAuditor.h"
7 #include "GaudiKernel/IService.h"
8 #include "GaudiKernel/ISvcLocator.h" /*used by service(..)*/
9 #include "GaudiKernel/PropertyMgr.h"
10 #include <Gaudi/PluginService.h>
11 #include <string>
12 #include <vector>
13 
14 // Forward declarations
15 class IService;
16 class IMessageSvc;
17 class Property;
18 class Algorithm;
19 
34 class GAUDI_API Auditor : public implements2<IAuditor, IProperty> {
35 public:
36 #ifndef __REFLEX__
38  const std::string&,
39  ISvcLocator*> Factory;
40 #endif
41 
45  Auditor( const std::string& name, ISvcLocator *svcloc );
47  ~Auditor() override = default;
48 
52  StatusCode sysInitialize();
56  StatusCode sysFinalize();
57 
59 
60  void before(StandardEventType, INamedInterface*) override;
61  void before(StandardEventType, const std::string&) override;
62 
63  void before(CustomEventTypeRef, INamedInterface*) override;
64  void before(CustomEventTypeRef, const std::string&) override;
65 
66  void after(StandardEventType, INamedInterface*, const StatusCode&) override;
67  void after(StandardEventType, const std::string&, const StatusCode&) override;
68 
69  void after(CustomEventTypeRef, INamedInterface*, const StatusCode&) override;
70  void after(CustomEventTypeRef, const std::string&, const StatusCode&) override;
71 
72  // Obsolete methods
73 
74  void beforeInitialize(INamedInterface* ) override;
75  void afterInitialize(INamedInterface* ) override;
76 
77  void beforeReinitialize(INamedInterface* ) override;
78  void afterReinitialize(INamedInterface* ) override;
79 
80  void beforeExecute(INamedInterface* ) override;
81  void afterExecute(INamedInterface*, const StatusCode& ) override;
82 
83  void beforeFinalize(INamedInterface* ) override;
84  void afterFinalize(INamedInterface* ) override;
85 
86  void beforeBeginRun(INamedInterface* ) override;
87  void afterBeginRun(INamedInterface* ) override;
88 
89  void beforeEndRun(INamedInterface* ) override;
90  void afterEndRun(INamedInterface* ) override;
91 
92  virtual StatusCode initialize();
93  virtual StatusCode finalize();
94 
95  const std::string& name() const override;
96 
97  bool isEnabled() const override;
98 
102  SmartIF<IMessageSvc>& msgSvc() const;
103 
105  int outputLevel() const { return m_outputLevel; }
106 
108  void setOutputLevel( int level );
109 
114  SmartIF<ISvcLocator>& serviceLocator() const;
115 
118  template <class T>
119  StatusCode service( const std::string& name, T*& svc, bool createIf = false ) const {
120  auto ptr = serviceLocator()->service<T>(name, createIf);
121  if (ptr) {
122  svc = ptr.get();
123  svc->addRef();
124  return StatusCode::SUCCESS;
125  }
126  svc = nullptr;
127  return StatusCode::FAILURE;
128  }
129 
130  template <class T = IService>
131  SmartIF<T> service( const std::string& name, bool createIf = false ) const {
132  return serviceLocator()->service<T>(name, createIf);
133  }
134 
136  StatusCode setProperty(const Property& p) override;
137 
139  StatusCode setProperty( const std::string& s ) override;
140 
142  StatusCode setProperty( const std::string& n, const std::string& v) override;
143 
145  StatusCode getProperty(Property* p) const override;
146 
148  const Property& getProperty( const std::string& name) const override;
149 
151  StatusCode getProperty( const std::string& n, std::string& v ) const override;
152 
154  const std::vector<Property*>& getProperties( ) const;
155 
157  bool hasProperty(const std::string& name) const override;
158 
199  template <class TYPE>
201  ( const std::string& name ,
202  const TYPE& value )
203  { return Gaudi::Utils::setProperty ( m_PropertyMgr.get() , name , value ) ; }
204 
210  StatusCode setProperties();
211 
212  // ==========================================================================
240  template <class T>
241  Property* declareProperty( const std::string& name, T& property,
242  const std::string& doc = "none") const {
243  return m_PropertyMgr->declareProperty(name, property, doc);
244  }
245 
246  private:
247 
248  std::string m_name;
249 
250  mutable SmartIF<IMessageSvc> m_MS;
251  mutable SmartIF<ISvcLocator> m_pSvcLocator;
252  SmartIF<PropertyMgr> m_PropertyMgr;
253  int m_outputLevel;
254  bool m_isEnabled;
255  bool m_isInitialized;
256  bool m_isFinalized;
257 
258  // Private Copy constructor: NO COPY ALLOWED
259  Auditor(const Auditor& a);
260 
261  // Private assignment operator: NO ASSIGNMENT ALLOWED
262  Auditor& operator=(const Auditor& rhs);
263 };
264 
265 #ifndef GAUDI_NEW_PLUGIN_SERVICE
266 template <class T>
267 class AudFactory {
268 public:
269 #ifndef __REFLEX__
270  template <typename S, typename... Args>
271  static typename S::ReturnType create(Args&&... args) {
272  return new T(std::forward<Args>(args)...);
273  }
274 #endif
275 };
276 
277 // Macros to declare component factories
278 #define DECLARE_AUDITOR_FACTORY(x) \
279  DECLARE_FACTORY_WITH_CREATOR(x, AudFactory< x >, Auditor::Factory)
280 #define DECLARE_NAMESPACE_AUDITOR_FACTORY(n, x) \
281  DECLARE_AUDITOR_FACTORY(n::x)
282 
283 #else
284 
285 // macros to declare factories
286 #define DECLARE_AUDITOR_FACTORY(x) DECLARE_COMPONENT(x)
287 #define DECLARE_NAMESPACE_AUDITOR_FACTORY(n, x) DECLARE_COMPONENT(n::x)
288 
289 #endif
290 
291 #endif //GAUDIKERNEL_AUDITOR_H
292 
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
Base class used to implement the interfaces.
Definition: implements.h:8
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
#define GAUDI_API
Definition: Kernel.h:107
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:157
const char *PyHelper() getProperty(IInterface *p, char *name)
Definition: Bootstrap.cpp:259
implements & operator=(const implements &)
Assignment operator (do not touch the reference count).
Definition: implements.h:37
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:255
Base class from which all concrete algorithm classes should be derived.
Definition: Algorithm.h:61
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:291
Class wrapping the signature for a factory with any number of arguments.
Definition: PluginService.h:47
string s
Definition: gaudirun.py:246
static S::ReturnType create(Args &&...args)
Definition: Auditor.h:271
The IAuditor is the interface implmented by the AlgAuditor base class.
Definition: IAuditor.h:18
Base class from which all concrete auditor classes should be derived.
Definition: Auditor.h:34