00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
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
00023 aida2root = gaudimodule.gbl.Gaudi.Utils.Aida2ROOT.aida2root
00024
00025
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
00034
00035
00036
00037 class Aida2RootEx1 (HistoAlgo) :
00038
00039 def __init__ ( self , name = "Aida2RootEx1" ) :
00040 """ Standard Constructor """
00041 HistoAlgo.__init__( self , name )
00042
00043
00044 def execute ( self ) :
00045 " The main excution method "
00046
00047
00048 for path in paths :
00049 self.Print("AIDA object: '%s'" % path )
00050
00051 aida = self.histoSvc( path )
00052 if not aida : return self.Error ( "Invalid AIDA at '%s'" % path )
00053
00054 root = aida2root( aida )
00055 if not root : return self.Error ( "Invalid conversion to ROOT '%s'" % path )
00056
00057 root.Print()
00058
00059 return SUCCESS
00060
00061
00062
00063
00064
00065
00066
00067 class Aida2RootEx2 (HistoAlgo) :
00068
00069 def __init__ ( self , name = "Aida2RootEx2" ) :
00070 """ Standard Constructor """
00071 HistoAlgo.__init__( self , name )
00072
00073
00074 def execute ( self ) :
00075 " The main execution method "
00076
00077
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
00085 root.Print()
00086
00087 return SUCCESS
00088
00089
00090
00091
00092
00093
00094
00095
00096 def configure( gaudi = None ) :
00097 """ the main configuration method """
00098
00099 if not gaudi : gaudi = gaudimodule.AppMgr()
00100
00101
00102 import HistoEx2
00103 HistoEx2.configure( gaudi )
00104
00105
00106 alg1 = Aida2RootEx1()
00107 alg2 = Aida2RootEx2()
00108
00109 gaudi.addAlgorithm( alg1 )
00110 gaudi.addAlgorithm( alg2 )
00111
00112 return SUCCESS
00113
00114
00115
00116
00117
00118
00119
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
00147
00148 if '__main__' == __name__ :
00149 print __doc__ , __author__
00150 gaudi = gaudimodule.AppMgr()
00151 configure( gaudi )
00152 gaudi.run(5)
00153
00154
00155 useScript( paths )
00156
00157
00158
00159