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)
192 The iterator for MapBase-based containers
194 >>> m = ... ## the map
195 >>> for key in m : print(key , m[key])
200 while _index < _size:
201 yield self.key_at(_index)
230 The iterator for MapBase-based containers
232 >>> m = ... ## the map
233 >>> for key,value in m.iteritems() : print(key, value)
238 while _index < _size:
239 _key = self.key_at(_index)
240 yield (_key, self.at(_key))
268 >>> m = ... ## the map
269 >>> keys = m.keys() ## get the list of keys
274 for i
in range(0, _size):
275 _keys.append(self.key_at(i))
301 Get the list of items
303 >>> m = ... ## the map
304 >>> items = m.keys() ## get the list of items
309 for i
in range(0, _size):
310 _key = self.key_at(i)
311 _value = self.at(_key)
312 _items.append((_key, _value))
338 Get the list of values
340 >>> m = ... ## the map
341 >>> values = m.values() ## get the list of values
346 for i
in range(0, _size):
347 _value = self.value_at(i)
348 _values.append(_value)
374 Check if the certainkey is in the map
376 >>> m = ... ## the map
377 >>> if 'a' in m : ... ## chekc the presence of the key in the map
380 _num = self.count(key)
381 return False if 0 == _num
else True
407 Get the value for the certain key, or 'value' otherwise
409 >>> m = ... ## the map
410 >>> v = m.get ( key , 15 )
437 Representation of MapBase-based maps:
439 >>> m = ... ## the map
445 for i
in range(0, _size):
446 _key = self.key_at(i)
450 _result +=
" %s : %s " % (str(_key), str(_val))
477 'Set-item' for MapBase-based maps:
479 >>> m = ... ## the map
480 >>> m[key] = value ## set the item
483 _replaced =
True if key
in self
else False
484 self.update(key, value)
511 'Del-item' for MapBase-based maps:
513 >>> m = ... ## the map
517 _erased =
True if key
in self
else False
522gbl.Gaudi.Utils.MapBase.__len__ =
lambda s: s.size()
523gbl.Gaudi.Utils.MapBase.__iter__ = __mapbase_iter__
524gbl.Gaudi.Utils.MapBase.keys = __mapbase_keys__
525gbl.Gaudi.Utils.MapBase.__iteritems__ = __mapbase_iteritems__
526gbl.Gaudi.Utils.MapBase.values = __mapbase_values__
527gbl.Gaudi.Utils.MapBase.__contains__ = __mapbase_contains__
528gbl.Gaudi.Utils.MapBase.get = __mapbase_get__
529gbl.Gaudi.Utils.MapBase.__str__ = __mapbase_str__
530gbl.Gaudi.Utils.MapBase.__repr__ = __mapbase_str__
531gbl.Gaudi.Utils.MapBase.__setitem__ = __mapbase_setitem__
532gbl.Gaudi.Utils.MapBase.__delitem__ = __mapbase_delitem__
533gbl.Gaudi.Utils.MapBase.__getitem__ =
lambda s, key: s.at(key)
534gbl.Gaudi.Utils.MapBase.items = __mapbase_iteritems__
542gbl.gInterpreter.Declare(
544#ifndef REENTINTERFACES_PYTHON_HELPERS
545#define REENTINTERFACES_PYTHON_HELPERS
546#include <GaudiKernel/IAlgorithm.h>
547#include <GaudiKernel/IEventProcessor.h>
548#include <GaudiKernel/ThreadLocalContext.h>
550namespace GaudiPython::Helpers {
551 StatusCode executeEvent( IEventProcessor* self ) {
552 return self->executeEvent( self->createEventContext() );
554 bool isExecuted( IAlgorithm* self ) {
555 return self->execState( Gaudi::Hive::currentContext() ).state() == AlgExecState::Done;
557 bool filterPassed( IAlgorithm* self ) {
558 return self->execState( Gaudi::Hive::currentContext() ).filterPassed();
560 StatusCode ialg_execute( IAlgorithm* self ) {
561 return self->execute( Gaudi::Hive::currentContext() );
568gbl.IEventProcessor.executeEvent = gbl.GaudiPython.Helpers.executeEvent
569gbl.IAlgorithm.isExecuted = gbl.GaudiPython.Helpers.isExecuted
570gbl.IAlgorithm.filterPassed = gbl.GaudiPython.Helpers.filterPassed
571gbl.IAlgorithm._execute_orig = gbl.IAlgorithm.execute
572gbl.IAlgorithm.execute =
lambda self, ctx=
None: (
573 gbl.GaudiPython.Helpers.ialg_execute(self)
575 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)