7 from __future__
import print_function
11 Wim Lavrijsen (WLavrijsen@lbl.gov),
12 Sebastien Binet (binet@cern.ch)
19 cppyy.load_library(
"libAthenaPythonDict" )
20 cppyy.load_library(
"libStoreGateBindingsDict" )
21 cppyy.load_library(
"libStoreGateBindings" )
24 py_retrieve = cppyy.gbl.AthenaInternal.retrieveObjectFromStore
27 py_record = cppyy.gbl.AthenaInternal.recordObjectToStore
30 py_sg_contains = cppyy.gbl.AthenaInternal.py_sg_contains
33 py_sg_getitem = cppyy.gbl.AthenaInternal.py_sg_getitem
37 StoreGateSvc = cppyy.gbl.StoreGateSvc
40 def retrieve( self, klass, key = None ):
41 ret = py_retrieve( self, klass, key )
42 if ret
and hasattr(ret,
'setStore')
and not ret.hasStore():
43 if not hasattr(ret,
'trackIndices')
or ret.trackIndices():
44 if py_sg_contains (self,
'SG::IConstAuxStore', key +
'Aux.'):
45 aux = py_retrieve (self,
'SG::IConstAuxStore', key +
'Aux.')
48 StoreGateSvc.retrieve = retrieve
51 def record( self, obj, key, allowMods=True, resetOnly=True, noHist=False ):
52 return py_record( self, obj, key, allowMods, resetOnly, noHist )
53 StoreGateSvc.record = record
56 def contains( self, klass_or_clid, key ):
57 from builtins
import int
58 if isinstance(klass_or_clid, str):
60 clid =
int(klass_or_clid)
61 klass = self._pyclidsvc.
typename(clid)
63 klass =
str(klass_or_clid)
65 elif isinstance(klass_or_clid, int):
66 klass = self._pyclidsvc.
typename(klass_or_clid)
67 elif isinstance(klass_or_clid, type):
68 klass = klass_or_clid.__name__
71 'argument 2 must be a typename, a clid or a type (got %r)' %
74 StoreGateSvc.contains = contains
78 return py_record( self, obj, key,
True,
True,
False )
79 StoreGateSvc.__setitem__ = __setitem__
85 except LookupError
as err:
86 raise KeyError(
str(err))
87 if ret
and hasattr(ret,
'setStore')
and hasattr(ret,
'hasStore')
and not ret.hasStore():
88 if not hasattr(ret,
'trackIndices')
or ret.trackIndices():
89 if py_sg_contains (self,
'SG::IConstAuxStore', key +
'Aux.'):
90 aux = py_retrieve (self,
'SG::IConstAuxStore', key +
'Aux.')
93 StoreGateSvc.__getitem__ = __getitem__
97 return len(self.keys())
98 StoreGateSvc.__len__ = __len__
101 def dump(self, fd = None):
105 print (self.__class__._dump( self ), file=fd)
106 StoreGateSvc._dump = StoreGateSvc.dump
107 StoreGateSvc.dump = dump
110 def __getattr__( self, attr ):
111 try:
from GaudiPython.Bindings
import iProperty
112 except ImportError:
from gaudimodule
import iProperty
113 return getattr( iProperty(
"StoreGateSvc", self), attr )
116 try:
from GaudiPython.Bindings
import iProperty
117 except ImportError:
from gaudimodule
import iProperty
118 return setattr( iProperty(
"StoreGateSvc", self), attr, value )
120 StoreGateSvc.__getattr__ = __getattr__
121 StoreGateSvc.__setattr__ = __setattr__
123 import AthenaPython.PyAthena
as PyAthena
124 StoreGateSvc._pyclidsvc = PyAthena.py_svc(
'ClassIDSvc')
126 def keys(self, clid=None, allKeys=False):
127 """return the list of keys for a given CLID (int, type or class_name)
128 if clid is None, it will return the list of all keys.
129 When 'allKeys' is True it will also return the key aliases.
131 if isinstance(clid, str):
132 clid = self._pyclidsvc.clid(clid)
133 if isinstance(clid, type):
134 clid = self._pyclidsvc.clid(clid.__name__)
136 return [p.name()
for p
in self.proxies()]
137 return [
str(x)
for x
in self._cpp_keys(clid, allKeys)]
138 StoreGateSvc._cpp_keys = StoreGateSvc.keys
139 StoreGateSvc.keys = keys
147 StoreGateSvc.__bool__ =
lambda self :
True