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(..)*/
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&,
40 #endif
41 
45  Auditor( const std::string& name, ISvcLocator *svcloc );
47  virtual ~Auditor();
48 
52  StatusCode sysInitialize();
56  StatusCode sysFinalize();
57 
59 
60  virtual void before(StandardEventType, INamedInterface*);
61  virtual void before(StandardEventType, const std::string&);
62 
63  virtual void before(CustomEventTypeRef, INamedInterface*);
64  virtual void before(CustomEventTypeRef, const std::string&);
65 
66  virtual void after(StandardEventType, INamedInterface*, const StatusCode&);
67  virtual void after(StandardEventType, const std::string&, const StatusCode&);
68 
69  virtual void after(CustomEventTypeRef, INamedInterface*, const StatusCode&);
70  virtual void after(CustomEventTypeRef, const std::string&, const StatusCode&);
71 
72  // Obsolete methods
73 
74  virtual void beforeInitialize(INamedInterface* ) ;
75  virtual void afterInitialize(INamedInterface* ) ;
76 
77  virtual void beforeReinitialize(INamedInterface* ) ;
78  virtual void afterReinitialize(INamedInterface* ) ;
79 
80  virtual void beforeExecute(INamedInterface* );
81  virtual void afterExecute(INamedInterface*, const StatusCode& );
82 
83  virtual void beforeFinalize(INamedInterface* ) ;
84  virtual void afterFinalize(INamedInterface* ) ;
85 
86  virtual void beforeBeginRun(INamedInterface* );
87  virtual void afterBeginRun(INamedInterface* );
88 
89  virtual void beforeEndRun(INamedInterface* );
90  virtual void afterEndRun(INamedInterface* );
91 
92  virtual StatusCode initialize();
93  virtual StatusCode finalize();
94 
95  virtual const std::string& name() const ;
96 
97  virtual bool isEnabled() const ;
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  SmartIF<T> ptr(serviceLocator()->service(name, createIf));
121  if (ptr.isValid()) {
122  svc = ptr.get();
123  svc->addRef();
124  return StatusCode::SUCCESS;
125  }
126  // else
127  svc = 0;
128  return StatusCode::FAILURE;
129  }
130 
132  virtual StatusCode setProperty(const Property& p);
133 
135  virtual StatusCode setProperty( const std::string& s );
136 
138  virtual StatusCode setProperty( const std::string& n, const std::string& v);
139 
141  virtual StatusCode getProperty(Property* p) const;
142 
144  virtual const Property& getProperty( const std::string& name) const;
145 
147  virtual StatusCode getProperty( const std::string& n, std::string& v ) const;
148 
150  const std::vector<Property*>& getProperties( ) const;
151 
153  virtual bool hasProperty(const std::string& name) const;
154 
195  template <class TYPE>
197  ( const std::string& name ,
198  const TYPE& value )
199  { return Gaudi::Utils::setProperty ( m_PropertyMgr , name , value ) ; }
200 
206  StatusCode setProperties();
207 
208  // ==========================================================================
236  template <class T>
237  Property* declareProperty( const std::string& name, T& property,
238  const std::string& doc = "none") const {
239  return m_PropertyMgr->declareProperty(name, property, doc);
240  }
241 
242  private:
243 
244  std::string m_name;
245 
250  bool m_isEnabled;
253 
254  // Private Copy constructor: NO COPY ALLOWED
255  Auditor(const Auditor& a);
256 
257  // Private assignment operator: NO ASSIGNMENT ALLOWED
258  Auditor& operator=(const Auditor& rhs);
259 };
260 
261 #ifndef GAUDI_NEW_PLUGIN_SERVICE
262 template <class T>
263 class AudFactory {
264 public:
265 #ifndef __REFLEX__
266  template <typename S, typename... Args>
267  static typename S::ReturnType create(Args... args) {
268  return new T(args...);
269  }
270 #endif
271 };
272 
273 // Macros to declare component factories
274 #define DECLARE_AUDITOR_FACTORY(x) \
275  DECLARE_FACTORY_WITH_CREATOR(x, AudFactory< x >, Auditor::Factory)
276 #define DECLARE_NAMESPACE_AUDITOR_FACTORY(n, x) \
277  DECLARE_AUDITOR_FACTORY(n::x)
278 
279 #else
280 
281 // macros to declare factories
282 #define DECLARE_AUDITOR_FACTORY(x) DECLARE_COMPONENT(x)
283 #define DECLARE_NAMESPACE_AUDITOR_FACTORY(n, x) DECLARE_COMPONENT(n::x)
284 
285 #endif
286 
287 #endif //GAUDIKERNEL_AUDITOR_H
288 
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:1212
bool m_isEnabled
Auditor is enabled flag.
Definition: Auditor.h:250
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
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:26
StandardEventType
Defines the standard (= used by the framework) auditable event types.
Definition: IAuditor.h:24
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:232
Base class used to implement the interfaces.
Definition: implements.h:150
const CustomEventType & CustomEventTypeRef
Used in function calls for optimization purposes.
Definition: IAuditor.h:41
const char *PyHelper() getProperty(IInterface *p, char *name)
Definition: Bootstrap.cpp:297
Property manager helper class.
Definition: PropertyMgr.h:34
std::string m_name
Auditor's name for identification.
Definition: Auditor.h:244
SmartIF< IMessageSvc > m_MS
Message service.
Definition: Auditor.h:246
TYPE * get() const
Get interface pointer.
Definition: SmartIF.h:62
Property * declareProperty(const std::string &name, T &property, const std::string &doc="none") const
Declare the named property.
Definition: Auditor.h:237
bool m_isInitialized
Auditor has been initialized flag.
Definition: Auditor.h:251
SmartIF< ISvcLocator > m_pSvcLocator
Pointer to service locator service.
Definition: Auditor.h:247
Gaudi::PluginService::Factory< IAuditor *, const std::string &, ISvcLocator * > Factory
Definition: Auditor.h:39
General service interface definition.
Definition: IService.h:19
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:30
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:290
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:43
list args
Definition: gaudirun.py:262
Class wrapping the signature for a factory with any number of arguments.
Definition: PluginService.h:47
bool isValid() const
Allow for check if smart pointer is valid.
Definition: SmartIF.h:51
PropertyMgr * m_PropertyMgr
For management of properties.
Definition: Auditor.h:248
string s
Definition: gaudirun.py:217
int outputLevel() const
Retrieve the output level of current auditor.
Definition: Auditor.h:105
static S::ReturnType create(Args...args)
Definition: Auditor.h:267
#define GAUDI_API
Definition: Kernel.h:108
The IAuditor is the interface implmented by the AlgAuditor base class.
Definition: IAuditor.h:18
int m_outputLevel
Auditor output level.
Definition: Auditor.h:249
Base class from which all concrete auditor classes should be derived.
Definition: Auditor.h:34
bool m_isFinalized
Auditor has been finalized flag.
Definition: Auditor.h:252