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