The Gaudi Framework  v31r0 (aeb156f0)
Helpers.cpp
Go to the documentation of this file.
1 // Python must always be the first.
2 #include "Python.h"
3 // ============================================================================
4 // GaudiKernel
5 // ============================================================================
7 #include "GaudiKernel/IAlgTool.h"
10 #include "GaudiKernel/IProperty.h"
12 #include "GaudiKernel/IToolSvc.h"
13 #include "GaudiKernel/Property.h"
14 #include "GaudiKernel/SmartIF.h"
15 // ============================================================================
16 // GaudiPython
17 // ============================================================================
18 #include "GaudiPython/Helpers.h"
19 // ============================================================================
28 // ============================================================================
29 /* Simple wrapper for IDataProviderSvc::findObject
30  * The method does NOT trigger the loading
31  * the object from tape or Data-On-Demand action
32  * @see IDataProviderSvc
33  * @see IDataProviderSvc::findObject
34  * @param dpsvc (INPUT) pointer to Data Provider Service
35  * @param oath full path in TES
36  * @return the object
37  * @author Vanya BELYAEV Ivan.Belyaev@nikhef.nl
38  * @date 2009-10-09
39  */
40 // ===========================================================================
42  DataObject* o = nullptr;
43  if ( !dpsvc ) { return nullptr; } // RETURN
44  StatusCode sc = dpsvc->findObject( path, o ); // NB!
45  return sc.isSuccess() ? o : nullptr; // RETURN
46 }
47 // ===========================================================================
49 namespace {
50  // ==========================================================================
54  const std::string s_NAME = "EnableFaultHandler";
55  // ======================================================================
56  class Disabler {
57  public:
58  // =========================================================================
60  Disabler( IInterface* svc, bool disable ) : m_svc( svc ), m_old( s_NAME, true ), m_enable( !disable ) {
61  if ( !m_svc ) {
62  m_code = StatusCode::FAILURE;
63  } else if ( m_enable ) { /* no action here!! */
64  ;
65  } // No action!
66  else {
67  const Gaudi::Details::PropertyBase* property = Gaudi::Utils::getProperty( m_svc.get(), s_NAME );
68  if ( !property || !m_old.assign( *property ) ) {
69  m_code = StatusCode::FAILURE;
70  } else if ( m_old.value() != m_enable ) {
71  m_code = Gaudi::Utils::setProperty( m_svc.get(), s_NAME, m_enable );
72  }
73  }
74  }
75  // =========================================================================
77  ~Disabler() {
78  if ( m_enable ) { /* no action here! */
79  } // no action here
80  else if ( code().isSuccess() && m_old.value() != m_enable ) {
81  m_code = Gaudi::Utils::setProperty( m_svc.get(), s_NAME, m_old );
82  }
83  m_code.ignore();
84  }
85  // ========================================================================
86  StatusCode code() const { return m_enable ? StatusCode::SUCCESS : m_code; }
87  // ========================================================================
88  private:
89  // ========================================================================
91  SmartIF<IProperty> m_svc; // the property interface
92  Gaudi::Property<bool> m_old = {s_NAME, true};
93  bool m_enable;
94  StatusCode m_code = StatusCode::SUCCESS; // status code
95  // ========================================================================
96  };
97  // ==========================================================================
98 } // end of anonymous namespace
99 // ===========================================================================
100 /* the generic function to get object from TES
101  * @see IDataProviderSvc
102  * @see IDataProviderSvc::findObject
103  * @see IDataProviderSvc::retriveObject
104  * @param dpsvc (INPUT) pointer to Data Provider Service
105  * @author Vanya BELYAEV Ivan.Belyaev@nikhef.nl
106  * @date 2009-10-09
107  */
108 // ===========================================================================
110  const bool disable ) {
111  if ( !dpsvc ) { return nullptr; } // RETURN 0
112  // create the sentry:
113  Disabler sentry( dpsvc, disable );
114  //
115  DataObject* result = nullptr;
116  //
117  StatusCode sc = retrieve ? dpsvc->retrieveObject( path, result ) : dpsvc->findObject( path, result );
118  //
119  return sc.isSuccess() ? result : nullptr;
120 }
121 // ============================================================================
122 // The END
123 // ============================================================================
StatusCode setProperty(IProperty *component, const std::string &name, const TYPE &value, const std::string &doc)
simple function to set the property of the given object from the value
Definition: Property.h:1178
Implementation of property with value of concrete type.
Definition: Property.h:352
static GAUDI_API DataObject * findobject(IDataProviderSvc *dpsvc, const std::string &path)
simple wrapper for IDataProviderSvc::findObject The methdod does NOT trigger the loading the object f...
Definition: Helpers.cpp:41
virtual bool assign(const PropertyBase &source)=0
import the property value form the source
virtual StatusCode findObject(IRegistry *pDirectory, boost::string_ref path, DataObject *&pObject)=0
Find object identified by its directory entry.
bool isSuccess() const
Definition: StatusCode.h:267
Gaudi::Details::PropertyBase * property(const std::string &name) const
constexpr static const auto SUCCESS
Definition: StatusCode.h:85
Data provider interface definition.
STL class.
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:50
Definition of the basic interface.
Definition: IInterface.h:244
PropertyBase base class allowing PropertyBase* collections to be "homogeneous".
Definition: Property.h:32
virtual StatusCode retrieveObject(IRegistry *pDirectory, boost::string_ref path, DataObject *&pObject)=0
Retrieve object identified by its directory entry.
static GAUDI_API DataObject * getobject(IDataProviderSvc *dpsvc, const std::string &path, const bool retrieve=true, const bool disableDoD=false)
the generic function to get object from TES
Definition: Helpers.cpp:109
const StatusCode & ignore() const
Ignore/check StatusCode.
Definition: StatusCode.h:153
constexpr static const auto FAILURE
Definition: StatusCode.h:86
A DataObject is the base class of any identifiable object on any data store.
Definition: DataObject.h:30
GAUDI_API Gaudi::Details::PropertyBase * getProperty(const IProperty *p, const std::string &name)
simple function which gets the property with given name from the component
Definition: Property.cpp:204