The Gaudi Framework  master (82fdf313)
Loading...
Searching...
No Matches
Helpers.cpp
Go to the documentation of this file.
1/***********************************************************************************\
2* (c) Copyright 1998-2024 CERN for the benefit of the LHCb and ATLAS collaborations *
3* *
4* This software is distributed under the terms of the Apache version 2 licence, *
5* copied verbatim in the file "LICENSE". *
6* *
7* In applying this licence, CERN does not waive the privileges and immunities *
8* granted to it by virtue of its status as an Intergovernmental Organization *
9* or submit itself to any jurisdiction. *
10\***********************************************************************************/
11// Python must always be the first.
12#include <Python.h>
13// ============================================================================
14// GaudiKernel
15// ============================================================================
16#include <Gaudi/Property.h>
24#include <GaudiKernel/SmartIF.h>
25// ============================================================================
26// GaudiPython
27// ============================================================================
28#include <GaudiPython/Helpers.h>
29// ============================================================================
38// ============================================================================
39/* Simple wrapper for IDataProviderSvc::findObject
40 * The method does NOT trigger the loading
41 * the object from tape or Data-On-Demand action
42 * @see IDataProviderSvc
43 * @see IDataProviderSvc::findObject
44 * @param dpsvc (INPUT) pointer to Data Provider Service
45 * @param oath full path in TES
46 * @return the object
47 * @author Vanya BELYAEV Ivan.Belyaev@nikhef.nl
48 * @date 2009-10-09
49 */
50// ===========================================================================
51DataObject* GaudiPython::Helper::findobject( IDataProviderSvc* dpsvc, const std::string& path ) {
52 DataObject* o = nullptr;
53 if ( !dpsvc ) { return nullptr; } // RETURN
54 StatusCode sc = dpsvc->findObject( path, o ); // NB!
55 return sc.isSuccess() ? o : nullptr; // RETURN
56}
57// ===========================================================================
59namespace {
60 // ==========================================================================
64 const std::string s_NAME = "EnableFaultHandler";
65 // ======================================================================
66 class Disabler {
67 public:
68 // =========================================================================
70 Disabler( IInterface* svc, bool disable ) : m_svc( svc ), m_old( s_NAME, true ), m_enable( !disable ) {
71 if ( !m_svc ) {
72 m_code = StatusCode::FAILURE;
73 } else if ( m_enable ) { /* no action here!! */
74 ;
75 } // No action!
76 else {
77 const Gaudi::Details::PropertyBase* property = Gaudi::Utils::getProperty( m_svc.get(), s_NAME );
78 if ( !property || !m_old.assign( *property ) ) {
79 m_code = StatusCode::FAILURE;
80 } else if ( m_old.value() != m_enable ) {
81 m_code = Gaudi::Utils::setProperty( m_svc.get(), s_NAME, m_enable );
82 }
83 }
84 }
85 // =========================================================================
87 ~Disabler() {
88 if ( m_enable ) { /* no action here! */
89 } // no action here
90 else if ( code().isSuccess() && m_old.value() != m_enable ) {
91 m_code = Gaudi::Utils::setProperty( m_svc.get(), s_NAME, m_old );
92 }
93 m_code.ignore();
94 }
95 // ========================================================================
96 StatusCode code() const { return m_enable ? StatusCode::SUCCESS : m_code; }
97 // ========================================================================
98 private:
99 // ========================================================================
101 SmartIF<IProperty> m_svc; // the property interface
102 Gaudi::Property<bool> m_old = { s_NAME, true };
103 bool m_enable;
104 StatusCode m_code = StatusCode::SUCCESS; // status code
105 // ========================================================================
106 };
107 // ==========================================================================
108} // end of anonymous namespace
109// ===========================================================================
110/* the generic function to get object from TES
111 * @see IDataProviderSvc
112 * @see IDataProviderSvc::findObject
113 * @see IDataProviderSvc::retriveObject
114 * @param dpsvc (INPUT) pointer to Data Provider Service
115 * @author Vanya BELYAEV Ivan.Belyaev@nikhef.nl
116 * @date 2009-10-09
117 */
118// ===========================================================================
119DataObject* GaudiPython::Helper::getobject( IDataProviderSvc* dpsvc, const std::string& path, const bool retrieve,
120 const bool disable ) {
121 if ( !dpsvc ) { return nullptr; } // 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// ============================================================================
Data provider interface definition.
virtual StatusCode retrieveObject(IRegistry *pDirectory, std::string_view path, DataObject *&pObject)=0
Retrieve object identified by its directory entry.
virtual StatusCode findObject(IRegistry *pDirectory, std::string_view path, DataObject *&pObject)=0
Find object identified by its directory entry.
Definition of the basic interface.
Definition IInterface.h:225
This class is used for returning status codes from appropriate routines.
Definition StatusCode.h:64
bool isSuccess() const
Definition StatusCode.h:314
constexpr static const auto SUCCESS
Definition StatusCode.h:99
constexpr static const auto FAILURE
Definition StatusCode.h:100
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:891
GAUDI_API Gaudi::Details::PropertyBase * getProperty(const IProperty *p, std::string_view name)
simple function which gets the property with given name from the component
Definition Property.cpp:191
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:119
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:51