Gaudi Framework, version v23r4

Home   Generated: Mon Sep 17 2012

Helpers.cpp

Go to the documentation of this file.
00001 // Python must always be the first.
00002 #include "Python.h"
00003 // ============================================================================
00004 // GaudiKernel
00005 // ============================================================================
00006 #include "GaudiKernel/IProperty.h"
00007 #include "GaudiKernel/Property.h"
00008 #include "GaudiKernel/SmartIF.h"
00009 #include "GaudiKernel/ISvcLocator.h"
00010 #include "GaudiKernel/IHistogramSvc.h"
00011 #include "GaudiKernel/IDataProviderSvc.h"
00012 #include "GaudiKernel/IAlgTool.h"
00013 #include "GaudiKernel/IToolSvc.h"
00014 #include "GaudiKernel/DataObject.h"
00015 // ============================================================================
00016 // GaudiPython
00017 // ============================================================================
00018 #include "GaudiPython/Helpers.h"
00019 // ============================================================================
00028 // ============================================================================
00029 /*  Simple wrapper for IDataProviderSvc::findObject
00030  *  The method does NOT trigger the loading
00031  *  the object from tape or Data-On-Demand action
00032  *  @see IDataProviderSvc
00033  *  @see IDataProviderSvc::findObject
00034  *  @param dpsvc (INPUT) pointer to Data Provider Service
00035  *  @param oath full path in TES
00036  *  @return the object
00037  *  @author Vanya BELYAEV Ivan.Belyaev@nikhef.nl
00038  *  @date 2009-10-09
00039  */
00040 // ===========================================================================
00041 DataObject* GaudiPython::Helper::findobject
00042 ( IDataProviderSvc*  dpsvc ,
00043   const std::string& path  )
00044 {
00045   DataObject* o = 0 ;
00046   if ( 0 == dpsvc     ) { return 0 ; }                              // RETURN
00047   StatusCode sc = dpsvc -> findObject ( path , o ) ;  // NB!
00048   if ( sc.isFailure() ) { return 0 ; }                              // RETURN
00049   return o ;                                                        // RETURN
00050 }
00051 // ===========================================================================
00053 namespace
00054 {
00055   // ==========================================================================
00059   const std::string s_NAME = "EnableFaultHandler" ;
00060   // ======================================================================
00061   class Disabler
00062   {
00063   public:
00064     // =========================================================================
00066     Disabler ( IInterface* svc     ,
00067                const bool  disable )
00068       : m_svc     ( svc     )
00069       , m_old     (  s_NAME , true      )
00070       , m_enable  ( !disable            )
00071       , m_code    ( StatusCode::SUCCESS )
00072     {
00073       if      ( !m_svc   ) { m_code = StatusCode::FAILURE ; }
00074       else if ( m_enable ) { /* no action here!! */    ; }  // No action!
00075       else
00076       {
00077         const Property* property =
00078           Gaudi::Utils::getProperty ( m_svc.get() , s_NAME ) ;
00079         if ( 0 == property || !m_old.assign ( *property ) )
00080         { m_code = StatusCode::FAILURE ; }
00081         else if ( m_old.value() != m_enable )
00082         {
00083           m_code = Gaudi::Utils::setProperty
00084             ( m_svc.get() , s_NAME , m_enable ) ;
00085         }
00086       }
00087     }
00088     // =========================================================================
00090     ~Disabler()
00091     {
00092       if      ( m_enable ) { /* no action here! */ } // no action here
00093       else if ( code().isSuccess() && m_old.value() != m_enable ) {
00094         // This line results in an ambiguous overload resolution on g++ 3.4
00095         //   m_code = Gaudi::Utils::setProperty ( m_svc.get() , s_NAME , m_old );
00096         // The problem is that m_old could be any of:
00097         //  - const TYPE &
00098         //  - const Property &
00099         //  - const SimpleProperty<TYPE, BoundedVerifier<TYPE> >&
00100         // So we force the the template argument to help the compiler
00101         m_code = Gaudi::Utils::setProperty<bool>(m_svc.get(), s_NAME, m_old);
00102       }
00103       m_code.ignore() ;
00104     }
00105     // ========================================================================
00106     StatusCode code () const
00107     {
00108       if ( m_enable ) { return StatusCode::SUCCESS ; }
00109       return m_code ;
00110     }
00111     // ========================================================================
00112   private:
00113     // ========================================================================
00115     SmartIF<IProperty> m_svc      ; // the property interface
00116     BooleanProperty    m_old      ;
00117     bool               m_enable   ;
00118     StatusCode         m_code     ; // status code
00119     // ========================================================================
00120   } ;
00121   // ==========================================================================
00122 } //                                                 end of anonymous namespace
00123 // ===========================================================================
00124 /*  the generic function to get object from TES
00125  *  @see IDataProviderSvc
00126  *  @see IDataProviderSvc::findObject
00127  *  @see IDataProviderSvc::retriveObject
00128  *  @param dpsvc (INPUT) pointer to Data Provider Service
00129  *  @author Vanya BELYAEV Ivan.Belyaev@nikhef.nl
00130  *  @date 2009-10-09
00131  */
00132 // ===========================================================================
00133 DataObject* GaudiPython::Helper::getobject
00134 ( IDataProviderSvc*  dpsvc    ,
00135   const std::string& path     ,
00136   const bool         retrieve ,
00137   const bool         disable  )
00138 {
00139   if ( 0 == dpsvc ) { return 0 ; }  // RETURN 0
00140   // create the sentry:
00141   Disabler sentry ( dpsvc , disable ) ;
00142   //
00143   DataObject * result = 0 ;
00144   //
00145   StatusCode sc =
00146     retrieve ?
00147     dpsvc -> retrieveObject ( path , result ) :
00148     dpsvc -> findObject     ( path , result ) ;
00149   //
00150   if ( sc.isFailure() ) { return 0 ; }                               // RETURN
00151   //
00152   return result ;                                                    // RETURN
00153 }
00154 // ============================================================================
00155 // The END
00156 // ============================================================================
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines

Generated at Mon Sep 17 2012 13:49:29 for Gaudi Framework, version v23r4 by Doxygen version 1.7.2 written by Dimitri van Heesch, © 1997-2004