|
ATLAS Offline Software
|
|
CLID | getClid (IClassIDSvc *self, const std::string &typeName) |
|
StatusCode | initPyInterpreter () |
| correctly initialize the python interpreter in case it hasn't been done yet. More...
|
|
PyObject * | recordObjectToStore (StoreGateSvc *store, PyObject *obj, PyObject *pykey, bool allowMods=true, bool resetOnly=true, bool noHist=false) |
| record object to storegate More...
|
|
void | py_sg_clearProxyPayload (StoreGateSvc *self, SG::DataProxy *) |
|
PyObject * | retrieveObjectFromStore (PyObject *storeGateSvc, PyObject *tp, PyObject *key) |
|
PyObject * | recordObjectToStore (PyObject *storeGateSvc, PyObject *obj, PyObject *key, bool allowMods=true, bool resetOnly=true, bool noHist=false) |
|
PyObject * | py_sg_contains (PyObject *storeGateSvc, PyObject *tp, PyObject *key) |
|
PyObject * | py_sg_getitem (PyObject *storeGateSvc, PyObject *key) |
|
PyObject * | retrieveObjectFromStore (StoreGateSvc *store, PyObject *tp, PyObject *pykey) |
| retrieve object of specified type from storegate More...
|
|
PyObject * | py_sg_getitem (StoreGateSvc *self, PyObject *pykey) |
| typeless retrieve ... slower than above, and potential to return unexpected type if objects of different type but same key More...
|
|
PyObject * | py_sg_contains (StoreGateSvc *store, PyObject *tp, PyObject *pykey) |
| check if object of specified type is in storegate More...
|
|
◆ getClid()
CLID AthenaInternal::getClid |
( |
IClassIDSvc * |
self, |
|
|
const std::string & |
typeName |
|
) |
| |
◆ initPyInterpreter()
StatusCode AthenaInternal::initPyInterpreter |
( |
| ) |
|
correctly initialize the python interpreter in case it hasn't been done yet.
Definition at line 60 of file initPyInterpreter.cxx.
62 if (Py_IsInitialized()) {
63 return StatusCode::SUCCESS;
70 #if PY_MAJOR_VERSION == 3 && PY_MINOR_VERSION < 11
73 if (!Py_IsInitialized()) {
74 ::report_py_exception();
75 return StatusCode::FAILURE;
80 []() { std::vector<std::wstring> wargs;
84 using convert_t = std::codecvt_utf8<wchar_t>;
85 std::wstring_convert<convert_t, wchar_t> strconverter;
87 wargs.push_back (strconverter.from_bytes (
argv[
i]));
91 static const std::vector<std::wstring> wargs = wargsinit();
94 [](
const std::vector<std::wstring>& wargs)
95 { std::vector<const wchar_t*> wargv;
98 wargv.push_back (wargs[
i].
data());
102 static const std::vector<const wchar_t*> wargv = wargvinit (wargs);
109 PyConfig_InitPythonConfig (&
config);
112 if (PyStatus_Exception (
status)) {
113 report_py_exception();
115 return StatusCode::FAILURE;
119 if (PyStatus_Exception (
status)) {
120 report_py_exception();
122 return StatusCode::FAILURE;
126 return StatusCode::SUCCESS;
◆ py_sg_clearProxyPayload()
◆ py_sg_contains() [1/2]
◆ py_sg_contains() [2/2]
check if object of specified type is in storegate
Definition at line 354 of file StoreGatePyExt.cxx.
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"))
◆ py_sg_getitem() [1/2]
◆ py_sg_getitem() [2/2]
typeless retrieve ... slower than above, and potential to return unexpected type if objects of different type but same key
Definition at line 422 of file StoreGatePyExt.cxx.
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",
◆ recordObjectToStore() [1/2]
PyObject * AthenaInternal::recordObjectToStore |
( |
PyObject * |
storeGateSvc, |
|
|
PyObject * |
obj, |
|
|
PyObject * |
key, |
|
|
bool |
allowMods = true , |
|
|
bool |
resetOnly = true , |
|
|
bool |
noHist = false |
|
) |
| |
◆ recordObjectToStore() [2/2]
record object to storegate
Definition at line 476 of file StoreGatePyExt.cxx.
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 );
◆ retrieveObjectFromStore() [1/2]
◆ retrieveObjectFromStore() [2/2]
retrieve object of specified type from storegate
Definition at line 109 of file StoreGatePyExt.cxx.
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" );
char data[hepevt_bytes_allocation_ATLAS]
PyObject * newPyDataObject(const char *klass, void *addr=0)
static TScopeAdapter ByNameNoQuiet(const std::string &name, Bool_t load=kTRUE)
A non-templated base class for DataBucket, allows to access the transient object address as a void*.
const char * load_type(CLID id)
ensure everything has been loaded for the clid id (classid, reflex dict, baseinfobase,...
virtual void * object()=0
virtual void * object() override
Return the held object.
PyObject * pyclid(PyObject *tp)
returns a borrowed reference
a python front-end to the IProxyDict interface PyProxyDict encapsulates getting python objects from t...
T * cast(SG::IRegisterTransient *irt=0, bool isConst=true)
Return the contents of the DataBucket, converted to type T.
PyObject * proxy(PyObject *pyclid, PyObject *pykey)
SG::PyProxyDict * pyproxy(StoreGateSvc *sg)
PyObject * py_sg_contains(PyObject *storeGateSvc, PyObject *tp, PyObject *key)
#define CPPInstance_ASVOIDPTR(o)
The Athena Transient Store API.
virtual void * cast(CLID clid, IRegisterTransient *itr=0, bool isConst=true) override
Return the contents of the DataBucket, converted to type given by clid.
std::pair< std::vector< unsigned int >, bool > res
PyObject * py_sg_getitem(PyObject *storeGateSvc, PyObject *key)
uint32_t CLID
The Class ID type.
virtual const CLID & clID() const override
Retrieve reference to class definition structure.
std::pair< std::string, bool > PyGetString(PyObject *s)
Convert python string -> C++ string for py2 and py3.
Concrete DataBucket that holds the object via a void* and uses the Root dictionary to do conversions.
PyObject * pytp(PyObject *clid)
returns a borrowed reference
static PyProxyMgr & instance()
#define ATLAS_THREAD_SAFE
PyObject * retrieveObjectFromStore(PyObject *storeGateSvc, PyObject *tp, PyObject *key)
PyObject * recordObjectToStore(StoreGateSvc *, PyObject *, PyObject *, bool, bool, bool)
record object to storegate
A helper class to manage accesses to PyProxies.