00001 // $Id: AlgContextAuditor.cpp,v 1.4 2007/11/13 12:53:54 marcocle Exp $ 00002 // ============================================================================ 00003 // CVS tag $Name: GAUDI_v20r4-pre $, 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/INamedInterface.h" 00035 #include "GaudiKernel/SmartIF.h" 00036 #include "GaudiKernel/MsgStream.h" 00037 // ============================================================================ 00038 // local 00039 // ============================================================================ 00040 #include "AlgContextAuditor.h" 00041 // ============================================================================ 00047 // ============================================================================ 00048 namespace 00049 { 00058 inline IAlgorithm* toAlg ( IInterface* ni ) 00059 { 00060 if ( 0 == ni ) { return 0 ; } 00061 SmartIF<IAlgorithm> alg ( IAlgorithm::interfaceID() , ni ) ; 00062 return alg ; 00063 } 00064 } 00065 // ============================================================================ 00066 // mandatory auditor fatcory, needed for instantiation 00067 // ============================================================================ 00068 DECLARE_AUDITOR_FACTORY(AlgContextAuditor) ; 00069 // ============================================================================ 00070 // standard constructor @see Auditor 00071 // ============================================================================ 00072 AlgContextAuditor::AlgContextAuditor 00073 ( const std::string& name , 00074 ISvcLocator* pSvc ) 00075 : Auditor( name , pSvc ) 00076 , m_svc ( 0 ) 00077 {} 00078 // ============================================================================ 00079 // destructor 00080 // ============================================================================ 00081 AlgContextAuditor::~AlgContextAuditor() {} 00082 // ============================================================================ 00083 // standard initialization, see @IAuditor 00084 // ============================================================================ 00085 StatusCode AlgContextAuditor::initialize() 00086 { 00087 // initialize the base class 00088 StatusCode sc = Auditor::initialize() ; 00089 if ( sc.isFailure() ) { return sc ; } // RETURN 00090 if ( 0 != m_svc ) { m_svc -> release() ; m_svc = 0 ; } 00091 sc = Auditor::service ( "AlgContextSvc" , m_svc , true ) ; 00092 if ( sc.isFailure() ) 00093 { 00094 MsgStream log ( msgSvc() , name() ) ; 00095 log << MSG::ERROR << "Unable to locate 'AlgContextSvc'" << sc << endreq ; 00096 m_svc = 0 ; 00097 return sc ; // RETURN 00098 } 00099 if ( 0 == m_svc ) 00100 { 00101 MsgStream log ( msgSvc() , name() ) ; 00102 log << MSG::ERROR << "Invalid pointer to IAlgContextSvc" << endreq ; 00103 return StatusCode::FAILURE ; // RETURN 00104 } 00105 return StatusCode::SUCCESS ; 00106 } 00107 // ============================================================================ 00108 // standard finalization, see @IAuditor 00109 // ============================================================================ 00110 StatusCode AlgContextAuditor::finalize () 00111 { 00112 if ( 0 != m_svc ) { m_svc-> release() ; m_svc = 0 ; } 00113 // finalize the base class 00114 return Auditor::finalize () ; 00115 } 00116 // ============================================================================ 00117 void AlgContextAuditor::beforeInitialize ( INamedInterface* a ) { 00118 if ( 0 != m_svc ) { 00119 IAlgorithm* alg = toAlg(a); 00120 if (alg != 0) m_svc -> setCurrentAlg ( alg ).ignore() ; 00121 } 00122 } 00123 // ============================================================================ 00124 void AlgContextAuditor::afterInitialize ( INamedInterface* a ) { 00125 if ( 0 != m_svc ) { 00126 IAlgorithm* alg = toAlg(a); 00127 if (alg != 0) m_svc -> unSetCurrentAlg ( alg ).ignore() ; 00128 } 00129 } 00130 // ============================================================================ 00131 void AlgContextAuditor::beforeFinalize ( INamedInterface* a ) { 00132 if ( 0 != m_svc ) { 00133 IAlgorithm* alg = toAlg(a); 00134 if (alg != 0) m_svc -> setCurrentAlg ( alg ).ignore() ; 00135 } 00136 } 00137 // ============================================================================ 00138 void AlgContextAuditor::afterFinalize ( INamedInterface* a ) { 00139 if ( 0 != m_svc ) { 00140 IAlgorithm* alg = toAlg(a); 00141 if (alg != 0) m_svc -> unSetCurrentAlg ( alg ).ignore() ; 00142 } 00143 } 00144 // ============================================================================ 00145 void AlgContextAuditor::beforeExecute ( INamedInterface* a ) { 00146 if ( 0 != m_svc ) { 00147 IAlgorithm* alg = toAlg(a); 00148 if (alg != 0) m_svc -> setCurrentAlg ( alg ).ignore() ; 00149 } 00150 } 00151 // ============================================================================ 00152 void AlgContextAuditor::afterExecute ( INamedInterface* a , 00153 const StatusCode& /* s */ ) { 00154 if ( 0 != m_svc ) { 00155 IAlgorithm* alg = toAlg(a); 00156 if (alg != 0) m_svc -> unSetCurrentAlg ( alg ).ignore() ; 00157 } 00158 } 00159 // ============================================================================ 00160 00161 // ============================================================================ 00162 // The END 00163 // ============================================================================ 00164