Gaudi Framework, version v20r4

Generated: 8 Jan 2009

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 
00014 // Constructor
00015 Auditor::Auditor( const std::string& name, ISvcLocator *pSvcLocator )
00016 : m_refCount(0),
00017   m_name(name),
00018   m_MS (0),
00019   m_pSvcLocator(pSvcLocator),
00020   m_isEnabled(true),
00021   m_isInitialized(false),
00022   m_isFinalized(false)
00023 {
00024   m_PropertyMgr = new PropertyMgr();
00025 
00026   // Declare common Auditor properties with their defaults
00027   declareProperty( "OutputLevel", m_outputLevel = MSG::NIL);
00028   declareProperty( "Enable", m_isEnabled = true);
00029 
00030 }
00031 
00032 // Default Destructor
00033 Auditor::~Auditor() {
00034   delete m_PropertyMgr;
00035 }
00036 
00037 // IAuditor implementation
00038 StatusCode Auditor::sysInitialize() {
00039   StatusCode sc;
00040 
00041   // Bypass the initialization if the auditor is disabled or
00042   // has already been initialized.
00043   if ( isEnabled( ) && ! m_isInitialized ) {
00044 
00045     // Setup the default service ... this should be upgraded so as to be configurable.
00046     if( 0 == m_pSvcLocator )
00047       return StatusCode::FAILURE;
00048 
00049     // Set up message service
00050     sc = m_pSvcLocator->getService("MessageSvc", IID_IMessageSvc, *pp_cast<IInterface>(&m_MS));
00051     if( !sc.isSuccess() )  return StatusCode::FAILURE;
00052 
00053     // Set the Auditor's properties
00054     sc = setProperties();
00055     if( !sc.isSuccess() )  return StatusCode::FAILURE;
00056 
00057     // Check current outputLevel to evetually inform the MessagsSvc
00058     if( m_outputLevel != MSG::NIL ) {
00059       setOutputLevel( m_outputLevel );
00060     }
00061 
00062     {
00063       try{
00064         // Invoke the initialize() method of the derived class
00065         sc = initialize();
00066         if( !sc.isSuccess() )  return StatusCode::FAILURE;
00067         m_isInitialized = true;
00068 
00069         return sc;                                               
00070       }
00071       catch ( const GaudiException& Exception )                  
00072         {
00074           MsgStream log ( msgSvc() , name() + ".sysInitialize()" );
00075           log << MSG::FATAL << " Exception with tag=" << Exception.tag() << " is catched " << endreq;
00077           MsgStream logEx ( msgSvc() , Exception.tag() );
00078           logEx << MSG::ERROR << Exception  << endreq;
00079         }
00080       catch( const std::exception& Exception )                   
00081         {
00083           MsgStream log ( msgSvc() , name() + ".sysInitialize()" );
00084           log << MSG::FATAL << " Standard std::exception is catched " << endreq;
00086           MsgStream logEx ( msgSvc() , name() + "*std::exception*" );
00087           logEx << MSG::ERROR << Exception.what()  << endreq;
00088         }
00089       catch(...)
00090         {
00092           MsgStream log ( msgSvc() , name() + ".sysInitialize()" );
00093           log << MSG::FATAL << " UNKNOWN Exception is  catched " << endreq;
00094         }
00095     }
00096   }
00098   return StatusCode::FAILURE;
00099 }
00100 
00101 StatusCode Auditor::initialize() {
00102   return StatusCode::SUCCESS;
00103 }
00104 
00105 // Implemented for backward compatibility
00106 void Auditor::before(StandardEventType evt, INamedInterface* obj){
00107   switch (evt) {
00108   case Initialize:   beforeInitialize(obj);   break;
00109   case ReInitialize: beforeReinitialize(obj); break;
00110   case Execute:      beforeExecute(obj);      break;
00111   case BeginRun:     beforeBeginRun(obj);     break;
00112   case EndRun:       beforeEndRun(obj);       break;
00113   case Finalize:     beforeFinalize(obj);     break;
00114   case Start:        break;
00115   case Stop:         break;
00116   case ReStart:      break;
00117   default: ;// do nothing
00118   }
00119 }
00120 void Auditor::before(StandardEventType, const std::string&) {}
00121 
00122 void Auditor::before(CustomEventTypeRef, INamedInterface*){}
00123 void Auditor::before(CustomEventTypeRef, const std::string&){}
00124 
00125 // Implemented for backward compatibility
00126 void Auditor::after(StandardEventType evt, INamedInterface* obj, const StatusCode& sc){
00127   switch (evt) {
00128   case Initialize:   afterInitialize(obj);   break;
00129   case ReInitialize: afterReinitialize(obj); break;
00130   case Execute:      afterExecute(obj, sc);  break;
00131   case BeginRun:     afterBeginRun(obj);     break;
00132   case EndRun:       afterEndRun(obj);       break;
00133   case Finalize:     afterFinalize(obj);     break;
00134   case Start:        break;
00135   case Stop:         break;
00136   case ReStart:      break;
00137   default: ;// do nothing
00138   }
00139 }
00140 void Auditor::after(StandardEventType, const std::string&, const StatusCode&) {}
00141 
00142 void Auditor::after(CustomEventTypeRef, INamedInterface*, const StatusCode&){}
00143 void Auditor::after(CustomEventTypeRef, const std::string&, const StatusCode&){}
00144 
00145 void Auditor::beforeInitialize(INamedInterface* ) {}
00146 
00147 void Auditor::afterInitialize(INamedInterface* ) {}
00148 
00149 void Auditor::beforeReinitialize(INamedInterface* ) {}
00150 
00151 void Auditor::afterReinitialize(INamedInterface* ) {}
00152 
00153 void Auditor::beforeExecute(INamedInterface* ) {}
00154 
00155 void Auditor::afterExecute(INamedInterface*, const StatusCode& ) {}
00156 
00157 void Auditor::beforeBeginRun(INamedInterface* ) {}
00158 
00159 void Auditor::afterBeginRun(INamedInterface* ) {}
00160 
00161 void Auditor::beforeEndRun(INamedInterface* ) {}
00162 
00163 void Auditor::afterEndRun(INamedInterface* ) {}
00164 
00165 void Auditor::beforeFinalize(INamedInterface* ) {}
00166 
00167 void Auditor::afterFinalize(INamedInterface* ) {}
00168 
00169 StatusCode Auditor::sysFinalize() {
00170   StatusCode sc = StatusCode::SUCCESS;
00171   try{
00172     //
00173     // Invoke the finalize() method of the derived class if
00174     // it has been initilized.
00175     if ( m_isInitialized && ! m_isFinalized ) {
00176       m_isFinalized = true;
00177       sc = finalize();
00178       if( !sc.isSuccess() )  return StatusCode::FAILURE;
00179     }
00180     return sc;                                               
00181     //
00182   }
00183   catch( const GaudiException& Exception )                   
00184     {
00186       MsgStream log ( msgSvc() , name() + ".sysFinalize()" );
00187       log << MSG::FATAL
00188           << " Exception with tag=" << Exception.tag() << " is catched " << endreq;
00191       MsgStream logEx ( msgSvc() , Exception.tag() );
00192       logEx << MSG::ERROR
00193             << Exception  << endreq;
00194     }
00195   catch( const std::exception& Exception )                   
00196     {
00198       MsgStream log ( msgSvc() , name() + ".sysFinalize()" );
00199       log << MSG::FATAL
00200           << " Standard std::exception is catched " << endreq;
00202       MsgStream logEx ( msgSvc() , name() + "*std::exception*" );
00203       logEx << MSG::ERROR
00204             << Exception.what()  << endreq;
00205     }
00206   catch( ... )                                                
00207     {
00209       MsgStream log ( msgSvc() , name() + ".sysFinalize()" );
00210       log << MSG::FATAL
00211           << " UNKNOWN Exception is  catched " << endreq;
00212     }
00214   return StatusCode::FAILURE ;
00215 }
00216 
00217 StatusCode Auditor::finalize() {
00218   if( m_MS ) {
00219     m_MS->release();
00220     m_MS = 0;
00221   }
00222   return StatusCode::SUCCESS;
00223 }
00224 
00225 const std::string& Auditor::name() const {
00226   return m_name;
00227 }
00228 
00229 bool Auditor::isEnabled( ) const {
00230   return m_isEnabled;
00231 }
00232 
00233 IMessageSvc* Auditor::msgSvc() const {
00234   return m_MS;
00235 }
00236 
00237 void Auditor::setOutputLevel( int level ) {
00238   if( m_MS != 0) {
00239     m_MS->setOutputLevel( name(), level );
00240   }
00241 }
00242 
00243 ISvcLocator * Auditor::serviceLocator() const {
00244   return m_pSvcLocator;
00245 }
00246 
00247 
00248 // IInterface implementation
00249 unsigned long Auditor::addRef() {
00250   return ++m_refCount;
00251 }
00252 
00253 unsigned long Auditor::release() {
00254   long count = --m_refCount;
00255   if( count <= 0) {
00256     delete this;
00257   }
00258   return count;
00259 }
00260 
00261 StatusCode Auditor::queryInterface
00262 ( const InterfaceID& riid   ,
00263   void**             ppISvc )
00264 {
00265   if ( 0 == ppISvc ) { return StatusCode::FAILURE ; } // RETURN
00266 
00267   if      ( IAuditor        ::interfaceID() . versionMatch ( riid ) )
00268   { *ppISvc = static_cast<IAuditor*>         ( this ) ; }
00269   else if ( IProperty       ::interfaceID() . versionMatch ( riid ) )
00270   { *ppISvc = static_cast<IProperty*>        ( this ) ; }
00271   else if ( INamedInterface ::interfaceID() . versionMatch ( riid ) )
00272   { *ppISvc = static_cast<INamedInterface*>  ( this ) ; }
00273   else if ( IInterface      ::interfaceID() . versionMatch ( riid ) )
00274   { *ppISvc = static_cast<IInterface*>       ( this ) ; }
00275   else { *ppISvc = 0 ; return StatusCode::FAILURE; } // RETURN
00276   // increment the reference counter
00277   addRef();
00278   //
00279   return StatusCode::SUCCESS;
00280 }
00281 
00282 
00283 // Use the job options service to set declared properties
00284 StatusCode Auditor::setProperties() {
00285   if( 0 != m_pSvcLocator )    {
00286     IJobOptionsSvc* jos;
00287     StatusCode sc = service("JobOptionsSvc", jos);
00288     if( sc.isSuccess() )    {
00289       jos->setMyProperties( name(), this ).ignore();
00290       jos->release();
00291       return StatusCode::SUCCESS;
00292     }
00293   }
00294   return StatusCode::FAILURE;
00295 }
00296 
00297 // IProperty implementation
00298 // Delegate to the Property manager
00299 StatusCode Auditor::setProperty(const Property& p) {
00300         return m_PropertyMgr->setProperty(p);
00301 }
00302 StatusCode Auditor::setProperty(const std::string& s) {
00303         return m_PropertyMgr->setProperty(s);
00304 }
00305 StatusCode Auditor::setProperty(const std::string& n, const std::string& v) {
00306         return m_PropertyMgr->setProperty(n,v);
00307 }
00308 StatusCode Auditor::getProperty(Property* p) const {
00309         return m_PropertyMgr->getProperty(p);
00310 }
00311 const Property& Auditor::getProperty( const std::string& name) const{
00312         return m_PropertyMgr->getProperty(name);
00313 }
00314 StatusCode Auditor::getProperty(const std::string& n, std::string& v ) const {
00315         return m_PropertyMgr->getProperty(n,v);
00316 }
00317 const std::vector<Property*>& Auditor::getProperties( ) const {
00318         return m_PropertyMgr->getProperties();
00319 }

Generated at Thu Jan 8 17:44:21 2009 for Gaudi Framework, version v20r4 by Doxygen version 1.5.6 written by Dimitri van Heesch, © 1997-2004