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__
146if not hasattr(gbl.StatusCode,
"SUCCESS"):
148 gbl.StatusCode.SUCCESS = 1
149 gbl.StatusCode.FAILURE = 0
152if hasattr(gbl.Gaudi.StringKey,
"__cpp_eq__"):
153 _eq = gbl.Gaudi.StringKey.__cpp_eq__
154 setattr(gbl.Gaudi.StringKey,
"__eq__", _eq)
157if hasattr(gbl.Gaudi.StringKey,
"__cpp_ne__"):
158 _ne = gbl.Gaudi.StringKey.__cpp_ne__
159 setattr(gbl.Gaudi.StringKey,
"__ne__", _ne)
185 The iterator for MapBase-based containers
187 >>> m = ... ## the map
188 >>> for key in m : print(key , m[key])
193 while _index < _size:
194 yield self.key_at(_index)
223 The iterator for MapBase-based containers
225 >>> m = ... ## the map
226 >>> for key,value in m.iteritems() : print(key, value)
231 while _index < _size:
232 _key = self.key_at(_index)
233 yield (_key, self.at(_key))
261 >>> m = ... ## the map
262 >>> keys = m.keys() ## get the list of keys
267 for i
in range(0, _size):
268 _keys.append(self.key_at(i))
294 Get the list of items
296 >>> m = ... ## the map
297 >>> items = m.keys() ## get the list of items
302 for i
in range(0, _size):
303 _key = self.key_at(i)
304 _value = self.at(_key)
305 _items.append((_key, _value))
331 Get the list of values
333 >>> m = ... ## the map
334 >>> values = m.values() ## get the list of values
339 for i
in range(0, _size):
340 _value = self.value_at(i)
341 _values.append(_value)
367 Check if the certainkey is in the map
369 >>> m = ... ## the map
370 >>> if 'a' in m : ... ## chekc the presence of the key in the map
373 _num = self.count(key)
374 return False if 0 == _num
else True
400 Get the value for the certain key, or 'value' otherwise
402 >>> m = ... ## the map
403 >>> v = m.get ( key , 15 )
430 Representation of MapBase-based maps:
432 >>> m = ... ## the map
438 for i
in range(0, _size):
439 _key = self.key_at(i)
443 _result +=
" %s : %s " % (str(_key), str(_val))
470 'Set-item' for MapBase-based maps:
472 >>> m = ... ## the map
473 >>> m[key] = value ## set the item
476 _replaced =
True if key
in self
else False
477 self.update(key, value)
504 'Del-item' for MapBase-based maps:
506 >>> m = ... ## the map
510 _erased =
True if key
in self
else False
515gbl.Gaudi.Utils.MapBase.__len__ =
lambda s: s.size()
516gbl.Gaudi.Utils.MapBase.__iter__ = __mapbase_iter__
517gbl.Gaudi.Utils.MapBase.keys = __mapbase_keys__
518gbl.Gaudi.Utils.MapBase.__iteritems__ = __mapbase_iteritems__
519gbl.Gaudi.Utils.MapBase.values = __mapbase_values__
520gbl.Gaudi.Utils.MapBase.__contains__ = __mapbase_contains__
521gbl.Gaudi.Utils.MapBase.get = __mapbase_get__
522gbl.Gaudi.Utils.MapBase.__str__ = __mapbase_str__
523gbl.Gaudi.Utils.MapBase.__repr__ = __mapbase_str__
524gbl.Gaudi.Utils.MapBase.__setitem__ = __mapbase_setitem__
525gbl.Gaudi.Utils.MapBase.__delitem__ = __mapbase_delitem__
526gbl.Gaudi.Utils.MapBase.__getitem__ =
lambda s, key: s.at(key)
527gbl.Gaudi.Utils.MapBase.items = __mapbase_iteritems__
535gbl.gInterpreter.Declare(
537#ifndef REENTINTERFACES_PYTHON_HELPERS
538#define REENTINTERFACES_PYTHON_HELPERS
539#include <GaudiKernel/IAlgorithm.h>
540#include <GaudiKernel/IEventProcessor.h>
541#include <GaudiKernel/ThreadLocalContext.h>
543namespace GaudiPython::Helpers {
544 StatusCode executeEvent( IEventProcessor* self ) {
545 return self->executeEvent( self->createEventContext() );
547 bool isExecuted( IAlgorithm* self ) {
548 return self->execState( Gaudi::Hive::currentContext() ).state() == AlgExecState::Done;
550 bool filterPassed( IAlgorithm* self ) {
551 return self->execState( Gaudi::Hive::currentContext() ).filterPassed();
553 StatusCode ialg_execute( IAlgorithm* self ) {
554 return self->execute( Gaudi::Hive::currentContext() );
561gbl.IEventProcessor.executeEvent = gbl.GaudiPython.Helpers.executeEvent
562gbl.IAlgorithm.isExecuted = gbl.GaudiPython.Helpers.isExecuted
563gbl.IAlgorithm.filterPassed = gbl.GaudiPython.Helpers.filterPassed
564gbl.IAlgorithm._execute_orig = gbl.IAlgorithm.execute
565gbl.IAlgorithm.execute =
lambda self, ctx=
None: (
566 gbl.GaudiPython.Helpers.ialg_execute(self)
568 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)