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