10 Wim Lavrijsen (WLavrijsen@lbl.gov),
11 Sebastien Binet (binet@cern.ch)
18 cppyy.load_library(
"libAthenaPythonDict" )
19 cppyy.load_library(
"libStoreGateBindingsDict" )
20 cppyy.load_library(
"libStoreGateBindings" )
23 py_retrieve = cppyy.gbl.AthenaInternal.retrieveObjectFromStore
26 py_record = cppyy.gbl.AthenaInternal.recordObjectToStore
29 py_sg_contains = cppyy.gbl.AthenaInternal.py_sg_contains
32 py_sg_getitem = cppyy.gbl.AthenaInternal.py_sg_getitem
36 StoreGateSvc = cppyy.gbl.StoreGateSvc
39 def retrieve( self, klass, key = None ):
40 ret = py_retrieve( self, klass, key )
41 if ret
and hasattr(ret,
'setStore')
and not ret.hasStore():
42 if not hasattr(ret,
'trackIndices')
or ret.trackIndices():
43 if py_sg_contains (self,
'SG::IConstAuxStore', key +
'Aux.'):
44 aux = py_retrieve (self,
'SG::IConstAuxStore', key +
'Aux.')
47 StoreGateSvc.retrieve = retrieve
50 def record( self, obj, key, allowMods=True, resetOnly=True, noHist=False ):
51 return py_record( self, obj, key, allowMods, resetOnly, noHist )
52 StoreGateSvc.record = record
55 def contains( self, klass_or_clid, key ):
56 from builtins
import int
57 if isinstance(klass_or_clid, str):
59 clid =
int(klass_or_clid)
60 klass = self._pyclidsvc.
typename(clid)
62 klass =
str(klass_or_clid)
64 elif isinstance(klass_or_clid, int):
65 klass = self._pyclidsvc.
typename(klass_or_clid)
66 elif isinstance(klass_or_clid, type):
67 klass = klass_or_clid.__name__
70 'argument 2 must be a typename, a clid or a type (got %r)' %
73 StoreGateSvc.contains = contains
77 return py_record( self, obj, key,
True,
True,
False )
78 StoreGateSvc.__setitem__ = __setitem__
84 except LookupError
as err:
85 raise KeyError(
str(err))
86 if ret
and hasattr(ret,
'setStore')
and hasattr(ret,
'hasStore')
and not ret.hasStore():
87 if not hasattr(ret,
'trackIndices')
or ret.trackIndices():
88 if py_sg_contains (self,
'SG::IConstAuxStore', key +
'Aux.'):
89 aux = py_retrieve (self,
'SG::IConstAuxStore', key +
'Aux.')
92 StoreGateSvc.__getitem__ = __getitem__
96 return len(self.keys())
97 StoreGateSvc.__len__ = __len__
100 def dump(self, fd = None):
104 print (self.__class__._dump( self ), file=fd)
105 StoreGateSvc._dump = StoreGateSvc.dump
106 StoreGateSvc.dump = dump
109 def __getattr__( self, attr ):
110 try:
from GaudiPython.Bindings
import iProperty
111 except ImportError:
from gaudimodule
import iProperty
112 return getattr( iProperty(
"StoreGateSvc", self), attr )
115 try:
from GaudiPython.Bindings
import iProperty
116 except ImportError:
from gaudimodule
import iProperty
117 return setattr( iProperty(
"StoreGateSvc", self), attr, value )
119 StoreGateSvc.__getattr__ = __getattr__
120 StoreGateSvc.__setattr__ = __setattr__
122 import AthenaPython.PyAthena
as PyAthena
123 StoreGateSvc._pyclidsvc = PyAthena.py_svc(
'ClassIDSvc')
125 def keys(self, clid=None, allKeys=False):
126 """return the list of keys for a given CLID (int, type or class_name)
127 if clid is None, it will return the list of all keys.
128 When 'allKeys' is True it will also return the key aliases.
130 if isinstance(clid, str):
131 clid = self._pyclidsvc.clid(clid)
132 if isinstance(clid, type):
133 clid = self._pyclidsvc.clid(clid.__name__)
135 return [p.name()
for p
in self.proxies()]
136 return [
str(x)
for x
in self._cpp_keys(clid, allKeys)]
137 StoreGateSvc._cpp_keys = StoreGateSvc.keys
138 StoreGateSvc.keys = keys
146 StoreGateSvc.__bool__ =
lambda self :
True