The Gaudi Framework  v33r1 (b1225454)
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
23  : m_name( std::move( name ) ), m_pSvcLocator( pSvcLocator ) {}
24 
25 // IAuditor implementation
27  StatusCode sc;
28 
29  // Bypass the initialization if the auditor is disabled or
30  // has already been initialized.
31  if ( isEnabled() && !m_isInitialized ) {
32 
33  // Setup the default service ... this should be upgraded so as to be configurable.
34  if ( !m_pSvcLocator ) return StatusCode::FAILURE;
35 
36  // Set the Auditor's properties
37  sc = setProperties();
38  if ( !sc.isSuccess() ) return StatusCode::FAILURE;
39 
40  {
41  try {
42  // Invoke the initialize() method of the derived class
43  sc = initialize();
44  if ( !sc.isSuccess() ) return StatusCode::FAILURE;
45  m_isInitialized = true;
46 
47  return sc;
48  } catch ( const GaudiException& Exception )
49  {
51  MsgStream log( msgSvc(), name() + ".sysInitialize()" );
52  log << MSG::FATAL << " Exception with tag=" << Exception.tag() << " is caught " << endmsg;
54  MsgStream logEx( msgSvc(), Exception.tag() );
55  logEx << MSG::ERROR << Exception << endmsg;
56  } catch ( const std::exception& Exception )
57  {
59  MsgStream log( msgSvc(), name() + ".sysInitialize()" );
60  log << MSG::FATAL << " Standard std::exception is caught " << endmsg;
62  MsgStream logEx( msgSvc(), name() + "*std::exception*" );
63  logEx << MSG::ERROR << Exception.what() << endmsg;
64  } catch ( ... ) {
66  MsgStream log( msgSvc(), name() + ".sysInitialize()" );
67  log << MSG::FATAL << " UNKNOWN Exception is caught " << endmsg;
68  }
69  }
70  }
72  return StatusCode::FAILURE;
73 }
74 
76 
77 // Implemented for backward compatibility
78 void Auditor::before( StandardEventType evt, INamedInterface* obj ) {
79  switch ( evt ) {
80  case Initialize:
81  beforeInitialize( obj );
82  break;
83  case ReInitialize:
84  beforeReinitialize( obj );
85  break;
86  case Execute:
87  beforeExecute( obj );
88  break;
89  case Finalize:
90  beforeFinalize( obj );
91  break;
92  case Start:
93  break;
94  case Stop:
95  break;
96  case ReStart:
97  break;
98  default:
99  break; // do nothing
100  }
101 }
102 void Auditor::before( StandardEventType, const std::string& ) {}
103 
104 void Auditor::before( CustomEventTypeRef, INamedInterface* ) {}
105 void Auditor::before( CustomEventTypeRef, const std::string& ) {}
106 
107 // Implemented for backward compatibility
108 void Auditor::after( StandardEventType evt, INamedInterface* obj, const StatusCode& sc ) {
109  switch ( evt ) {
110  case Initialize:
111  afterInitialize( obj );
112  break;
113  case ReInitialize:
114  afterReinitialize( obj );
115  break;
116  case Execute:
117  afterExecute( obj, sc );
118  break;
119  case Finalize:
120  afterFinalize( obj );
121  break;
122  case Start:
123  break;
124  case Stop:
125  break;
126  case ReStart:
127  break;
128  default:
129  break; // do nothing
130  }
131 }
132 void Auditor::after( StandardEventType, const std::string&, const StatusCode& ) {}
133 
134 void Auditor::after( CustomEventTypeRef, INamedInterface*, const StatusCode& ) {}
135 void Auditor::after( CustomEventTypeRef, const std::string&, const StatusCode& ) {}
136 
145 
148  try {
149  //
150  // Invoke the finalize() method of the derived class if
151  // it has been initialized.
152  if ( m_isInitialized && !m_isFinalized ) {
153  m_isFinalized = true;
154  sc = finalize();
155  if ( !sc.isSuccess() ) return StatusCode::FAILURE;
156  }
157  return sc;
158  //
159  } catch ( const GaudiException& Exception )
160  {
162  MsgStream log( msgSvc(), name() + ".sysFinalize()" );
163  log << MSG::FATAL << " Exception with tag=" << Exception.tag() << " is catched " << endmsg;
166  MsgStream logEx( msgSvc(), Exception.tag() );
167  logEx << MSG::ERROR << Exception << endmsg;
168  } catch ( const std::exception& Exception )
169  {
171  MsgStream log( msgSvc(), name() + ".sysFinalize()" );
172  log << MSG::FATAL << " Standard std::exception is caught " << endmsg;
174  MsgStream logEx( msgSvc(), name() + "*std::exception*" );
175  logEx << MSG::ERROR << Exception.what() << endmsg;
176  } catch ( ... )
177  {
179  MsgStream log( msgSvc(), name() + ".sysFinalize()" );
180  log << MSG::FATAL << " UNKNOWN Exception is caught " << endmsg;
181  }
183  return StatusCode::FAILURE;
184 }
185 
187 
188 const std::string& Auditor::name() const { return m_name; }
189 
190 bool Auditor::isEnabled() const { return m_isEnabled; }
191 
193 
194 // Use the job options service to set declared properties
196  if ( !m_pSvcLocator ) return StatusCode::FAILURE;
197  auto jos = service<IJobOptionsSvc>( "JobOptionsSvc" );
198  if ( !jos ) return StatusCode::FAILURE;
199 
200  // this initializes the messaging, in case property update handlers need to print
201  // and update the property value bypassing the update handler
202  m_outputLevel.value() = setUpMessaging();
203 
204  return jos->setMyProperties( name(), this );
205 }
StatusCode sysInitialize() override
Initialization method invoked by the framework.
Definition: Auditor.cpp:26
Definition of the MsgStream class used to transmit messages.
Definition: MsgStream.h:34
virtual StatusCode finalize()
Definition: Auditor.cpp:186
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:137
const SmartIF< IMessageSvc > & msgSvc() const
The standard message service.
StatusCode setProperties()
Set the auditor's properties.
Definition: Auditor.cpp:195
virtual const std::string & tag() const
name tag for the exception, or exception type
constexpr static const auto SUCCESS
Definition: StatusCode.h:100
STL namespace.
Auditor(std::string name, ISvcLocator *svcloc)
Constructor.
Definition: Auditor.cpp:22
StatusCode sysFinalize() override
Finalization method invoked by the framework.
Definition: Auditor.cpp:146
SmartIF< ISvcLocator > & serviceLocator() const override
The standard service locator.
Definition: Auditor.cpp:192
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:141
SmartIF< ISvcLocator > m_pSvcLocator
Pointer to service locator service.
Definition: Auditor.h:135
T what(T... args)
void afterExecute(INamedInterface *, const StatusCode &) override
Definition: Auditor.cpp:142
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:61
void beforeReinitialize(INamedInterface *) override
Definition: Auditor.cpp:139
void after(StandardEventType, INamedInterface *, const StatusCode &) override
Definition: Auditor.cpp:108
bool isSuccess() const
Definition: StatusCode.h:365
STL class.
void afterInitialize(INamedInterface *) override
Definition: Auditor.cpp:138
IInterface compliant class extending IInterface with the name() method.
bool isEnabled() const override
Definition: Auditor.cpp:190
const std::string & name() const override
Definition: Auditor.cpp:188
constexpr static const auto FAILURE
Definition: StatusCode.h:101
void afterFinalize(INamedInterface *) override
Definition: Auditor.cpp:144
void beforeFinalize(INamedInterface *) override
Definition: Auditor.cpp:143
virtual StatusCode initialize()
Definition: Auditor.cpp:75
void before(StandardEventType, INamedInterface *) override
The following methods are meant to be implemented by the child class...
Definition: Auditor.cpp:78
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:140
bool m_isFinalized
Auditor has been finalized flag.
Definition: Auditor.h:144