4 """ This Pythonizations module provides a number of useful pythonizations
5 of adaptation of some classes.
14 print "# WARNING: using PyCintex as cppyy implementation"
15 from PyCintex
import gbl
17 if not hasattr(gbl,
'ostream') : gbl.gROOT.ProcessLine(
"#include <ostream>")
18 if not hasattr(gbl,
'stringstream') : gbl.gROOT.ProcessLine(
"#include <sstream>")
23 return 'Histogram 1D "%s" %d bins [%f,%f]' % (h.title(), x.bins(), x.lowerEdge(), x.upperEdge())
26 return map(h.binEntries,
range(x.bins()))
28 x,y = h.xAxis(),h.yAxis()
29 return 'Histogram 2D "%s" %d xbins [%f,%f], %d ybins [%f,%f]' % \
30 (h.title(), x.bins(), x.lowerEdge(), x.upperEdge(), y.bins(), y.lowerEdge(), y.upperEdge() )
32 if s.isSuccess() :
return 'SUCCESS'
33 else :
return 'FAILURE'
35 return str(1==b.bool())
38 s = gbl.stringstream()
42 out = o.__class__.__name__ +
' object'
43 if hasattr( o,
'hasKey')
and o.hasKey() :
44 out +=
' key = '+ str(o.key())
46 out = o.__class__.__name__ +
' NULL object'
49 return self.containedObject(k)
51 return self.numberOfObjects()
53 if hasattr(self,
'containedObjects') : sequential = self.containedObjects()
54 else : sequential = self
56 limit = self.__len__()
58 yield sequential.__getitem__(count)
63 Draw AIDA histogram (through access to internal ROOT histogram
65 >>> aida = ... # get the historgam
69 _fun = gbl.Gaudi.Utils.Aida2ROOT.aida2root
71 return _root.Draw( *args )
73 gbl.AIDA.IHistogram1D.__repr__ = _printHisto1D
74 gbl.AIDA.IHistogram1D.contents = _contentsHisto1D
75 gbl.AIDA.IHistogram2D.__repr__ = _printHisto2D
76 for h
in ( gbl.AIDA.IHistogram ,
77 gbl.AIDA.IHistogram1D ,
78 gbl.AIDA.IHistogram2D ,
79 gbl.AIDA.IHistogram3D ,
81 gbl.AIDA.IProfile2D ) :
85 gbl.StatusCode.__repr__ = _printStatusCode
86 try: gbl._Bit_reference.__repr__ = _printBitReference
88 gbl.ContainedObject.__repr__ = _printFillStream
89 gbl.DataObject.__repr__ = _printFillStream
90 gbl.ObjectContainerBase.__getitem__ = _container__getitem__
91 gbl.ObjectContainerBase.__len__ = _container__len__
92 gbl.ObjectContainerBase.__iter__ = _container__iter__
94 gbl.IUpdateManagerSvc.update =
lambda self,obj: gbl.IUpdateManagerSvc.PythonHelper.update(self,obj)
95 gbl.IUpdateManagerSvc.invalidate =
lambda self,obj: gbl.IUpdateManagerSvc.PythonHelper.invalidate(self,obj)
98 if not hasattr(gbl.StatusCode,
'SUCCESS'):
100 gbl.StatusCode.SUCCESS = 1
101 gbl.StatusCode.FAILURE = 0
104 if hasattr ( gbl.Gaudi.StringKey ,
'__cpp_eq__' ) :
105 _eq = gbl.Gaudi.StringKey.__cpp_eq__
106 setattr ( gbl.Gaudi.StringKey ,
'__eq__' , _eq )
109 if hasattr ( gbl.Gaudi.StringKey ,
'__cpp_ne__' ) :
110 _ne = gbl.Gaudi.StringKey.__cpp_ne__
111 setattr ( gbl.Gaudi.StringKey ,
'__ne__' , _ne )
115 if gbl.gROOT.GetVersionInt() <= 51800 :
117 gbl.GaudiPython.PyROOTPickle.Initialize(libPyROOT, libPyROOT.ObjectProxy)
141 The iterator for MapBase-based containers
143 >>> m = ... ## the map
144 >>> for key in m : print key , m[key]
149 while _index < _size :
150 yield self.key_at ( _index )
176 The iterator for MapBase-based containers
178 >>> m = ... ## the map
179 >>> for key,value in m.iteritems() : print key, value
184 while _index < _size :
185 _key = self.key_at ( _index )
186 yield ( _key , self.at ( _key ) )
211 >>> m = ... ## the map
212 >>> keys = m.keys() ## get the list of keys
217 for i
in range ( 0 , _size ) : _keys.append ( self.key_at ( i ) )
240 Get the list of items
242 >>> m = ... ## the map
243 >>> items = m.keys() ## get the list of items
248 for i
in range ( 0 , _size ) :
249 _key = self.key_at ( i )
250 _value = self.at ( _key )
251 _items.append ( ( _key , _value ) )
274 Get the list of values
276 >>> m = ... ## the map
277 >>> values = m.values() ## get the list of values
282 for i
in range ( 0 , _size ) :
283 _value = self.value_at ( i )
284 _values.append ( _value )
307 Check if the certainkey is in the map
309 >>> m = ... ## the map
310 >>> if 'a' in m : ... ## chekc the presence of the key in the map
313 _num = self.count ( key )
314 return False if 0 == _num
else True
337 Get the value for the certain key, or 'value' otherwise
339 >>> m = ... ## the map
340 >>> v = m.get ( key , 15 )
343 if key
in self :
return self.at( key )
363 Representation of MapBase-based maps:
365 >>> m = ... ## the map
371 for i
in range ( 0 , _size ) :
372 _key = self.key_at ( i )
373 _val = self.at ( _key )
374 if 0 != i : _result +=
' , '
375 _result +=
" %s : %s " % ( str ( _key ) , str ( _val ) )
399 'Set-item' for MapBase-based maps:
401 >>> m = ... ## the map
402 >>> m[key] = value ## set the item
405 _replaced =
True if key
in self
else False
406 self.update ( key , value )
430 'Del-item' for MapBase-based maps:
432 >>> m = ... ## the map
436 _erased =
True if key
in self
else False
440 gbl.Gaudi.Utils.MapBase . __len__ =
lambda s : s.size()
441 gbl.Gaudi.Utils.MapBase . __iter__ = __mapbase_iter__
442 gbl.Gaudi.Utils.MapBase . keys = __mapbase_keys__
443 gbl.Gaudi.Utils.MapBase . __iteritems__ = __mapbase_iteritems__
444 gbl.Gaudi.Utils.MapBase . iteritems = __mapbase_iteritems__
445 gbl.Gaudi.Utils.MapBase . items = __mapbase_items__
446 gbl.Gaudi.Utils.MapBase . values = __mapbase_values__
447 gbl.Gaudi.Utils.MapBase . __contains__ = __mapbase_contains__
448 gbl.Gaudi.Utils.MapBase . has_key = __mapbase_contains__
449 gbl.Gaudi.Utils.MapBase . get = __mapbase_get__
450 gbl.Gaudi.Utils.MapBase . __str__ = __mapbase_str__
451 gbl.Gaudi.Utils.MapBase . __repr__ = __mapbase_str__
452 gbl.Gaudi.Utils.MapBase . __setitem__ = __mapbase_setitem__
453 gbl.Gaudi.Utils.MapBase . __delitem__ = __mapbase_delitem__
454 gbl.Gaudi.Utils.MapBase . __getitem__ =
lambda s,key : s.at ( key )
def _container__iter__(self)
def __mapbase_str__(self)
Representation of MapBase-based maps.
def __mapbase_keys__(self)
Get the list of keys for the map.
def __mapbase_get__
Get the value for certain key, return predefined value otherwise.
struct GAUDI_API map
Parametrisation class for map-like implementation.
NamedRange_< CONTAINER > range(const CONTAINER &cnt, std::string name)
simple function to create the named range form arbitrary container
def _draw_aida_(self, args)
def __mapbase_iter__(self)
decorate some map-like objects The iterator for MapBase class
def __mapbase_delitem__(self, key)
"Del-item" for MapBase-based maps:
def _container__getitem__(self, k)
def _container__len__(self)
def __mapbase_items__(self)
Get the list of items for the map.
def __mapbase_values__(self)
Get the list of values for the map.
def __mapbase_contains__(self, key)
Check if the certain key is in the map.
def __mapbase_setitem__(self, key, value)
"Setitem" for MapBase-based maps:
def __mapbase_iteritems__(self)
The iterator for MapBase class.
def _printBitReference(b)