CMS 3D CMS Logo

htmlCreator.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 
3 ##########################################################################
4 # Creates html out of the histograms, parsed data and a given template.
5 
6 
7 import logging
8 import os
9 import string
10 
11 from Alignment.MillePedeAlignmentAlgorithm.mpsvalidate.classes import MonitorData, PedeDumpData
12 from Alignment.MillePedeAlignmentAlgorithm.mpsvalidate.geometry import Alignables, Structure
13 
14 
15 # create class to have delimiter %% which is not used in latex
16 
17 
18 class TexTemplate(string.Template):
19  delimiter = "%%"
20 
21 
22 def create(alignables, pedeDump, additionalData, outputFile, config):
23  logger = logging.getLogger("mpsvalidate")
24 
25  # load template
26  with open(os.path.join(config.mpspath, "html_template.html"), "r") as template:
27  data = template.read()
28  template.close()
29 
30  # create object where data could be substituted
31  data = TexTemplate(data)
32 
33  # output string
34  out = ""
35 
36  # general information
37 
38  out += "<h1>General information</h1>\n"
39 
40  if (config.message):
41  out += "Project: {0}\n<br>".format(config.message)
42  out += "Input-Path: {0}\n<br>".format(config.jobDataPath)
43 
44  # alignment_merge.py
45  try:
46  out += "<h2>Alignment Configuration</h2>\n"
47  out += "<b>PedeSteerer method:</b> {0}<br>\n".format(
48  additionalData.pedeSteererMethod)
49  out += "<b>PedeSteerer options:</b>\n"
50  for line in additionalData.pedeSteererOptions:
51  out += "{0}<br>\n".format(line)
52  out += "<b>PedeSteerer command:</b> {0}<br>\n".format(
53  additionalData.pedeSteererCommand)
54 
55  for selector in additionalData.pattern:
56  out += "<b>{0}:</b><br>\n".format(additionalData.pattern[selector][3])
57  for line in additionalData.pattern[selector][0]:
58  for i in line:
59  out += "{0} ".format(i)
60  out += "<br>\n"
61  for line in additionalData.pattern[selector][2]:
62  out += "{0} \n".format(line)
63  out += "<br>\n"
64  except Exception as e:
65  logger.error("data not found - {0} {1}".format(type(e), e))
66 
67  # table of input files with number of tracks
68  if (config.showmonitor):
69  out += "<h2>Datasets with tracks</h2>\n"
70  out += """<table border="1">
71  <tr>
72  <th>Dataset</th>
73  <th>Number of used tracks</th>
74  <tr>"""
75  for monitor in MonitorData.monitors:
76  out += """<tr>
77  <th>{0}</th>
78  <th>{1}</th>
79  </tr>""".format(monitor.name, monitor.ntracks)
80  try:
81  if (pedeDump.nrec):
82  out += """<tr>
83  <th>Number of records</th>
84  <th>{0}</th>
85  </tr>""".format(pedeDump.nrec)
86  except Exception as e:
87  logger.error("data not found - {0} {1}".format(type(e), e))
88  out += """</table>"""
89  out += "The information in this table is based on the monitor root files. Note that the number of tracks which where used in the pede step can differ from this table."
90 
91  # pede.dump.gz
92  try:
93  out += "<h2>Pede monitoring information</h2>\n"
94  if (pedeDump.sumValue != 0):
95  out += r"<b>Sum(Chi^2)/Sum(Ndf)</b> &= {0}<br> &= {1}".format(
96  pedeDump.sumSteps, pedeDump.sumValue)
97  else:
98  out += r"<b>Sum(W*Chi^2)/Sum(Ndf)/<W></b> &= {0}<br> &= {1}".format(
99  pedeDump.sumSteps, pedeDump.sumWValue)
100  out += r"<b>with correction for down-weighting:</b> {0}<br>".format(
101  pedeDump.correction)
102  out += r"<b>Peak dynamic memory allocation:</b> {0} GB<br>".format(
103  pedeDump.memory)
104  out += r"<b>Total time:</b> {0} h {1} m {2} s<br>".format(
105  pedeDump.time[0], pedeDump.time[1], pedeDump.time[2])
106  out += r"<b>Number of records:</b> {0}<br>".format(pedeDump.nrec)
107  out += r"<b>Total number of parameters:</b> {0}<br>".format(pedeDump.ntgb)
108  out += r"<b>Number of variable parameters:</b> {0}<br>".format(pedeDump.nvgb)
109  out += r"<b>Warning:</b><br>"
110  for line in pedeDump.warning:
111 
112  # check if line empty
113  if line.replace(r" ", r""):
114  out += "{0}<br>\n".format(line)
115  except Exception as e:
116  logger.error("data not found - {0} {1}".format(type(e), e))
117 
118  # high level structures
119 
120  big = [x for x in config.outputList if (x.plottype == "big")]
121 
122  if big:
123  out += "<h1>High-level parameters</h1>\n"
124  for i in big:
125  out += "<a href='plots/pdf/{0}.pdf'><img src='plots/png/{0}.png'></a>\n".format(
126  i.filename)
127 
128  # time (IOV) dependent plots
129 
130  time = [x for x in config.outputList if (x.plottype == "time")]
131 
132  if time:
133  out += "<h1>High-level parameters versus time (IOV)</h1>\n"
134  # get list with names of the structures
135  for structure in [x.name for x in time if x.parameter == "xyz"]:
136  out += "<h2>{0}<h2>\n".format(structure)
137  for mode in ["xyz", "rot"]:
138  if any([x.filename for x in time if (x.parameter == mode and x.name == structure)]):
139  filename = [x.filename for x in time if (x.parameter == mode and x.name == structure)][0]
140  out += "<a href='plots/pdf/{0}.pdf'><img src='plots/png/{0}.png'></a>\n".format(
141  filename)
142 
143  # hole modules
144 
145  # check if there are module plots
146  if any(x for x in config.outputList if (x.plottype == "mod" and x.number == "")):
147  out += "<h1>Module-level parameters</h1>\n"
148 
149  # loop over all structures
150  for moduleName in [x.name for x in alignables.structures]:
151 
152  # check if there is a plot for this module
153  if any(x for x in config.outputList if (x.plottype == "mod" and x.number == "" and x.name == moduleName)):
154  out += "<h2>{0}</h2>\n".format(moduleName)
155 
156  # loop over modes
157  for mode in ["xyz", "rot", "dist"]:
158 
159  # get module plot
160  module = [x for x in config.outputList if (
161  x.plottype == "mod" and x.number == "" and x.name == moduleName and x.parameter == mode)]
162  # get list of sub module plots
163  moduleSub = [x for x in config.outputList if (
164  x.plottype == "subMod" and x.number != "" and x.name == moduleName and x.parameter == mode)]
165 
166  # check if plot there is a plot in this mode
167  if module:
168  out += "<a href='plots/pdf/{0}.pdf'><img src='plots/png/{0}.png'></a>\n".format(module[
169  0].filename)
170 
171  # loop over submodules
172  for plot in moduleSub:
173  out += "<a href='plots/pdf/{0}.pdf'><img src='plots/png/{0}.png'></a>\n".format(
174  plot.filename)
175 
176  # plot taken from the millePedeMonitor_merge.root file
177 
178  if any(x for x in config.outputList if x.plottype == "monitor"):
179  out += "<h1>Monitor</h1>\n"
180  for plot in [x for x in config.outputList if x.plottype == "monitor"]:
181  out += "<h3>{0}</h3>\n".format(plot.name)
182  out += "<a href='plots/pdf/{0}.pdf'><img src='plots/png/{0}.png'></a>\n".format(
183  plot.filename)
184 
185  data = data.substitute(message=config.message, out=out)
186 
187  with open(os.path.join(config.outputPath, outputFile), "w") as output:
188  output.write(data)
def create(alignables, pedeDump, additionalData, outputFile, config)
Definition: htmlCreator.py:22
bool any(const std::vector< T > &v, const T &what)
Definition: ECalSD.cc:34