13 """This Pythonizations module provides a number of useful pythonizations
14 of adaptation of some classes.
23 print(
"# WARNING: using PyCintex as cppyy implementation")
24 from PyCintex
import gbl
26 if not hasattr(gbl,
"ostream"):
27 gbl.gROOT.ProcessLine(
"#include <ostream>")
28 if not hasattr(gbl,
"stringstream"):
29 gbl.gROOT.ProcessLine(
"#include <sstream>")
36 return 'Histogram 1D "%s" %d bins [%f,%f]' % (
46 return map(h.binEntries,
range(x.bins()))
50 x, y = h.xAxis(), h.yAxis()
51 return 'Histogram 2D "%s" %d xbins [%f,%f], %d ybins [%f,%f]' % (
70 return str(1 == b.bool())
75 s = gbl.stringstream()
79 out = o.__class__.__name__ +
" object"
80 if hasattr(o,
"hasKey")
and o.hasKey():
81 out +=
" key = " + str(o.key())
83 out = o.__class__.__name__ +
" NULL object"
88 return self.containedObject(k)
92 return self.numberOfObjects()
96 if hasattr(self,
"containedObjects"):
97 sequential = self.containedObjects()
101 limit = self.__len__()
103 yield sequential.__getitem__(count)
109 Draw AIDA histogram (through access to internal ROOT histogram
111 >>> aida = ... # get the historgam
115 _fun = gbl.Gaudi.Utils.Aida2ROOT.aida2root
117 return _root.Draw(*args)
120 gbl.AIDA.IHistogram1D.__str__ = _printHisto1D
121 gbl.AIDA.IHistogram1D.contents = _contentsHisto1D
122 gbl.AIDA.IHistogram2D.__str__ = _printHisto2D
125 gbl.AIDA.IHistogram1D,
126 gbl.AIDA.IHistogram2D,
127 gbl.AIDA.IHistogram3D,
134 gbl.StatusCode.__repr__ = _printStatusCode
136 gbl._Bit_reference.__repr__ = _printBitReference
139 gbl.ContainedObject.__repr__ = _printFillStream
140 gbl.DataObject.__repr__ = _printFillStream
141 gbl.ObjectContainerBase.__getitem__ = _container__getitem__
142 gbl.ObjectContainerBase.__len__ = _container__len__
143 gbl.ObjectContainerBase.__iter__ = _container__iter__
145 gbl.IUpdateManagerSvc.update = (
146 lambda self, obj: gbl.IUpdateManagerSvc.PythonHelper.update(self, obj)
148 gbl.IUpdateManagerSvc.invalidate = (
149 lambda self, obj: gbl.IUpdateManagerSvc.PythonHelper.invalidate(self, obj)
153 if not hasattr(gbl.StatusCode,
"SUCCESS"):
155 gbl.StatusCode.SUCCESS = 1
156 gbl.StatusCode.FAILURE = 0
159 if hasattr(gbl.Gaudi.StringKey,
"__cpp_eq__"):
160 _eq = gbl.Gaudi.StringKey.__cpp_eq__
161 setattr(gbl.Gaudi.StringKey,
"__eq__", _eq)
164 if hasattr(gbl.Gaudi.StringKey,
"__cpp_ne__"):
165 _ne = gbl.Gaudi.StringKey.__cpp_ne__
166 setattr(gbl.Gaudi.StringKey,
"__ne__", _ne)
169 if gbl.gROOT.GetVersionInt() <= 51800:
172 gbl.GaudiPython.PyROOTPickle.Initialize(libPyROOT, libPyROOT.ObjectProxy)
198 The iterator for MapBase-based containers
200 >>> m = ... ## the map
201 >>> for key in m : print(key , m[key])
206 while _index < _size:
207 yield self.key_at(_index)
236 The iterator for MapBase-based containers
238 >>> m = ... ## the map
239 >>> for key,value in m.iteritems() : print(key, value)
244 while _index < _size:
245 _key = self.key_at(_index)
246 yield (_key, self.at(_key))
274 >>> m = ... ## the map
275 >>> keys = m.keys() ## get the list of keys
280 for i
in range(0, _size):
281 _keys.append(self.key_at(i))
307 Get the list of items
309 >>> m = ... ## the map
310 >>> items = m.keys() ## get the list of items
315 for i
in range(0, _size):
316 _key = self.key_at(i)
317 _value = self.at(_key)
318 _items.append((_key, _value))
344 Get the list of values
346 >>> m = ... ## the map
347 >>> values = m.values() ## get the list of values
352 for i
in range(0, _size):
353 _value = self.value_at(i)
354 _values.append(_value)
380 Check if the certainkey is in the map
382 >>> m = ... ## the map
383 >>> if 'a' in m : ... ## chekc the presence of the key in the map
386 _num = self.count(key)
387 return False if 0 == _num
else True
413 Get the value for the certain key, or 'value' otherwise
415 >>> m = ... ## the map
416 >>> v = m.get ( key , 15 )
443 Representation of MapBase-based maps:
445 >>> m = ... ## the map
451 for i
in range(0, _size):
452 _key = self.key_at(i)
456 _result +=
" %s : %s " % (str(_key), str(_val))
483 'Set-item' for MapBase-based maps:
485 >>> m = ... ## the map
486 >>> m[key] = value ## set the item
489 _replaced =
True if key
in self
else False
490 self.update(key, value)
517 'Del-item' for MapBase-based maps:
519 >>> m = ... ## the map
523 _erased =
True if key
in self
else False
528 gbl.Gaudi.Utils.MapBase.__len__ =
lambda s: s.size()
529 gbl.Gaudi.Utils.MapBase.__iter__ = __mapbase_iter__
530 gbl.Gaudi.Utils.MapBase.keys = __mapbase_keys__
531 gbl.Gaudi.Utils.MapBase.__iteritems__ = __mapbase_iteritems__
532 gbl.Gaudi.Utils.MapBase.values = __mapbase_values__
533 gbl.Gaudi.Utils.MapBase.__contains__ = __mapbase_contains__
534 gbl.Gaudi.Utils.MapBase.get = __mapbase_get__
535 gbl.Gaudi.Utils.MapBase.__str__ = __mapbase_str__
536 gbl.Gaudi.Utils.MapBase.__repr__ = __mapbase_str__
537 gbl.Gaudi.Utils.MapBase.__setitem__ = __mapbase_setitem__
538 gbl.Gaudi.Utils.MapBase.__delitem__ = __mapbase_delitem__
539 gbl.Gaudi.Utils.MapBase.__getitem__ =
lambda s, key: s.at(key)
540 gbl.Gaudi.Utils.MapBase.items = __mapbase_iteritems__
548 gbl.gInterpreter.Declare(
550 #ifndef REENTINTERFACES_PYTHON_HELPERS
551 #define REENTINTERFACES_PYTHON_HELPERS
552 #include <GaudiKernel/IAlgorithm.h>
553 #include <GaudiKernel/IEventProcessor.h>
554 #include <GaudiKernel/ThreadLocalContext.h>
556 namespace GaudiPython::Helpers {
557 StatusCode executeEvent( IEventProcessor* self ) {
558 return self->executeEvent( self->createEventContext() );
560 bool isExecuted( IAlgorithm* self ) {
561 return self->execState( Gaudi::Hive::currentContext() ).state() == AlgExecState::State::Done;
563 bool filterPassed( IAlgorithm* self ) {
564 return self->execState( Gaudi::Hive::currentContext() ).filterPassed();
566 StatusCode ialg_execute( IAlgorithm* self ) {
567 return self->execute( Gaudi::Hive::currentContext() );
574 gbl.IEventProcessor.executeEvent = gbl.GaudiPython.Helpers.executeEvent
575 gbl.IAlgorithm.isExecuted = gbl.GaudiPython.Helpers.isExecuted
576 gbl.IAlgorithm.filterPassed = gbl.GaudiPython.Helpers.filterPassed
577 gbl.IAlgorithm._execute_orig = gbl.IAlgorithm.execute
578 gbl.IAlgorithm.execute =
lambda self, ctx=
None: (
579 gbl.GaudiPython.Helpers.ialg_execute(self)
581 else self._execute_orig(ctx)