Gaudi Framework, version v21r8

Home   Generated: 17 Mar 2010

AlgContextAuditor.cpp

Go to the documentation of this file.
00001 // $Id: AlgContextAuditor.cpp,v 1.4 2007/11/13 12:53:54 marcocle Exp $
00002 // ============================================================================
00003 // CVS tag $Name:  $, version $Revision: 1.4 $
00004 // ============================================================================
00005 // $Log: AlgContextAuditor.cpp,v $
00006 // Revision 1.4  2007/11/13 12:53:54  marcocle
00007 // Charles Leggett
00008 //  - bug #28570.
00009 //    Modified AlgContextAuditor to avoid that it passes a null pointer to
00010 //    AlgContextSvc. It happens if the AuditorSvc is auditing objects that inherit
00011 //    from INamedInterface, but not from IAlgorithm (e.g. services).
00012 //
00013 // Revision 1.3  2007/05/24 13:49:20  hmd
00014 // ( Vanya Belyaev) patch #1171. The enhancement of existing Algorithm Context Service
00015 //    is the primary goal of the proposed patch. The existing
00016 //    AlgContextSvc is not safe with respect to e.g. Data-On-Demand
00017 //    service or to operations with subalgorithms. The patched service
00018 //    essentially implements the queue of executing algorithms, thus the
00019 //    problems are eliminiated. In addition the enriched interface
00020 //    provides the access to the whole queue of executing algorithms.
00021 //
00022 // ============================================================================
00023 // Incldue files
00024 // ============================================================================
00025 // STD & STL
00026 // ============================================================================
00027 #include <cassert>
00028 // ============================================================================
00029 // GaudiKernel
00030 // ============================================================================
00031 #include "GaudiKernel/IAlgContextSvc.h"
00032 #include "GaudiKernel/IAlgorithm.h"
00033 #include "GaudiKernel/AudFactory.h"
00034 #include "GaudiKernel/SmartIF.h"
00035 #include "GaudiKernel/MsgStream.h"
00036 // ============================================================================
00037 // local
00038 // ============================================================================
00039 #include "AlgContextAuditor.h"
00040 // ============================================================================
00046 // ============================================================================
00047 namespace
00048 {
00057   inline IAlgorithm* toAlg ( IInterface* ni )
00058   {
00059     if ( 0 == ni ) { return 0 ; }
00060     SmartIF<IAlgorithm> alg ( ni ) ;
00061     return alg ;
00062   }
00063 }
00064 // ============================================================================
00065 // mandatory auditor fatcory, needed for instantiation
00066 // ============================================================================
00067 DECLARE_AUDITOR_FACTORY(AlgContextAuditor)
00068 // ============================================================================
00069 // standard constructor @see Auditor
00070 // ============================================================================
00071 AlgContextAuditor::AlgContextAuditor
00072 ( const std::string& name ,
00073   ISvcLocator*       pSvc )
00074   : Auditor( name , pSvc )
00075   , m_svc   ( 0    )
00076 {}
00077 // ============================================================================
00078 // destructor
00079 // ============================================================================
00080 AlgContextAuditor::~AlgContextAuditor() {}
00081 // ============================================================================
00082 // standard initialization, see @IAuditor
00083 // ============================================================================
00084 StatusCode AlgContextAuditor::initialize()
00085 {
00086   // initialize the base class
00087   StatusCode sc = Auditor::initialize() ;
00088   if ( sc.isFailure() ) { return sc ; }                           // RETURN
00089   if ( 0 != m_svc ) { m_svc -> release() ; m_svc = 0 ; }
00090   sc = Auditor::service ( "AlgContextSvc" , m_svc , true ) ;
00091   if ( sc.isFailure() )
00092   {
00093     MsgStream log ( msgSvc() , name() ) ;
00094     log << MSG::ERROR << "Unable to locate 'AlgContextSvc'" << sc << endmsg ;
00095     m_svc = 0 ;
00096     return sc ;  // RETURN
00097   }
00098   if ( 0 == m_svc     )
00099   {
00100     MsgStream log ( msgSvc() , name() ) ;
00101     log << MSG::ERROR << "Invalid pointer to IAlgContextSvc" << endmsg ;
00102     return StatusCode::FAILURE ;           // RETURN
00103   }
00104   return StatusCode::SUCCESS ;
00105 }
00106 // ============================================================================
00107 // standard finalization, see @IAuditor
00108 // ============================================================================
00109 StatusCode AlgContextAuditor::finalize ()
00110 {
00111   if ( 0 != m_svc ) { m_svc-> release() ; m_svc = 0 ; }
00112   // finalize the base class
00113   return Auditor::finalize () ;
00114 }
00115 // ============================================================================
00116 void AlgContextAuditor::beforeInitialize ( INamedInterface*  a ) {
00117   if ( 0 != m_svc ) {
00118     IAlgorithm* alg = toAlg(a);
00119     if (alg != 0) m_svc -> setCurrentAlg ( alg ).ignore() ;
00120   }
00121 }
00122 // ============================================================================
00123 void AlgContextAuditor::afterInitialize  ( INamedInterface*  a ) {
00124   if ( 0 != m_svc ) {
00125     IAlgorithm* alg = toAlg(a);
00126     if (alg != 0) m_svc -> unSetCurrentAlg ( alg ).ignore() ;
00127   }
00128 }
00129 // ============================================================================
00130 void AlgContextAuditor::beforeFinalize   ( INamedInterface*  a ) {
00131   if ( 0 != m_svc ) {
00132     IAlgorithm* alg = toAlg(a);
00133     if (alg != 0) m_svc -> setCurrentAlg ( alg ).ignore() ;
00134   }
00135 }
00136 // ============================================================================
00137 void AlgContextAuditor::afterFinalize    ( INamedInterface*  a ) {
00138   if ( 0 != m_svc ) {
00139     IAlgorithm* alg = toAlg(a);
00140     if (alg != 0) m_svc -> unSetCurrentAlg ( alg ).ignore() ;
00141   }
00142 }
00143 // ============================================================================
00144 void AlgContextAuditor::beforeExecute    ( INamedInterface*  a ) {
00145   if ( 0 != m_svc ) {
00146     IAlgorithm* alg = toAlg(a);
00147     if (alg != 0) m_svc -> setCurrentAlg ( alg ).ignore() ;
00148   }
00149 }
00150 // ============================================================================
00151 void AlgContextAuditor::afterExecute     ( INamedInterface*  a       ,
00152                                            const StatusCode& /* s */ ) {
00153   if ( 0 != m_svc ) {
00154     IAlgorithm* alg = toAlg(a);
00155     if (alg != 0) m_svc -> unSetCurrentAlg ( alg ).ignore() ;
00156   }
00157 }
00158 // ============================================================================
00159 
00160 // ============================================================================
00161 // The END
00162 // ============================================================================
00163 

Generated at Wed Mar 17 18:06:09 2010 for Gaudi Framework, version v21r8 by Doxygen version 1.5.6 written by Dimitri van Heesch, © 1997-2004