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

In This Package:

Aida2RootEx.py

Go to the documentation of this file.
00001 #!/usr/bin/env python2.4
00002 # =============================================================================
00003 # $Id: Aida2RootEx.py,v 1.3 2007/08/07 13:00:28 marcocle Exp $
00004 # =============================================================================
00005 # CVS tag $Name: GAUDI_v20r4-pre $ ,version $Revision: 1.3 $
00006 # =============================================================================
00007 ## @file
00008 #  Simple algorith to illustrate the usage of aida2root converter
00009 #  @see Gaudi::Aida2ROOT
00010 #  @author Vanya BELYAEV ibelyaev@physics.syr.edu
00011 #  @date 2007-01-24
00012 # =============================================================================
00013 " Simple example to illustrate the usage of aida2root converter "
00014 # =============================================================================
00015 __author__ = "Vanya BELYAEV ibelyaev@phys.syr.edu"
00016 # =============================================================================
00017 import os,ROOT, gaudimodule
00018 from   GaudiAlgs   import HistoAlgo
00019 
00020 SUCCESS   = gaudimodule.SUCCESS
00021 
00022 ## @see Gaudi::Aida2ROOT 
00023 aida2root = gaudimodule.gbl.Gaudi.Utils.Aida2ROOT.aida2root
00024 
00025 ## list of booked histograms 
00026 paths = [ 'HistoEx/1'  , 'HistoEx/2'  , 'HistoEx/3'  ,
00027           'HistoEx1/1' , 'HistoEx1/2' , 'HistoEx1/3' ,
00028           'HistoEx2/1' , 'HistoEx2/2' , 'HistoEx2/3' ,
00029           'HistoEx2/4' , 'HistoEx2/5' , 'HistoEx2/6' ]
00030 
00031 
00032 # =============================================================================
00033 ## @class Aida2RootEx1
00034 #  Simple algorithm which used aida2root utility 
00035 #  @author Vanya BELYAEV ibelyaev@physics.syr.edu
00036 #  @date 2007-01-24
00037 class Aida2RootEx1 (HistoAlgo) :
00038     ## Standard Constructor 
00039     def __init__ ( self , name = "Aida2RootEx1" ) :
00040         """ Standard Constructor """
00041         HistoAlgo.__init__( self , name )
00042         
00043     ## the main excution method
00044     def execute ( self ) :
00045         " The main excution method " 
00046             
00047         # list of booked histograms 
00048         for path in paths :
00049             self.Print("AIDA object: '%s'" % path )
00050             # get AIDA pointer 
00051             aida = self.histoSvc( path )
00052             if not aida : return self.Error ( "Invalid AIDA at '%s'" % path )
00053             # explicitely convert to ROOT 
00054             root = aida2root( aida )
00055             if not root : return self.Error ( "Invalid conversion to ROOT '%s'" % path )
00056             # use the native ROOT printout 
00057             root.Print()
00058         
00059         return SUCCESS 
00060 # =============================================================================
00061 
00062 # =============================================================================
00063 ## @class Aida2RootEx2
00064 #  Simple algorithm which uses aida2root utility 
00065 #  @author Vanya BELYAEV ibelyaev@physics.syr.edu
00066 #  @date 2007-01-24
00067 class Aida2RootEx2 (HistoAlgo) :
00068     ## Standard Constructor 
00069     def __init__ ( self , name = "Aida2RootEx2" ) :
00070         """ Standard Constructor """
00071         HistoAlgo.__init__( self , name )
00072 
00073     ## the main excution method
00074     def execute ( self ) :
00075         " The main execution method "
00076 
00077         # get the service itself 
00078         s = self.histoSvc()
00079 
00080         for path in paths :            
00081             self.Print("AIDA object: '%s'" % path )
00082             root = s.getAsROOT( path )
00083             if not root : return self.Error ( "Invalid conversion to ROOT '%s'" % path )
00084             # use the native ROOT printout 
00085             root.Print()
00086 
00087         return SUCCESS 
00088 # =============================================================================
00089 
00090 
00091 # =============================================================================
00092 ## @fn configure
00093 #  The main configuration method
00094 #  @author Vanya BELYAEV ibelyaev@physics.syr.edu
00095 #  @date 2007-01-24
00096 def configure( gaudi = None ) :
00097     """ the main configuration method """
00098     
00099     if not gaudi : gaudi = gaudimodule.AppMgr()
00100     
00101     # reuse the previous example 
00102     import HistoEx2
00103     HistoEx2.configure( gaudi )
00104 
00105     # create the algorithms 
00106     alg1 = Aida2RootEx1()
00107     alg2 = Aida2RootEx2()
00108     # append them to the list of Top-Level algorithms 
00109     gaudi.addAlgorithm( alg1 )
00110     gaudi.addAlgorithm( alg2 )
00111 
00112     return SUCCESS 
00113 
00114 
00115 # =============================================================================
00116 ## @fn useScript
00117 #  the third way to convert AIDA histograms into ROOT
00118 #  @author Vanya BELYAEV ibelyaev@physics.syr.edu
00119 #  @date 2007-01-24
00120 def useScript( histos ) :
00121     "  the third way to convert AIDA hoistograms into ROOT "
00122     
00123     g    = gaudimodule.AppMgr() 
00124     hsvc = g.histsvc()
00125     
00126     for histo in histos :
00127         root   = hsvc.getAsROOT(histo)
00128         if not root :
00129             print "ERROR in access the histogram '%s' "%histo
00130             continue
00131         canvas = ROOT.TCanvas('canvas',histo,250,250)
00132         root.Draw()
00133         name = histo.replace ('/','_')
00134         name = name.replace  ('\\','_')
00135         name = name.replace  ('"','_')
00136         name = name.replace  ("'",'_')
00137         name = name.replace  ("'",'_')
00138         name = name.replace(os.sep,'_') + '.gif'
00139         canvas.Print(name)
00140         print "The file name is '%s'"%name
00141         
00142 # =============================================================================
00143 
00144 
00145 # =============================================================================
00146 # The actual job excution 
00147 # =============================================================================
00148 if '__main__' == __name__ :
00149     print __doc__ , __author__
00150     gaudi = gaudimodule.AppMgr()
00151     configure( gaudi )
00152     gaudi.run(5)
00153 
00154     # use the scrtipts
00155     useScript( paths )
00156     
00157 # =============================================================================
00158 # The END 
00159 # =============================================================================
| Classes | Job Modules | Data Objects | Services | Algorithms | Tools | Packages | Directories | Tracs |

Generated on Mon Apr 11 19:59:39 2011 for GaudiExamples by doxygen 1.4.7