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>")
37 f
'Histogram 1D "{h.title()}" {x.bins()} bins [{x.lowerEdge()},{x.upperEdge()}]'
43 return map(h.binEntries, range(x.bins()))
47 x, y = h.xAxis(), h.yAxis()
48 return f
'Histogram 2D "{h.title()}" {x.bins()} xbins [{x.lowerEdge()},{x.upperEdge()}], {y.bins()} ybins [{y.lowerEdge()},{y.upperEdge()}]'
59 return str(1 == b.bool())
64 s = gbl.stringstream()
68 out = o.__class__.__name__ +
" object"
69 if hasattr(o,
"hasKey")
and o.hasKey():
70 out +=
" key = " + str(o.key())
72 out = o.__class__.__name__ +
" NULL object"
77 return self.containedObject(k)
81 return self.numberOfObjects()
85 if hasattr(self,
"containedObjects"):
86 sequential = self.containedObjects()
90 limit = self.__len__()
92 yield sequential.__getitem__(count)
98 Draw AIDA histogram (through access to internal ROOT histogram
100 >>> aida = ... # get the historgam
104 _fun = gbl.Gaudi.Utils.Aida2ROOT.aida2root
106 return _root.Draw(*args)
109gbl.AIDA.IHistogram1D.__str__ = _printHisto1D
110gbl.AIDA.IHistogram1D.contents = _contentsHisto1D
111gbl.AIDA.IHistogram2D.__str__ = _printHisto2D
114 gbl.AIDA.IHistogram1D,
115 gbl.AIDA.IHistogram2D,
116 gbl.AIDA.IHistogram3D,
123gbl.StatusCode.__repr__ = _printStatusCode
125 gbl._Bit_reference.__repr__ = _printBitReference
128gbl.ContainedObject.__repr__ = _printFillStream
129gbl.DataObject.__repr__ = _printFillStream
130gbl.ObjectContainerBase.__getitem__ = _container__getitem__
131gbl.ObjectContainerBase.__len__ = _container__len__
132gbl.ObjectContainerBase.__iter__ = _container__iter__
135if not hasattr(gbl.StatusCode,
"SUCCESS"):
137 gbl.StatusCode.SUCCESS = 1
138 gbl.StatusCode.FAILURE = 0
141if hasattr(gbl.Gaudi.StringKey,
"__cpp_eq__"):
142 _eq = gbl.Gaudi.StringKey.__cpp_eq__
143 setattr(gbl.Gaudi.StringKey,
"__eq__", _eq)
146if hasattr(gbl.Gaudi.StringKey,
"__cpp_ne__"):
147 _ne = gbl.Gaudi.StringKey.__cpp_ne__
148 setattr(gbl.Gaudi.StringKey,
"__ne__", _ne)
174 The iterator for MapBase-based containers
176 >>> m = ... ## the map
177 >>> for key in m : print(key , m[key])
182 while _index < _size:
183 yield self.key_at(_index)
212 The iterator for MapBase-based containers
214 >>> m = ... ## the map
215 >>> for key,value in m.iteritems() : print(key, value)
220 while _index < _size:
221 _key = self.key_at(_index)
222 yield (_key, self.at(_key))
250 >>> m = ... ## the map
251 >>> keys = m.keys() ## get the list of keys
256 for i
in range(0, _size):
257 _keys.append(self.key_at(i))
283 Get the list of items
285 >>> m = ... ## the map
286 >>> items = m.keys() ## get the list of items
291 for i
in range(0, _size):
292 _key = self.key_at(i)
293 _value = self.at(_key)
294 _items.append((_key, _value))
320 Get the list of values
322 >>> m = ... ## the map
323 >>> values = m.values() ## get the list of values
328 for i
in range(0, _size):
329 _value = self.value_at(i)
330 _values.append(_value)
356 Check if the certainkey is in the map
358 >>> m = ... ## the map
359 >>> if 'a' in m : ... ## chekc the presence of the key in the map
362 _num = self.count(key)
363 return False if 0 == _num
else True
389 Get the value for the certain key, or 'value' otherwise
391 >>> m = ... ## the map
392 >>> v = m.get ( key , 15 )
419 Representation of MapBase-based maps:
421 >>> m = ... ## the map
427 for i
in range(0, _size):
428 _key = self.key_at(i)
432 _result += f
" {_key} : {_val} "
459 'Set-item' for MapBase-based maps:
461 >>> m = ... ## the map
462 >>> m[key] = value ## set the item
465 _replaced =
True if key
in self
else False
466 self.update(key, value)
493 'Del-item' for MapBase-based maps:
495 >>> m = ... ## the map
499 _erased =
True if key
in self
else False
504gbl.Gaudi.Utils.MapBase.__len__ =
lambda s: s.size()
505gbl.Gaudi.Utils.MapBase.__iter__ = __mapbase_iter__
506gbl.Gaudi.Utils.MapBase.keys = __mapbase_keys__
507gbl.Gaudi.Utils.MapBase.__iteritems__ = __mapbase_iteritems__
508gbl.Gaudi.Utils.MapBase.values = __mapbase_values__
509gbl.Gaudi.Utils.MapBase.__contains__ = __mapbase_contains__
510gbl.Gaudi.Utils.MapBase.get = __mapbase_get__
511gbl.Gaudi.Utils.MapBase.__str__ = __mapbase_str__
512gbl.Gaudi.Utils.MapBase.__repr__ = __mapbase_str__
513gbl.Gaudi.Utils.MapBase.__setitem__ = __mapbase_setitem__
514gbl.Gaudi.Utils.MapBase.__delitem__ = __mapbase_delitem__
515gbl.Gaudi.Utils.MapBase.__getitem__ =
lambda s, key: s.at(key)
516gbl.Gaudi.Utils.MapBase.items = __mapbase_iteritems__
524gbl.gInterpreter.Declare(
526#ifndef REENTINTERFACES_PYTHON_HELPERS
527#define REENTINTERFACES_PYTHON_HELPERS
528#include <GaudiKernel/IAlgorithm.h>
529#include <GaudiKernel/IEventProcessor.h>
530#include <GaudiKernel/ThreadLocalContext.h>
532namespace GaudiPython::Helpers {
533 StatusCode executeEvent( IEventProcessor* self ) {
534 return self->executeEvent( self->createEventContext() );
536 bool isExecuted( IAlgorithm* self ) {
537 return self->execState( Gaudi::Hive::currentContext() ).state() == AlgExecState::Done;
539 bool filterPassed( IAlgorithm* self ) {
540 return self->execState( Gaudi::Hive::currentContext() ).filterPassed();
542 StatusCode ialg_execute( IAlgorithm* self ) {
543 return self->execute( Gaudi::Hive::currentContext() );
550gbl.IEventProcessor.executeEvent = gbl.GaudiPython.Helpers.executeEvent
551gbl.IAlgorithm.isExecuted = gbl.GaudiPython.Helpers.isExecuted
552gbl.IAlgorithm.filterPassed = gbl.GaudiPython.Helpers.filterPassed
553gbl.IAlgorithm._execute_orig = gbl.IAlgorithm.execute
554gbl.IAlgorithm.execute =
lambda self, ctx=
None: (
555 gbl.GaudiPython.Helpers.ialg_execute(self)
557 else self._execute_orig(ctx)
__mapbase_get__(self, key, value=None)
_container__getitem__(self, k)
__mapbase_setitem__(self, key, value)
__mapbase_iteritems__(self)
__mapbase_contains__(self, key)
__mapbase_delitem__(self, key)