Go to the documentation of this file.
11 #ifndef GAUDIPYTHON_HELPERS_H
12 #define GAUDIPYTHON_HELPERS_H
17 #if PY_MAJOR_VERSION >= 3
19 # define PyInt_FromLong PyLong_FromLong
21 # define PyBuffer_Type PyMemoryView_Type
44 #if PY_VERSION_HEX < 0x02050000
71 #if PY_MAJOR_VERSION >= 3
73 static PyObject* PyBuffer_FromReadWriteMemory(
void* ptr,
int size ) {
74 # if PY_VERSION_HEX > 0x03000000
93 # if PY_VERSION_HEX < 0x03030000
98 return PyMemoryView_FromBuffer( &bufinfo );
151 const bool retrieve =
true,
const bool disableDoD =
false );
187 #if PY_MAJOR_VERSION >= 3
189 ( *(
self->ob_type->tp_as_buffer->bf_getbuffer ) )(
self, &bufinfo, PyBUF_SIMPLE );
192 # if PY_VERSION_HEX < 0x02050000
196 Py_ssize_t size = ( *(
self->ob_type->tp_as_buffer->bf_getcharbuffer ) )(
self, 0, &buf );
198 return size /
sizeof( T );
214 #if PY_VERSION_HEX < 0x02050000
218 #if PY_MAJOR_VERSION >= 3
220 ( *(
self->ob_type->tp_as_buffer->bf_getbuffer ) )(
self, &bufinfo, PyBUF_SIMPLE );
223 Py_ssize_t size = ( *(
self->ob_type->tp_as_buffer->bf_getcharbuffer ) )(
self, 0, &buf );
225 if ( idx < 0 || idx >=
size /
int(
sizeof( T ) ) ) {
226 PyErr_SetString( PyExc_IndexError,
"buffer index out of range" );
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>;
241 meth.sq_item = (ssizeargfunc)&Array_item<T>;
242 meth.sq_length = (lenfunc)&Array_length<T>;
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 );
273 template int* Helper::toAddress<int>(
void* );
274 template float* Helper::toAddress<float>(
void* );
275 template double* Helper::toAddress<double>(
void* );
279 #endif // !GAUDIPYTHON_HELPERS_H
static PyObject * toIntArray(void *ptr, Py_ssize_t size)
static PyObject * toPython(short *o)
static PyObject * toPython(float *o)
static DataObject * dataobject(IDataProviderSvc *dpsvc, const std::string &path)
GAUDI_API unsigned long loadDynamicLib(const std::string &name, ImageHandle *handle)
Load dynamic link library.
virtual StatusCode unregisterObject(std::string_view fullPath)=0
Unregister object from the data store.
int Py_ssize_t
For compatibility with Python 2.4 and 2.5.
constexpr auto size(const T &, Args &&...) noexcept
static PyObject * toDoubleArray(void *ptr, Py_ssize_t size)
virtual StatusCode findObject(const std::string &fullPath, AIDA::IHistogram1D *&h1dObj)=0
static PyObject * toPython(char *o)
static PyObject * toPython(T *)
static IAlgTool * tool(IToolSvc *toolsvc, const std::string &type, const std::string &name, IInterface *p, bool cif)
static StatusCode registerObject(IDataProviderSvc *dpsvc, const std::string &path, DataObject *pObject)
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
static PyObject * toPython(int *o)
static PyObject * toArray(T *ptr, Py_ssize_t size)
static PyObject * Array_item(PyObject *self, Py_ssize_t idx)
static IHistogram3D * histo3D(IHistogramSvc *hsvc, const std::string &path)
StatusCode registerObject(std::string_view fullPath, DataObject *pObject)
Register object with the data store.
static T * toAddress(std::vector< T > &v)
static T * toAddress(void *a)
virtual SmartIF< IAlgorithm > & algorithm(const Gaudi::Utils::TypeNameString &typeName, const bool createIf=true)=0
Returns a smart pointer to a service.
static PyObject * toPython(long *o)
static const InterfaceID & interfaceID()
Return an instance of InterfaceID identifying the interface.
virtual StatusCode retrieveObject(IRegistry *pDirectory, std::string_view path, DataObject *&pObject)=0
Retrieve object identified by its directory entry.
StatusCode service(const Gaudi::Utils::TypeNameString &name, T *&svc, bool createIf=true)
Templated method to access a service by name.
static IHistogram1D * histo1D(IHistogramSvc *hsvc, const std::string &path)
static long loadDynamicLib(const std::string &name)
static PyObject * toPython(double *o)
static PyObject * toShortArray(void *ptr, Py_ssize_t size)
static IService * service(ISvcLocator *svcloc, const std::string &name, bool createif=false)
static Py_ssize_t Array_length(PyObject *self)
TYPE * get() const
Get interface pointer.
static IProfile2D * profile2D(IHistogramSvc *hsvc, const std::string &path)
Namespace for all classes interfacing Gaudi to Python.
static IAlgorithm * algorithm(IAlgManager *algmgr, const std::string &name, const bool createIf=false)
static PyObject * toFloatArray(void *ptr, Py_ssize_t size)
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...
static IHistogram2D * histo2D(IHistogramSvc *hsvc, const std::string &path)
static IProfile1D * profile1D(IHistogramSvc *hsvc, const std::string &path)
static StatusCode unregisterObject(IDataProviderSvc *dpsvc, const std::string &path)