13"""This Pythonizations module provides a number of useful pythonizations
14of adaptation of some classes.
23 print(
"# WARNING: using PyCintex as cppyy implementation")
24 from PyCintex
import gbl
26if not hasattr(gbl,
"ostream"):
27 gbl.gROOT.ProcessLine(
"#include <ostream>")
28if 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)
120gbl.AIDA.IHistogram1D.__str__ = _printHisto1D
121gbl.AIDA.IHistogram1D.contents = _contentsHisto1D
122gbl.AIDA.IHistogram2D.__str__ = _printHisto2D
125 gbl.AIDA.IHistogram1D,
126 gbl.AIDA.IHistogram2D,
127 gbl.AIDA.IHistogram3D,
134gbl.StatusCode.__repr__ = _printStatusCode
136 gbl._Bit_reference.__repr__ = _printBitReference
139gbl.ContainedObject.__repr__ = _printFillStream
140gbl.DataObject.__repr__ = _printFillStream
141gbl.ObjectContainerBase.__getitem__ = _container__getitem__
142gbl.ObjectContainerBase.__len__ = _container__len__
143gbl.ObjectContainerBase.__iter__ = _container__iter__
145gbl.IUpdateManagerSvc.update = (
146 lambda self, obj: gbl.IUpdateManagerSvc.PythonHelper.update(self, obj)
148gbl.IUpdateManagerSvc.invalidate = (
149 lambda self, obj: gbl.IUpdateManagerSvc.PythonHelper.invalidate(self, obj)
153if not hasattr(gbl.StatusCode,
"SUCCESS"):
155 gbl.StatusCode.SUCCESS = 1
156 gbl.StatusCode.FAILURE = 0
159if hasattr(gbl.Gaudi.StringKey,
"__cpp_eq__"):
160 _eq = gbl.Gaudi.StringKey.__cpp_eq__
161 setattr(gbl.Gaudi.StringKey,
"__eq__", _eq)
164if hasattr(gbl.Gaudi.StringKey,
"__cpp_ne__"):
165 _ne = gbl.Gaudi.StringKey.__cpp_ne__
166 setattr(gbl.Gaudi.StringKey,
"__ne__", _ne)
169if 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
528gbl.Gaudi.Utils.MapBase.__len__ =
lambda s: s.size()
529gbl.Gaudi.Utils.MapBase.__iter__ = __mapbase_iter__
530gbl.Gaudi.Utils.MapBase.keys = __mapbase_keys__
531gbl.Gaudi.Utils.MapBase.__iteritems__ = __mapbase_iteritems__
532gbl.Gaudi.Utils.MapBase.values = __mapbase_values__
533gbl.Gaudi.Utils.MapBase.__contains__ = __mapbase_contains__
534gbl.Gaudi.Utils.MapBase.get = __mapbase_get__
535gbl.Gaudi.Utils.MapBase.__str__ = __mapbase_str__
536gbl.Gaudi.Utils.MapBase.__repr__ = __mapbase_str__
537gbl.Gaudi.Utils.MapBase.__setitem__ = __mapbase_setitem__
538gbl.Gaudi.Utils.MapBase.__delitem__ = __mapbase_delitem__
539gbl.Gaudi.Utils.MapBase.__getitem__ =
lambda s, key: s.at(key)
540gbl.Gaudi.Utils.MapBase.items = __mapbase_iteritems__
548gbl.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>
556namespace 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::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() );
574gbl.IEventProcessor.executeEvent = gbl.GaudiPython.Helpers.executeEvent
575gbl.IAlgorithm.isExecuted = gbl.GaudiPython.Helpers.isExecuted
576gbl.IAlgorithm.filterPassed = gbl.GaudiPython.Helpers.filterPassed
577gbl.IAlgorithm._execute_orig = gbl.IAlgorithm.execute
578gbl.IAlgorithm.execute =
lambda self, ctx=
None: (
579 gbl.GaudiPython.Helpers.ialg_execute(self)
581 else self._execute_orig(ctx)
__mapbase_iteritems__(self)
__mapbase_contains__(self, key)
__mapbase_get__(self, key, value=None)
_container__getitem__(self, k)
__mapbase_delitem__(self, key)
__mapbase_setitem__(self, key, value)