Loading [MathJax]/extensions/tex2jax.js
 |
ATLAS Offline Software
|
Go to the documentation of this file.
7 #ifndef STOREGATEBINDINGS_SGPYDATAMODEL_H
8 #define STOREGATEBINDINGS_SGPYDATAMODEL_H 1
16 #include "GaudiKernel/Bootstrap.h"
17 #include "GaudiKernel/ClassID.h"
18 #include "GaudiKernel/DataObject.h"
19 #include "GaudiKernel/IClassIDSvc.h"
31 #include "TClassEdit.h"
32 #include "TClassRef.h"
35 #include "TMethodCall.h"
39 #include "CPyCppyy/PyException.h"
41 #include <unordered_map>
48 namespace SG {
struct PyProxyMgr; }
49 namespace SG {
struct PyProxyDict; }
54 std::string::size_type
55 cxx_replace(std::string&
s,
56 const std::string& from,
57 const std::string&
to)
59 std::string::size_type
cnt(std::string::npos);
61 if(from !=
to && !from.empty()) {
62 std::string::size_type pos1(0);
63 std::string::size_type pos2(0);
64 const std::string::size_type from_len(from.size());
65 const std::string::size_type to_len(
to.size());
68 while((pos1 =
s.find(from, pos2)) != std::string::npos) {
69 s.replace(pos1, from_len,
to);
135 bool isConst =
true)
override;
146 virtual void*
cast (
const std::type_info&
tinfo,
148 bool isConst =
true)
override;
158 virtual const std::type_info&
tinfo()
const override
174 virtual void lock()
override;
201 typedef std::unordered_map<StoreGateSvc*,SG::PyProxyDict*>
PyProxyMap_t;
205 typedef std::unordered_map<CLID, std::string>
ClidMap_t;
222 if ( NULL ==
clid ) {
224 if (
id == CLID_NULL ) {
227 clid = PyLong_FromLong(
id);
244 cpp_tp).isSuccess()) {
251 tp = PyUnicode_FromString(cpp_tp.c_str());
285 R__WRITE_LOCKGUARD(ROOT::gCoreMutex);
286 tn = TClassEdit::ShortType(tpstr.c_str(),
287 TClassEdit::kDropAllDefault);
289 m_clidSvc->getIDOfTypeName(tn,
id).ignore();
290 if (
id == CLID_NULL ) {
295 m_clidSvc->getIDOfTypeName(aliasstr,
id).ignore();
298 if (
id == CLID_NULL) {
317 R__WRITE_LOCKGUARD(ROOT::gCoreMutex);
318 tn = TClassEdit::ShortType(tpstr.c_str(),
319 TClassEdit::kDropAllDefault);
321 m_clidSvc->getIDOfTypeInfoName(tn,
id).ignore();
322 if (
id == CLID_NULL ) {
344 return i->second.c_str();
349 ::cxx_replace(tname,
"basic_string<char> >",
"string>");
350 ::cxx_replace(tname,
"basic_string<char>",
"string");
354 std::string bibname =
"SG::BaseInfo<" + tname +
">";
355 TClass* bibcl = gROOT->GetClass (bibname.c_str());
357 TMethod*
m = bibcl->GetMethodAny (
"baseinfo");
359 TMethodCall
call (
m);
371 const std::string moduleName =
"AthenaPython.Bindings";
373 (
const_cast<char*
>(moduleName.c_str()) );
375 std::cerr <<
"SG::PyProxyDict WARNING: could not import module '"
376 << moduleName <<
"' !\n";
383 (
char*)
"_clid_typename_aliases");
390 std::cerr <<
"SG::PyProxyDict WARNING: could not retrieve the "
391 <<
"dictionary of aliases from '"
392 << moduleName <<
"' !\n";
423 unsigned int id_tmp = 0;
424 if (!PyArg_Parse( pyclid,
"I", &id_tmp )) {
430 if (pykey != Py_None) {
439 pyproxy = TPython::CPPInstance_FromVoidPtr((
void*)
proxy,
442 _SGPY_MSG(
"PyProxyDict::proxy(...)... [done]");
450 if ( !(
obj = TPython::CPPInstance_FromVoidPtr((
void*)addr,
klass)) ) {
477 #endif // !STOREGATEBINDINGS_SGPYDATAMODEL_H
JetConstituentVector::iterator iterator
CPyCppyy::PyException PyException
Interface for registering a transient object in t2p map.
virtual const std::type_info & tinfo() const override
Return the type_info for the stored object.
virtual void lock() override
If the held object derives from ILockable, call lock() on it.
virtual void relinquish() override
Give up ownership of the DataBucket contents.
PyObject * newPyDataObject(const char *klass, void *addr=0)
const SG::BaseInfoBase * m_bib
pointer to the SG::BaseInfoBase structure holding the converter functions for objects held by StoreGa...
CLID m_clid
The class ID of the wrapped object.
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,...
IDictLoaderSvc * m_dictSvc
virtual void * object() override
Return the held object.
PyObject * m_aliases
a dictionary of "typedef'ed typename" -> "typename"
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 * m_pyObj
Pointer to the held pyroot object (or 'regular' PyObject)
PyObject * proxy(PyObject *pyclid, PyObject *pykey)
ATLAS_NO_CHECK_FILE_THREAD_SAFETY
SG::PyProxyDict * pyproxy(StoreGateSvc *sg)
This class describe the base functionalities of a HypoTool used by the ComboAlg.
#define CPPInstance_ASVOIDPTR(o)
std::unordered_map< StoreGateSvc *, SG::PyProxyDict * > PyProxyMap_t
The Athena Transient Store API.
virtual const RootType load_type(const std::string &type_name, bool recursive=false)=0
retrieve a RootType by name (auto)loading the dictionary by any necessary means.
def call(args, bufsize=0, executable=None, stdin=None, preexec_fn=None, close_fds=False, shell=False, cwd=None, env=None, universal_newlines=False, startupinfo=None, creationflags=0, message="", logger=msg, loglevel=None, timeout=None, retry=2, timefactor=1.5, sleeptime=10)
virtual void * cast(CLID clid, IRegisterTransient *itr=0, bool isConst=true) override
Return the contents of the DataBucket, converted to type given by clid.
Provide an interface for finding inheritance information at run time.
PyObject * pytp(CLID clid)
returns a borrowed reference
uint32_t CLID
The Class ID type.
PyObject * importDictAliases()
import the dictionary of aliases from a well known location
std::string Name(unsigned int mod=Reflex::SCOPED) const
CLID clid_from_tid(PyObject *tp)
PyObject * m_clids
a dictionary of 'typename' -> CLID (and reverse CLID->'typename')
virtual SG::DataProxy * proxy(const void *const pTransient) const override final
get proxy for a given data object address in memory
virtual const CLID & clID() const override
Retrieve reference to class definition structure.
PyProxyDict(StoreGateSvc *sgSvc)
virtual ~PyDataBucket() override
Destructor.
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
The non-template portion of the BaseInfo implementation.
static PyProxyMgr & instance()
const std::type_info & typeinfo() const
Return the std::type_info for this class.
Define macros for attributes used to control the static checker.
std::unordered_map< CLID, std::string > ClidMap_t
a dictionary of CLID -> reflex typename
PyDataBucket(PyObject *obj, CLID clid)
Constructor.
A helper class to manage accesses to PyProxies.