Loading [MathJax]/extensions/tex2jax.js
The Gaudi Framework  v31r0 (aeb156f0)
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
Auditor.cpp
Go to the documentation of this file.
4 #include "GaudiKernel/Kernel.h"
5 
6 #include "GaudiKernel/Auditor.h"
7 
10 
11 // Constructor
12 Auditor::Auditor( const std::string& name, ISvcLocator* pSvcLocator ) : m_name( name ), m_pSvcLocator( pSvcLocator ) {}
13 
14 // IAuditor implementation
16  StatusCode sc;
17 
18  // Bypass the initialization if the auditor is disabled or
19  // has already been initialized.
20  if ( isEnabled() && !m_isInitialized ) {
21 
22  // Setup the default service ... this should be upgraded so as to be configurable.
23  if ( !m_pSvcLocator ) return StatusCode::FAILURE;
24 
25  // Set the Auditor's properties
26  sc = setProperties();
27  if ( !sc.isSuccess() ) return StatusCode::FAILURE;
28 
29  {
30  try {
31  // Invoke the initialize() method of the derived class
32  sc = initialize();
33  if ( !sc.isSuccess() ) return StatusCode::FAILURE;
34  m_isInitialized = true;
35 
36  return sc;
37  } catch ( const GaudiException& Exception )
38  {
40  MsgStream log( msgSvc(), name() + ".sysInitialize()" );
41  log << MSG::FATAL << " Exception with tag=" << Exception.tag() << " is caught " << endmsg;
43  MsgStream logEx( msgSvc(), Exception.tag() );
44  logEx << MSG::ERROR << Exception << endmsg;
45  } catch ( const std::exception& Exception )
46  {
48  MsgStream log( msgSvc(), name() + ".sysInitialize()" );
49  log << MSG::FATAL << " Standard std::exception is caught " << endmsg;
51  MsgStream logEx( msgSvc(), name() + "*std::exception*" );
52  logEx << MSG::ERROR << Exception.what() << endmsg;
53  } catch ( ... ) {
55  MsgStream log( msgSvc(), name() + ".sysInitialize()" );
56  log << MSG::FATAL << " UNKNOWN Exception is caught " << endmsg;
57  }
58  }
59  }
61  return StatusCode::FAILURE;
62 }
63 
65 
66 // Implemented for backward compatibility
67 void Auditor::before( StandardEventType evt, INamedInterface* obj ) {
68  switch ( evt ) {
69  case Initialize:
70  beforeInitialize( obj );
71  break;
72  case ReInitialize:
73  beforeReinitialize( obj );
74  break;
75  case Execute:
76  beforeExecute( obj );
77  break;
78  case BeginRun:
79  beforeBeginRun( obj );
80  break;
81  case EndRun:
82  beforeEndRun( obj );
83  break;
84  case Finalize:
85  beforeFinalize( obj );
86  break;
87  case Start:
88  break;
89  case Stop:
90  break;
91  case ReStart:
92  break;
93  default:
94  break; // do nothing
95  }
96 }
97 void Auditor::before( StandardEventType, const std::string& ) {}
98 
99 void Auditor::before( CustomEventTypeRef, INamedInterface* ) {}
100 void Auditor::before( CustomEventTypeRef, const std::string& ) {}
101 
102 // Implemented for backward compatibility
103 void Auditor::after( StandardEventType evt, INamedInterface* obj, const StatusCode& sc ) {
104  switch ( evt ) {
105  case Initialize:
106  afterInitialize( obj );
107  break;
108  case ReInitialize:
109  afterReinitialize( obj );
110  break;
111  case Execute:
112  afterExecute( obj, sc );
113  break;
114  case BeginRun:
115  afterBeginRun( obj );
116  break;
117  case EndRun:
118  afterEndRun( obj );
119  break;
120  case Finalize:
121  afterFinalize( obj );
122  break;
123  case Start:
124  break;
125  case Stop:
126  break;
127  case ReStart:
128  break;
129  default:
130  break; // do nothing
131  }
132 }
133 void Auditor::after( StandardEventType, const std::string&, const StatusCode& ) {}
134 
135 void Auditor::after( CustomEventTypeRef, INamedInterface*, const StatusCode& ) {}
136 void Auditor::after( CustomEventTypeRef, const std::string&, const StatusCode& ) {}
137 
150 
153  try {
154  //
155  // Invoke the finalize() method of the derived class if
156  // it has been initialized.
157  if ( m_isInitialized && !m_isFinalized ) {
158  m_isFinalized = true;
159  sc = finalize();
160  if ( !sc.isSuccess() ) return StatusCode::FAILURE;
161  }
162  return sc;
163  //
164  } catch ( const GaudiException& Exception )
165  {
167  MsgStream log( msgSvc(), name() + ".sysFinalize()" );
168  log << MSG::FATAL << " Exception with tag=" << Exception.tag() << " is catched " << endmsg;
171  MsgStream logEx( msgSvc(), Exception.tag() );
172  logEx << MSG::ERROR << Exception << endmsg;
173  } catch ( const std::exception& Exception )
174  {
176  MsgStream log( msgSvc(), name() + ".sysFinalize()" );
177  log << MSG::FATAL << " Standard std::exception is caught " << endmsg;
179  MsgStream logEx( msgSvc(), name() + "*std::exception*" );
180  logEx << MSG::ERROR << Exception.what() << endmsg;
181  } catch ( ... )
182  {
184  MsgStream log( msgSvc(), name() + ".sysFinalize()" );
185  log << MSG::FATAL << " UNKNOWN Exception is caught " << endmsg;
186  }
188  return StatusCode::FAILURE;
189 }
190 
192 
193 const std::string& Auditor::name() const { return m_name; }
194 
195 bool Auditor::isEnabled() const { return m_isEnabled; }
196 
198 
199 // Use the job options service to set declared properties
201  if ( !m_pSvcLocator ) return StatusCode::FAILURE;
202  auto jos = service<IJobOptionsSvc>( "JobOptionsSvc" );
203  if ( !jos ) return StatusCode::FAILURE;
204 
205  // this initializes the messaging, in case property update handlers need to print
206  // and update the property value bypassing the update handler
207  m_outputLevel.value() = setUpMessaging();
208 
209  return jos->setMyProperties( name(), this );
210 }
StatusCode sysInitialize() override
Initialization method invoked by the framework.
Definition: Auditor.cpp:15
bool isEnabled() const override
Definition: Auditor.cpp:195
Definition of the MsgStream class used to transmit messages.
Definition: MsgStream.h:24
virtual StatusCode finalize()
Definition: Auditor.cpp:191
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:25
void beforeInitialize(INamedInterface *) override
Definition: Auditor.cpp:138
bool isSuccess() const
Definition: StatusCode.h:267
StatusCode setProperties()
Set the auditor&#39;s properties.
Definition: Auditor.cpp:200
void beforeBeginRun(INamedInterface *) override
Definition: Auditor.cpp:144
constexpr static const auto SUCCESS
Definition: StatusCode.h:85
StatusCode sysFinalize() override
Finalization method invoked by the framework.
Definition: Auditor.cpp:151
void afterEndRun(INamedInterface *) override
Definition: Auditor.cpp:147
std::string m_name
Auditor&#39;s name for identification.
Definition: Auditor.h:129
STL class.
Gaudi::Property< bool > m_isEnabled
Definition: Auditor.h:137
void afterBeginRun(INamedInterface *) override
Definition: Auditor.cpp:145
bool m_isInitialized
Auditor has been initialized flag.
Definition: Auditor.h:139
void beforeExecute(INamedInterface *) override
Definition: Auditor.cpp:142
SmartIF< ISvcLocator > m_pSvcLocator
Pointer to service locator service.
Definition: Auditor.h:131
Auditor(const std::string &name, ISvcLocator *svcloc)
Constructor.
Definition: Auditor.cpp:12
T what(T...args)
void afterExecute(INamedInterface *, const StatusCode &) override
Definition: Auditor.cpp:143
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:50
SmartIF< ISvcLocator > & serviceLocator() const override
The standard service locator.
Definition: Auditor.cpp:197
MSG::Level setUpMessaging() const
Set up local caches.
void beforeReinitialize(INamedInterface *) override
Definition: Auditor.cpp:140
void after(StandardEventType, INamedInterface *, const StatusCode &) override
Definition: Auditor.cpp:103
virtual const std::string & tag() const
name tag for the exception, or exception type
const SmartIF< IMessageSvc > & msgSvc() const
The standard message service.
STL class.
void afterInitialize(INamedInterface *) override
Definition: Auditor.cpp:139
IInterface compliant class extending IInterface with the name() method.
constexpr static const auto FAILURE
Definition: StatusCode.h:86
void afterFinalize(INamedInterface *) override
Definition: Auditor.cpp:149
void beforeFinalize(INamedInterface *) override
Definition: Auditor.cpp:148
virtual StatusCode initialize()
Definition: Auditor.cpp:64
void before(StandardEventType, INamedInterface *) override
The following methods are meant to be implemented by the child class...
Definition: Auditor.cpp:67
Gaudi::Property< int > m_outputLevel
Definition: Auditor.h:133
void beforeEndRun(INamedInterface *) override
Definition: Auditor.cpp:146
const std::string & name() const override
Definition: Auditor.cpp:193
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:192
evt
Definition: IOTest.py:94
void afterReinitialize(INamedInterface *) override
Definition: Auditor.cpp:141
bool m_isFinalized
Auditor has been finalized flag.
Definition: Auditor.h:140