The Gaudi Framework  v39r1 (adb068b2)
Auditor.h
Go to the documentation of this file.
1 /***********************************************************************************\
2 * (c) Copyright 1998-2024 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
15 #include <Gaudi/PluginService.h>
16 #include <Gaudi/PropertyFwd.h>
18 #include <GaudiKernel/IAuditor.h>
19 #include <GaudiKernel/IProperty.h>
20 #include <GaudiKernel/IService.h>
21 #include <GaudiKernel/ISvcLocator.h> /*used by service(..)*/
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  [[deprecated( "use service<T>(name, createIf) -> SmartIF<T>" )]] StatusCode service( std::string_view name, T*& svc,
110  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( std::string_view name, bool createIf = false ) const {
123  return serviceLocator()->service<T>( name, createIf );
124  }
125 
126 private:
128 
130 
131  Gaudi::Property<int> m_outputLevel{
132  this, "OutputLevel", MSG::NIL,
133  [this]( Gaudi::Details::PropertyBase& ) { this->updateMsgStreamOutputLevel( this->m_outputLevel ); },
134  "output level" };
135  Gaudi::Property<bool> m_isEnabled{ this, "Enable", true, "should the auditor be used or not" };
136 
137  bool m_isInitialized = false;
138  bool m_isFinalized = false;
139 };
140 
141 #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
Auditor::m_name
std::string m_name
Auditor's name for identification.
Definition: Auditor.h:127
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:129
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:122
INamedInterface
Definition: INamedInterface.h:25
StatusCode::SUCCESS
constexpr static const auto SUCCESS
Definition: StatusCode.h:100
ConditionsStallTest.name
name
Definition: ConditionsStallTest.py:77
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