3 """ This Pythonizations module provides a number of useful pythonizations 4 of adaptation of some classes. 13 print "# WARNING: using PyCintex as cppyy implementation" 14 from PyCintex
import gbl
16 if not hasattr(gbl,
'ostream'):
17 gbl.gROOT.ProcessLine(
"#include <ostream>")
18 if not hasattr(gbl,
'stringstream'):
19 gbl.gROOT.ProcessLine(
"#include <sstream>")
26 return 'Histogram 1D "%s" %d bins [%f,%f]' % (h.title(), x.bins(),
27 x.lowerEdge(), x.upperEdge())
32 return map(h.binEntries,
range(x.bins()))
36 x, y = h.xAxis(), h.yAxis()
37 return 'Histogram 2D "%s" %d xbins [%f,%f], %d ybins [%f,%f]' % \
38 (h.title(), x.bins(), x.lowerEdge(), x.upperEdge(),
39 y.bins(), y.lowerEdge(), y.upperEdge())
50 return str(1 == b.bool())
55 s = gbl.stringstream()
59 out = o.__class__.__name__ +
' object' 60 if hasattr(o,
'hasKey')
and o.hasKey():
61 out +=
' key = ' + str(o.key())
63 out = o.__class__.__name__ +
' NULL object' 68 return self.containedObject(k)
72 return self.numberOfObjects()
76 if hasattr(self,
'containedObjects'):
77 sequential = self.containedObjects()
81 limit = self.__len__()
83 yield sequential.__getitem__(count)
89 Draw AIDA histogram (through access to internal ROOT histogram 91 >>> aida = ... # get the historgam 95 _fun = gbl.Gaudi.Utils.Aida2ROOT.aida2root
97 return _root.Draw(*args)
100 gbl.AIDA.IHistogram1D.__repr__ = _printHisto1D
101 gbl.AIDA.IHistogram1D.contents = _contentsHisto1D
102 gbl.AIDA.IHistogram2D.__repr__ = _printHisto2D
103 for h
in (gbl.AIDA.IHistogram, gbl.AIDA.IHistogram1D, gbl.AIDA.IHistogram2D,
104 gbl.AIDA.IHistogram3D, gbl.AIDA.IProfile1D, gbl.AIDA.IProfile2D):
108 gbl.StatusCode.__repr__ = _printStatusCode
110 gbl._Bit_reference.__repr__ = _printBitReference
113 gbl.ContainedObject.__repr__ = _printFillStream
114 gbl.DataObject.__repr__ = _printFillStream
115 gbl.ObjectContainerBase.__getitem__ = _container__getitem__
116 gbl.ObjectContainerBase.__len__ = _container__len__
117 gbl.ObjectContainerBase.__iter__ = _container__iter__
119 gbl.IUpdateManagerSvc.update =
lambda self, obj: gbl.IUpdateManagerSvc.PythonHelper.update(
121 gbl.IUpdateManagerSvc.invalidate =
lambda self, obj: gbl.IUpdateManagerSvc.PythonHelper.invalidate(
125 if not hasattr(gbl.StatusCode,
'SUCCESS'):
127 gbl.StatusCode.SUCCESS = 1
128 gbl.StatusCode.FAILURE = 0
131 if hasattr(gbl.Gaudi.StringKey,
'__cpp_eq__'):
132 _eq = gbl.Gaudi.StringKey.__cpp_eq__
133 setattr(gbl.Gaudi.StringKey,
'__eq__', _eq)
136 if hasattr(gbl.Gaudi.StringKey,
'__cpp_ne__'):
137 _ne = gbl.Gaudi.StringKey.__cpp_ne__
138 setattr(gbl.Gaudi.StringKey,
'__ne__', _ne)
141 if gbl.gROOT.GetVersionInt() <= 51800:
143 gbl.GaudiPython.PyROOTPickle.Initialize(libPyROOT, libPyROOT.ObjectProxy)
169 The iterator for MapBase-based containers 171 >>> m = ... ## the map 172 >>> for key in m : print key , m[key] 177 while _index < _size:
178 yield self.key_at(_index)
207 The iterator for MapBase-based containers 209 >>> m = ... ## the map 210 >>> for key,value in m.iteritems() : print key, value 215 while _index < _size:
216 _key = self.key_at(_index)
217 yield (_key, self.at(_key))
245 >>> m = ... ## the map 246 >>> keys = m.keys() ## get the list of keys 251 for i
in range(0, _size):
252 _keys.append(self.key_at(i))
278 Get the list of items 280 >>> m = ... ## the map 281 >>> items = m.keys() ## get the list of items 286 for i
in range(0, _size):
287 _key = self.key_at(i)
288 _value = self.at(_key)
289 _items.append((_key, _value))
315 Get the list of values 317 >>> m = ... ## the map 318 >>> values = m.values() ## get the list of values 323 for i
in range(0, _size):
324 _value = self.value_at(i)
325 _values.append(_value)
351 Check if the certainkey is in the map 353 >>> m = ... ## the map 354 >>> if 'a' in m : ... ## chekc the presence of the key in the map 357 _num = self.count(key)
358 return False if 0 == _num
else True 384 Get the value for the certain key, or 'value' otherwise 386 >>> m = ... ## the map 387 >>> v = m.get ( key , 15 ) 414 Representation of MapBase-based maps: 416 >>> m = ... ## the map 422 for i
in range(0, _size):
423 _key = self.key_at(i)
427 _result +=
" %s : %s " % (str(_key), str(_val))
454 'Set-item' for MapBase-based maps: 456 >>> m = ... ## the map 457 >>> m[key] = value ## set the item 460 _replaced =
True if key
in self
else False 461 self.update(key, value)
488 'Del-item' for MapBase-based maps: 490 >>> m = ... ## the map 494 _erased =
True if key
in self
else False 499 gbl.Gaudi.Utils.MapBase.__len__ =
lambda s: s.size()
500 gbl.Gaudi.Utils.MapBase.__iter__ = __mapbase_iter__
501 gbl.Gaudi.Utils.MapBase.keys = __mapbase_keys__
502 gbl.Gaudi.Utils.MapBase.__iteritems__ = __mapbase_iteritems__
503 gbl.Gaudi.Utils.MapBase.iteritems = __mapbase_iteritems__
504 gbl.Gaudi.Utils.MapBase.items = __mapbase_items__
505 gbl.Gaudi.Utils.MapBase.values = __mapbase_values__
506 gbl.Gaudi.Utils.MapBase.__contains__ = __mapbase_contains__
507 gbl.Gaudi.Utils.MapBase.has_key = __mapbase_contains__
508 gbl.Gaudi.Utils.MapBase.get = __mapbase_get__
509 gbl.Gaudi.Utils.MapBase.__str__ = __mapbase_str__
510 gbl.Gaudi.Utils.MapBase.__repr__ = __mapbase_str__
511 gbl.Gaudi.Utils.MapBase.__setitem__ = __mapbase_setitem__
512 gbl.Gaudi.Utils.MapBase.__delitem__ = __mapbase_delitem__
513 gbl.Gaudi.Utils.MapBase.__getitem__ =
lambda s, key: s.at(key)
def __mapbase_values__(self)
def __mapbase_setitem__(self, key, value)
def __mapbase_contains__(self, key)
def _container__getitem__(self, k)
def __mapbase_iteritems__(self)
def _printBitReference(b)
def __mapbase_items__(self)
def _container__iter__(self)
def __mapbase_keys__(self)
struct GAUDI_API map
Parametrisation class for map-like implementation.
def _draw_aida_(self, args)
def __mapbase_get__(self, key, value=None)
def __mapbase_iter__(self)
decltype(auto) range(Args &&...args)
Zips multiple containers together to form a single range.
def __mapbase_delitem__(self, key)
def _container__len__(self)
def __mapbase_str__(self)