CMS 3D CMS Logo

indexGenCompare.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 
3 
4 from __future__ import print_function
5 import shutil, sys, os, re, valtools, string
6 
7 from string import Template
8 
9 from optparse import OptionParser
10 from subprocess import Popen,PIPE
11 
12 
13 def processBenchmark( path, outputRootFile ):
14  (release, bname, extension ) = valtools.decodePath( path )
15  if bname != webpage.benchmarkName_:
16  print("sorry, you have to go to the",bname,"directory to produce this comparison. Note that you cannot compare different benchmarks.")
17  sys.exit(4)
18  benchmark = valtools.benchmark( extension )
19  benchmark.release_ = release
20  print(benchmark.benchmarkUrl( website ))
21  root = benchmark.rootFileOnWebSite( website )
22  shutil.copy(root, outputRootFile)
23  print('retrieved ', root)
24  return benchmark
25 
26 
27 webpage = valtools.webpage()
28 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."
29 webpage.parser_.add_option("-m", "--macro", dest="macro",
30  help="specify the ROOT macro to be used for comparison. If empty, skip the plotting stage", default="compare.C")
31 webpage.parser_.add_option("-s", "--submit", dest="submit",
32  action="store_true",
33  help="submit the comparison to the web site",
34  default=False)
35 webpage.parser_.add_option("-S", "--submit-force", dest="submitForce",
36  action="store_true",
37  help="force the submission of the comparison to the web site",
38  default=False)
39 webpage.parseArgs()
40 
41 if len(webpage.args_)!=2:
42  webpage.parser_.print_help()
43  sys.exit(1)
44 
45 
46 website = valtools.website()
47 
48 macro = webpage.options_.macro
49 templateFile = 'indexCompare.html'
50 indexhtml = "%s/%s" % (webpage.templates_,templateFile)
51 
52 # setting up benchmarks
53 print()
54 benchmark1 = processBenchmark( webpage.args_[0],
55  'benchmark_0.root' )
56 print()
57 benchmark2 = processBenchmark( webpage.args_[1],
58  'benchmark_1.root' )
59 
60 
61 webpage.setOutputDir(benchmark2.fullName())
62 
63 # do the plots
64 if webpage.options_.macro != "":
65  os.system('root -b ' + macro)
66 
67 valtools.testFileType(indexhtml, ".html")
68 infonotfoundhtml = "%s/%s" % (webpage.templates_,"infoNotFound.html")
69 valtools.testFileType(infonotfoundhtml, ".html")
70 
71 images = webpage.readCaptions('c_captions.txt')
72 
73 title = webpage.benchmarkName_
74 
75 benchmark1Link = benchmark1.benchmarkUrl( website )
76 benchmark1Name = benchmark1.fullName()
77 
78 benchmark2Link = benchmark2.benchmarkUrl( website )
79 benchmark2Name = benchmark2.fullName()
80 
81 macroLink = valtools.processFile( macro, webpage.outputDir_ )
82 macroName = os.path.basename(macro)
83 
84 comments = webpage.options_.comments
85 username = os.environ['USER']
86 
87 ifile = open( indexhtml )
88 indexTemplate = ifile.read()
89 s = Template(indexTemplate)
90 subst = s.substitute(title = title,
91  benchmark1Link = benchmark1Link,
92  benchmark1Name = benchmark1Name,
93  benchmark2Link = benchmark2Link,
94  benchmark2Name = benchmark2Name,
95  macroLink = macroLink,
96  macroName = macroName,
97  comments = comments,
98  images = images,
99  username = username,
100  date = webpage.date_
101  )
102 ofile = open( '%s/index.html' % webpage.outputDir_, 'w' )
103 ofile.write( subst )
104 ofile.close()
105 
106 ifile = open( infonotfoundhtml )
107 infoNotFoundTemplate = ifile.read()
108 s2 = Template(infoNotFoundTemplate)
109 subst2 = s2.substitute( username = os.environ['USER'] )
110 ofile2 = open( '%s/infoNotFound.html' % webpage.outputDir_, 'w' )
111 ofile2.write( subst2 )
112 ofile2.close()
113 
114 # if submission is forced, it means that the user does want
115 # to submit.
116 if webpage.options_.submitForce:
117  webpage.options_.submit = True
118 
119 if (webpage.options_.submit == True):
120  remoteName = benchmark1.benchmarkOnWebSite(website) + '/' + webpage.outputDir_
121  comparison = valtools.comparison( benchmark1, webpage.outputDir_)
122  comparison.submit( website,
123  webpage.options_.submitForce)
124  benchmark1.addLinkToComparison( website, comparison )
125  benchmark2.addLinkToComparison( website, comparison )
126 
127 
valtools.testFileType
def testFileType(file, ext)
Definition: valtools.py:287
valtools.decodePath
def decodePath(path)
Definition: valtools.py:275
valtools.comparison
Definition: valtools.py:230
valtools.webpage
Definition: valtools.py:11
valtools.processFile
def processFile(file, outputDir)
Definition: valtools.py:305
edm::print
S & print(S &os, JobReport::InputFile const &f)
Definition: JobReport.cc:66
valtools.benchmark
Definition: valtools.py:135
indexGenCompare.processBenchmark
def processBenchmark(path, outputRootFile)
Definition: indexGenCompare.py:13
valtools.website
Definition: valtools.py:87