Loading [MathJax]/extensions/tex2jax.js
The Gaudi Framework  v29r5 (37229091)
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
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 {
43  DataObject* o = nullptr;
44  if ( !dpsvc ) {
45  return nullptr;
46  } // RETURN
47  StatusCode sc = dpsvc->findObject( path, o ); // NB!
48  return sc.isSuccess() ? o : nullptr; // RETURN
49 }
50 // ===========================================================================
52 namespace
53 {
54  // ==========================================================================
58  const std::string s_NAME = "EnableFaultHandler";
59  // ======================================================================
60  class Disabler
61  {
62  public:
63  // =========================================================================
65  Disabler( IInterface* svc, bool disable ) : m_svc( svc ), m_old( s_NAME, true ), m_enable( !disable )
66  {
67  if ( !m_svc ) {
68  m_code = StatusCode::FAILURE;
69  } else if ( m_enable ) { /* no action here!! */
70  ;
71  } // No action!
72  else {
73  const Gaudi::Details::PropertyBase* property = Gaudi::Utils::getProperty( m_svc.get(), s_NAME );
74  if ( !property || !m_old.assign( *property ) ) {
75  m_code = StatusCode::FAILURE;
76  } else if ( m_old.value() != m_enable ) {
77  m_code = Gaudi::Utils::setProperty( m_svc.get(), s_NAME, m_enable );
78  }
79  }
80  }
81  // =========================================================================
83  ~Disabler()
84  {
85  if ( m_enable ) { /* no action here! */
86  } // no action here
87  else if ( code().isSuccess() && m_old.value() != m_enable ) {
88  m_code = Gaudi::Utils::setProperty( m_svc.get(), s_NAME, m_old );
89  }
90  m_code.ignore();
91  }
92  // ========================================================================
93  StatusCode code() const { return m_enable ? StatusCode::SUCCESS : m_code; }
94  // ========================================================================
95  private:
96  // ========================================================================
98  SmartIF<IProperty> m_svc; // the property interface
99  Gaudi::Property<bool> m_old = {s_NAME, true};
100  bool m_enable;
101  StatusCode m_code = StatusCode::SUCCESS; // status code
102  // ========================================================================
103  };
104  // ==========================================================================
105 } // end of anonymous namespace
106 // ===========================================================================
107 /* the generic function to get object from TES
108  * @see IDataProviderSvc
109  * @see IDataProviderSvc::findObject
110  * @see IDataProviderSvc::retriveObject
111  * @param dpsvc (INPUT) pointer to Data Provider Service
112  * @author Vanya BELYAEV Ivan.Belyaev@nikhef.nl
113  * @date 2009-10-09
114  */
115 // ===========================================================================
117  const bool disable )
118 {
119  if ( !dpsvc ) {
120  return nullptr;
121  } // RETURN 0
122  // create the sentry:
123  Disabler sentry( dpsvc, disable );
124  //
125  DataObject* result = nullptr;
126  //
127  StatusCode sc = retrieve ? dpsvc->retrieveObject( path, result ) : dpsvc->findObject( path, result );
128  //
129  return sc.isSuccess() ? result : nullptr;
130 }
131 // ============================================================================
132 // The END
133 // ============================================================================
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:1173
Implementation of property with value of concrete type.
Definition: Property.h:319
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
bool isSuccess() const
Test for a status code of SUCCESS.
Definition: StatusCode.h:50
Gaudi::Details::PropertyBase * property(const std::string &name) const
Data provider interface definition.
STL class.
virtual StatusCode findObject(IRegistry *pDirectory, const std::string &path, DataObject *&pObject)=0
Find object identified by its directory entry.
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:26
Definition of the basic interface.
Definition: IInterface.h:277
PropertyBase base class allowing PropertyBase* collections to be "homogeneous".
Definition: Property.h:32
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:116
void ignore() const
Definition: StatusCode.h:84
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:223
virtual StatusCode retrieveObject(IRegistry *pDirectory, const std::string &path, DataObject *&pObject)=0
Retrieve object identified by its directory entry.