| The Gaudi Framework v32r1 (f65d50dc)

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 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 // ===========================================================================
109 DataObject* GaudiPython::Helper::getobject( IDataProviderSvc* dpsvc, const std::string& path, const bool retrieve,
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 // ============================================================================
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:1179
SmartIF< IProperty >
GaudiPython.HistoUtils.path
path
Definition: HistoUtils.py:932
Gaudi::Property
Implementation of property with value of concrete type.
Definition: Property.h:352
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
StatusCode::SUCCESS
constexpr static const auto SUCCESS
Definition: StatusCode.h:85
IDataProviderSvc
Data provider interface definition.
Definition: IDataProviderSvc.h:43
IToolSvc.h
IDataProviderSvc::findObject
virtual StatusCode findObject(IRegistry *pDirectory, std::string_view path, DataObject *&pObject)=0
Find object identified by its directory entry.
Helpers.h
std::string
STL class.
IDataProviderSvc.h
StatusCode
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:50
IInterface
Definition of the basic interface.
Definition: IInterface.h:244
SmartIF.h
IAlgTool.h
Gaudi::Details::PropertyBase
PropertyBase base class allowing PropertyBase* collections to be "homogeneous".
Definition: Property.h:32
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:109
StatusCode::isSuccess
bool isSuccess() const
Definition: StatusCode.h:267
StatusCode::ignore
const StatusCode & ignore() const
Ignore/check StatusCode.
Definition: StatusCode.h:153
IProperty.h
IDataProviderSvc::retrieveObject
virtual StatusCode retrieveObject(IRegistry *pDirectory, std::string_view path, DataObject *&pObject)=0
Retrieve object identified by its directory entry.
Property.h
StatusCode::FAILURE
constexpr static const auto FAILURE
Definition: StatusCode.h:86
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:204
IHistogramSvc.h