The Gaudi Framework  master (37c0b60a)
GaudiPython::Helper Struct Reference

#include </builds/gaudi/Gaudi/GaudiPython/include/GaudiPython/Helpers.h>

Public Member Functions

 Helper ()
 

Static Public Member Functions

static IServiceservice (ISvcLocator *svcloc, const std::string &name, bool createif=false)
 
static IAlgorithmalgorithm (IAlgManager *algmgr, const std::string &name, const bool createIf=false)
 
static DataObjectdataobject (IDataProviderSvc *dpsvc, const std::string &path)
 
static StatusCode registerObject (IDataProviderSvc *dpsvc, const std::string &path, DataObject *pObject)
 
static StatusCode unregisterObject (IDataProviderSvc *dpsvc, const std::string &path)
 
static GAUDI_API DataObjectfindobject (IDataProviderSvc *dpsvc, const std::string &path)
 simple wrapper for IDataProviderSvc::findObject The methdod does NOT trigger the loading the object from tape or Data-On-Demand action More...
 
static GAUDI_API DataObjectgetobject (IDataProviderSvc *dpsvc, const std::string &path, const bool retrieve=true, const bool disableDoD=false)
 the generic function to get object from TES More...
 
static IAlgTooltool (IToolSvc *toolsvc, const std::string &type, const std::string &name, IInterface *p, bool cif)
 
static long loadDynamicLib (const std::string &name)
 
static IHistogram1D * histo1D (IHistogramSvc *hsvc, const std::string &path)
 
static IHistogram2D * histo2D (IHistogramSvc *hsvc, const std::string &path)
 
static IHistogram3D * histo3D (IHistogramSvc *hsvc, const std::string &path)
 
static IProfile1D * profile1D (IHistogramSvc *hsvc, const std::string &path)
 
static IProfile2D * profile2D (IHistogramSvc *hsvc, const std::string &path)
 
template<class T >
static PyObject * toArray (T *ptr, Py_ssize_t size)
 
static PyObject * toIntArray (void *ptr, Py_ssize_t size)
 
static PyObject * toShortArray (void *ptr, Py_ssize_t size)
 
static PyObject * toFloatArray (void *ptr, Py_ssize_t size)
 
static PyObject * toDoubleArray (void *ptr, Py_ssize_t size)
 
template<class T >
static T * toAddress (std::vector< T > &v)
 
template<class T >
static T * toAddress (void *a)
 

Static Private Member Functions

template<class T >
static Py_ssize_t Array_length (PyObject *self)
 
template<class T >
static PyObject * toPython (T *)
 
static PyObject * toPython (int *o)
 
static PyObject * toPython (short *o)
 
static PyObject * toPython (char *o)
 
static PyObject * toPython (long *o)
 
static PyObject * toPython (float *o)
 
static PyObject * toPython (double *o)
 
template<class T >
static PyObject * Array_item (PyObject *self, Py_ssize_t idx)
 

Detailed Description

Definition at line 69 of file Helpers.h.

Constructor & Destructor Documentation

◆ Helper()

GaudiPython::Helper::Helper ( )
inline

Definition at line 104 of file Helpers.h.

104 {}

Member Function Documentation

◆ algorithm()

static IAlgorithm* GaudiPython::Helper::algorithm ( IAlgManager algmgr,
const std::string name,
const bool  createIf = false 
)
inlinestatic

Definition at line 110 of file Helpers.h.

110  {
111  return algmgr->algorithm( name, createIf ).get();
112  }

◆ Array_item()

template<class T >
static PyObject* GaudiPython::Helper::Array_item ( PyObject *  self,
Py_ssize_t  idx 
)
inlinestaticprivate

Definition at line 213 of file Helpers.h.

213  {
214 #if PY_VERSION_HEX < 0x02050000
215  const
216 #endif
217  char* buf = nullptr;
218 #if PY_MAJOR_VERSION >= 3
219  Py_buffer bufinfo;
220  ( *( self->ob_type->tp_as_buffer->bf_getbuffer ) )( self, &bufinfo, PyBUF_SIMPLE );
221  Py_ssize_t size = bufinfo.len;
222 #else
223  Py_ssize_t size = ( *( self->ob_type->tp_as_buffer->bf_getcharbuffer ) )( self, 0, &buf );
224 #endif
225  if ( idx < 0 || idx >= size / int( sizeof( T ) ) ) {
226  PyErr_SetString( PyExc_IndexError, "buffer index out of range" );
227  return nullptr;
228  }
229  return toPython( (T*)buf + idx );
230  }

◆ Array_length()

template<class T >
static Py_ssize_t GaudiPython::Helper::Array_length ( PyObject *  self)
inlinestaticprivate

Definition at line 186 of file Helpers.h.

186  {
187 #if PY_MAJOR_VERSION >= 3
188  Py_buffer bufinfo;
189  ( *( self->ob_type->tp_as_buffer->bf_getbuffer ) )( self, &bufinfo, PyBUF_SIMPLE );
190  Py_ssize_t size = bufinfo.len;
191 #else
192 # if PY_VERSION_HEX < 0x02050000
193  const
194 # endif
195  char* buf = 0;
196  Py_ssize_t size = ( *( self->ob_type->tp_as_buffer->bf_getcharbuffer ) )( self, 0, &buf );
197 #endif
198  return size / sizeof( T );
199  }

◆ dataobject()

static DataObject* GaudiPython::Helper::dataobject ( IDataProviderSvc dpsvc,
const std::string path 
)
inlinestatic

Definition at line 114 of file Helpers.h.

114  {
115  DataObject* o;
116  return dpsvc->retrieveObject( path, o ).isSuccess() ? o : nullptr;
117  }

◆ findobject()

DataObject * GaudiPython::Helper::findobject ( IDataProviderSvc dpsvc,
const std::string path 
)
static

simple wrapper for IDataProviderSvc::findObject The methdod does NOT trigger the loading the object from tape or Data-On-Demand action

See also
IDataProviderSvc
IDataProviderSvc::findObject
Parameters
psvc(INPUT) pointer to Data ProviderService
paththe full path in TES
Returns
the object
Author
Vanya BELYAEV Ivan..nosp@m.Bely.nosp@m.aev@n.nosp@m.ikhe.nosp@m.f.nl
Date
2009-10-09

Definition at line 51 of file Helpers.cpp.

51  {
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 }

◆ getobject()

DataObject * GaudiPython::Helper::getobject ( IDataProviderSvc dpsvc,
const std::string path,
const bool  retrieve = true,
const bool  disableDoD = false 
)
static

the generic function to get object from TES

See also
IDataProviderSvc
IDataProviderSvc::findObject
IDataProviderSvc::retriveObject
Parameters
psvc(INPUT) pointer to Data ProviderService
paththe full path in TES
rerieve(INPUT) retrieve or find object ?
disableDoD(INPUT) disable 'on-demand-actions' ?
Author
Vanya BELYAEV Ivan..nosp@m.Bely.nosp@m.aev@n.nosp@m.ikhe.nosp@m.f.nl
Date
2009-10-09

Definition at line 119 of file Helpers.cpp.

120  {
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 }

◆ histo1D()

static IHistogram1D* GaudiPython::Helper::histo1D ( IHistogramSvc hsvc,
const std::string path 
)
inlinestatic

Definition at line 162 of file Helpers.h.

162  {
163  IHistogram1D* h;
164  return ( hsvc->findObject( path, h ).isSuccess() ) ? h : nullptr;
165  }

◆ histo2D()

static IHistogram2D* GaudiPython::Helper::histo2D ( IHistogramSvc hsvc,
const std::string path 
)
inlinestatic

Definition at line 166 of file Helpers.h.

166  {
167  IHistogram2D* h;
168  return ( hsvc->findObject( path, h ).isSuccess() ) ? h : nullptr;
169  }

◆ histo3D()

static IHistogram3D* GaudiPython::Helper::histo3D ( IHistogramSvc hsvc,
const std::string path 
)
inlinestatic

Definition at line 170 of file Helpers.h.

170  {
171  IHistogram3D* h;
172  return ( hsvc->findObject( path, h ).isSuccess() ) ? h : nullptr;
173  }

◆ loadDynamicLib()

static long GaudiPython::Helper::loadDynamicLib ( const std::string name)
inlinestatic

Definition at line 158 of file Helpers.h.

158  {
159  void* h;
160  return System::loadDynamicLib( name, &h );
161  }

◆ profile1D()

static IProfile1D* GaudiPython::Helper::profile1D ( IHistogramSvc hsvc,
const std::string path 
)
inlinestatic

Definition at line 174 of file Helpers.h.

174  {
175  IProfile1D* h = 0;
176  return ( hsvc && hsvc->findObject( path, h ).isSuccess() ) ? h : nullptr;
177  }

◆ profile2D()

static IProfile2D* GaudiPython::Helper::profile2D ( IHistogramSvc hsvc,
const std::string path 
)
inlinestatic

Definition at line 178 of file Helpers.h.

178  {
179  IProfile2D* h = 0;
180  return ( hsvc && hsvc->findObject( path, h ).isSuccess() ) ? h : nullptr;
181  }

◆ registerObject()

static StatusCode GaudiPython::Helper::registerObject ( IDataProviderSvc dpsvc,
const std::string path,
DataObject pObject 
)
inlinestatic

Definition at line 119 of file Helpers.h.

119  {
120  return dpsvc->registerObject( path, pObject );
121  }

◆ service()

static IService* GaudiPython::Helper::service ( ISvcLocator svcloc,
const std::string name,
bool  createif = false 
)
inlinestatic

Definition at line 106 of file Helpers.h.

106  {
107  return svcloc->service( name, createif ).get();
108  }

◆ toAddress() [1/2]

template<class T >
static T* GaudiPython::Helper::toAddress ( std::vector< T > &  v)
inlinestatic

Definition at line 256 of file Helpers.h.

256  {
257  return v.data();
258  }

◆ toAddress() [2/2]

template<class T >
static T* GaudiPython::Helper::toAddress ( void *  a)
inlinestatic

Definition at line 260 of file Helpers.h.

260  {
261  return (T*)a;
262  }

◆ toArray()

template<class T >
template PyObject * GaudiPython::Helper::toArray ( T *  ptr,
Py_ssize_t  size 
)
inlinestatic

Definition at line 234 of file Helpers.h.

234  {
235  static PyTypeObject type = PyBuffer_Type;
236  static PySequenceMethods meth = *( PyBuffer_Type.tp_as_sequence );
237 #if PY_VERSION_HEX < 0x02050000
238  meth.sq_item = (intargfunc)&Array_item<T>;
239  meth.sq_length = (inquiry)&Array_length<T>;
240 #else
241  meth.sq_item = (ssizeargfunc)&Array_item<T>;
242  meth.sq_length = (lenfunc)&Array_length<T>;
243 #endif
244  type.tp_as_sequence = &meth;
245  PyObject* buf = PyBuffer_FromReadWriteMemory( ptr, size * sizeof( T ) );
246  buf->ob_type = &type;
247  Py_INCREF( buf->ob_type );
248  return buf;
249  }

◆ toDoubleArray()

static PyObject* GaudiPython::Helper::toDoubleArray ( void *  ptr,
Py_ssize_t  size 
)
inlinestatic

Definition at line 253 of file Helpers.h.

253 { return toArray( (double*)ptr, size ); }

◆ toFloatArray()

static PyObject* GaudiPython::Helper::toFloatArray ( void *  ptr,
Py_ssize_t  size 
)
inlinestatic

Definition at line 252 of file Helpers.h.

252 { return toArray( (float*)ptr, size ); }

◆ toIntArray()

static PyObject* GaudiPython::Helper::toIntArray ( void *  ptr,
Py_ssize_t  size 
)
inlinestatic

Definition at line 250 of file Helpers.h.

250 { return toArray( (int*)ptr, size ); }

◆ tool()

static IAlgTool* GaudiPython::Helper::tool ( IToolSvc toolsvc,
const std::string type,
const std::string name,
IInterface p,
bool  cif 
)
inlinestatic

Definition at line 153 of file Helpers.h.

154  {
155  IAlgTool* o;
156  return toolsvc->retrieve( type, name, IAlgTool::interfaceID(), o, p, cif ).isSuccess() ? o : nullptr;
157  }

◆ toPython() [1/7]

static PyObject* GaudiPython::Helper::toPython ( char *  o)
inlinestaticprivate

Definition at line 207 of file Helpers.h.

207 { return PyInt_FromLong( (long)*o ); }

◆ toPython() [2/7]

static PyObject* GaudiPython::Helper::toPython ( double *  o)
inlinestaticprivate

Definition at line 210 of file Helpers.h.

210 { return PyFloat_FromDouble( *o ); }

◆ toPython() [3/7]

static PyObject* GaudiPython::Helper::toPython ( float *  o)
inlinestaticprivate

Definition at line 209 of file Helpers.h.

209 { return PyFloat_FromDouble( (double)*o ); }

◆ toPython() [4/7]

static PyObject* GaudiPython::Helper::toPython ( int *  o)
inlinestaticprivate

Definition at line 205 of file Helpers.h.

205 { return PyInt_FromLong( (long)*o ); }

◆ toPython() [5/7]

static PyObject* GaudiPython::Helper::toPython ( long *  o)
inlinestaticprivate

Definition at line 208 of file Helpers.h.

208 { return PyInt_FromLong( *o ); }

◆ toPython() [6/7]

static PyObject* GaudiPython::Helper::toPython ( short *  o)
inlinestaticprivate

Definition at line 206 of file Helpers.h.

206 { return PyInt_FromLong( (long)*o ); }

◆ toPython() [7/7]

template<class T >
static PyObject* GaudiPython::Helper::toPython ( T *  )
inlinestaticprivate

Definition at line 202 of file Helpers.h.

202  {
203  return 0;
204  }

◆ toShortArray()

static PyObject* GaudiPython::Helper::toShortArray ( void *  ptr,
Py_ssize_t  size 
)
inlinestatic

Definition at line 251 of file Helpers.h.

251 { return toArray( (short*)ptr, size ); }

◆ unregisterObject()

static StatusCode GaudiPython::Helper::unregisterObject ( IDataProviderSvc dpsvc,
const std::string path 
)
inlinestatic

Definition at line 123 of file Helpers.h.

123  {
124  return dpsvc->unregisterObject( path );
125  }

The documentation for this struct was generated from the following files:
System::loadDynamicLib
GAUDI_API unsigned long loadDynamicLib(const std::string &name, ImageHandle *handle)
Load dynamic link library.
Definition: System.cpp:150
IDataProviderSvc::unregisterObject
virtual StatusCode unregisterObject(std::string_view fullPath)=0
Unregister object from the data store.
Py_ssize_t
int Py_ssize_t
For compatibility with Python 2.4 and 2.5.
Definition: Helpers.h:53
IAlgTool
Definition: IAlgTool.h:33
details::size
constexpr auto size(const T &, Args &&...) noexcept
Definition: AnyDataWrapper.h:23
AtlasMCRecoFullPrecedenceDump.path
path
Definition: AtlasMCRecoFullPrecedenceDump.py:49
StatusCode::isSuccess
bool isSuccess() const
Definition: StatusCode.h:314
IHistogramSvc::findObject
virtual StatusCode findObject(const std::string &fullPath, AIDA::IHistogram1D *&h1dObj)=0
GaudiPython::Helper::toPython
static PyObject * toPython(T *)
Definition: Helpers.h:202
GaudiPython::Helper::toArray
static PyObject * toArray(T *ptr, Py_ssize_t size)
Definition: Helpers.h:234
IDataProviderSvc::registerObject
StatusCode registerObject(std::string_view fullPath, DataObject *pObject)
Register object with the data store.
Definition: IDataProviderSvc.h:72
IAlgManager::algorithm
virtual SmartIF< IAlgorithm > & algorithm(const Gaudi::Utils::TypeNameString &typeName, const bool createIf=true)=0
Returns a smart pointer to a service.
StatusCode
Definition: StatusCode.h:65
IInterface::interfaceID
static const InterfaceID & interfaceID()
Return an instance of InterfaceID identifying the interface.
Definition: IInterface.h:248
IDataProviderSvc::retrieveObject
virtual StatusCode retrieveObject(IRegistry *pDirectory, std::string_view path, DataObject *&pObject)=0
Retrieve object identified by its directory entry.
AlgSequencer.h
h
Definition: AlgSequencer.py:31
ISvcLocator::service
StatusCode service(const Gaudi::Utils::TypeNameString &name, T *&svc, bool createIf=true)
Templated method to access a service by name.
Definition: ISvcLocator.h:98
IToolSvc::retrieve
virtual StatusCode retrieve(std::string_view type, const InterfaceID &iid, IAlgTool *&tool, const IInterface *parent=0, bool createIf=true)=0
Retrieve tool with tool dependent part of the name automatically assigned.
SmartRefVectorImpl::PyObject
_object PyObject
Definition: SmartRefVector.h:32
gaudirun.type
type
Definition: gaudirun.py:160
ConditionsStallTest.name
name
Definition: ConditionsStallTest.py:77
SmartIF::get
TYPE * get() const
Get interface pointer.
Definition: SmartIF.h:86
DataObject
Definition: DataObject.h:36
Properties.v
v
Definition: Properties.py:122
IDataProviderSvc::findObject
virtual StatusCode findObject(IRegistry *pDirectory, std::string_view path, DataObject *&pObject)=0
Find object identified by its directory entry.