| The Gaudi Framework v30r0 (c919700c)

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

Helpers.cpp
Go to the documentation of this file.
1 // Python must always be the first.
2 #include "Python.h"
3 // ============================================================================
4 // GaudiKernel
5 // ============================================================================
6 #include "GaudiKernel/DataObject.h"
7 #include "GaudiKernel/IAlgTool.h"
8 #include "GaudiKernel/IDataProviderSvc.h"
9 #include "GaudiKernel/IHistogramSvc.h"
10 #include "GaudiKernel/IProperty.h"
11 #include "GaudiKernel/ISvcLocator.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 // ===========================================================================
41 DataObject* GaudiPython::Helper::findobject( IDataProviderSvc* dpsvc, const std::string& path )
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 // ===========================================================================
116 DataObject* GaudiPython::Helper::getobject( IDataProviderSvc* dpsvc, const std::string& path, const bool retrieve,
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 // ============================================================================
Gaudi::Utils::setProperty
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:1172
StatusCode::SUCCESS
Definition: StatusCode.h:29
SmartIF< IProperty >
GaudiPython.HistoUtils.path
path
Definition: HistoUtils.py:895
Gaudi::Property
Implementation of property with value of concrete type.
Definition: Property.h:319
GaudiPython::Helper::findobject
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
Gaudi::Details::PropertyBase::assign
virtual bool assign(const PropertyBase &source)=0
import the property value form the source
IDataProviderSvc::findObject
virtual StatusCode findObject(IRegistry *pDirectory, boost::string_ref path, DataObject *&pObject)=0
Find object identified by its directory entry.
Helpers.h
StatusCode::isSuccess
bool isSuccess() const
Test for a status code of SUCCESS.
Definition: StatusCode.h:50
property
Gaudi::Details::PropertyBase * property(const std::string &name) const
IDataProviderSvc
Data provider interface definition.
Definition: IDataProviderSvc.h:46
IToolSvc.h
std::string
STL class.
IDataProviderSvc.h
StatusCode
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:26
IInterface
Definition of the basic interface.
Definition: IInterface.h:277
SmartIF.h
IAlgTool.h
Gaudi::Details::PropertyBase
PropertyBase base class allowing PropertyBase* collections to be "homogeneous".
Definition: Property.h:32
IDataProviderSvc::retrieveObject
virtual StatusCode retrieveObject(IRegistry *pDirectory, boost::string_ref path, DataObject *&pObject)=0
Retrieve object identified by its directory entry.
GaudiPython::Helper::getobject
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
IProperty.h
Property.h
StatusCode::FAILURE
Definition: StatusCode.h:29
StatusCode::ignore
void ignore() const
Definition: StatusCode.h:84
DataObject
A DataObject is the base class of any identifiable object on any data store.
Definition: DataObject.h:30
ISvcLocator.h
DataObject.h
Gaudi::Utils::getProperty
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
IHistogramSvc.h