All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
Auditor.cpp
Go to the documentation of this file.
1 #include "GaudiKernel/Kernel.h"
2 #include "GaudiKernel/ISvcLocator.h"
3 #include "GaudiKernel/IMessageSvc.h"
4 #include "GaudiKernel/IJobOptionsSvc.h"
5 
6 #include "GaudiKernel/Auditor.h"
7 
8 #include "GaudiKernel/MsgStream.h"
9 #include "GaudiKernel/GaudiException.h"
10 
11 // Constructor
12 Auditor::Auditor( const std::string& name, ISvcLocator *pSvcLocator )
13 : m_name(name),
14  m_pSvcLocator(pSvcLocator),
15  m_PropertyMgr{ new PropertyMgr() },
16  m_isEnabled(true),
17  m_isInitialized(false),
18  m_isFinalized(false)
19 {
20 
21  // Declare common Auditor properties with their defaults
22  declareProperty( "OutputLevel", m_outputLevel = MSG::NIL);
23  declareProperty( "Enable", m_isEnabled = true);
24 }
25 
26 
27 // IAuditor implementation
29  StatusCode sc;
30 
31  // Bypass the initialization if the auditor is disabled or
32  // has already been initialized.
33  if ( isEnabled( ) && ! m_isInitialized ) {
34 
35  // Setup the default service ... this should be upgraded so as to be configurable.
36  if( !m_pSvcLocator )
37  return StatusCode::FAILURE;
38 
39  // Set up message service
40  m_MS = serviceLocator(); // get default message service
41  if( !m_MS ) return StatusCode::FAILURE;
42 
43  // Set the Auditor's properties
44  sc = setProperties();
45  if( !sc.isSuccess() ) return StatusCode::FAILURE;
46 
47  // Check current outputLevel to eventually inform the MessagsSvc
48  if( m_outputLevel != MSG::NIL ) {
50  }
51 
52  {
53  try{
54  // Invoke the initialize() method of the derived class
55  sc = initialize();
56  if( !sc.isSuccess() ) return StatusCode::FAILURE;
57  m_isInitialized = true;
58 
59  return sc;
60  }
61  catch ( const GaudiException& Exception )
62  {
64  MsgStream log ( msgSvc() , name() + ".sysInitialize()" );
65  log << MSG::FATAL << " Exception with tag=" << Exception.tag() << " is catched " << endmsg;
67  MsgStream logEx ( msgSvc() , Exception.tag() );
68  logEx << MSG::ERROR << Exception << endmsg;
69  }
70  catch( const std::exception& Exception )
71  {
73  MsgStream log ( msgSvc() , name() + ".sysInitialize()" );
74  log << MSG::FATAL << " Standard std::exception is catched " << endmsg;
76  MsgStream logEx ( msgSvc() , name() + "*std::exception*" );
77  logEx << MSG::ERROR << Exception.what() << endmsg;
78  }
79  catch(...)
80  {
82  MsgStream log ( msgSvc() , name() + ".sysInitialize()" );
83  log << MSG::FATAL << " UNKNOWN Exception is catched " << endmsg;
84  }
85  }
86  }
88  return StatusCode::FAILURE;
89 }
90 
92  return StatusCode::SUCCESS;
93 }
94 
95 // Implemented for backward compatibility
96 void Auditor::before(StandardEventType evt, INamedInterface* obj){
97  switch (evt) {
98  case Initialize: beforeInitialize(obj); break;
99  case ReInitialize: beforeReinitialize(obj); break;
100  case Execute: beforeExecute(obj); break;
101  case BeginRun: beforeBeginRun(obj); break;
102  case EndRun: beforeEndRun(obj); break;
103  case Finalize: beforeFinalize(obj); break;
104  case Start: break;
105  case Stop: break;
106  case ReStart: break;
107  default: break ;// do nothing
108  }
109 }
110 void Auditor::before(StandardEventType, const std::string&) {}
111 
112 void Auditor::before(CustomEventTypeRef, INamedInterface*){}
113 void Auditor::before(CustomEventTypeRef, const std::string&){}
114 
115 // Implemented for backward compatibility
116 void Auditor::after(StandardEventType evt, INamedInterface* obj, const StatusCode& sc){
117  switch (evt) {
118  case Initialize: afterInitialize(obj); break;
119  case ReInitialize: afterReinitialize(obj); break;
120  case Execute: afterExecute(obj, sc); break;
121  case BeginRun: afterBeginRun(obj); break;
122  case EndRun: afterEndRun(obj); break;
123  case Finalize: afterFinalize(obj); break;
124  case Start: break;
125  case Stop: break;
126  case ReStart: break;
127  default: break ;// do nothing
128  }
129 }
130 void Auditor::after(StandardEventType, const std::string&, const StatusCode&) {}
131 
132 void Auditor::after(CustomEventTypeRef, INamedInterface*, const StatusCode&){}
133 void Auditor::after(CustomEventTypeRef, const std::string&, const StatusCode&){}
134 
136 
138 
140 
142 
144 
146 
148 
150 
152 
154 
156 
158 
161  try{
162  //
163  // Invoke the finalize() method of the derived class if
164  // it has been initialized.
165  if ( m_isInitialized && ! m_isFinalized ) {
166  m_isFinalized = true;
167  sc = finalize();
168  if( !sc.isSuccess() ) return StatusCode::FAILURE;
169  }
170  return sc;
171  //
172  }
173  catch( const GaudiException& Exception )
174  {
176  MsgStream log ( msgSvc() , name() + ".sysFinalize()" );
177  log << MSG::FATAL
178  << " Exception with tag=" << Exception.tag() << " is catched " << endmsg;
181  MsgStream logEx ( msgSvc() , Exception.tag() );
182  logEx << MSG::ERROR
183  << Exception << endmsg;
184  }
185  catch( const std::exception& Exception )
186  {
188  MsgStream log ( msgSvc() , name() + ".sysFinalize()" );
189  log << MSG::FATAL
190  << " Standard std::exception is caught " << endmsg;
192  MsgStream logEx ( msgSvc() , name() + "*std::exception*" );
193  logEx << MSG::ERROR
194  << Exception.what() << endmsg;
195  }
196  catch( ... )
197  {
199  MsgStream log ( msgSvc() , name() + ".sysFinalize()" );
200  log << MSG::FATAL
201  << " UNKNOWN Exception is caught " << endmsg;
202  }
204  return StatusCode::FAILURE ;
205 }
206 
208  m_MS.reset();// release message service
209  return StatusCode::SUCCESS;
210 }
211 
212 const std::string& Auditor::name() const {
213  return m_name;
214 }
215 
216 bool Auditor::isEnabled( ) const {
217  return m_isEnabled;
218 }
219 
221  return m_MS;
222 }
223 
225  if( m_MS ) m_MS->setOutputLevel( name(), level );
226 }
227 
229  return m_pSvcLocator;
230 }
231 
232 // Use the job options service to set declared properties
234  if( m_pSvcLocator ) {
235  auto jos = service<IJobOptionsSvc>("JobOptionsSvc");
236  if( jos ) {
237  jos->setMyProperties( name(), this ).ignore();
238  return StatusCode::SUCCESS;
239  }
240  }
241  return StatusCode::FAILURE;
242 }
243 
244 // IProperty implementation
245 // Delegate to the Property manager
247  return m_PropertyMgr->setProperty(p);
248 }
249 StatusCode Auditor::setProperty(const std::string& s) {
250  return m_PropertyMgr->setProperty(s);
251 }
252 StatusCode Auditor::setProperty(const std::string& n, const std::string& v) {
253  return m_PropertyMgr->setProperty(n,v);
254 }
256  return m_PropertyMgr->getProperty(p);
257 }
258 const Property& Auditor::getProperty( const std::string& name) const{
259  return m_PropertyMgr->getProperty(name);
260 }
261 StatusCode Auditor::getProperty(const std::string& n, std::string& v ) const {
262  return m_PropertyMgr->getProperty(n,v);
263 }
264 const std::vector<Property*>& Auditor::getProperties( ) const {
265  return m_PropertyMgr->getProperties();
266 }
267 bool Auditor::hasProperty(const std::string& name) const {
268  return m_PropertyMgr->hasProperty(name);
269 }
StatusCode sysInitialize() override
Initialization method invoked by the framework.
Definition: Auditor.cpp:28
Definition of the MsgStream class used to transmit messages.
Definition: MsgStream.h:24
bool m_isEnabled
Auditor is enabled flag.
Definition: Auditor.h:254
virtual StatusCode finalize()
Definition: Auditor.cpp:207
void setOutputLevel(int level)
Set the output level for current auditor.
Definition: Auditor.cpp:224
bool hasProperty(const std::string &name) const override
Implementation of IProperty::hasProperty.
Definition: Auditor.cpp:267
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:135
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244
SmartIF< IMessageSvc > & msgSvc() const
The standard message service.
Definition: Auditor.cpp:220
StatusCode getProperty(Property *p) const override
Get the value of a property.
Definition: Auditor.cpp:255
StatusCode setProperty(const Property &p) override
set the property form another property
bool isSuccess() const
Test for a status code of SUCCESS.
Definition: StatusCode.h:76
StatusCode setProperties()
Set the auditor's properties.
Definition: Auditor.cpp:233
void beforeBeginRun(INamedInterface *) override
Definition: Auditor.cpp:147
SmartIF< IMessageSvc > m_MS
Message service.
Definition: Auditor.h:250
StatusCode sysFinalize() override
Finalization method invoked by the framework.
Definition: Auditor.cpp:159
void afterEndRun(INamedInterface *) override
Definition: Auditor.cpp:153
Property manager helper class.
Definition: PropertyMgr.h:35
std::string m_name
Auditor's name for identification.
Definition: Auditor.h:248
StatusCode getProperty(Property *p) const override
get the property
void afterBeginRun(INamedInterface *) override
Definition: Auditor.cpp:149
bool m_isInitialized
Auditor has been initialized flag.
Definition: Auditor.h:255
void beforeExecute(INamedInterface *) override
Definition: Auditor.cpp:143
Auditor(const std::string &name, ISvcLocator *svcloc)
Constructor.
Definition: Auditor.cpp:12
SmartIF< PropertyMgr > m_PropertyMgr
For management of properties.
Definition: Auditor.h:252
void afterExecute(INamedInterface *, const StatusCode &) override
Definition: Auditor.cpp:145
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:26
void beforeReinitialize(INamedInterface *) override
Definition: Auditor.cpp:139
const std::vector< Property * > & getProperties() const override
get all properties
void after(StandardEventType, INamedInterface *, const StatusCode &) override
Definition: Auditor.cpp:116
virtual const std::string & tag() const
name tag for the exception, or exception type
const std::vector< Property * > & getProperties() const override
Get all properties.
Definition: Auditor.cpp:264
SmartIF< ISvcLocator > & serviceLocator() const
The standard service locator.
Definition: Auditor.cpp:228
void afterInitialize(INamedInterface *) override
Definition: Auditor.cpp:137
StatusCode setProperty(const Property &p) override
Set a value of a property of an auditor.
Definition: Auditor.cpp:246
IInterface compliant class extending IInterface with the name() method.
Property base class allowing Property* collections to be "homogeneous".
Definition: Property.h:38
bool isEnabled() const override
Definition: Auditor.cpp:216
const std::string & name() const override
Definition: Auditor.cpp:212
string s
Definition: gaudirun.py:245
bool hasProperty(const std::string &name) const override
Return true if we have a property with the given name.
void afterFinalize(INamedInterface *) override
Definition: Auditor.cpp:157
void beforeFinalize(INamedInterface *) override
Definition: Auditor.cpp:155
void reset(TYPE *ptr=nullptr)
Set the internal pointer to the passed one disposing of the old one.
Definition: SmartIF.h:88
virtual StatusCode initialize()
Definition: Auditor.cpp:91
void ignore() const
Definition: StatusCode.h:108
void before(StandardEventType, INamedInterface *) override
The following methods are meant to be implemented by the child class...
Definition: Auditor.cpp:96
void beforeEndRun(INamedInterface *) override
Definition: Auditor.cpp:151
virtual void setOutputLevel(int new_level)=0
Set new global output level threshold.
int m_outputLevel
Auditor output level.
Definition: Auditor.h:253
void afterReinitialize(INamedInterface *) override
Definition: Auditor.cpp:141
SmartIF< ISvcLocator > m_pSvcLocator
Pointer to service locator service.
Definition: Auditor.h:251
bool m_isFinalized
Auditor has been finalized flag.
Definition: Auditor.h:256