CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_10_patch1/src/Validation/RecoParticleFlow/Benchmarks/Tools/indexGenCompare.py

Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 
00003 
00004 import shutil, sys, os, re, valtools, string
00005 
00006 from string import Template
00007 
00008 from optparse import OptionParser 
00009 from subprocess import Popen,PIPE
00010 
00011 
00012 def processBenchmark( path, outputRootFile ):
00013     (release, bname, extension ) = valtools.decodePath( path )
00014     if bname != webpage.benchmarkName_:
00015         print "sorry, you have to go to the",bname,"directory to produce this comparison. Note that you cannot compare different benchmarks."
00016         sys.exit(4)
00017     benchmark = valtools.benchmark( extension )
00018     benchmark.release_ = release
00019     print benchmark.benchmarkUrl( website ) 
00020     root = benchmark.rootFileOnWebSite( website )
00021     shutil.copy(root, outputRootFile)
00022     print 'retrieved ', root
00023     return benchmark
00024     
00025 
00026 webpage = valtools.webpage()
00027 webpage.parser_.usage = "example: %prog CMSSW_3_1_0_pre7/TauBenchmarkGeneric_ZTT_FastSim_IDEAL CMSSW_3_1_0_pre7/TauBenchmarkGeneric_TEST\nThe list of benchmarks can be obtained using the listBenchmarks.py command."
00028 webpage.parser_.add_option("-m", "--macro", dest="macro",
00029                            help="specify the ROOT macro to be used for comparison. If empty, skip the plotting stage", default="compare.C")
00030 webpage.parser_.add_option("-s", "--submit", dest="submit",
00031                            action="store_true",
00032                            help="submit the comparison to the web site",
00033                            default=False)
00034 webpage.parser_.add_option("-S", "--submit-force", dest="submitForce",
00035                            action="store_true",
00036                            help="force the submission of the comparison to the web site",
00037                            default=False)
00038 webpage.parseArgs()
00039 
00040 if len(webpage.args_)!=2:
00041     webpage.parser_.print_help()
00042     sys.exit(1)
00043 
00044 
00045 website = valtools.website()
00046 
00047 macro = webpage.options_.macro
00048 templateFile = 'indexCompare.html'
00049 indexhtml = "%s/%s" % (webpage.templates_,templateFile)
00050 
00051 # setting up benchmarks
00052 print 
00053 benchmark1 = processBenchmark( webpage.args_[0],
00054                                'benchmark_0.root' )
00055 print
00056 benchmark2 = processBenchmark( webpage.args_[1],
00057                                'benchmark_1.root' )
00058 
00059 
00060 webpage.setOutputDir(benchmark2.fullName())
00061 
00062 # do the plots
00063 if webpage.options_.macro != "":
00064     os.system('root -b ' + macro)
00065 
00066 valtools.testFileType(indexhtml, ".html")
00067 infonotfoundhtml = "%s/%s" % (webpage.templates_,"infoNotFound.html")
00068 valtools.testFileType(infonotfoundhtml, ".html")
00069 
00070 images = webpage.readCaptions('c_captions.txt')
00071 
00072 title = webpage.benchmarkName_
00073 
00074 benchmark1Link = benchmark1.benchmarkUrl( website )
00075 benchmark1Name = benchmark1.fullName()
00076 
00077 benchmark2Link = benchmark2.benchmarkUrl( website )
00078 benchmark2Name = benchmark2.fullName()
00079 
00080 macroLink = valtools.processFile( macro, webpage.outputDir_  )
00081 macroName = os.path.basename(macro)
00082 
00083 comments = webpage.options_.comments
00084 username = os.environ['USER']
00085 
00086 ifile = open( indexhtml )
00087 indexTemplate = ifile.read()
00088 s = Template(indexTemplate)
00089 subst = s.substitute(title = title,
00090                      benchmark1Link = benchmark1Link,
00091                      benchmark1Name = benchmark1Name,
00092                      benchmark2Link = benchmark2Link,
00093                      benchmark2Name = benchmark2Name,
00094                      macroLink = macroLink,
00095                      macroName = macroName, 
00096                      comments = comments,
00097                      images = images, 
00098                      username = username,
00099                      date = webpage.date_
00100                      )
00101 ofile = open( '%s/index.html' % webpage.outputDir_, 'w' )
00102 ofile.write( subst )
00103 ofile.close()
00104 
00105 ifile = open( infonotfoundhtml )
00106 infoNotFoundTemplate = ifile.read()
00107 s2 = Template(infoNotFoundTemplate)
00108 subst2 = s2.substitute( username = os.environ['USER'] )
00109 ofile2 = open( '%s/infoNotFound.html' % webpage.outputDir_, 'w' )
00110 ofile2.write( subst2 )
00111 ofile2.close()
00112 
00113 # if submission is forced, it means that the user does want
00114 # to submit. 
00115 if  webpage.options_.submitForce:
00116     webpage.options_.submit = True
00117 
00118 if (webpage.options_.submit == True):
00119     remoteName = benchmark1.benchmarkOnWebSite(website) + '/' + webpage.outputDir_
00120     comparison = valtools.comparison( benchmark1, webpage.outputDir_)
00121     comparison.submit( website,
00122                        webpage.options_.submitForce)
00123     benchmark1.addLinkToComparison( website, comparison )
00124     benchmark2.addLinkToComparison( website, comparison )
00125 
00126