Gaudi Framework, version v22r0

Home   Generated: 9 Feb 2011

AlgContextSvc.cpp

Go to the documentation of this file.
00001 // $Id: AlgContextSvc.cpp,v 1.4 2007/05/24 13:49:47 hmd Exp $
00002 // ============================================================================
00003 // Include files
00004 // ============================================================================
00005 // GaudiKernel
00006 // ============================================================================
00007 #include "GaudiKernel/MsgStream.h"
00008 #include "GaudiKernel/ISvcLocator.h"
00009 #include "GaudiKernel/SvcFactory.h"
00010 #include "GaudiKernel/IIncidentSvc.h"
00011 // ============================================================================
00012 // Local
00013 // ============================================================================
00014 #include "AlgContextSvc.h"
00015 // ============================================================================
00022 // ============================================================================
00026 DECLARE_SERVICE_FACTORY(AlgContextSvc)
00027 // ============================================================================
00028 // Standard Constructor
00029 // ============================================================================
00030 AlgContextSvc::AlgContextSvc
00031 ( const std::string& name ,
00032   ISvcLocator*       svc  )
00033   : base_class ( name , svc  )
00034   , m_algorithms (  0   )
00035   , m_inc        (  0   )
00036   , m_check      ( true )
00037 {
00038   declareProperty ( "Check" , m_check , "Flag to perform more checks" );
00039 }
00040 // ============================================================================
00041 // Standard Destructor
00042 // ============================================================================
00043 AlgContextSvc::~AlgContextSvc() {}
00044 // ============================================================================
00045 // standard initialization of the service
00046 // ============================================================================
00047 StatusCode AlgContextSvc::initialize ()
00048 {
00049   // Initialize the base class
00050   StatusCode sc = Service::initialize () ;
00051   if ( sc.isFailure () ) { return sc ; }
00052   // Incident Service
00053   if ( 0 != m_inc     )
00054   {
00055     m_inc -> removeListener ( this ) ;
00056     m_inc -> release() ;
00057     m_inc = 0 ;
00058   }
00059   // perform more checks?
00060   if ( m_check )
00061   {
00062     sc = Service::service ( "IncidentSvc" , m_inc , true ) ;
00063     if ( sc.isFailure() )
00064     {
00065       MsgStream log ( msgSvc() , name() )  ;
00066       log << MSG::ERROR << "Could not locate 'IncidentSvc'" << sc << endmsg ;
00067       return sc ;                                               // RETURN
00068     }
00069     if ( 0 == m_inc )
00070     {
00071       MsgStream log ( msgSvc() , name() ) ;
00072       log << MSG::ERROR << "Invalid pointer to IIncindentSvc" << endmsg ;
00073       return StatusCode::FAILURE ;                               // RETURN
00074     }
00075     m_inc -> addListener ( this , IncidentType::BeginEvent ) ;
00076     m_inc -> addListener ( this , IncidentType::EndEvent   ) ;
00077   }
00078   if ( !m_algorithms.empty() )
00079   {
00080     MsgStream log ( msgSvc() , name() ) ;
00081     log << MSG::WARNING
00082         << "Non-empty stack of algorithms #"
00083         << m_algorithms.size() << endmsg ;
00084   }
00085   return StatusCode::SUCCESS ;
00086 }
00087 // ============================================================================
00088 // standard finalization  of the service  @see IService
00089 // ============================================================================
00090 StatusCode AlgContextSvc::finalize   ()
00091 {
00092   if ( !m_algorithms.empty() )
00093   {
00094     MsgStream log ( msgSvc() , name() ) ;
00095     log << MSG::WARNING
00096         << "Non-empty stack of algorithms #"
00097         << m_algorithms.size() << endmsg ;
00098   }
00099   // Incident Service
00100   if ( 0 != m_inc     )
00101   {
00102     m_inc -> removeListener ( this ) ;
00103     m_inc -> release() ;
00104     m_inc = 0 ;
00105   }
00106   // finalize the base class
00107   return Service::finalize () ;
00108 }
00109 // ============================================================================
00110 // set     the currently executing algorithm  ("push_back") @see IAlgContextSvc
00111 // ============================================================================
00112 StatusCode AlgContextSvc::setCurrentAlg  ( IAlgorithm* a )
00113 {
00114   if ( 0 == a )
00115   {
00116     MsgStream log ( msgSvc() , name() ) ;
00117     log << MSG::WARNING << "IAlgorithm* points to NULL" << endmsg ;
00118     //
00119     return StatusCode::RECOVERABLE ;                              // RETURN
00120   }
00121   m_algorithms.push_back ( a ) ;
00122   //
00123   return StatusCode::SUCCESS ;                                    // RETURN
00124 }
00125 // ============================================================================
00126 // remove the algorithm                       ("pop_back") @see IAlgContextSvc
00127 // ============================================================================
00128 StatusCode AlgContextSvc::unSetCurrentAlg ( IAlgorithm* a )
00129 {
00130   if ( 0 == a )
00131   {
00132     MsgStream log ( msgSvc() , name() ) ;
00133     log << MSG::WARNING << "IAlgorithm* points to NULL" << endmsg ;
00134     //
00135     return StatusCode::RECOVERABLE ;                              // RETURN
00136   }
00137   if ( m_algorithms.empty() || m_algorithms.back() != a )
00138   {
00139     MsgStream log ( msgSvc() , name() ) ;
00140     log << MSG::ERROR << "Algorithm stack is invalid" << endmsg ;
00141     //
00142     return StatusCode::FAILURE ;
00143   }
00144   //
00145   m_algorithms.pop_back() ;                                      // POP_BACK
00146   //
00147   return StatusCode::SUCCESS ;
00148 }
00149 // ============================================================================
00151 // ============================================================================
00152 IAlgorithm* AlgContextSvc::currentAlg  () const
00153 { return m_algorithms.empty() ? 0 : m_algorithms.back() ; }
00154 // ============================================================================
00155 // handle incident @see IIncidentListener
00156 // ============================================================================
00157 void AlgContextSvc::handle ( const Incident& )
00158 {
00159   if ( !m_algorithms.empty() )
00160   {
00161     MsgStream log ( msgSvc() , name() ) ;
00162     log << MSG::ERROR
00163         << "Non-empty stack of algorithms #"
00164         << m_algorithms.size() << endmsg ;
00165   }
00166 }
00167 // ============================================================================
00168 
00169 
00170 
00171 
00172 // ============================================================================
00174 // ============================================================================
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines

Generated at Wed Feb 9 16:25:00 2011 for Gaudi Framework, version v22r0 by Doxygen version 1.6.2 written by Dimitri van Heesch, © 1997-2004