The Gaudi Framework  v38r0 (2143aa4c)
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
Auditor.h
Go to the documentation of this file.
1 /***********************************************************************************\
2 * (c) Copyright 1998-2022 CERN for the benefit of the LHCb and ATLAS collaborations *
3 * *
4 * This software is distributed under the terms of the Apache version 2 licence, *
5 * copied verbatim in the file "LICENSE". *
6 * *
7 * In applying this licence, CERN does not waive the privileges and immunities *
8 * granted to it by virtue of its status as an Intergovernmental Organization *
9 * or submit itself to any jurisdiction. *
10 \***********************************************************************************/
11 #ifndef GAUDIKERNEL_AUDITOR_H
12 #define GAUDIKERNEL_AUDITOR_H
13 
14 // Include files
16 #include "GaudiKernel/IAuditor.h"
17 #include "GaudiKernel/IProperty.h"
18 #include "GaudiKernel/IService.h"
19 #include "GaudiKernel/ISvcLocator.h" /*used by service(..)*/
21 #include <Gaudi/PluginService.h>
22 #include <Gaudi/PropertyFwd.h>
23 #include <string>
24 #include <vector>
25 
26 // Forward declarations
27 class IService;
28 class IMessageSvc;
29 
44 class GAUDI_API Auditor : public PropertyHolder<CommonMessaging<implements<IAuditor, IProperty>>> {
45 public:
46  using Factory = Gaudi::PluginService::Factory<IAuditor*( const std::string&, ISvcLocator* )>;
47 
51  Auditor( std::string name, ISvcLocator* svcloc );
52 
53  Auditor( const Auditor& a ) = delete;
54  Auditor& operator=( const Auditor& rhs ) = delete;
55 
59  StatusCode sysInitialize() override;
63  StatusCode sysFinalize() override;
64 
66 
67  void before( StandardEventType, INamedInterface* ) override;
68  void before( StandardEventType, const std::string& ) override;
69 
70  void before( CustomEventTypeRef, INamedInterface* ) override;
71  void before( CustomEventTypeRef, const std::string& ) override;
72 
73  void after( StandardEventType, INamedInterface*, const StatusCode& ) override;
74  void after( StandardEventType, const std::string&, const StatusCode& ) override;
75 
76  void after( CustomEventTypeRef, INamedInterface*, const StatusCode& ) override;
77  void after( CustomEventTypeRef, const std::string&, const StatusCode& ) override;
78 
79  // Obsolete methods
80 
81  void beforeInitialize( INamedInterface* ) override;
82  void afterInitialize( INamedInterface* ) override;
83 
84  void beforeReinitialize( INamedInterface* ) override;
85  void afterReinitialize( INamedInterface* ) override;
86 
87  void beforeExecute( INamedInterface* ) override;
88  void afterExecute( INamedInterface*, const StatusCode& ) override;
89 
90  void beforeFinalize( INamedInterface* ) override;
91  void afterFinalize( 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( std::string_view name, T*& svc, bool createIf = false ) const {
110  auto ptr = serviceLocator()->service<T>( name, createIf );
111  if ( ptr ) {
112  svc = ptr.get();
113  svc->addRef();
114  return StatusCode::SUCCESS;
115  }
116  svc = nullptr;
117  return StatusCode::FAILURE;
118  }
119 
120  template <class T = IService>
121  SmartIF<T> service( std::string_view name, bool createIf = false ) const {
122  return serviceLocator()->service<T>( name, createIf );
123  }
124 
125 private:
127 
129 
130  Gaudi::Property<int> m_outputLevel{
131  this, "OutputLevel", MSG::NIL,
132  [this]( Gaudi::Details::PropertyBase& ) { this->updateMsgStreamOutputLevel( this->m_outputLevel ); },
133  "output level" };
134  Gaudi::Property<bool> m_isEnabled{ this, "Enable", true, "should the auditor be used or not" };
135 
136  bool m_isInitialized = false;
137  bool m_isFinalized = false;
138 };
139 
140 #endif // GAUDIKERNEL_AUDITOR_H
IService
Definition: IService.h:28
Gaudi::Details::PropertyBase
PropertyBase base class allowing PropertyBase* collections to be "homogeneous".
Definition: PropertyBase.h:35
IService.h
std::string
STL class.
IMessageSvc
Definition: IMessageSvc.h:47
bug_34121.name
name
Definition: bug_34121.py:20
Auditor::m_name
std::string m_name
Auditor's name for identification.
Definition: Auditor.h:126
ISvcLocator
Definition: ISvcLocator.h:46
PropertyHolder
Helper class to implement the IProperty interface.
Definition: PropertyHolder.h:82
Auditor::m_pSvcLocator
SmartIF< ISvcLocator > m_pSvcLocator
Pointer to service locator service.
Definition: Auditor.h:128
Auditor::Factory
Gaudi::PluginService::Factory< IAuditor *(const std::string &, ISvcLocator *)> Factory
Definition: Auditor.h:46
PluginService.h
Auditor
Definition: Auditor.h:44
StatusCode
Definition: StatusCode.h:65
Auditor::Auditor
Auditor(const Auditor &a)=delete
PropertyFwd.h
IAuditor.h
SmartIF< ISvcLocator >
CommonMessaging.h
Auditor::service
SmartIF< T > service(std::string_view name, bool createIf=false) const
Definition: Auditor.h:121
INamedInterface
Definition: INamedInterface.h:25
StatusCode::SUCCESS
constexpr static const auto SUCCESS
Definition: StatusCode.h:100
MSG::NIL
@ NIL
Definition: IMessageSvc.h:25
IProperty.h
Auditor::operator=
Auditor & operator=(const Auditor &rhs)=delete
StatusCode::FAILURE
constexpr static const auto FAILURE
Definition: StatusCode.h:101
ISvcLocator.h
PropertyHolder.h
Auditor::service
StatusCode service(std::string_view name, T *&svc, bool createIf=false) const
Access a service by name, creating it if it doesn't already exist.
Definition: Auditor.h:109
GAUDI_API
#define GAUDI_API
Definition: Kernel.h:81
Gaudi::Property< int >
IAuditor
Definition: IAuditor.h:28