All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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:
37  const std::string&,
39 
43  Auditor( const std::string& name, ISvcLocator *svcloc );
45  virtual ~Auditor();
46 
50  StatusCode sysInitialize();
54  StatusCode sysFinalize();
55 
57 
58  virtual void before(StandardEventType, INamedInterface*);
59  virtual void before(StandardEventType, const std::string&);
60 
61  virtual void before(CustomEventTypeRef, INamedInterface*);
62  virtual void before(CustomEventTypeRef, const std::string&);
63 
64  virtual void after(StandardEventType, INamedInterface*, const StatusCode&);
65  virtual void after(StandardEventType, const std::string&, const StatusCode&);
66 
67  virtual void after(CustomEventTypeRef, INamedInterface*, const StatusCode&);
68  virtual void after(CustomEventTypeRef, const std::string&, const StatusCode&);
69 
70  // Obsolete methods
71 
72  virtual void beforeInitialize(INamedInterface* ) ;
73  virtual void afterInitialize(INamedInterface* ) ;
74 
75  virtual void beforeReinitialize(INamedInterface* ) ;
76  virtual void afterReinitialize(INamedInterface* ) ;
77 
78  virtual void beforeExecute(INamedInterface* );
79  virtual void afterExecute(INamedInterface*, const StatusCode& );
80 
81  virtual void beforeFinalize(INamedInterface* ) ;
82  virtual void afterFinalize(INamedInterface* ) ;
83 
84  virtual void beforeBeginRun(INamedInterface* );
85  virtual void afterBeginRun(INamedInterface* );
86 
87  virtual void beforeEndRun(INamedInterface* );
88  virtual void afterEndRun(INamedInterface* );
89 
90  virtual StatusCode initialize();
91  virtual StatusCode finalize();
92 
93  virtual const std::string& name() const ;
94 
95  virtual bool isEnabled() const ;
96 
100  SmartIF<IMessageSvc>& msgSvc() const;
101 
103  int outputLevel() const { return m_outputLevel; }
104 
106  void setOutputLevel( int level );
107 
112  SmartIF<ISvcLocator>& serviceLocator() const;
113 
116  template <class T>
117  StatusCode service( const std::string& name, T*& svc, bool createIf = false ) const {
118  SmartIF<T> ptr(serviceLocator()->service(name, createIf));
119  if (ptr.isValid()) {
120  svc = ptr.get();
121  svc->addRef();
122  return StatusCode::SUCCESS;
123  }
124  // else
125  svc = 0;
126  return StatusCode::FAILURE;
127  }
128 
130  virtual StatusCode setProperty(const Property& p);
131 
133  virtual StatusCode setProperty( const std::string& s );
134 
136  virtual StatusCode setProperty( const std::string& n, const std::string& v);
137 
139  virtual StatusCode getProperty(Property* p) const;
140 
142  virtual const Property& getProperty( const std::string& name) const;
143 
145  virtual StatusCode getProperty( const std::string& n, std::string& v ) const;
146 
148  const std::vector<Property*>& getProperties( ) const;
149 
150 
191  template <class TYPE>
193  ( const std::string& name ,
194  const TYPE& value )
195  { return Gaudi::Utils::setProperty ( m_PropertyMgr , name , value ) ; }
196 
202  StatusCode setProperties();
203 
204  // ==========================================================================
232  template <class T>
233  Property* declareProperty( const std::string& name, T& property,
234  const std::string& doc = "none") const {
235  return m_PropertyMgr->declareProperty(name, property, doc);
236  }
237 
238  private:
239 
240  std::string m_name;
241 
246  bool m_isEnabled;
249 
250  // Private Copy constructor: NO COPY ALLOWED
251  Auditor(const Auditor& a);
252 
253  // Private assignment operator: NO ASSIGNMENT ALLOWED
254  Auditor& operator=(const Auditor& rhs);
255 };
256 
257 #ifndef GAUDI_NEW_PLUGIN_SERVICE
258 template <class T>
259 class AudFactory {
260 public:
261  template <typename S>
262  static typename S::ReturnType create(typename S::Arg1Type a1,
263  typename S::Arg2Type a2) {
264  return new T(a1, a2);
265  }
266 };
267 
268 // Macros to declare component factories
269 #define DECLARE_AUDITOR_FACTORY(x) \
270  DECLARE_FACTORY_WITH_CREATOR(x, AudFactory< x >, Auditor::Factory)
271 #define DECLARE_NAMESPACE_AUDITOR_FACTORY(n, x) \
272  DECLARE_AUDITOR_FACTORY(n::x)
273 
274 #else
275 
276 // macros to declare factories
277 #define DECLARE_AUDITOR_FACTORY(x) DECLARE_COMPONENT(x)
278 #define DECLARE_NAMESPACE_AUDITOR_FACTORY(n, x) DECLARE_COMPONENT(n::x)
279 
280 #endif
281 
282 #endif //GAUDIKERNEL_AUDITOR_H
283 
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:246
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:117
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
Base class used to implement the interfaces.
Definition: implements.h:150
static S::ReturnType create(typename S::Arg1Type a1, typename S::Arg2Type a2)
Definition: Auditor.h:262
const CustomEventType & CustomEventTypeRef
Used in function calls for optimization purposes.
Definition: IAuditor.h:41
GAUDI_API Property * getProperty(const IProperty *p, const std::string &name)
simple function which gets the property with given name from the component
Definition: Property.cpp:349
Property manager helper class.
Definition: PropertyMgr.h:38
std::string m_name
Auditor's name for identification.
Definition: Auditor.h:240
SmartIF< IMessageSvc > m_MS
Message service.
Definition: Auditor.h:242
Property * declareProperty(const std::string &name, T &property, const std::string &doc="none") const
Declare the named property.
Definition: Auditor.h:233
bool m_isInitialized
Auditor has been initialized flag.
Definition: Auditor.h:247
SmartIF< ISvcLocator > m_pSvcLocator
Pointer to service locator service.
Definition: Auditor.h:243
bool isValid() const
Allow for check if smart pointer is valid.
Definition: SmartIF.h:51
General service interface definition.
Definition: IService.h:19
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:30
Gaudi::PluginService::Factory2< IAuditor *, const std::string &, ISvcLocator * > Factory
Definition: Auditor.h:38
The IMessage is the interface implemented by the message service.
Definition: IMessageSvc.h:57
TYPE * get() const
Get interface pointer.
Definition: SmartIF.h:62
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
Class wrapping the signature for a factory with 2 arguments.
Definition: PluginService.h:86
PropertyMgr * m_PropertyMgr
For management of properties.
Definition: Auditor.h:244
string s
Definition: gaudirun.py:210
int outputLevel() const
Retrieve the output level of current auditor.
Definition: Auditor.h:103
#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:245
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:248