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