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_isEnabled(true),
16  m_isInitialized(false),
17  m_isFinalized(false)
18 {
19  m_PropertyMgr = new PropertyMgr();
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 // Default Destructor
28  delete m_PropertyMgr;
29 }
30 
31 // IAuditor implementation
33  StatusCode sc;
34 
35  // Bypass the initialization if the auditor is disabled or
36  // has already been initialized.
37  if ( isEnabled( ) && ! m_isInitialized ) {
38 
39  // Setup the default service ... this should be upgraded so as to be configurable.
40  if( m_pSvcLocator == 0 )
41  return StatusCode::FAILURE;
42 
43  // Set up message service
44  m_MS = serviceLocator(); // get default message service
45  if( !m_MS.isValid() ) return StatusCode::FAILURE;
46 
47  // Set the Auditor's properties
48  sc = setProperties();
49  if( !sc.isSuccess() ) return StatusCode::FAILURE;
50 
51  // Check current outputLevel to eventually inform the MessagsSvc
52  if( m_outputLevel != MSG::NIL ) {
54  }
55 
56  {
57  try{
58  // Invoke the initialize() method of the derived class
59  sc = initialize();
60  if( !sc.isSuccess() ) return StatusCode::FAILURE;
61  m_isInitialized = true;
62 
63  return sc;
64  }
65  catch ( const GaudiException& Exception )
66  {
68  MsgStream log ( msgSvc() , name() + ".sysInitialize()" );
69  log << MSG::FATAL << " Exception with tag=" << Exception.tag() << " is catched " << endmsg;
71  MsgStream logEx ( msgSvc() , Exception.tag() );
72  logEx << MSG::ERROR << Exception << endmsg;
73  }
74  catch( const std::exception& Exception )
75  {
77  MsgStream log ( msgSvc() , name() + ".sysInitialize()" );
78  log << MSG::FATAL << " Standard std::exception is catched " << endmsg;
80  MsgStream logEx ( msgSvc() , name() + "*std::exception*" );
81  logEx << MSG::ERROR << Exception.what() << endmsg;
82  }
83  catch(...)
84  {
86  MsgStream log ( msgSvc() , name() + ".sysInitialize()" );
87  log << MSG::FATAL << " UNKNOWN Exception is catched " << endmsg;
88  }
89  }
90  }
92  return StatusCode::FAILURE;
93 }
94 
96  return StatusCode::SUCCESS;
97 }
98 
99 // Implemented for backward compatibility
101  switch (evt) {
102  case Initialize: beforeInitialize(obj); break;
103  case ReInitialize: beforeReinitialize(obj); break;
104  case Execute: beforeExecute(obj); break;
105  case BeginRun: beforeBeginRun(obj); break;
106  case EndRun: beforeEndRun(obj); break;
107  case Finalize: beforeFinalize(obj); break;
108  case Start: break;
109  case Stop: break;
110  case ReStart: break;
111  default: break ;// do nothing
112  }
113 }
114 void Auditor::before(StandardEventType, const std::string&) {}
115 
117 void Auditor::before(CustomEventTypeRef, const std::string&){}
118 
119 // Implemented for backward compatibility
121  switch (evt) {
122  case Initialize: afterInitialize(obj); break;
123  case ReInitialize: afterReinitialize(obj); break;
124  case Execute: afterExecute(obj, sc); break;
125  case BeginRun: afterBeginRun(obj); break;
126  case EndRun: afterEndRun(obj); break;
127  case Finalize: afterFinalize(obj); break;
128  case Start: break;
129  case Stop: break;
130  case ReStart: break;
131  default: break ;// do nothing
132  }
133 }
134 void Auditor::after(StandardEventType, const std::string&, const StatusCode&) {}
135 
137 void Auditor::after(CustomEventTypeRef, const std::string&, const StatusCode&){}
138 
140 
142 
144 
146 
148 
150 
152 
154 
156 
158 
160 
162 
165  try{
166  //
167  // Invoke the finalize() method of the derived class if
168  // it has been initialized.
169  if ( m_isInitialized && ! m_isFinalized ) {
170  m_isFinalized = true;
171  sc = finalize();
172  if( !sc.isSuccess() ) return StatusCode::FAILURE;
173  }
174  return sc;
175  //
176  }
177  catch( const GaudiException& Exception )
178  {
180  MsgStream log ( msgSvc() , name() + ".sysFinalize()" );
181  log << MSG::FATAL
182  << " Exception with tag=" << Exception.tag() << " is catched " << endmsg;
185  MsgStream logEx ( msgSvc() , Exception.tag() );
186  logEx << MSG::ERROR
187  << Exception << endmsg;
188  }
189  catch( const std::exception& Exception )
190  {
192  MsgStream log ( msgSvc() , name() + ".sysFinalize()" );
193  log << MSG::FATAL
194  << " Standard std::exception is caught " << endmsg;
196  MsgStream logEx ( msgSvc() , name() + "*std::exception*" );
197  logEx << MSG::ERROR
198  << Exception.what() << endmsg;
199  }
200  catch( ... )
201  {
203  MsgStream log ( msgSvc() , name() + ".sysFinalize()" );
204  log << MSG::FATAL
205  << " UNKNOWN Exception is caught " << endmsg;
206  }
208  return StatusCode::FAILURE ;
209 }
210 
212  m_MS = 0; // release message service
213  return StatusCode::SUCCESS;
214 }
215 
216 const std::string& Auditor::name() const {
217  return m_name;
218 }
219 
220 bool Auditor::isEnabled( ) const {
221  return m_isEnabled;
222 }
223 
225  return m_MS;
226 }
227 
229  if( m_MS != 0) {
230  m_MS->setOutputLevel( name(), level );
231  }
232 }
233 
235  return m_pSvcLocator;
236 }
237 
238 // Use the job options service to set declared properties
240  if( m_pSvcLocator != 0 ) {
241  IJobOptionsSvc* jos;
242  StatusCode sc = service("JobOptionsSvc", jos);
243  if( sc.isSuccess() ) {
244  jos->setMyProperties( name(), this ).ignore();
245  jos->release();
246  return StatusCode::SUCCESS;
247  }
248  }
249  return StatusCode::FAILURE;
250 }
251 
252 // IProperty implementation
253 // Delegate to the Property manager
255  return m_PropertyMgr->setProperty(p);
256 }
257 StatusCode Auditor::setProperty(const std::string& s) {
258  return m_PropertyMgr->setProperty(s);
259 }
260 StatusCode Auditor::setProperty(const std::string& n, const std::string& v) {
261  return m_PropertyMgr->setProperty(n,v);
262 }
264  return m_PropertyMgr->getProperty(p);
265 }
266 const Property& Auditor::getProperty( const std::string& name) const{
267  return m_PropertyMgr->getProperty(name);
268 }
269 StatusCode Auditor::getProperty(const std::string& n, std::string& v ) const {
270  return m_PropertyMgr->getProperty(n,v);
271 }
272 const std::vector<Property*>& Auditor::getProperties( ) const {
273  return m_PropertyMgr->getProperties();
274 }
275 bool Auditor::hasProperty(const std::string& name) const {
276  return m_PropertyMgr->hasProperty(name);
277 }
Definition of the MsgStream class used to transmit messages.
Definition: MsgStream.h:24
bool m_isEnabled
Auditor is enabled flag.
Definition: Auditor.h:250
StatusCode setProperty(const Property &p)
set the property form another property
virtual StatusCode finalize()
Definition: Auditor.cpp:211
void setOutputLevel(int level)
Set the output level for current auditor.
Definition: Auditor.cpp:228
Define general base for Gaudi exception.
StatusCode service(const std::string &name, T *&svc, bool createIf=false) const
Access a service by name, creating it if it doesn't already exist.
Definition: Auditor.h:119
The ISvcLocator is the interface implemented by the Service Factory in the Application Manager to loc...
Definition: ISvcLocator.h:26
virtual const std::string & name() const
Retrieve the name of the instance.
Definition: Auditor.cpp:216
virtual ~Auditor()
Destructor.
Definition: Auditor.cpp:27
SmartIF< IMessageSvc > & msgSvc() const
The standard message service.
Definition: Auditor.cpp:224
StandardEventType
Defines the standard (= used by the framework) auditable event types.
Definition: IAuditor.h:24
virtual void afterBeginRun(INamedInterface *)
Definition: Auditor.cpp:153
virtual StatusCode setProperty(const Property &p)
Set a value of a property of an auditor.
Definition: Auditor.cpp:254
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244
bool isSuccess() const
Test for a status code of SUCCESS.
Definition: StatusCode.h:75
StatusCode setProperties()
Set the auditor's properties.
Definition: Auditor.cpp:239
SmartIF< IMessageSvc > m_MS
Message service.
Definition: Auditor.h:246
const CustomEventType & CustomEventTypeRef
Used in function calls for optimization purposes.
Definition: IAuditor.h:41
return false
Definition: Bootstrap.cpp:338
Property manager helper class.
Definition: PropertyMgr.h:34
bool hasProperty(const std::string &name) const
Return true if we have a property with the given name.
virtual void afterFinalize(INamedInterface *)
Definition: Auditor.cpp:161
virtual void beforeBeginRun(INamedInterface *)
Definition: Auditor.cpp:151
std::string m_name
Auditor's name for identification.
Definition: Auditor.h:244
virtual void before(StandardEventType, INamedInterface *)
The following methods are meant to be implemented by the child class...
Definition: Auditor.cpp:100
Property * declareProperty(const std::string &name, T &property, const std::string &doc="none") const
Declare the named property.
Definition: Auditor.h:237
bool m_isInitialized
Auditor has been initialized flag.
Definition: Auditor.h:251
Main interface for the JobOptions service.
Auditor(const std::string &name, ISvcLocator *svcloc)
Constructor.
Definition: Auditor.cpp:12
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:30
virtual void beforeExecute(INamedInterface *)
Definition: Auditor.cpp:147
virtual StatusCode setMyProperties(const std::string &client, IProperty *me)=0
Override default properties of the calling client.
virtual bool hasProperty(const std::string &name) const
Implementation of IProperty::hasProperty.
Definition: Auditor.cpp:275
StatusCode getProperty(Property *p) const
get the property
virtual void afterExecute(INamedInterface *, const StatusCode &)
Definition: Auditor.cpp:149
virtual StatusCode getProperty(Property *p) const
Get the value of a property.
Definition: Auditor.cpp:263
virtual const std::string & tag() const
name tag for the exception, or exception type
PropertyMgr * m_PropertyMgr
For management of properties.
Definition: Auditor.h:248
StatusCode sysFinalize()
Finalization method invoked by the framework.
Definition: Auditor.cpp:163
SmartIF< ISvcLocator > & serviceLocator() const
The standard service locator.
Definition: Auditor.cpp:234
virtual void afterReinitialize(INamedInterface *)
Definition: Auditor.cpp:145
const std::vector< Property * > & getProperties() const
get all properties
IInterface compliant class extending IInterface with the name() method.
Property base class allowing Property* collections to be "homogeneous".
Definition: Property.h:43
virtual unsigned long release()=0
Release Interface instance.
virtual void beforeReinitialize(INamedInterface *)
Definition: Auditor.cpp:143
bool isValid() const
Allow for check if smart pointer is valid.
Definition: SmartIF.h:51
StatusCode sysInitialize()
Initialization method invoked by the framework.
Definition: Auditor.cpp:32
virtual void beforeFinalize(INamedInterface *)
Definition: Auditor.cpp:159
const std::vector< Property * > & getProperties() const
Get all properties.
Definition: Auditor.cpp:272
string s
Definition: gaudirun.py:244
virtual void afterInitialize(INamedInterface *)
Definition: Auditor.cpp:141
virtual void beforeEndRun(INamedInterface *)
Definition: Auditor.cpp:155
virtual void beforeInitialize(INamedInterface *)
Definition: Auditor.cpp:139
virtual StatusCode initialize()
Definition: Auditor.cpp:95
void ignore() const
Definition: StatusCode.h:107
virtual void afterEndRun(INamedInterface *)
Definition: Auditor.cpp:157
virtual void setOutputLevel(int new_level)=0
Set new global output level threshold.
virtual void after(StandardEventType, INamedInterface *, const StatusCode &)
Audit the end of a standard "event".
Definition: Auditor.cpp:120
virtual bool isEnabled() const
Tell if the auditor is enabled or not.
Definition: Auditor.cpp:220
int m_outputLevel
Auditor output level.
Definition: Auditor.h:249
SmartIF< ISvcLocator > m_pSvcLocator
Pointer to service locator service.
Definition: Auditor.h:247
bool m_isFinalized
Auditor has been finalized flag.
Definition: Auditor.h:252