The Gaudi Framework  v30r4 (9b837755)
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 {
17  StatusCode sc;
18 
19  // Bypass the initialization if the auditor is disabled or
20  // has already been initialized.
21  if ( isEnabled() && !m_isInitialized ) {
22 
23  // Setup the default service ... this should be upgraded so as to be configurable.
24  if ( !m_pSvcLocator ) return StatusCode::FAILURE;
25 
26  // Set the Auditor's properties
27  sc = setProperties();
28  if ( !sc.isSuccess() ) return StatusCode::FAILURE;
29 
30  {
31  try {
32  // Invoke the initialize() method of the derived class
33  sc = initialize();
34  if ( !sc.isSuccess() ) return StatusCode::FAILURE;
35  m_isInitialized = true;
36 
37  return sc;
38  } catch ( const GaudiException& Exception )
39  {
41  MsgStream log( msgSvc(), name() + ".sysInitialize()" );
42  log << MSG::FATAL << " Exception with tag=" << Exception.tag() << " is caught " << endmsg;
44  MsgStream logEx( msgSvc(), Exception.tag() );
45  logEx << MSG::ERROR << Exception << endmsg;
46  } catch ( const std::exception& Exception )
47  {
49  MsgStream log( msgSvc(), name() + ".sysInitialize()" );
50  log << MSG::FATAL << " Standard std::exception is caught " << endmsg;
52  MsgStream logEx( msgSvc(), name() + "*std::exception*" );
53  logEx << MSG::ERROR << Exception.what() << endmsg;
54  } catch ( ... ) {
56  MsgStream log( msgSvc(), name() + ".sysInitialize()" );
57  log << MSG::FATAL << " UNKNOWN Exception is caught " << endmsg;
58  }
59  }
60  }
62  return StatusCode::FAILURE;
63 }
64 
66 
67 // Implemented for backward compatibility
68 void Auditor::before( StandardEventType evt, INamedInterface* obj )
69 {
70  switch ( evt ) {
71  case Initialize:
72  beforeInitialize( obj );
73  break;
74  case ReInitialize:
75  beforeReinitialize( obj );
76  break;
77  case Execute:
78  beforeExecute( obj );
79  break;
80  case BeginRun:
81  beforeBeginRun( obj );
82  break;
83  case EndRun:
84  beforeEndRun( obj );
85  break;
86  case Finalize:
87  beforeFinalize( obj );
88  break;
89  case Start:
90  break;
91  case Stop:
92  break;
93  case ReStart:
94  break;
95  default:
96  break; // do nothing
97  }
98 }
99 void Auditor::before( StandardEventType, const std::string& ) {}
100 
101 void Auditor::before( CustomEventTypeRef, INamedInterface* ) {}
102 void Auditor::before( CustomEventTypeRef, const std::string& ) {}
103 
104 // Implemented for backward compatibility
105 void Auditor::after( StandardEventType evt, INamedInterface* obj, const StatusCode& sc )
106 {
107  switch ( evt ) {
108  case Initialize:
109  afterInitialize( obj );
110  break;
111  case ReInitialize:
112  afterReinitialize( obj );
113  break;
114  case Execute:
115  afterExecute( obj, sc );
116  break;
117  case BeginRun:
118  afterBeginRun( obj );
119  break;
120  case EndRun:
121  afterEndRun( obj );
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 
153 
155 {
157  try {
158  //
159  // Invoke the finalize() method of the derived class if
160  // it has been initialized.
161  if ( m_isInitialized && !m_isFinalized ) {
162  m_isFinalized = true;
163  sc = finalize();
164  if ( !sc.isSuccess() ) return StatusCode::FAILURE;
165  }
166  return sc;
167  //
168  } catch ( const GaudiException& Exception )
169  {
171  MsgStream log( msgSvc(), name() + ".sysFinalize()" );
172  log << MSG::FATAL << " Exception with tag=" << Exception.tag() << " is catched " << endmsg;
175  MsgStream logEx( msgSvc(), Exception.tag() );
176  logEx << MSG::ERROR << Exception << endmsg;
177  } catch ( const std::exception& Exception )
178  {
180  MsgStream log( msgSvc(), name() + ".sysFinalize()" );
181  log << MSG::FATAL << " Standard std::exception is caught " << endmsg;
183  MsgStream logEx( msgSvc(), name() + "*std::exception*" );
184  logEx << MSG::ERROR << Exception.what() << endmsg;
185  } catch ( ... )
186  {
188  MsgStream log( msgSvc(), name() + ".sysFinalize()" );
189  log << MSG::FATAL << " UNKNOWN Exception is caught " << endmsg;
190  }
192  return StatusCode::FAILURE;
193 }
194 
196 
197 const std::string& Auditor::name() const { return m_name; }
198 
199 bool Auditor::isEnabled() const { return m_isEnabled; }
200 
202 
203 // Use the job options service to set declared properties
205 {
206  if ( !m_pSvcLocator ) return StatusCode::FAILURE;
207  auto jos = service<IJobOptionsSvc>( "JobOptionsSvc" );
208  if ( !jos ) return StatusCode::FAILURE;
209 
210  // this initializes the messaging, in case property update handlers need to print
211  // and update the property value bypassing the update handler
212  m_outputLevel.value() = setUpMessaging();
213 
214  return jos->setMyProperties( name(), this );
215 }
StatusCode sysInitialize() override
Initialization method invoked by the framework.
Definition: Auditor.cpp:15
bool isEnabled() const override
Definition: Auditor.cpp:199
constexpr static const auto FAILURE
Definition: StatusCode.h:88
Definition of the MsgStream class used to transmit messages.
Definition: MsgStream.h:24
virtual StatusCode finalize()
Definition: Auditor.cpp:195
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:141
bool isSuccess() const
Definition: StatusCode.h:287
StatusCode setProperties()
Set the auditor&#39;s properties.
Definition: Auditor.cpp:204
void beforeBeginRun(INamedInterface *) override
Definition: Auditor.cpp:147
StatusCode sysFinalize() override
Finalization method invoked by the framework.
Definition: Auditor.cpp:154
void afterEndRun(INamedInterface *) override
Definition: Auditor.cpp:150
std::string m_name
Auditor&#39;s name for identification.
Definition: Auditor.h:133
STL class.
Gaudi::Property< bool > m_isEnabled
Definition: Auditor.h:141
void afterBeginRun(INamedInterface *) override
Definition: Auditor.cpp:148
bool m_isInitialized
Auditor has been initialized flag.
Definition: Auditor.h:143
void beforeExecute(INamedInterface *) override
Definition: Auditor.cpp:145
SmartIF< ISvcLocator > m_pSvcLocator
Pointer to service locator service.
Definition: Auditor.h:135
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:146
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:51
SmartIF< ISvcLocator > & serviceLocator() const override
The standard service locator.
Definition: Auditor.cpp:201
MSG::Level setUpMessaging() const
Set up local caches.
void beforeReinitialize(INamedInterface *) override
Definition: Auditor.cpp:143
void after(StandardEventType, INamedInterface *, const StatusCode &) override
Definition: Auditor.cpp:105
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.
constexpr static const auto SUCCESS
Definition: StatusCode.h:87
void afterInitialize(INamedInterface *) override
Definition: Auditor.cpp:142
IInterface compliant class extending IInterface with the name() method.
void afterFinalize(INamedInterface *) override
Definition: Auditor.cpp:152
void beforeFinalize(INamedInterface *) override
Definition: Auditor.cpp:151
virtual StatusCode initialize()
Definition: Auditor.cpp:65
void before(StandardEventType, INamedInterface *) override
The following methods are meant to be implemented by the child class...
Definition: Auditor.cpp:68
Gaudi::Property< int > m_outputLevel
Definition: Auditor.h:137
void beforeEndRun(INamedInterface *) override
Definition: Auditor.cpp:149
const std::string & name() const override
Definition: Auditor.cpp:197
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:209
evt
Definition: IOTest.py:96
void afterReinitialize(INamedInterface *) override
Definition: Auditor.cpp:144
bool m_isFinalized
Auditor has been finalized flag.
Definition: Auditor.h:144