CMS 3D CMS Logo

indexGen.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
6 
7 from string import Template
8 
9 from optparse import OptionParser
10 
11 
12 
13 webpage = valtools.webpage()
14 
15 webpage.parser_.usage = "usage: %prog. Run from your Benchmark directory"
16 webpage.parser_.add_option("-r", "--recipe", dest="recipe",
17  help="url pointing to a recipe",
18  default="None")
19 webpage.parser_.add_option("-t", "--title", dest="title",
20  help="Benchmark title",
21  default="")
22 webpage.parser_.add_option("-g", "--gensource", dest="pyGenSource",
23  help="python file for the CMSSW source of the generated events, which is used in input to your simulation and reconstruction process",
24  default="None")
25 webpage.parser_.add_option("-s", "--simulation", dest="pySim",
26  help="python file for your CMSSW simulation and/or reconstruction process.",
27  default="None")
28 webpage.parseArgs()
29 
30 
31 if len(webpage.args_)!=0:
32  webpage.parser_.print_help()
33  sys.exit(1)
34 
35 benchmark = valtools.benchmark()
36 
37 webpage.setOutputDir( benchmark.fullName() )
38 
39 macro = 'plot.C'
40 recipe = webpage.options_.recipe
41 genConfig = webpage.options_.pyGenSource
42 simConfig = webpage.options_.pySim
43 benchmarkConfig = 'benchmark_cfg.py'
44 
45 # information about CMSSW
46 cmssw = os.environ['CMSSW_VERSION']
47 showTags = os.popen( 'showtags -t -r -u').read()
48 
49 title = webpage.benchmarkName_
50 
51 templateFile = 'index.html'
52 
53 outputDir = webpage.outputDir_
54 indexhtml = "%s/%s" % (webpage.templates_,templateFile)
55 
56 
57 valtools.testFileType(genConfig, ".py")
58 valtools.testFileType(simConfig, ".py")
59 valtools.testFileType(benchmarkConfig, ".py")
60 valtools.testFileType(macro, ".C")
61 
62 valtools.testFileType(indexhtml, ".html")
63 infonotfoundhtml = "%s/%s" % (webpage.templates_,"infoNotFound.html")
64 valtools.testFileType(infonotfoundhtml, ".html")
65 
66 
67 recipeLink = valtools.processFile( recipe, webpage.outputDir_ )
68 genConfigLink = valtools.processFile(genConfig, webpage.outputDir_ )
69 simConfigLink = valtools.processFile( simConfig, webpage.outputDir_ )
70 benchmarkConfigLink = valtools.processFile( benchmarkConfig,
71  webpage.outputDir_ )
72 macroLink = valtools.processFile(macro, webpage.outputDir_ )
73 rootFileLink = valtools.processFile(webpage.rootFile_, webpage.outputDir_ )
74 
75 comments = webpage.options_.comments
76 images = webpage.readCaptions('captions.txt')
77 
78 ifile = open( indexhtml )
79 indexTemplate = ifile.read()
80 s = Template(indexTemplate)
81 subst = s.substitute(title = title,
82  recipe = recipe,
83  recipeLink = recipeLink,
84  genConfig = os.path.basename(genConfig),
85  genConfigLink = genConfigLink,
86  simConfig = os.path.basename(simConfig),
87  simConfigLink = simConfigLink,
88  benchmarkConfig = os.path.basename(benchmarkConfig),
89  benchmarkConfigLink = benchmarkConfigLink,
90  macro = os.path.basename(macro),
91  macroLink = macroLink,
92  rootFile = os.path.basename(webpage.rootFile_),
93  rootFileLink = rootFileLink,
94  comments = comments,
95  cmssw = cmssw,
96  showTags = showTags,
97  images = images,
98  username = os.environ['USER'],
99  date = webpage.date_
100  )
101 
102 ofile = open( '%s/index.html' % outputDir, 'w' )
103 ofile.write( subst )
104 
105 ifile = open( infonotfoundhtml )
106 infoNotFoundTemplate = ifile.read()
107 s2 = Template(infoNotFoundTemplate)
108 subst2 = s2.substitute( username = os.environ['USER'] )
109 ofile2 = open( '%s/infoNotFound.html' % outputDir, 'w' )
110 ofile2.write( subst2 )
111 
112 print('webpage directory successfully created in', outputDir)
113 
valtools.testFileType
def testFileType(file, ext)
Definition: valtools.py:287
valtools.webpage
Definition: valtools.py:11
valtools.processFile
def processFile(file, outputDir)
Definition: valtools.py:305
print
void print(TMatrixD &m, const char *label=nullptr, bool mathematicaFormat=false)
Definition: Utilities.cc:46
readEcalDQMStatus.read
read
Definition: readEcalDQMStatus.py:38
valtools.benchmark
Definition: valtools.py:135