All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups 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/Property.h"
8 #include "GaudiKernel/SmartIF.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 = 0 ;
46  if ( 0 == dpsvc ) { return 0 ; } // RETURN
47  StatusCode sc = dpsvc -> findObject ( path , o ) ; // NB!
48  if ( sc.isFailure() ) { return 0 ; } // RETURN
49  return o ; // RETURN
50 }
51 // ===========================================================================
53 namespace
54 {
55  // ==========================================================================
59  const std::string s_NAME = "EnableFaultHandler" ;
60  // ======================================================================
61  class Disabler
62  {
63  public:
64  // =========================================================================
66  Disabler ( IInterface* svc ,
67  const bool disable )
68  : m_svc ( svc )
69  , m_old ( s_NAME , true )
70  , m_enable ( !disable )
71  , m_code ( StatusCode::SUCCESS )
72  {
73  if ( !m_svc ) { m_code = StatusCode::FAILURE ; }
74  else if ( m_enable ) { /* no action here!! */ ; } // No action!
75  else
76  {
77  const Property* property =
78  Gaudi::Utils::getProperty ( m_svc.get() , s_NAME ) ;
79  if ( 0 == property || !m_old.assign ( *property ) )
80  { m_code = StatusCode::FAILURE ; }
81  else if ( m_old.value() != m_enable )
82  {
84  ( m_svc.get() , s_NAME , m_enable ) ;
85  }
86  }
87  }
88  // =========================================================================
90  ~Disabler()
91  {
92  if ( m_enable ) { /* no action here! */ } // no action here
93  else if ( code().isSuccess() && m_old.value() != m_enable ) {
94  // This line results in an ambiguous overload resolution on g++ 3.4
95  // m_code = Gaudi::Utils::setProperty ( m_svc.get() , s_NAME , m_old );
96  // The problem is that m_old could be any of:
97  // - const TYPE &
98  // - const Property &
99  // - const SimpleProperty<TYPE, BoundedVerifier<TYPE> >&
100  // So we force the the template argument to help the compiler
101  m_code = Gaudi::Utils::setProperty<bool>(m_svc.get(), s_NAME, m_old);
102  }
103  m_code.ignore() ;
104  }
105  // ========================================================================
106  StatusCode code () const
107  {
108  if ( m_enable ) { return StatusCode::SUCCESS ; }
109  return m_code ;
110  }
111  // ========================================================================
112  private:
113  // ========================================================================
115  SmartIF<IProperty> m_svc ; // the property interface
116  BooleanProperty m_old ;
117  bool m_enable ;
118  StatusCode m_code ; // status code
119  // ========================================================================
120  } ;
121  // ==========================================================================
122 } // end of anonymous namespace
123 // ===========================================================================
124 /* the generic function to get object from TES
125  * @see IDataProviderSvc
126  * @see IDataProviderSvc::findObject
127  * @see IDataProviderSvc::retriveObject
128  * @param dpsvc (INPUT) pointer to Data Provider Service
129  * @author Vanya BELYAEV Ivan.Belyaev@nikhef.nl
130  * @date 2009-10-09
131  */
132 // ===========================================================================
135  const std::string& path ,
136  const bool retrieve ,
137  const bool disable )
138 {
139  if ( 0 == dpsvc ) { return 0 ; } // RETURN 0
140  // create the sentry:
141  Disabler sentry ( dpsvc , disable ) ;
142  //
143  DataObject * result = 0 ;
144  //
145  StatusCode sc =
146  retrieve ?
147  dpsvc -> retrieveObject ( path , result ) :
148  dpsvc -> findObject ( path , result ) ;
149  //
150  if ( sc.isFailure() ) { return 0 ; } // RETURN
151  //
152  return result ; // RETURN
153 }
154 // ============================================================================
155 // The END
156 // ============================================================================
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:1212
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
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:349
Data provider interface definition.
bool isFailure() const
Test for a status code of FAILURE.
Definition: StatusCode.h:85
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:30
Definition of the basic interface.
Definition: IInterface.h:160
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:134
GAUDI_API std::string path(const AIDA::IBaseHistogram *aida)
get the path in THS for AIDA histogram
Property base class allowing Property* collections to be "homogeneous".
Definition: Property.h:43
void ignore() const
Definition: StatusCode.h:107
A DataObject is the base class of any identifiable object on any data store.
Definition: DataObject.h:31