14 #include "GaudiKernel/Bootstrap.h"
15 #include "GaudiKernel/DataObject.h"
16 #include "GaudiKernel/IClassIDSvc.h"
27 #include "TClassRef.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?" );
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()
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() <<
"]");
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 ) {
325 if (fromType.Class() && toType.
Class())
326 res = fromType.Class()->DynamicCast (toType.
Class(),
res);
335 PyErr_SetString( PyExc_TypeError,
"cast to requested type failed" );
363 PyErr_SetString( PyExc_RuntimeError,
364 "no store available, is Athena initialized?" );
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" );
445 if ( CLID_NULL == clid ) {
446 PyErr_Format (PyExc_LookupError,
447 "no clid for key=%s",
460 return self->clearProxyPayload(
dp);
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 );