The Gaudi Framework  master (37c0b60a)
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 
25 // Forward declarations
26 class IService;
27 class IMessageSvc;
28 
43 class GAUDI_API Auditor : public PropertyHolder<CommonMessaging<implements<IAuditor, IProperty>>> {
44 public:
45  using Factory = Gaudi::PluginService::Factory<IAuditor*( const std::string&, ISvcLocator* )>;
46 
50  Auditor( std::string name, ISvcLocator* svcloc );
51 
52  Auditor( const Auditor& a ) = delete;
53  Auditor& operator=( const Auditor& rhs ) = delete;
54 
58  StatusCode sysInitialize() override;
62  StatusCode sysFinalize() override;
63 
65 
66  void before( StandardEventType, INamedInterface* ) override;
67  void before( StandardEventType, const std::string& ) override;
68 
69  void before( CustomEventTypeRef, INamedInterface* ) override;
70  void before( CustomEventTypeRef, const std::string& ) override;
71 
72  void after( StandardEventType, INamedInterface*, const StatusCode& ) override;
73  void after( StandardEventType, const std::string&, const StatusCode& ) override;
74 
75  void after( CustomEventTypeRef, INamedInterface*, const StatusCode& ) override;
76  void after( CustomEventTypeRef, const std::string&, const StatusCode& ) override;
77 
78  // Obsolete methods
79 
80  void beforeInitialize( INamedInterface* ) override;
81  void afterInitialize( INamedInterface* ) override;
82 
83  void beforeReinitialize( INamedInterface* ) override;
84  void afterReinitialize( INamedInterface* ) override;
85 
86  void beforeExecute( INamedInterface* ) override;
87  void afterExecute( INamedInterface*, const StatusCode& ) override;
88 
89  void beforeFinalize( INamedInterface* ) override;
90  void afterFinalize( 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 
103  SmartIF<ISvcLocator>& serviceLocator() const override;
104 
107  template <class T>
108  [[deprecated( "use service<T>(name, createIf) -> SmartIF<T>" )]] StatusCode service( std::string_view name, T*& svc,
109  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
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:45
PluginService.h
Auditor
Definition: Auditor.h:43
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
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:108
GAUDI_API
#define GAUDI_API
Definition: Kernel.h:81
Gaudi::Property< int >
IAuditor
Definition: IAuditor.h:28