Gaudi Framework, version v21r7p1

Home   Generated: 15 Feb 2010

Pythonizations.py

Go to the documentation of this file.
00001 # File: GaudiPython/Pythonizations.py
00002 # Author: Pere Mato (pere.mato@cern.ch)
00003 
00004 """ This Pythonizations module provides a number of useful pythonizations
00005     of adaptation of some classes.
00006 """
00007 
00008 __all__ = [ ]
00009 
00010 import PyCintex
00011 gbl = PyCintex.gbl
00012 
00013 if not hasattr(gbl,'ostream') : gbl.gROOT.ProcessLine("#include <ostream>")
00014 if not hasattr(gbl,'stringstream') : gbl.gROOT.ProcessLine("#include <sstream>")
00015 
00016 #--- Hack to match the name scheme of dictionary on Linux ----------------------------
00017 _loadDict_save = PyCintex.loadDict
00018 def _loadDict(name):
00019     import sys
00020     if sys.platform != 'win32' and name[:3] != 'lib' : name = 'lib'+name
00021     return _loadDict_save(name)
00022 PyCintex.loadDict = _loadDict
00023 
00024 #--- Adding extra functionality to C++ raw classes------------------------------------
00025 def _printHisto1D(h) :
00026     x = h.axis()
00027     return  'Histogram 1D "%s" %d bins [%f,%f]' % (h.title(), x.bins(), x.lowerEdge(), x.upperEdge())
00028 def _contentsHisto1D(h) :
00029     x = h.axis()
00030     return  map(h.binEntries, range(x.bins()))
00031 def _printHisto2D(h) :
00032     x,y = h.xAxis(),h.yAxis()
00033     return  'Histogram 2D "%s" %d xbins [%f,%f], %d ybins [%f,%f]' % \
00034     (h.title(), x.bins(), x.lowerEdge(), x.upperEdge(), y.bins(), y.lowerEdge(), y.upperEdge() )
00035 def _printStatusCode(s) :
00036     if s.isSuccess() : return 'SUCCESS'
00037     else             : return 'FAILURE'
00038 def _printBitReference(b) :
00039     return str(1==b.bool())
00040 def _printFillStream(o) :
00041     if  o :
00042         s = gbl.stringstream()
00043         o.fillStream(s)
00044         out = s.str()
00045         if out == '' :
00046             out = o.__class__.__name__ + ' object'
00047             if hasattr( o, 'hasKey') and o.hasKey() :
00048                 out += ' key = '+ str(o.key())
00049     else :
00050         out = o.__class__.__name__ + ' NULL object'
00051     return out
00052 def _container__getitem__(self, k) :
00053     return self.containedObject(k)
00054 def _container__len__(self) :
00055     return self.numberOfObjects()
00056 def _container__iter__(self) :
00057     if hasattr(self,'containedObjects') : sequential = self.containedObjects()
00058     else                                : sequential = self
00059     count = 0
00060     limit = self.__len__()
00061     while count < limit :
00062         yield sequential.__getitem__(count)
00063         count += 1
00064 
00065 def _draw_aida_ ( self , *args ) :
00066     """
00067     Draw AIDA histogram (through access to internal ROOT histogram
00068 
00069     >>> aida = ...    # get the historgam
00070     >>> aida.Draw()
00071 
00072     """
00073     _fun = PyCintex.gbl.Gaudi.Utils.Aida2ROOT.aida2root
00074     _root = _fun ( self )
00075     return _root.Draw( *args )
00076 
00077 gbl.AIDA.IHistogram1D.__repr__ = _printHisto1D
00078 gbl.AIDA.IHistogram1D.contents = _contentsHisto1D
00079 gbl.AIDA.IHistogram2D.__repr__ = _printHisto2D
00080 for h in (  gbl.AIDA.IHistogram   ,
00081             gbl.AIDA.IHistogram1D ,
00082             gbl.AIDA.IHistogram2D ,
00083             gbl.AIDA.IHistogram3D ,
00084             gbl.AIDA.IProfile1D   ,
00085             gbl.AIDA.IProfile2D   ) :
00086     h.Draw = _draw_aida_
00087     h.plot = _draw_aida_
00088 
00089 gbl.StatusCode.__repr__ = _printStatusCode
00090 try: gbl._Bit_reference.__repr__ = _printBitReference
00091 except: pass
00092 gbl.ContainedObject.__repr__ = _printFillStream
00093 gbl.DataObject.__repr__ = _printFillStream
00094 gbl.ObjectContainerBase.__getitem__ = _container__getitem__
00095 gbl.ObjectContainerBase.__len__ = _container__len__
00096 gbl.ObjectContainerBase.__iter__ = _container__iter__
00097 
00098 gbl.IUpdateManagerSvc.update = lambda self,obj: gbl.IUpdateManagerSvc.PythonHelper.update(self,obj)
00099 gbl.IUpdateManagerSvc.invalidate = lambda self,obj: gbl.IUpdateManagerSvc.PythonHelper.invalidate(self,obj)
00100 
00101 #---Globals--------------------------------------------------------------------
00102 gbl.StatusCode.SUCCESS = 1
00103 gbl.StatusCode.FAILURE = 0
00104 
00105 # - string key, equality
00106 if hasattr ( gbl.Gaudi.StringKey ,'__cpp_eq__' ) :
00107     _eq = gbl.Gaudi.StringKey.__cpp_eq__
00108     setattr ( gbl.Gaudi.StringKey ,'__eq__' , _eq )
00109 
00110 # - string key, non-equality
00111 if hasattr ( gbl.Gaudi.StringKey ,'__cpp_ne__' ) :
00112     _ne = gbl.Gaudi.StringKey.__cpp_ne__
00113     setattr ( gbl.Gaudi.StringKey ,'__ne__' , _ne )
00114 
00115 
00116 #---Enabling Pickle support----------------------------------------------------
00117 if  gbl.gROOT.GetVersionInt() <= 51800 :
00118     import libPyROOT
00119     gbl.GaudiPython.PyROOTPickle.Initialize(libPyROOT, libPyROOT.ObjectProxy)

Generated at Mon Feb 15 17:27:28 2010 for Gaudi Framework, version v21r7p1 by Doxygen version 1.5.6 written by Dimitri van Heesch, © 1997-2004