| # Gaudi Framework, version v21r11 |

Home |  | Generated: 30 Sep 2010

# Auditor.cpp

Go to the documentation of this file.

    00001 // $Id: Auditor.cpp,v 1.20 2008/10/27 19:22:21 marcocle Exp $
    00002
    00003 #include "GaudiKernel/Kernel.h"
    00004 #include "GaudiKernel/ISvcLocator.h"
    00005 #include "GaudiKernel/IMessageSvc.h"
    00006 #include "GaudiKernel/IJobOptionsSvc.h"
    00007
    00008 #include "GaudiKernel/Auditor.h"
    00009
    00010 #include "GaudiKernel/MsgStream.h"
    00011 #include "GaudiKernel/GaudiException.h"
    00012
    00013 // Constructor
    00014 Auditor::Auditor( const std::string& name, ISvcLocator *pSvcLocator )
    00015 : m_name(name),
    00016   m_pSvcLocator(pSvcLocator),
    00017   m_isEnabled(true),
    00018   m_isInitialized(false),
    00019   m_isFinalized(false)
    00020 {
    00021   m_PropertyMgr = new PropertyMgr();
    00022
    00023   // Declare common Auditor properties with their defaults
    00024   declareProperty( "OutputLevel", m_outputLevel = MSG::NIL);
    00025   declareProperty( "Enable", m_isEnabled = true);
    00026 }
    00027
    00028 // Default Destructor
    00029 Auditor::~Auditor() {
    00030   delete m_PropertyMgr;
    00031 }
    00032
    00033 // IAuditor implementation
    00034 StatusCode Auditor::sysInitialize() {
    00035   StatusCode sc;
    00036
    00037   // Bypass the initialization if the auditor is disabled or
    00038   // has already been initialized.
    00039   if ( isEnabled( ) && ! m_isInitialized ) {
    00040
    00041     // Setup the default service ... this should be upgraded so as to be configurable.
    00042     if( m_pSvcLocator == 0 )
    00043       return StatusCode::FAILURE;
    00044
    00045     // Set up message service
    00046     m_MS = serviceLocator(); // get default message service
    00047     if( !m_MS.isValid() )  return StatusCode::FAILURE;
    00048
    00049     // Set the Auditor's properties
    00050     sc = setProperties();
    00051     if( !sc.isSuccess() )  return StatusCode::FAILURE;
    00052
    00053     // Check current outputLevel to eventually inform the MessagsSvc
    00054     if( m_outputLevel != MSG::NIL ) {
    00055       setOutputLevel( m_outputLevel );
    00056     }
    00057
    00058     {
    00059       try{
    00060         // Invoke the initialize() method of the derived class
    00061         sc = initialize();
    00062         if( !sc.isSuccess() )  return StatusCode::FAILURE;
    00063         m_isInitialized = true;
    00064
    00065         return sc;
    00066       }
    00067       catch ( const GaudiException& Exception )
    00068         {
    00070           MsgStream log ( msgSvc() , name() + ".sysInitialize()" );
    00071           log << MSG::FATAL << " Exception with tag=" << Exception.tag() << " is catched " << endmsg;
    00073           MsgStream logEx ( msgSvc() , Exception.tag() );
    00074           logEx << MSG::ERROR << Exception  << endmsg;
    00075         }
    00076       catch( const std::exception& Exception )
    00077         {
    00079           MsgStream log ( msgSvc() , name() + ".sysInitialize()" );
    00080           log << MSG::FATAL << " Standard std::exception is catched " << endmsg;
    00082           MsgStream logEx ( msgSvc() , name() + "*std::exception*" );
    00083           logEx << MSG::ERROR << Exception.what()  << endmsg;
    00084         }
    00085       catch(...)
    00086         {
    00088           MsgStream log ( msgSvc() , name() + ".sysInitialize()" );
    00089           log << MSG::FATAL << " UNKNOWN Exception is  catched " << endmsg;
    00090         }
    00091     }
    00092   }
    00094   return StatusCode::FAILURE;
    00095 }
    00096
    00097 StatusCode Auditor::initialize() {
    00098   return StatusCode::SUCCESS;
    00099 }
    00100
    00101 // Implemented for backward compatibility
    00102 void Auditor::before(StandardEventType evt, INamedInterface* obj){
    00103   switch (evt) {
    00104   case Initialize:   beforeInitialize(obj);   break;
    00105   case ReInitialize: beforeReinitialize(obj); break;
    00106   case Execute:      beforeExecute(obj);      break;
    00107   case BeginRun:     beforeBeginRun(obj);     break;
    00108   case EndRun:       beforeEndRun(obj);       break;
    00109   case Finalize:     beforeFinalize(obj);     break;
    00110   case Start:        break;
    00111   case Stop:         break;
    00112   case ReStart:      break;
    00113   default: ;// do nothing
    00114   }
    00115 }
    00116 void Auditor::before(StandardEventType, const std::string&) {}
    00117
    00118 void Auditor::before(CustomEventTypeRef, INamedInterface*){}
    00119 void Auditor::before(CustomEventTypeRef, const std::string&){}
    00120
    00121 // Implemented for backward compatibility
    00122 void Auditor::after(StandardEventType evt, INamedInterface* obj, const StatusCode& sc){
    00123   switch (evt) {
    00124   case Initialize:   afterInitialize(obj);   break;
    00125   case ReInitialize: afterReinitialize(obj); break;
    00126   case Execute:      afterExecute(obj, sc);  break;
    00127   case BeginRun:     afterBeginRun(obj);     break;
    00128   case EndRun:       afterEndRun(obj);       break;
    00129   case Finalize:     afterFinalize(obj);     break;
    00130   case Start:        break;
    00131   case Stop:         break;
    00132   case ReStart:      break;
    00133   default: ;// do nothing
    00134   }
    00135 }
    00136 void Auditor::after(StandardEventType, const std::string&, const StatusCode&) {}
    00137
    00138 void Auditor::after(CustomEventTypeRef, INamedInterface*, const StatusCode&){}
    00139 void Auditor::after(CustomEventTypeRef, const std::string&, const StatusCode&){}
    00140
    00141 void Auditor::beforeInitialize(INamedInterface* ) {}
    00142
    00143 void Auditor::afterInitialize(INamedInterface* ) {}
    00144
    00145 void Auditor::beforeReinitialize(INamedInterface* ) {}
    00146
    00147 void Auditor::afterReinitialize(INamedInterface* ) {}
    00148
    00149 void Auditor::beforeExecute(INamedInterface* ) {}
    00150
    00151 void Auditor::afterExecute(INamedInterface*, const StatusCode& ) {}
    00152
    00153 void Auditor::beforeBeginRun(INamedInterface* ) {}
    00154
    00155 void Auditor::afterBeginRun(INamedInterface* ) {}
    00156
    00157 void Auditor::beforeEndRun(INamedInterface* ) {}
    00158
    00159 void Auditor::afterEndRun(INamedInterface* ) {}
    00160
    00161 void Auditor::beforeFinalize(INamedInterface* ) {}
    00162
    00163 void Auditor::afterFinalize(INamedInterface* ) {}
    00164
    00165 StatusCode Auditor::sysFinalize() {
    00166   StatusCode sc = StatusCode::SUCCESS;
    00167   try{
    00168     //
    00169     // Invoke the finalize() method of the derived class if
    00170     // it has been initialized.
    00171     if ( m_isInitialized && ! m_isFinalized ) {
    00172       m_isFinalized = true;
    00173       sc = finalize();
    00174       if( !sc.isSuccess() )  return StatusCode::FAILURE;
    00175     }
    00176     return sc;
    00177     //
    00178   }
    00179   catch( const GaudiException& Exception )
    00180     {
    00182       MsgStream log ( msgSvc() , name() + ".sysFinalize()" );
    00183       log << MSG::FATAL
    00184           << " Exception with tag=" << Exception.tag() << " is catched " << endmsg;
    00187       MsgStream logEx ( msgSvc() , Exception.tag() );
    00188       logEx << MSG::ERROR
    00189             << Exception  << endmsg;
    00190     }
    00191   catch( const std::exception& Exception )
    00192     {
    00194       MsgStream log ( msgSvc() , name() + ".sysFinalize()" );
    00195       log << MSG::FATAL
    00196           << " Standard std::exception is caught " << endmsg;
    00198       MsgStream logEx ( msgSvc() , name() + "*std::exception*" );
    00199       logEx << MSG::ERROR
    00200             << Exception.what()  << endmsg;
    00201     }
    00202   catch( ... )
    00203     {
    00205       MsgStream log ( msgSvc() , name() + ".sysFinalize()" );
    00206       log << MSG::FATAL
    00207           << " UNKNOWN Exception is caught " << endmsg;
    00208     }
    00210   return StatusCode::FAILURE ;
    00211 }
    00212
    00213 StatusCode Auditor::finalize() {
    00214   m_MS = 0; // release message service
    00215   return StatusCode::SUCCESS;
    00216 }
    00217
    00218 const std::string& Auditor::name() const {
    00219   return m_name;
    00220 }
    00221
    00222 bool Auditor::isEnabled( ) const {
    00223   return m_isEnabled;
    00224 }
    00225
    00226 SmartIF<IMessageSvc>& Auditor::msgSvc() const {
    00227   return m_MS;
    00228 }
    00229
    00230 void Auditor::setOutputLevel( int level ) {
    00231   if( m_MS != 0) {
    00232     m_MS->setOutputLevel( name(), level );
    00233   }
    00234 }
    00235
    00236 SmartIF<ISvcLocator>& Auditor::serviceLocator() const {
    00237   return m_pSvcLocator;
    00238 }
    00239
    00240 // Use the job options service to set declared properties
    00241 StatusCode Auditor::setProperties() {
    00242   if( m_pSvcLocator != 0 )    {
    00243     IJobOptionsSvc* jos;
    00244     StatusCode sc = service("JobOptionsSvc", jos);
    00245     if( sc.isSuccess() )    {
    00246       jos->setMyProperties( name(), this ).ignore();
    00247       jos->release();
    00248       return StatusCode::SUCCESS;
    00249     }
    00250   }
    00251   return StatusCode::FAILURE;
    00252 }
    00253
    00254 // IProperty implementation
    00255 // Delegate to the Property manager
    00256 StatusCode Auditor::setProperty(const Property& p) {
    00257   return m_PropertyMgr->setProperty(p);
    00258 }
    00259 StatusCode Auditor::setProperty(const std::string& s) {
    00260   return m_PropertyMgr->setProperty(s);
    00261 }
    00262 StatusCode Auditor::setProperty(const std::string& n, const std::string& v) {
    00263   return m_PropertyMgr->setProperty(n,v);
    00264 }
    00265 StatusCode Auditor::getProperty(Property* p) const {
    00266   return m_PropertyMgr->getProperty(p);
    00267 }
    00268 const Property& Auditor::getProperty( const std::string& name) const{
    00269   return m_PropertyMgr->getProperty(name);
    00270 }
    00271 StatusCode Auditor::getProperty(const std::string& n, std::string& v ) const {
    00272   return m_PropertyMgr->getProperty(n,v);
    00273 }
    00274 const std::vector<Property*>& Auditor::getProperties( ) const {
    00275   return m_PropertyMgr->getProperties();
    00276 }