4 """ This Pythonizations module provides a number of useful pythonizations
5 of adaptation of some classes.
13 if not hasattr(gbl,
'ostream') : gbl.gROOT.ProcessLine(
"#include <ostream>")
14 if not hasattr(gbl,
'stringstream') : gbl.gROOT.ProcessLine(
"#include <sstream>")
17 _loadDict_save = PyCintex.loadDict
20 if sys.platform !=
'win32' and name[:3] !=
'lib' : name =
'lib'+name
22 PyCintex.loadDict = _loadDict
27 return 'Histogram 1D "%s" %d bins [%f,%f]' % (h.title(), x.bins(), x.lowerEdge(), x.upperEdge())
30 return map(h.binEntries,
range(x.bins()))
32 x,y = h.xAxis(),h.yAxis()
33 return 'Histogram 2D "%s" %d xbins [%f,%f], %d ybins [%f,%f]' % \
34 (h.title(), x.bins(), x.lowerEdge(), x.upperEdge(), y.bins(), y.lowerEdge(), y.upperEdge() )
36 if s.isSuccess() :
return 'SUCCESS'
37 else :
return 'FAILURE'
39 return str(1==b.bool())
42 s = gbl.stringstream()
46 out = o.__class__.__name__ +
' object'
47 if hasattr( o,
'hasKey')
and o.hasKey() :
48 out +=
' key = '+ str(o.key())
50 out = o.__class__.__name__ +
' NULL object'
53 return self.containedObject(k)
55 return self.numberOfObjects()
57 if hasattr(self,
'containedObjects') : sequential = self.containedObjects()
58 else : sequential = self
60 limit = self.__len__()
62 yield sequential.__getitem__(count)
67 Draw AIDA histogram (through access to internal ROOT histogram
69 >>> aida = ... # get the historgam
73 _fun = PyCintex.gbl.Gaudi.Utils.Aida2ROOT.aida2root
75 return _root.Draw( *args )
77 gbl.AIDA.IHistogram1D.__repr__ = _printHisto1D
78 gbl.AIDA.IHistogram1D.contents = _contentsHisto1D
79 gbl.AIDA.IHistogram2D.__repr__ = _printHisto2D
80 for h
in ( gbl.AIDA.IHistogram ,
81 gbl.AIDA.IHistogram1D ,
82 gbl.AIDA.IHistogram2D ,
83 gbl.AIDA.IHistogram3D ,
85 gbl.AIDA.IProfile2D ) :
89 gbl.StatusCode.__repr__ = _printStatusCode
90 try: gbl._Bit_reference.__repr__ = _printBitReference
92 gbl.ContainedObject.__repr__ = _printFillStream
93 gbl.DataObject.__repr__ = _printFillStream
94 gbl.ObjectContainerBase.__getitem__ = _container__getitem__
95 gbl.ObjectContainerBase.__len__ = _container__len__
96 gbl.ObjectContainerBase.__iter__ = _container__iter__
98 gbl.IUpdateManagerSvc.update =
lambda self,obj: gbl.IUpdateManagerSvc.PythonHelper.update(self,obj)
99 gbl.IUpdateManagerSvc.invalidate =
lambda self,obj: gbl.IUpdateManagerSvc.PythonHelper.invalidate(self,obj)
102 gbl.StatusCode.SUCCESS = 1
103 gbl.StatusCode.FAILURE = 0
106 if hasattr ( gbl.Gaudi.StringKey ,
'__cpp_eq__' ) :
107 _eq = gbl.Gaudi.StringKey.__cpp_eq__
108 setattr ( gbl.Gaudi.StringKey ,
'__eq__' , _eq )
111 if hasattr ( gbl.Gaudi.StringKey ,
'__cpp_ne__' ) :
112 _ne = gbl.Gaudi.StringKey.__cpp_ne__
113 setattr ( gbl.Gaudi.StringKey ,
'__ne__' , _ne )
117 if gbl.gROOT.GetVersionInt() <= 51800 :
119 gbl.GaudiPython.PyROOTPickle.Initialize(libPyROOT, libPyROOT.ObjectProxy)
143 The iterator for MapBase-based containers
145 >>> m = ... ## the map
146 >>> for key in m : print key , m[key]
151 while _index < _size :
152 yield self.key_at ( _index )
178 The iterator for MapBase-based containers
180 >>> m = ... ## the map
181 >>> for key,value in m.iteritems() : print key, value
186 while _index < _size :
187 _key = self.key_at ( _index )
188 yield ( _key , self.at ( _key ) )
213 >>> m = ... ## the map
214 >>> keys = m.keys() ## get the list of keys
219 for i
in range ( 0 , _size ) : _keys.append ( self.key_at ( i ) )
242 Get the list of items
244 >>> m = ... ## the map
245 >>> items = m.keys() ## get the list of items
250 for i
in range ( 0 , _size ) :
251 _key = self.key_at ( i )
252 _value = self.at ( _key )
253 _items.append ( ( _key , _value ) )
276 Get the list of values
278 >>> m = ... ## the map
279 >>> values = m.values() ## get the list of values
284 for i
in range ( 0 , _size ) :
285 _value = self.value_at ( i )
286 _values.append ( _value )
309 Check if the certainkey is in the map
311 >>> m = ... ## the map
312 >>> if 'a' in m : ... ## chekc the presence of the key in the map
315 _num = self.count ( key )
316 return False if 0 == _num
else True
339 Get the value for the certain key, or 'value' otherwise
341 >>> m = ... ## the map
342 >>> v = m.get ( key , 15 )
345 if key
in self :
return self.at( key )
365 Representation of MapBase-based maps:
367 >>> m = ... ## the map
373 for i
in range ( 0 , _size ) :
374 _key = self.key_at ( i )
375 _val = self.at ( _key )
376 if 0 != i : _result +=
' , '
377 _result +=
" %s : %s " % ( str ( _key ) , str ( _val ) )
401 'Set-item' for MapBase-based maps:
403 >>> m = ... ## the map
404 >>> m[key] = value ## set the item
407 _replaced =
True if key
in self
else False
408 self.update ( key , value )
432 'Del-item' for MapBase-based maps:
434 >>> m = ... ## the map
438 _erased =
True if key
in self
else False
442 gbl.Gaudi.Utils.MapBase . __len__ =
lambda s : s.size()
443 gbl.Gaudi.Utils.MapBase . __iter__ = __mapbase_iter__
444 gbl.Gaudi.Utils.MapBase . keys = __mapbase_keys__
445 gbl.Gaudi.Utils.MapBase . __iteritems__ = __mapbase_iteritems__
446 gbl.Gaudi.Utils.MapBase . iteritems = __mapbase_iteritems__
447 gbl.Gaudi.Utils.MapBase . items = __mapbase_items__
448 gbl.Gaudi.Utils.MapBase . values = __mapbase_values__
449 gbl.Gaudi.Utils.MapBase . __contains__ = __mapbase_contains__
450 gbl.Gaudi.Utils.MapBase . has_key = __mapbase_contains__
451 gbl.Gaudi.Utils.MapBase . get = __mapbase_get__
452 gbl.Gaudi.Utils.MapBase . __str__ = __mapbase_str__
453 gbl.Gaudi.Utils.MapBase . __repr__ = __mapbase_str__
454 gbl.Gaudi.Utils.MapBase . __setitem__ = __mapbase_setitem__
455 gbl.Gaudi.Utils.MapBase . __delitem__ = __mapbase_delitem__
456 gbl.Gaudi.Utils.MapBase . __getitem__ =
lambda s,key : s.at ( key )