| Classes | Job Modules | Data Objects | Services | Algorithms | Tools | Packages | Directories | Tracs |

In This Package:

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 _printFillStreamBroken(o) :
00041   import ROOT                   # https://savannah.cern.ch/bugs/?28426
00042   s = ROOT.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   return out
00050 def _printFillStream(o) :
00051   if  o :
00052     s = gbl.stringstream()
00053     o.fillStream(s)
00054     out = s.str()
00055     if out == '' :
00056       out = o.__class__.__name__ + ' object'
00057       if hasattr( o, 'hasKey') and o.hasKey() :
00058         out += ' key = '+ str(o.key())
00059   else :
00060     out = o.__class__.__name__ + ' NULL object'
00061   return out
00062 def _container__getitem__(self, k) :
00063   return self.containedObject(k)
00064 def _container__len__(self) :
00065   return self.numberOfObjects()
00066 def _container__iter__(self) :
00067   if hasattr(self,'containedObjects') : sequential = self.containedObjects()
00068   else                                : sequential = self
00069   count = 0
00070   limit = self.__len__()
00071   while count < limit :
00072     yield sequential.__getitem__(count)
00073     count += 1
00074 
00075 def _draw_aida_ ( self , *args ) :
00076   """
00077   Draw AIDA histogram (through access to internal ROOT histogram
00078 
00079   >>> aida = ...    # get the historgam 
00080   >>> aida.Draw()
00081   
00082   """
00083   _fun = PyCintex.gbl.Gaudi.Utils.Aida2ROOT.aida2root
00084   _root = _fun ( self ) 
00085   return _root.Draw( *args )
00086 
00087 gbl.AIDA.IHistogram1D.__repr__ = _printHisto1D
00088 gbl.AIDA.IHistogram1D.contents = _contentsHisto1D
00089 gbl.AIDA.IHistogram2D.__repr__ = _printHisto2D
00090 for h in (  gbl.AIDA.IHistogram   ,
00091             gbl.AIDA.IHistogram1D ,
00092             gbl.AIDA.IHistogram2D ,
00093             gbl.AIDA.IHistogram3D , 
00094             gbl.AIDA.IProfile1D   , 
00095             gbl.AIDA.IProfile2D   ) :
00096   h.Draw = _draw_aida_
00097   h.plot = _draw_aida_
00098 
00099 gbl.StatusCode.__repr__ = _printStatusCode
00100 try: gbl._Bit_reference.__repr__ = _printBitReference
00101 except: pass
00102 gbl.ContainedObject.__repr__ = _printFillStream
00103 gbl.DataObject.__repr__ = _printFillStream
00104 gbl.ObjectContainerBase.__getitem__ = _container__getitem__
00105 gbl.ObjectContainerBase.__len__ = _container__len__
00106 gbl.ObjectContainerBase.__iter__ = _container__iter__
00107 
00108 gbl.IUpdateManagerSvc.update = lambda self,obj: gbl.IUpdateManagerSvc.PythonHelper.update(self,obj)
00109 gbl.IUpdateManagerSvc.invalidate = lambda self,obj: gbl.IUpdateManagerSvc.PythonHelper.invalidate(self,obj)
00110 
00111 #---Globals--------------------------------------------------------------------
00112 gbl.StatusCode.SUCCESS = 1 
00113 gbl.StatusCode.FAILURE = 0
00114 
00115 #---Enabling Pickle support----------------------------------------------------
00116 if  gbl.gROOT.GetVersionInt() <= 51800 :
00117   import libPyROOT
00118   gbl.GaudiPython.PyROOTPickle.Initialize(libPyROOT, libPyROOT.ObjectProxy)   
| Classes | Job Modules | Data Objects | Services | Algorithms | Tools | Packages | Directories | Tracs |

Generated on Mon Apr 11 19:58:56 2011 for GaudiPython by doxygen 1.4.7