The Gaudi Framework  v33r0 (d5ea422b)
Auditor.cpp
Go to the documentation of this file.
1 /***********************************************************************************\
2 * (c) Copyright 1998-2019 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 \***********************************************************************************/
14 #include "GaudiKernel/Kernel.h"
15 
16 #include "GaudiKernel/Auditor.h"
17 
19 #include "GaudiKernel/MsgStream.h"
20 
21 // Constructor
22 Auditor::Auditor( const std::string& name, ISvcLocator* pSvcLocator ) : m_name( 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  // Set the Auditor's properties
36  sc = setProperties();
37  if ( !sc.isSuccess() ) return StatusCode::FAILURE;
38 
39  {
40  try {
41  // Invoke the initialize() method of the derived class
42  sc = initialize();
43  if ( !sc.isSuccess() ) return StatusCode::FAILURE;
44  m_isInitialized = true;
45 
46  return sc;
47  } catch ( const GaudiException& Exception )
48  {
50  MsgStream log( msgSvc(), name() + ".sysInitialize()" );
51  log << MSG::FATAL << " Exception with tag=" << Exception.tag() << " is caught " << endmsg;
53  MsgStream logEx( msgSvc(), Exception.tag() );
54  logEx << MSG::ERROR << Exception << endmsg;
55  } catch ( const std::exception& Exception )
56  {
58  MsgStream log( msgSvc(), name() + ".sysInitialize()" );
59  log << MSG::FATAL << " Standard std::exception is caught " << endmsg;
61  MsgStream logEx( msgSvc(), name() + "*std::exception*" );
62  logEx << MSG::ERROR << Exception.what() << endmsg;
63  } catch ( ... ) {
65  MsgStream log( msgSvc(), name() + ".sysInitialize()" );
66  log << MSG::FATAL << " UNKNOWN Exception is caught " << endmsg;
67  }
68  }
69  }
71  return StatusCode::FAILURE;
72 }
73 
75 
76 // Implemented for backward compatibility
77 void Auditor::before( StandardEventType evt, INamedInterface* obj ) {
78  switch ( evt ) {
79  case Initialize:
80  beforeInitialize( obj );
81  break;
82  case ReInitialize:
83  beforeReinitialize( obj );
84  break;
85  case Execute:
86  beforeExecute( obj );
87  break;
88  case Finalize:
89  beforeFinalize( obj );
90  break;
91  case Start:
92  break;
93  case Stop:
94  break;
95  case ReStart:
96  break;
97  default:
98  break; // do nothing
99  }
100 }
101 void Auditor::before( StandardEventType, const std::string& ) {}
102 
103 void Auditor::before( CustomEventTypeRef, INamedInterface* ) {}
104 void Auditor::before( CustomEventTypeRef, const std::string& ) {}
105 
106 // Implemented for backward compatibility
107 void Auditor::after( StandardEventType evt, INamedInterface* obj, const StatusCode& sc ) {
108  switch ( evt ) {
109  case Initialize:
110  afterInitialize( obj );
111  break;
112  case ReInitialize:
113  afterReinitialize( obj );
114  break;
115  case Execute:
116  afterExecute( obj, sc );
117  break;
118  case Finalize:
119  afterFinalize( obj );
120  break;
121  case Start:
122  break;
123  case Stop:
124  break;
125  case ReStart:
126  break;
127  default:
128  break; // do nothing
129  }
130 }
131 void Auditor::after( StandardEventType, const std::string&, const StatusCode& ) {}
132 
133 void Auditor::after( CustomEventTypeRef, INamedInterface*, const StatusCode& ) {}
134 void Auditor::after( CustomEventTypeRef, const std::string&, const StatusCode& ) {}
135 
144 
147  try {
148  //
149  // Invoke the finalize() method of the derived class if
150  // it has been initialized.
151  if ( m_isInitialized && !m_isFinalized ) {
152  m_isFinalized = true;
153  sc = finalize();
154  if ( !sc.isSuccess() ) return StatusCode::FAILURE;
155  }
156  return sc;
157  //
158  } catch ( const GaudiException& Exception )
159  {
161  MsgStream log( msgSvc(), name() + ".sysFinalize()" );
162  log << MSG::FATAL << " Exception with tag=" << Exception.tag() << " is catched " << endmsg;
165  MsgStream logEx( msgSvc(), Exception.tag() );
166  logEx << MSG::ERROR << Exception << endmsg;
167  } catch ( const std::exception& Exception )
168  {
170  MsgStream log( msgSvc(), name() + ".sysFinalize()" );
171  log << MSG::FATAL << " Standard std::exception is caught " << endmsg;
173  MsgStream logEx( msgSvc(), name() + "*std::exception*" );
174  logEx << MSG::ERROR << Exception.what() << endmsg;
175  } catch ( ... )
176  {
178  MsgStream log( msgSvc(), name() + ".sysFinalize()" );
179  log << MSG::FATAL << " UNKNOWN Exception is caught " << endmsg;
180  }
182  return StatusCode::FAILURE;
183 }
184 
186 
187 const std::string& Auditor::name() const { return m_name; }
188 
189 bool Auditor::isEnabled() const { return m_isEnabled; }
190 
192 
193 // Use the job options service to set declared properties
195  if ( !m_pSvcLocator ) return StatusCode::FAILURE;
196  auto jos = service<IJobOptionsSvc>( "JobOptionsSvc" );
197  if ( !jos ) return StatusCode::FAILURE;
198 
199  // this initializes the messaging, in case property update handlers need to print
200  // and update the property value bypassing the update handler
201  m_outputLevel.value() = setUpMessaging();
202 
203  return jos->setMyProperties( name(), this );
204 }
StatusCode sysInitialize() override
Initialization method invoked by the framework.
Definition: Auditor.cpp:25
Definition of the MsgStream class used to transmit messages.
Definition: MsgStream.h:34
virtual StatusCode finalize()
Definition: Auditor.cpp:185
Define general base for Gaudi exception.
The ISvcLocator is the interface implemented by the Service Factory in the Application Manager to loc...
Definition: ISvcLocator.h:35
void beforeInitialize(INamedInterface *) override
Definition: Auditor.cpp:136
const SmartIF< IMessageSvc > & msgSvc() const
The standard message service.
StatusCode setProperties()
Set the auditor's properties.
Definition: Auditor.cpp:194
virtual const std::string & tag() const
name tag for the exception, or exception type
constexpr static const auto SUCCESS
Definition: StatusCode.h:96
StatusCode sysFinalize() override
Finalization method invoked by the framework.
Definition: Auditor.cpp:145
SmartIF< ISvcLocator > & serviceLocator() const override
The standard service locator.
Definition: Auditor.cpp:191
std::string m_name
Auditor's name for identification.
Definition: Auditor.h:133
MSG::Level setUpMessaging() const
Set up local caches.
STL class.
Gaudi::Property< bool > m_isEnabled
Definition: Auditor.h:141
bool m_isInitialized
Auditor has been initialized flag.
Definition: Auditor.h:143
void beforeExecute(INamedInterface *) override
Definition: Auditor.cpp:140
SmartIF< ISvcLocator > m_pSvcLocator
Pointer to service locator service.
Definition: Auditor.h:135
Auditor(const std::string &name, ISvcLocator *svcloc)
Constructor.
Definition: Auditor.cpp:22
T what(T... args)
void afterExecute(INamedInterface *, const StatusCode &) override
Definition: Auditor.cpp:141
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:61
void beforeReinitialize(INamedInterface *) override
Definition: Auditor.cpp:138
void after(StandardEventType, INamedInterface *, const StatusCode &) override
Definition: Auditor.cpp:107
bool isSuccess() const
Definition: StatusCode.h:361
STL class.
void afterInitialize(INamedInterface *) override
Definition: Auditor.cpp:137
IInterface compliant class extending IInterface with the name() method.
bool isEnabled() const override
Definition: Auditor.cpp:189
const std::string & name() const override
Definition: Auditor.cpp:187
constexpr static const auto FAILURE
Definition: StatusCode.h:97
void afterFinalize(INamedInterface *) override
Definition: Auditor.cpp:143
void beforeFinalize(INamedInterface *) override
Definition: Auditor.cpp:142
virtual StatusCode initialize()
Definition: Auditor.cpp:74
void before(StandardEventType, INamedInterface *) override
The following methods are meant to be implemented by the child class...
Definition: Auditor.cpp:77
Gaudi::Property< int > m_outputLevel
Definition: Auditor.h:137
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:202
void afterReinitialize(INamedInterface *) override
Definition: Auditor.cpp:139
bool m_isFinalized
Auditor has been finalized flag.
Definition: Auditor.h:144