14#include "GaudiKernel/Bootstrap.h"
15#include "GaudiKernel/DataObject.h"
16#include "GaudiKernel/IClassIDSvc.h"
64 if ( ! PyType_Check( tp ) ) {
65 if ( ! PyUnicode_Check( tp ) )
67 PyErr_SetString( PyExc_TypeError,
68 "contains() argument 1 must be type or class name" );
77 pyname = PyObject_GetAttrString( tp, (
char*)
"__cpp_name__" );
79 pyname = PyObject_GetAttrString( tp, (
char*)
"__name__" );
81 if ( pyname && ! PyUnicode_Check( pyname ) )
83 PyObject* pystr = PyObject_Str( pyname );
90 if ( PyErr_Occurred() )
120 PyErr_SetString( PyExc_RuntimeError,
121 "no store available, is Athena initialized?" );
126 PyObject* pyname = pynameFromType( tp );
134 if (pykey == Py_None) {
138 PyErr_SetString( PyExc_TypeError,
139 "retrieve() argument 2 must be string key" );
149 PyErr_Format( PyExc_NameError,
150 "ID of \"%s\" is unknown", namestr.c_str() );
161 PyErr_Format( PyExc_LookupError,
162 "no py-proxies for (clid=%lu, type=%s, key=%s)",
163 PyLong_AsUnsignedLong(pyclid),
165 (pykey == Py_None) ?
"<None>" : keystr.c_str()
170 _SGPY_MSG(
"retrieved py-proxy [clid=" << PyLong_AsUnsignedLong(pyclid)
171 <<
", type=" << namestr.c_str()
172 <<
", key=" << (pykey == Py_None) ?
"<None>" : keystr.c_str()
178 PyErr_Format( PyExc_LookupError,
179 "no proxies for (clid=%lu, type=%s, key=%s)",
180 PyLong_AsUnsignedLong(pyclid),
182 (pykey == Py_None) ?
"<None>" : keystr.c_str()
187 _SGPY_MSG(
"retrieved cpp-proxy [clid=" << proxy->clID()
188 <<
", key=" << proxy->name() <<
"]");
191 DataObject* dobj = proxy->accessData();
193 PyErr_Format( PyExc_LookupError,
194 "no such object \"%s\"", namestr.c_str() );
198 _SGPY_MSG(
"retrieved dobj [clID=" << dobj->clID()
199 <<
", classID=" << dobj->classID()
200 <<
", name=" << dobj->name() <<
"]");
206 "unexpected kind of DataObject: can not verify final type" );
210 _SGPY_MSG(
"retrieved dbb [clID=" << dbb->clID()
211 <<
", classID=" << dbb->classID()
212 <<
", name=" << dbb->name() <<
"]");
214 CLID id = proxy->clID();
215 CLID realID = dbb->clID();
217 _SGPY_MSG(
"pyid= " << PyLong_AsUnsignedLong(pyclid)
219 <<
", realID=" << realID);
225 }
else if (realID == bool_clid) {
227 bool *v =
reinterpret_cast<bool*
>(
res);
228 objProxy = PyBool_FromLong(*v);
231 }
else if (realID == char_clid) {
233 char *v =
reinterpret_cast<char*
>(
res);
234 objProxy = PyUnicode_FromStringAndSize(v, 1);
237 }
else if (realID == int_clid) {
239 int *v =
reinterpret_cast<int*
>(
res);
240 objProxy = PyLong_FromLong(*v);
243 }
else if (realID == uint_clid) {
245 unsigned int *v =
reinterpret_cast<unsigned int*
>(
res);
246 objProxy = PyLong_FromLong(*v);
249 }
else if (realID == long_clid) {
251 long *v =
reinterpret_cast<long*
>(
res);
252 objProxy = PyLong_FromLong(*v);
255 }
else if (realID == ulong_clid) {
257 unsigned long *v =
reinterpret_cast<unsigned long*
>(
res);
258 objProxy = PyLong_FromUnsignedLong(*v);
261 }
else if (realID == longlong_clid) {
262 res = dbb->
cast( longlong_clid );
263 long long *v =
reinterpret_cast<long long*
>(
res);
264 objProxy = PyLong_FromUnsignedLong(*v);
267 }
else if (realID == float_clid) {
269 float *v =
reinterpret_cast<float*
>(
res);
270 objProxy = PyFloat_FromDouble(*v);
273 }
else if (realID == double_clid) {
274 res = dbb->
cast( double_clid );
275 double *v =
reinterpret_cast<double*
>(
res);
276 objProxy = PyFloat_FromDouble(*v);
279 }
else if (
id == realID ) {
282 _SGPY_MSG(
"pyid= " << PyLong_AsUnsignedLong(pyclid)
284 <<
", realID=" << realID <<
" => res = [" <<
res <<
"]");
287 PyErr_Format( PyExc_RuntimeError,
"found an invalid object" );
291 const char* klass_name = s_mgr.
load_type(
id);
292 _SGPY_MSG(
"retrieving objProxy(" << klass_name
293 <<
", " <<
res <<
")...");
295 _SGPY_MSG(
"retrieving objProxy(" << klass_name
296 <<
", " <<
res <<
")... [done]");
303 const char* real_typename = s_mgr.
load_type(realID);
313 std::string realName =
"";
314 if ( !clidSvc->getTypeNameOfID(realID, realName).isSuccess() ) {
315 PyErr_Format( PyExc_TypeError,
"actual type of CLID %lu unknown",
316 (
long unsigned int)realID );
322 if ( (
bool)fromType ) {
335 PyErr_SetString( PyExc_TypeError,
"cast to requested type failed" );
363 PyErr_SetString( PyExc_RuntimeError,
364 "no store available, is Athena initialized?" );
369 PyObject* pyname = pynameFromType( tp );
378 PyErr_SetString( PyExc_TypeError,
379 "contains() argument 2 must be string key" );
385 const CLID clid = s_mgr.
clid (pyname);
386 if ( clid == CLID_NULL ) {
387 PyErr_Format( PyExc_NameError,
388 "ID of \"%s\" is unknown", namestr.c_str() );
395 const bool sg_contains =
396 store->contains (clid, keystr) ;
399 <<
"/" << namestr.c_str() <<
", "
402 << (sg_contains ? std::string(
"true") : std::string(
"false"))
431 PyErr_SetString( PyExc_RuntimeError,
432 "no store available, is Athena initialized?" );
438 PyErr_SetString( PyExc_TypeError,
439 "__getitem__() argument 1 must be string key" );
444 const CLID clid = store->clid (keystr);
445 if ( CLID_NULL == clid ) {
446 PyErr_Format (PyExc_LookupError,
447 "no clid for key=%s",
489 PyErr_SetString( PyExc_RuntimeError,
490 "no store available, is Athena initialized?" );
495 PyObject* tp = PyObject_GetAttrString( obj, (
char*)
"__class__" );
496 if ( ! PyType_Check( tp ) ) {
497 PyErr_SetString( PyExc_RuntimeError,
498 "could not retrieve type of object" );
504 const bool isPlainPyObj = !TPython::CPPInstance_Check (obj);
505 if ( isPlainPyObj ) {
506 pyname = PyUnicode_FromString ((
char*)
"PyObject");
508 pyname = pynameFromType( tp );
511 if ( PyErr_Occurred() )
518 PyErr_SetString( PyExc_TypeError,
519 "record() argument 2 must be string key" );
526 if ( CLID_NULL ==
id ) {
527 PyErr_Format( PyExc_NameError,
528 "ID of \"%s\" is unknown", namestr.c_str() );
539 <<
", tp=" << namestr.c_str()
540 <<
", key=" << keystr.c_str());
544 _SGPY_MSG(
"created a pdb @" << dbb <<
", clID=" << dbb->
clID()
545 <<
", pdb-obj @" << dbb->
object()
546 <<
", obj @" << (
void*)obj
548 <<
", isplain-pyobj: [" << (
int)isPlainPyObj <<
"]"
552 int sc = store->typeless_record( dbb, keystr,
561 return Py_BuildValue(
const_cast<char*
>(
"i"),
sc );
#define CPPInstance_ASVOIDPTR(o)
Provide an interface for finding inheritance information at run time.
a traits class that associates a CLID to a type T It also detects whether T inherits from Gaudi DataO...
uint32_t CLID
The Class ID type.
std::pair< std::vector< unsigned int >, bool > res
Define macros for attributes used to control the static checker.
#define ATLAS_NO_CHECK_FILE_THREAD_SAFETY
A non-templated base class for DataBucket, allows to access the transient object address as a void*.
virtual void * object()=0
T * cast(SG::IRegisterTransient *irt=0, bool isConst=true)
Return the contents of the DataBucket, converted to type T.
Concrete DataBucket that holds the object via a void* and uses the Root dictionary to do conversions.
virtual void * object() override
Return the held object.
virtual const CLID & clID() const override
Retrieve reference to class definition structure.
virtual void * cast(CLID clid, IRegisterTransient *itr=0, bool isConst=true) override
Return the contents of the DataBucket, converted to type given by clid.
The Athena Transient Store API.
void clearProxyPayload(SG::DataProxy *)
use to reset a proxy (clearing the data object it contains) Unlike DataProxy::reset this method corre...
static TScopeAdapter ByNameNoQuiet(const std::string &name, Bool_t load=kTRUE)
PyObject * retrieveObjectFromStore(PyObject *storeGateSvc, PyObject *tp, PyObject *key)
PyObject * py_sg_getitem(PyObject *storeGateSvc, PyObject *key)
PyObject * py_sg_contains(PyObject *storeGateSvc, PyObject *tp, PyObject *key)
PyObject * recordObjectToStore(StoreGateSvc *, PyObject *, PyObject *, bool, bool, bool)
record object to storegate
void py_sg_clearProxyPayload(StoreGateSvc *self, SG::DataProxy *)
std::pair< std::string, bool > PyGetString(PyObject *s)
Convert python string -> C++ string for py2 and py3.
a python front-end to the IProxyDict interface PyProxyDict encapsulates getting python objects from t...
PyObject * proxy(PyObject *pyclid, PyObject *pykey)
PyObject * newPyDataObject(const char *klass, void *addr=0)
A helper class to manage accesses to PyProxies.
static PyProxyMgr & instance()
const char * load_type(CLID id)
ensure everything has been loaded for the clid id (classid, reflex dict, baseinfobase,...
SG::PyProxyDict * pyproxy(StoreGateSvc *sg)
PyObject * pyclid(PyObject *tp)
returns a borrowed reference
PyObject * pytp(PyObject *clid)
returns a borrowed reference