Gaudi Framework, version v20r4

Generated: 8 Jan 2009

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 
00012 #--- Hack to match the name scheme of dictionary on Linux ----------------------------
00013 _loadDict_save = PyCintex.loadDict
00014 def _loadDict(name):
00015   import sys
00016   if sys.platform != 'win32' and name[:3] != 'lib' : name = 'lib'+name
00017   return _loadDict_save(name)
00018 PyCintex.loadDict = _loadDict
00019  
00020 #--- Adding extra functionality to C++ raw classes------------------------------------
00021 def _printHisto1D(h) :
00022   x = h.axis()
00023   return  'Histogram 1D "%s" %d bins [%f,%f]' % (h.title(), x.bins(), x.lowerEdge(), x.upperEdge())
00024 def _contentsHisto1D(h) :
00025   x = h.axis()
00026   return  map(h.binEntries, range(x.bins()))
00027 def _printHisto2D(h) :
00028   x,y = h.xAxis(),h.yAxis()
00029   return  'Histogram 2D "%s" %d xbins [%f,%f], %d ybins [%f,%f]' % \
00030   (h.title(), x.bins(), x.lowerEdge(), x.upperEdge(), y.bins(), y.lowerEdge(), y.upperEdge() )
00031 def _printStatusCode(s) :
00032   if s.isSuccess() : return 'SUCCESS'
00033   else             : return 'FAILURE'
00034 def _printBitReference(b) :
00035   return str(1==b.bool())
00036 def _printFillStream(o) :
00037   s = gbl.stringstream()
00038   o.fillStream(s)
00039   out = s.str()
00040   if out == '' :
00041     out = o.__class__.__name__ + ' object'
00042     if hasattr( o, 'hasKey') and o.hasKey() :
00043       out += ' key = '+ str(o.key())
00044   return out
00045 def _container__getitem__(self, k) :
00046   return self.containedObject(k)
00047 def _container__len__(self) :
00048   return self.numberOfObjects()
00049 def _container__iter__(self) :
00050   if hasattr(self,'containedObjects') : sequential = self.containedObjects()
00051   else                                : sequential = self
00052   count = 0
00053   limit = self.__len__()
00054   while count < limit :
00055     yield sequential.__getitem__(count)
00056     count += 1
00057 
00058 def _draw_aida_ ( self , *args ) :
00059   """
00060   Draw AIDA histogram (through access to internal ROOT histogram
00061 
00062   >>> aida = ...    # get the historgam 
00063   >>> aida.Draw()
00064   
00065   """
00066   _fun = PyCintex.gbl.Gaudi.Utils.Aida2ROOT.aida2root
00067   _root = _fun ( self ) 
00068   return _root.Draw( *args )
00069 
00070 gbl = PyCintex.gbl
00071 
00072 gbl.AIDA.IHistogram1D.__repr__ = _printHisto1D
00073 gbl.AIDA.IHistogram1D.contents = _contentsHisto1D
00074 gbl.AIDA.IHistogram2D.__repr__ = _printHisto2D
00075 for h in (  gbl.AIDA.IHistogram   ,
00076             gbl.AIDA.IHistogram1D ,
00077             gbl.AIDA.IHistogram2D ,
00078             gbl.AIDA.IHistogram3D , 
00079             gbl.AIDA.IProfile1D   , 
00080             gbl.AIDA.IProfile2D   ) :
00081   h.Draw = _draw_aida_
00082   h.plot = _draw_aida_
00083 
00084 gbl.StatusCode.__repr__ = _printStatusCode
00085 try: gbl._Bit_reference.__repr__ = _printBitReference
00086 except: pass
00087 gbl.ContainedObject.__repr__ = _printFillStream
00088 gbl.DataObject.__repr__ = _printFillStream
00089 gbl.ObjectContainerBase.__getitem__ = _container__getitem__
00090 gbl.ObjectContainerBase.__len__ = _container__len__
00091 gbl.ObjectContainerBase.__iter__ = _container__iter__
00092 
00093 gbl.IUpdateManagerSvc.update = lambda self,obj: gbl.IUpdateManagerSvc.PythonHelper.update(self,obj)
00094 gbl.IUpdateManagerSvc.invalidate = lambda self,obj: gbl.IUpdateManagerSvc.PythonHelper.invalidate(self,obj)
00095 
00096 #---Globals--------------------------------------------------------------------
00097 gbl.StatusCode.SUCCESS = 1 
00098 gbl.StatusCode.FAILURE = 0
00099 
00100 #---Enabling Pickle support----------------------------------------------------
00101 if  gbl.gROOT.GetVersionInt() <= 51800 :
00102   import libPyROOT
00103   gbl.GaudiPython.PyROOTPickle.Initialize(libPyROOT, libPyROOT.ObjectProxy)   

Generated at Thu Jan 8 17:44:22 2009 for Gaudi Framework, version v20r4 by Doxygen version 1.5.6 written by Dimitri van Heesch, © 1997-2004