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 // ============================================================================
6 #include "GaudiKernel/IProperty.h"
7 #include "GaudiKernel/Property.h"
8 #include "GaudiKernel/SmartIF.h"
9 #include "GaudiKernel/ISvcLocator.h"
10 #include "GaudiKernel/IHistogramSvc.h"
11 #include "GaudiKernel/IDataProviderSvc.h"
12 #include "GaudiKernel/IAlgTool.h"
13 #include "GaudiKernel/IToolSvc.h"
14 #include "GaudiKernel/DataObject.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 ( IDataProviderSvc* dpsvc ,
43  const std::string& path )
44 {
45  DataObject* o = nullptr ;
46  if ( !dpsvc ) { return nullptr ; } // 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 ,
66  bool disable )
67  : m_svc ( svc )
68  , m_old ( s_NAME , true )
69  , m_enable ( !disable )
70  {
71  if ( !m_svc ) { m_code = StatusCode::FAILURE ; }
72  else if ( m_enable ) { /* no action here!! */ ; } // No action!
73  else
74  {
75  const Property* property =
76  Gaudi::Utils::getProperty ( m_svc.get() , s_NAME ) ;
77  if ( !property || !m_old.assign ( *property ) )
78  { m_code = StatusCode::FAILURE ; }
79  else if ( m_old.value() != m_enable )
80  {
82  ( m_svc.get() , s_NAME , m_enable ) ;
83  }
84  }
85  }
86  // =========================================================================
88  ~Disabler()
89  {
90  if ( m_enable ) { /* no action here! */ } // no action here
91  else if ( code().isSuccess() && m_old.value() != m_enable ) {
92  m_code = Gaudi::Utils::setProperty(m_svc.get(), s_NAME, m_old);
93  }
94  m_code.ignore() ;
95  }
96  // ========================================================================
97  StatusCode code () const
98  {
99  return m_enable ? StatusCode::SUCCESS : m_code ;
100  }
101  // ========================================================================
102  private:
103  // ========================================================================
105  SmartIF<IProperty> m_svc ; // the property interface
106  BooleanProperty m_old = { s_NAME, true } ;
107  bool m_enable ;
108  StatusCode m_code = StatusCode::SUCCESS ; // status code
109  // ========================================================================
110  } ;
111  // ==========================================================================
112 } // end of anonymous namespace
113 // ===========================================================================
114 /* the generic function to get object from TES
115  * @see IDataProviderSvc
116  * @see IDataProviderSvc::findObject
117  * @see IDataProviderSvc::retriveObject
118  * @param dpsvc (INPUT) pointer to Data Provider Service
119  * @author Vanya BELYAEV Ivan.Belyaev@nikhef.nl
120  * @date 2009-10-09
121  */
122 // ===========================================================================
125  const std::string& path ,
126  const bool retrieve ,
127  const bool disable )
128 {
129  if ( !dpsvc ) { return nullptr ; } // RETURN 0
130  // create the sentry:
131  Disabler sentry ( dpsvc , disable ) ;
132  //
133  DataObject * result = nullptr ;
134  //
135  StatusCode sc =
136  retrieve ?
137  dpsvc -> retrieveObject ( path , result ) :
138  dpsvc -> findObject ( path , result ) ;
139  //
140  return sc.isSuccess() ? result : nullptr ;
141 }
142 // ============================================================================
143 // The END
144 // ============================================================================
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:1187
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:42
bool isSuccess() const
Test for a status code of SUCCESS.
Definition: StatusCode.h:76
list path
Definition: __init__.py:15
Data provider interface definition.
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:26
Definition of the basic interface.
Definition: IInterface.h:234
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:124
GAUDI_API Property * getProperty(const IProperty *p, const std::string &name)
simple function which gets the property with given name from the component
Definition: Property.cpp:278
Property base class allowing Property* collections to be "homogeneous".
Definition: Property.h:38
void ignore() const
Definition: StatusCode.h:108
A DataObject is the base class of any identifiable object on any data store.
Definition: DataObject.h:30