Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 11:56:35

0001 ##########################################################################
0002 # Creates html out of the histograms, parsed data and a given template.
0003 ##
0004 
0005 import logging
0006 import os
0007 import string
0008 import Alignment.MillePedeAlignmentAlgorithm.mpsvalidate.classes as mpsv_classes
0009 
0010 
0011 # create class to have delimiter %% which is not used in latex
0012 
0013 
0014 class TexTemplate(string.Template):
0015     delimiter = "%%"
0016 
0017 
0018 def create(alignables, pedeDump, additionalData, outputFile, config):
0019     logger = logging.getLogger("mpsvalidate")
0020 
0021     # load template
0022     with open(os.path.join(config.mpspath, "templates",
0023                            "mpsvalidate_html_template.html")) as template:
0024         data = template.read()
0025         template.close()
0026 
0027     # create object where data could be substituted
0028     data = TexTemplate(data)
0029 
0030     # output string
0031     out = ""
0032 
0033     # general information
0034 
0035     out += "<h1>General information</h1>\n"
0036 
0037     if (config.message):
0038         out += "Project: {0}\n<br>".format(config.message)
0039     out += "Input-Path: {0}\n<br>".format(config.jobDataPath)
0040     
0041     # alignment_merge.py
0042     try:
0043         out += "<h2>Alignment Configuration</h2>\n"
0044         out += "<b>PedeSteerer method:</b> {0}<br>\n".format(
0045             additionalData.pede_steerer_method)
0046         out += "<b>PedeSteerer options:</b>\n"
0047         for line in additionalData.pede_steerer_options:
0048             out += "{0}<br>\n".format(line)
0049         out += "<b>PedeSteerer command:</b> {0}<br>\n".format(
0050             additionalData.pede_steerer_command)
0051 
0052         for i in sorted(additionalData.selectors):
0053             out += "<b>{0}:</b><br>\n".format(additionalData.selectors[i]["name"])
0054             for line in additionalData.selectors[i]["selector"].dumpPython().split("\n"):
0055                 out += line + "<br>\n"
0056 
0057         if len(additionalData.iov_definition) > 0:
0058             out += "<b>IOV defintion:</b><br>\n"
0059             for line in additionalData.iov_definition.dumpPython().split("\n"):
0060                 out += line + "<br>\n"
0061 
0062     except Exception as e:
0063         logger.error("data not found - {0} {1}".format(type(e), e))
0064             
0065     # table of input files with number of tracks
0066     if config.showmonitor:
0067         out += "<h2>Datasets with tracks</h2>\n"
0068         out += """<table border="1">
0069             <tr>
0070                <th>Dataset</th>
0071                <th>Number of used tracks</th>
0072                <th>Weight</th>
0073             <tr>"""
0074         for monitor in mpsv_classes.MonitorData.monitors:
0075             out += """<tr>
0076                 <th>{0}</th>
0077                 <th>{1}</th>
0078                 <th>{2}</th>
0079                 </tr>""".format(monitor.name, monitor.ntracks,
0080                 monitor.weight if monitor.weight != None else "&ndash;")
0081         try:
0082             if (pedeDump.nrec):
0083                 out += """<tr>
0084                     <th>Number of records</th>
0085                     <th>{0}</th>
0086                     </tr>""".format(pedeDump.nrec)
0087         except Exception as e:
0088             logger.error("data not found - {0} {1}".format(type(e), e))
0089         out += """</table>"""
0090         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."
0091 
0092     # pede.dump.gz
0093     try:
0094         out += "<h2>Pede monitoring information</h2>\n"
0095         if (pedeDump.sumValue != 0):
0096             out += r"<b>Sum(Chi^2)/Sum(Ndf)</b> &= {0}<br> &= {1}".format(
0097                 pedeDump.sumSteps, pedeDump.sumValue)
0098         else:
0099             out += r"<b>Sum(W*Chi^2)/Sum(Ndf)/<W></b> &= {0}<br> &= {1}".format(
0100                 pedeDump.sumSteps, pedeDump.sumWValue)
0101         out += r"<b>with correction for down-weighting:</b> {0}<br>".format(
0102             pedeDump.correction)
0103         out += r"<b>Peak dynamic memory allocation:</b> {0} GB<br>".format(
0104             pedeDump.memory)
0105         out += r"<b>Total time:</b> {0} h {1} m {2} s<br>".format(
0106             pedeDump.time[0], pedeDump.time[1], pedeDump.time[2])
0107         out += r"<b>Number of records:</b> {0}<br>".format(pedeDump.nrec)
0108         out += r"<b>Total number of parameters:</b> {0}<br>".format(pedeDump.ntgb)
0109         out += r"<b>Number of variable parameters:</b> {0}<br>".format(pedeDump.nvgb)
0110         out += r"<b>Warning:</b><br>"
0111         for line in pedeDump.warning:
0112 
0113             # check if line empty
0114             if line.replace(r" ", r""):
0115                 out += "{0}<br>\n".format(line)
0116     except Exception as e:
0117         logger.error("data not found - {0} {1}".format(type(e), e))
0118 
0119     # high level structures
0120 
0121     big = [x for x in config.outputList if (x.plottype == "big")]
0122 
0123     if big:
0124         out += "<h1>High-level parameters</h1>\n"
0125         for i in big:
0126             out += "<a href='plots/pdf/{0}.pdf'><img src='plots/png/{0}.png'></a>\n".format(
0127                 i.filename)
0128 
0129     # time (IOV) dependent plots
0130 
0131     time = [x for x in config.outputList if (x.plottype == "time")]
0132 
0133     if time:
0134         out += "<h1>High-level parameters versus time (IOV)</h1>\n"
0135         # get list with names of the structures
0136         for structure in [x.name for x in time if x.parameter == "xyz"]:
0137             out += "<h2>{0}<h2>\n".format(structure)
0138             for mode in ["xyz", "rot"]:
0139                 if any([x.filename for x in time if (x.parameter == mode and x.name == structure)]):
0140                     filename = [x.filename for x in time if (x.parameter == mode and x.name == structure)][0]
0141                     out += "<a href='plots/pdf/{0}.pdf'><img src='plots/png/{0}.png'></a>\n".format(
0142                         filename)
0143 
0144     # hole modules
0145 
0146     # check if there are module plots
0147     if any(x for x in config.outputList if (x.plottype == "mod" and x.number == "")):
0148         out += "<h1>Module-level parameters</h1>\n"
0149 
0150         # loop over all structures
0151         for moduleName in [x.name for x in alignables.structures]:
0152 
0153             # check if there is a plot for this module
0154             if any(x for x in config.outputList if (x.plottype == "mod" and x.number == "" and x.name == moduleName)):
0155                 out += "<h2>{0}</h2>\n".format(moduleName)
0156 
0157                 # loop over modes
0158                 for mode in ["xyz", "rot", "dist"]:
0159 
0160                     # get module plot
0161                     module = [x for x in config.outputList if (
0162                         x.plottype == "mod" and x.number == "" and x.name == moduleName and x.parameter == mode)]
0163                     # get list of sub module plots
0164                     moduleSub = [x for x in config.outputList if (
0165                         x.plottype == "subMod" and x.number != "" and x.name == moduleName and x.parameter == mode)]
0166 
0167                     # check if plot there is a plot in this mode
0168                     if module:
0169                         out += "<a href='plots/pdf/{0}.pdf'><img src='plots/png/{0}.png'></a>\n".format(module[
0170                                                                                                         0].filename)
0171 
0172                         # loop over submodules
0173                         for plot in moduleSub:
0174                             out += "<a href='plots/pdf/{0}.pdf'><img src='plots/png/{0}.png'></a>\n".format(
0175                                 plot.filename)
0176 
0177     # plot taken from the millePedeMonitor_merge.root file
0178 
0179     if any(x for x in config.outputList if x.plottype == "monitor"):
0180         out += "<h1>Monitor</h1>\n"
0181         for plot in [x for x in config.outputList if x.plottype == "monitor"]:
0182             out += "<h3>{0}</h3>\n".format(plot.name)
0183             out += "<a href='plots/pdf/{0}.pdf'><img src='plots/png/{0}.png'></a>\n".format(
0184                 plot.filename)
0185 
0186     data = data.substitute(message=config.message, out=out)
0187 
0188     with open(os.path.join(config.outputPath, outputFile), "w") as output:
0189         output.write(data)