![]() |
|
|
Generated: 8 Jan 2009 |
00001 // $Id: AlgContextSvc.cpp,v 1.4 2007/05/24 13:49:47 hmd Exp $ 00002 // ============================================================================ 00003 // CVS tag $Name: $, version $Revision: 1.4 $ 00004 // ============================================================================ 00005 // $Log: AlgContextSvc.cpp,v $ 00006 // Revision 1.4 2007/05/24 13:49:47 hmd 00007 // ( Vanya Belyaev) patch #1171. The enhancement of existing Algorithm Context Service 00008 // is the primary goal of the proposed patch. The existing 00009 // AlgContextSvc is not safe with respect to e.g. Data-On-Demand 00010 // service or to operations with subalgorithms. The patched service 00011 // essentially implements the queue of executing algorithms, thus the 00012 // problems are eliminiated. In addition the enriched interface 00013 // provides the access to the whole queue of executing algorithms. 00014 // 00015 // ============================================================================ 00016 // Include files 00017 // ============================================================================ 00018 // GaudiKernel 00019 // ============================================================================ 00020 #include "GaudiKernel/MsgStream.h" 00021 #include "GaudiKernel/ISvcLocator.h" 00022 #include "GaudiKernel/SvcFactory.h" 00023 #include "GaudiKernel/IIncidentSvc.h" 00024 // ============================================================================ 00025 // Local 00026 // ============================================================================ 00027 #include "AlgContextSvc.h" 00028 // ============================================================================ 00035 // ============================================================================ 00039 DECLARE_SERVICE_FACTORY(AlgContextSvc) 00040 // ============================================================================ 00041 // Standard Constructor 00042 // ============================================================================ 00043 AlgContextSvc::AlgContextSvc 00044 ( const std::string& name , 00045 ISvcLocator* svc ) 00046 : Service ( name , svc ) 00047 , m_algorithms ( 0 ) 00048 , m_inc ( 0 ) 00049 , m_check ( true ) 00050 { 00051 declareProperty ( "Check" , m_check , "Flag to perform more checks" ); 00052 } 00053 // ============================================================================ 00054 // Standard Destructor 00055 // ============================================================================ 00056 AlgContextSvc::~AlgContextSvc() {} 00057 // ============================================================================ 00058 // Query the interfaces. 00059 // ============================================================================ 00060 StatusCode AlgContextSvc::queryInterface 00061 ( const InterfaceID& riid , 00062 void** ppvi ) 00063 { 00064 if ( 0 == ppvi ) { return StatusCode::FAILURE ; } // RETURN 00065 else if ( IAlgContextSvc ::interfaceID() == riid ) 00066 { *ppvi = static_cast<IAlgContextSvc*> ( this ) ; } 00067 else if ( IIncidentListener ::interfaceID() == riid ) 00068 { *ppvi = static_cast<IIncidentListener*> ( this ) ; } 00069 else { return Service::queryInterface ( riid , ppvi ) ; } // RETURN 00070 // increment the reference count! 00071 addRef(); 00072 return StatusCode::SUCCESS ; 00073 } 00074 // ============================================================================ 00075 // standard initialization of the service 00076 // ============================================================================ 00077 StatusCode AlgContextSvc::initialize () 00078 { 00079 // intialize the base class 00080 StatusCode sc = Service::initialize () ; 00081 if ( sc.isFailure () ) { return sc ; } 00082 // Incindent Service 00083 if ( 0 != m_inc ) 00084 { 00085 m_inc -> removeListener ( this ) ; 00086 m_inc -> release() ; 00087 m_inc = 0 ; 00088 } 00089 // perform more checks? 00090 if ( m_check ) 00091 { 00092 sc = Service::service ( "IncidentSvc" , m_inc , true ) ; 00093 if ( sc.isFailure() ) 00094 { 00095 MsgStream log ( msgSvc() , name() ) ; 00096 log << MSG::ERROR << "Could not locate 'IncidentSvc'" << sc << endreq ; 00097 return sc ; // RETURN 00098 } 00099 if ( 0 == m_inc ) 00100 { 00101 MsgStream log ( msgSvc() , name() ) ; 00102 log << MSG::ERROR << "Invalid pointer to IIncindentSvc" << endreq ; 00103 return StatusCode::FAILURE ; // RETURN 00104 } 00105 m_inc -> addListener ( this , IncidentType::BeginEvent ) ; 00106 m_inc -> addListener ( this , IncidentType::EndEvent ) ; 00107 } 00108 if ( !m_algorithms.empty() ) 00109 { 00110 MsgStream log ( msgSvc() , name() ) ; 00111 log << MSG::WARNING 00112 << "Non-empty stack of algorihtms #" 00113 << m_algorithms.size() << endreq ; 00114 } 00115 return StatusCode::SUCCESS ; 00116 } 00117 // ============================================================================ 00118 // standard finalization of the service @see IService 00119 // ============================================================================ 00120 StatusCode AlgContextSvc::finalize () 00121 { 00122 if ( !m_algorithms.empty() ) 00123 { 00124 MsgStream log ( msgSvc() , name() ) ; 00125 log << MSG::WARNING 00126 << "Non-empty stack of algorihtms #" 00127 << m_algorithms.size() << endreq ; 00128 } 00129 // Incindent Service 00130 if ( 0 != m_inc ) 00131 { 00132 m_inc -> removeListener ( this ) ; 00133 m_inc -> release() ; 00134 m_inc = 0 ; 00135 } 00136 // finalize the base class 00137 return Service::finalize () ; 00138 } 00139 // ============================================================================ 00140 // set the currently executing algorithm ("push_back") @see IAlgContextSvc 00141 // ============================================================================ 00142 StatusCode AlgContextSvc::setCurrentAlg ( IAlgorithm* a ) 00143 { 00144 if ( 0 == a ) 00145 { 00146 MsgStream log ( msgSvc() , name() ) ; 00147 log << MSG::WARNING << "IAlgorithm* points to NULL" << endreq ; 00148 // 00149 return StatusCode::RECOVERABLE ; // RETURN 00150 } 00151 m_algorithms.push_back ( a ) ; 00152 // 00153 return StatusCode::SUCCESS ; // RETURN 00154 } 00155 // ============================================================================ 00156 // remove the algorithm ("pop_back") @see IAlgContextSvc 00157 // ============================================================================ 00158 StatusCode AlgContextSvc::unSetCurrentAlg ( IAlgorithm* a ) 00159 { 00160 if ( 0 == a ) 00161 { 00162 MsgStream log ( msgSvc() , name() ) ; 00163 log << MSG::WARNING << "IAlgorithm* points to NULL" << endreq ; 00164 // 00165 return StatusCode::RECOVERABLE ; // RETURN 00166 } 00167 if ( m_algorithms.empty() || m_algorithms.back() != a ) 00168 { 00169 MsgStream log ( msgSvc() , name() ) ; 00170 log << MSG::ERROR << "Algorithm stack is invalid" << endreq ; 00171 // 00172 return StatusCode::FAILURE ; 00173 } 00174 // 00175 m_algorithms.pop_back() ; // POP_BACK 00176 // 00177 return StatusCode::SUCCESS ; 00178 } 00179 // ============================================================================ 00181 // ============================================================================ 00182 IAlgorithm* AlgContextSvc::currentAlg () const 00183 { return m_algorithms.empty() ? 0 : m_algorithms.back() ; } 00184 // ============================================================================ 00185 // handle incident @see IIncidentListener 00186 // ============================================================================ 00187 void AlgContextSvc::handle ( const Incident& ) 00188 { 00189 if ( !m_algorithms.empty() ) 00190 { 00191 MsgStream log ( msgSvc() , name() ) ; 00192 log << MSG::ERROR 00193 << "Non-empty stack of algorihtms #" 00194 << m_algorithms.size() << endreq ; 00195 } 00196 } 00197 // ============================================================================ 00198 00199 00200 00201 00202 // ============================================================================ 00204 // ============================================================================