3 """ This Pythonizations module provides a number of useful pythonizations 4 of adaptation of some classes. 6 from __future__
import print_function
15 print(
"# WARNING: using PyCintex as cppyy implementation")
16 from PyCintex
import gbl
18 if not hasattr(gbl,
'ostream'):
19 gbl.gROOT.ProcessLine(
"#include <ostream>")
20 if not hasattr(gbl,
'stringstream'):
21 gbl.gROOT.ProcessLine(
"#include <sstream>")
28 return 'Histogram 1D "%s" %d bins [%f,%f]' % (h.title(), x.bins(),
29 x.lowerEdge(), x.upperEdge())
34 return map(h.binEntries,
range(x.bins()))
38 x, y = h.xAxis(), h.yAxis()
39 return 'Histogram 2D "%s" %d xbins [%f,%f], %d ybins [%f,%f]' % \
40 (h.title(), x.bins(), x.lowerEdge(), x.upperEdge(),
41 y.bins(), y.lowerEdge(), y.upperEdge())
52 return str(1 == b.bool())
57 s = gbl.stringstream()
61 out = o.__class__.__name__ +
' object' 62 if hasattr(o,
'hasKey')
and o.hasKey():
63 out +=
' key = ' + str(o.key())
65 out = o.__class__.__name__ +
' NULL object' 70 return self.containedObject(k)
74 return self.numberOfObjects()
78 if hasattr(self,
'containedObjects'):
79 sequential = self.containedObjects()
83 limit = self.__len__()
85 yield sequential.__getitem__(count)
91 Draw AIDA histogram (through access to internal ROOT histogram 93 >>> aida = ... # get the historgam 97 _fun = gbl.Gaudi.Utils.Aida2ROOT.aida2root
99 return _root.Draw(*args)
102 gbl.AIDA.IHistogram1D.__repr__ = _printHisto1D
103 gbl.AIDA.IHistogram1D.contents = _contentsHisto1D
104 gbl.AIDA.IHistogram2D.__repr__ = _printHisto2D
105 for h
in (gbl.AIDA.IHistogram, gbl.AIDA.IHistogram1D, gbl.AIDA.IHistogram2D,
106 gbl.AIDA.IHistogram3D, gbl.AIDA.IProfile1D, gbl.AIDA.IProfile2D):
110 gbl.StatusCode.__repr__ = _printStatusCode
112 gbl._Bit_reference.__repr__ = _printBitReference
115 gbl.ContainedObject.__repr__ = _printFillStream
116 gbl.DataObject.__repr__ = _printFillStream
117 gbl.ObjectContainerBase.__getitem__ = _container__getitem__
118 gbl.ObjectContainerBase.__len__ = _container__len__
119 gbl.ObjectContainerBase.__iter__ = _container__iter__
121 gbl.IUpdateManagerSvc.update =
lambda self, obj: gbl.IUpdateManagerSvc.PythonHelper.update(
123 gbl.IUpdateManagerSvc.invalidate =
lambda self, obj: gbl.IUpdateManagerSvc.PythonHelper.invalidate(
127 if not hasattr(gbl.StatusCode,
'SUCCESS'):
129 gbl.StatusCode.SUCCESS = 1
130 gbl.StatusCode.FAILURE = 0
133 if hasattr(gbl.Gaudi.StringKey,
'__cpp_eq__'):
134 _eq = gbl.Gaudi.StringKey.__cpp_eq__
135 setattr(gbl.Gaudi.StringKey,
'__eq__', _eq)
138 if hasattr(gbl.Gaudi.StringKey,
'__cpp_ne__'):
139 _ne = gbl.Gaudi.StringKey.__cpp_ne__
140 setattr(gbl.Gaudi.StringKey,
'__ne__', _ne)
143 if gbl.gROOT.GetVersionInt() <= 51800:
145 gbl.GaudiPython.PyROOTPickle.Initialize(libPyROOT, libPyROOT.ObjectProxy)
171 The iterator for MapBase-based containers 173 >>> m = ... ## the map 174 >>> for key in m : print key , m[key] 179 while _index < _size:
180 yield self.key_at(_index)
209 The iterator for MapBase-based containers 211 >>> m = ... ## the map 212 >>> for key,value in m.iteritems() : print key, value 217 while _index < _size:
218 _key = self.key_at(_index)
219 yield (_key, self.at(_key))
247 >>> m = ... ## the map 248 >>> keys = m.keys() ## get the list of keys 253 for i
in range(0, _size):
254 _keys.append(self.key_at(i))
280 Get the list of items 282 >>> m = ... ## the map 283 >>> items = m.keys() ## get the list of items 288 for i
in range(0, _size):
289 _key = self.key_at(i)
290 _value = self.at(_key)
291 _items.append((_key, _value))
317 Get the list of values 319 >>> m = ... ## the map 320 >>> values = m.values() ## get the list of values 325 for i
in range(0, _size):
326 _value = self.value_at(i)
327 _values.append(_value)
353 Check if the certainkey is in the map 355 >>> m = ... ## the map 356 >>> if 'a' in m : ... ## chekc the presence of the key in the map 359 _num = self.count(key)
360 return False if 0 == _num
else True 386 Get the value for the certain key, or 'value' otherwise 388 >>> m = ... ## the map 389 >>> v = m.get ( key , 15 ) 416 Representation of MapBase-based maps: 418 >>> m = ... ## the map 424 for i
in range(0, _size):
425 _key = self.key_at(i)
429 _result +=
" %s : %s " % (str(_key), str(_val))
456 'Set-item' for MapBase-based maps: 458 >>> m = ... ## the map 459 >>> m[key] = value ## set the item 462 _replaced =
True if key
in self
else False 463 self.update(key, value)
490 'Del-item' for MapBase-based maps: 492 >>> m = ... ## the map 496 _erased =
True if key
in self
else False 501 gbl.Gaudi.Utils.MapBase.__len__ =
lambda s: s.size()
502 gbl.Gaudi.Utils.MapBase.__iter__ = __mapbase_iter__
503 gbl.Gaudi.Utils.MapBase.keys = __mapbase_keys__
504 gbl.Gaudi.Utils.MapBase.__iteritems__ = __mapbase_iteritems__
505 gbl.Gaudi.Utils.MapBase.values = __mapbase_values__
506 gbl.Gaudi.Utils.MapBase.__contains__ = __mapbase_contains__
507 gbl.Gaudi.Utils.MapBase.get = __mapbase_get__
508 gbl.Gaudi.Utils.MapBase.__str__ = __mapbase_str__
509 gbl.Gaudi.Utils.MapBase.__repr__ = __mapbase_str__
510 gbl.Gaudi.Utils.MapBase.__setitem__ = __mapbase_setitem__
511 gbl.Gaudi.Utils.MapBase.__delitem__ = __mapbase_delitem__
512 gbl.Gaudi.Utils.MapBase.__getitem__ =
lambda s, key: s.at(key)
515 gbl.Gaudi.Utils.MapBase.iteritems = __mapbase_iteritems__
516 gbl.Gaudi.Utils.MapBase.items = __mapbase_items__
517 gbl.Gaudi.Utils.MapBase.has_key = __mapbase_contains__
520 gbl.Gaudi.Utils.MapBase.items = __mapbase_iteritems__
528 gbl.gInterpreter.Declare(
""" 529 #ifndef REENTINTERFACES_PYTHON_HELPERS 530 #define REENTINTERFACES_PYTHON_HELPERS 531 #include <GaudiKernel/IAlgorithm.h> 532 #include <GaudiKernel/IEventProcessor.h> 533 #include <GaudiKernel/ThreadLocalContext.h> 535 namespace GaudiPython::Helpers { 536 StatusCode executeEvent( IEventProcessor* self ) { 537 return self->executeEvent( self->createEventContext() ); 539 bool isExecuted( IAlgorithm* self ) { 540 return self->execState( Gaudi::Hive::currentContext() ).state() == AlgExecState::State::Done; 542 bool filterPassed( IAlgorithm* self ) { 543 return self->execState( Gaudi::Hive::currentContext() ).filterPassed(); 545 StatusCode ialg_execute( IAlgorithm* self ) { 546 return self->execute( Gaudi::Hive::currentContext() ); 552 gbl.IEventProcessor.executeEvent = gbl.GaudiPython.Helpers.executeEvent
553 gbl.IAlgorithm.isExecuted = gbl.GaudiPython.Helpers.isExecuted
554 gbl.IAlgorithm.filterPassed = gbl.GaudiPython.Helpers.filterPassed
555 gbl.IAlgorithm._execute_orig = gbl.IAlgorithm.execute
556 gbl.IAlgorithm.execute =
lambda self, ctx=
None: (gbl.GaudiPython.Helpers.ialg_execute(self)
if ctx
is None else self._execute_orig(ctx))
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 __mapbase_get__(self, key, value=None)
def __mapbase_iter__(self)
def __mapbase_delitem__(self, key)
def _container__len__(self)
decltype(auto) range(Args &&... args)
Zips multiple containers together to form a single range.
def _draw_aida_(self, *args)
def __mapbase_str__(self)