The Gaudi Framework  master (37c0b60a)
Auditor.cpp
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 \***********************************************************************************/
13 #include <GaudiKernel/Kernel.h>
14 
15 #include <GaudiKernel/Auditor.h>
16 
18 #include <GaudiKernel/MsgStream.h>
19 
20 // Constructor
22  : m_name( std::move( name ) ), m_pSvcLocator( pSvcLocator ) {}
23 
24 // IAuditor implementation
26  StatusCode sc;
27 
28  // Bypass the initialization if the auditor is disabled or
29  // has already been initialized.
30  if ( isEnabled() && !m_isInitialized ) {
31 
32  // Setup the default service ... this should be upgraded so as to be configurable.
33  if ( !m_pSvcLocator ) return StatusCode::FAILURE;
34 
35  // this initializes the messaging, in case property update handlers need to print
36  // and update the property value bypassing the update handler
38 
39  // Set the Algorithm's properties
40  bindPropertiesTo( serviceLocator()->getOptsSvc() );
41 
42  if ( !sc.isSuccess() ) return StatusCode::FAILURE;
43 
44  {
45  try {
46  // Invoke the initialize() method of the derived class
47  sc = initialize();
48  if ( !sc.isSuccess() ) return StatusCode::FAILURE;
49  m_isInitialized = true;
50 
51  return sc;
52  } catch ( const GaudiException& Exception )
53  {
55  MsgStream log( msgSvc(), name() + ".sysInitialize()" );
56  log << MSG::FATAL << " Exception with tag=" << Exception.tag() << " is caught " << endmsg;
58  MsgStream logEx( msgSvc(), Exception.tag() );
59  logEx << MSG::ERROR << Exception << endmsg;
60  } catch ( const std::exception& Exception )
61  {
63  MsgStream log( msgSvc(), name() + ".sysInitialize()" );
64  log << MSG::FATAL << " Standard std::exception is caught " << endmsg;
66  MsgStream logEx( msgSvc(), name() + "*std::exception*" );
67  logEx << MSG::ERROR << Exception.what() << endmsg;
68  } catch ( ... ) {
70  MsgStream log( msgSvc(), name() + ".sysInitialize()" );
71  log << MSG::FATAL << " UNKNOWN Exception is caught " << endmsg;
72  }
73  }
74  }
76  return StatusCode::FAILURE;
77 }
78 
80 
81 // Implemented for backward compatibility
82 void Auditor::before( StandardEventType evt, INamedInterface* obj ) {
83  switch ( evt ) {
84  case Initialize:
85  beforeInitialize( obj );
86  break;
87  case ReInitialize:
88  beforeReinitialize( obj );
89  break;
90  case Execute:
91  beforeExecute( obj );
92  break;
93  case Finalize:
94  beforeFinalize( obj );
95  break;
96  case Start:
97  break;
98  case Stop:
99  break;
100  case ReStart:
101  break;
102  default:
103  break; // do nothing
104  }
105 }
106 void Auditor::before( StandardEventType, const std::string& ) {}
107 
108 void Auditor::before( CustomEventTypeRef, INamedInterface* ) {}
109 void Auditor::before( CustomEventTypeRef, const std::string& ) {}
110 
111 // Implemented for backward compatibility
112 void Auditor::after( StandardEventType evt, INamedInterface* obj, const StatusCode& sc ) {
113  switch ( evt ) {
114  case Initialize:
115  afterInitialize( obj );
116  break;
117  case ReInitialize:
118  afterReinitialize( obj );
119  break;
120  case Execute:
121  afterExecute( obj, sc );
122  break;
123  case Finalize:
124  afterFinalize( obj );
125  break;
126  case Start:
127  break;
128  case Stop:
129  break;
130  case ReStart:
131  break;
132  default:
133  break; // do nothing
134  }
135 }
136 void Auditor::after( StandardEventType, const std::string&, const StatusCode& ) {}
137 
138 void Auditor::after( CustomEventTypeRef, INamedInterface*, const StatusCode& ) {}
139 void Auditor::after( CustomEventTypeRef, const std::string&, const StatusCode& ) {}
140 
149 
152  try {
153  //
154  // Invoke the finalize() method of the derived class if
155  // it has been initialized.
156  if ( m_isInitialized && !m_isFinalized ) {
157  m_isFinalized = true;
158  sc = finalize();
159  if ( !sc.isSuccess() ) return StatusCode::FAILURE;
160  }
161  return sc;
162  //
163  } catch ( const GaudiException& Exception )
164  {
166  MsgStream log( msgSvc(), name() + ".sysFinalize()" );
167  log << MSG::FATAL << " Exception with tag=" << Exception.tag() << " is catched " << endmsg;
170  MsgStream logEx( msgSvc(), Exception.tag() );
171  logEx << MSG::ERROR << Exception << endmsg;
172  } catch ( const std::exception& Exception )
173  {
175  MsgStream log( msgSvc(), name() + ".sysFinalize()" );
176  log << MSG::FATAL << " Standard std::exception is caught " << endmsg;
178  MsgStream logEx( msgSvc(), name() + "*std::exception*" );
179  logEx << MSG::ERROR << Exception.what() << endmsg;
180  } catch ( ... )
181  {
183  MsgStream log( msgSvc(), name() + ".sysFinalize()" );
184  log << MSG::FATAL << " UNKNOWN Exception is caught " << endmsg;
185  }
187  return StatusCode::FAILURE;
188 }
189 
191 
192 const std::string& Auditor::name() const { return m_name; }
193 
194 bool Auditor::isEnabled() const { return m_isEnabled; }
195 
IOTest.evt
evt
Definition: IOTest.py:107
Auditor::beforeInitialize
void beforeInitialize(INamedInterface *) override
Definition: Auditor.cpp:141
std::string
STL class.
std::exception
STL class.
Gaudi.Configuration.log
log
Definition: Configuration.py:28
StatusCode::isSuccess
bool isSuccess() const
Definition: StatusCode.h:314
GaudiException.h
Auditor::m_name
std::string m_name
Auditor's name for identification.
Definition: Auditor.h:126
ISvcLocator
Definition: ISvcLocator.h:46
Auditor::m_outputLevel
Gaudi::Property< int > m_outputLevel
Definition: Auditor.h:130
GaudiException
Definition: GaudiException.h:31
Auditor::before
void before(StandardEventType, INamedInterface *) override
The following methods are meant to be implemented by the child class...
Definition: Auditor.cpp:82
Auditor::beforeReinitialize
void beforeReinitialize(INamedInterface *) override
Definition: Auditor.cpp:143
Auditor::afterExecute
void afterExecute(INamedInterface *, const StatusCode &) override
Definition: Auditor.cpp:146
IMessageSvc.h
Auditor::m_pSvcLocator
SmartIF< ISvcLocator > m_pSvcLocator
Pointer to service locator service.
Definition: Auditor.h:128
PropertyHolder< CommonMessaging< implements< IAuditor, IProperty > > >::bindPropertiesTo
void bindPropertiesTo(Gaudi::Interfaces::IOptionsSvc &optsSvc)
Definition: PropertyHolder.h:252
AvalancheSchedulerErrorTest.msgSvc
msgSvc
Definition: AvalancheSchedulerErrorTest.py:80
Auditor::finalize
virtual StatusCode finalize()
Definition: Auditor.cpp:190
Auditor::initialize
virtual StatusCode initialize()
Definition: Auditor.cpp:79
Auditor::name
const std::string & name() const override
Definition: Auditor.cpp:192
Auditor::beforeFinalize
void beforeFinalize(INamedInterface *) override
Definition: Auditor.cpp:147
Auditor::after
void after(StandardEventType, INamedInterface *, const StatusCode &) override
Definition: Auditor.cpp:112
CommonMessaging< implements< IAuditor, IProperty > >::setUpMessaging
MSG::Level setUpMessaging() const
Set up local caches.
Definition: CommonMessaging.h:174
Auditor::m_isFinalized
bool m_isFinalized
Auditor has been finalized flag.
Definition: Auditor.h:137
StatusCode
Definition: StatusCode.h:65
Auditor::afterReinitialize
void afterReinitialize(INamedInterface *) override
Definition: Auditor.cpp:144
Auditor::sysFinalize
StatusCode sysFinalize() override
Finalization method invoked by the framework.
Definition: Auditor.cpp:150
Auditor::afterFinalize
void afterFinalize(INamedInterface *) override
Definition: Auditor.cpp:148
Gaudi::Property::value
const ValueType & value() const
Definition: Property.h:237
SmartIF< ISvcLocator >
Auditor::afterInitialize
void afterInitialize(INamedInterface *) override
Definition: Auditor.cpp:142
endmsg
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:202
MsgStream
Definition: MsgStream.h:33
MSG::FATAL
@ FATAL
Definition: IMessageSvc.h:25
Auditor::beforeExecute
void beforeExecute(INamedInterface *) override
Definition: Auditor.cpp:145
INamedInterface
Definition: INamedInterface.h:25
Auditor::isEnabled
bool isEnabled() const override
Definition: Auditor.cpp:194
StatusCode::SUCCESS
constexpr static const auto SUCCESS
Definition: StatusCode.h:100
ConditionsStallTest.name
name
Definition: ConditionsStallTest.py:77
Auditor::m_isEnabled
Gaudi::Property< bool > m_isEnabled
Definition: Auditor.h:134
std
STL namespace.
Kernel.h
MSG::ERROR
@ ERROR
Definition: IMessageSvc.h:25
Auditor::Auditor
Auditor(std::string name, ISvcLocator *svcloc)
Constructor.
Definition: Auditor.cpp:21
Auditor::m_isInitialized
bool m_isInitialized
Auditor has been initialized flag.
Definition: Auditor.h:136
StatusCode::FAILURE
constexpr static const auto FAILURE
Definition: StatusCode.h:101
Auditor::sysInitialize
StatusCode sysInitialize() override
Initialization method invoked by the framework.
Definition: Auditor.cpp:25
ISvcLocator.h
Auditor::serviceLocator
SmartIF< ISvcLocator > & serviceLocator() const override
The standard service locator.
Definition: Auditor.cpp:196
MsgStream.h
Auditor.h