CMS 3D CMS Logo

pdfCreator.py
Go to the documentation of this file.
1 
4 
5 from builtins import range
6 import logging
7 import os
8 import string
9 import Alignment.MillePedeAlignmentAlgorithm.mpsvalidate.classes as mpsv_classes
10 
11 
12 # create class to have delimiter %% which is not used in latex
13 
14 
15 class TexTemplate(string.Template):
16  delimiter = "%%"
17 
18 
19 def create(alignables, pedeDump, additionalData, outputFile, config):
20  logger = logging.getLogger("mpsvalidate")
21 
22  # load template
23  with open(os.path.join(config.mpspath, "templates",
24  "mpsvalidate_tex_template.tex")) as template:
25  data = template.read()
26  template.close()
27 
28  # create object where data could be substituted
29  data = TexTemplate(data)
30 
31  # output string
32  out = ""
33 
34  # title page
35  if (config.message):
36  out += """\\begin{{titlepage}}
37  \centering
38  \\vspace*{{4cm}}
39  \Huge\\bfseries Alignment Validation\par
40  \\vspace{{2cm}}
41  \scshape\huge Alignment Campaign\\\\ {{{0}}}\par
42  \\vfill
43  \large \\today\par
44  \\end{{titlepage}}
45  \\tableofcontents
46  \\newpage""".format(config.message)
47  else:
48  out += """\\begin{titlepage}
49  \centering
50  \\vspace*{4cm}
51  \Huge\\bfseries Alignment Validation\par
52  \\vfill
53  \large \\today\par
54  \\end{titlepage}
55  \\tableofcontents
56  \\newpage"""
57 
58  # general information
59 
60  out += "\section{{General information}}\n"
61 
62  if (config.message):
63  out += "Project: {{{0}}}\\\\\n".format(config.message)
64  out += "Input-Path:\n"
65  out += "\\begin{verbatim}\n"
66  out += config.jobDataPath+"\n"
67  out += "\\end{verbatim}\n"
68 
69  # alignment_merge.py
70  try:
71  out += "\subsection{Alignment Configuration}\n"
72  out += "\\textbf{{PedeSteerer method:}} {{{0}}}\\\\\n".format(
73  additionalData.pede_steerer_method)
74  out += "\\textbf{{PedeSteerer options:}}\\\\\n"
75  for line in additionalData.pede_steerer_options:
76  out += "{{{0}}}\\\\\n".format(line)
77  out += "\\textbf{{PedeSteerer command:}} {0}\\\\\n".format(
78  additionalData.pede_steerer_command)
79 
80  for i in sorted(additionalData.selectors):
81  out += "\\textbf{{{0}:}}\n".format(additionalData.selectors[i]["name"])
82  out += "\\begin{verbatim}\n"
83  for line in additionalData.selectors[i]["selector"].dumpPython().split("\n"):
84  out += line + "\n"
85  out += "\\end{verbatim}\n"
86 
87  if len(additionalData.iov_definition) > 0:
88  out += "\\textbf{{IOV defintion:}}\n"
89  out += "\\begin{verbatim}\n"
90  for line in additionalData.iov_definition.dumpPython().split("\n"):
91  out += line + "\n"
92  out += "\\end{verbatim}\n\n"
93  out += "\n"
94 
95  except Exception as e:
96  logger.error("data not found - {0} {1}".format(type(e), e))
97 
98  # table of input files with number of tracks
99  if config.showmonitor:
100  out += "\subsection{Datasets with tracks}\n"
101  out += """\\begin{table}[h]
102  \centering
103  \caption{Datasets with tracks}
104  \\begin{tabular}{ccc}
105  \hline
106  Dataset & Number of used tracks & Weight \\\\
107  \hline \n"""
108  for monitor in mpsv_classes.MonitorData.monitors:
109  out += "{0} & {1} & {2}\\\\\n".format(monitor.name, monitor.ntracks,
110  monitor.weight if monitor.weight != None else "--")
111  try:
112  if (pedeDump.nrec):
113  out += "\hline\nNumber of records & {0}\\\\\n".format(pedeDump.nrec)
114  except Exception as e:
115  logger.error("data not found - {0} {1}".format(type(e), e))
116  out += """\hline
117  \end{tabular}\n
118  \end{table}\n"""
119  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.\n"
120  try:
121  # pede.dump.gz
122  if config.showdump:
123  out += "\subsection{{Pede monitoring information}}\n"
124  if (pedeDump.sumValue != 0):
125  out += r"\begin{{align*}}Sum(Chi^2)/Sum(Ndf) &= {0}\\ &= {1}\end{{align*}}".format(
126  pedeDump.sumSteps, pedeDump.sumValue)
127  else:
128  out += r"\begin{{align*}}Sum(W*Chi^2)/Sum(Ndf)/<W> &= {0}\\ &= {1}\end{{align*}}".format(
129  pedeDump.sumSteps, pedeDump.sumWValue)
130  out += r"with correction for down-weighting: {0}\\".format(
131  pedeDump.correction)
132  out += r"Peak dynamic memory allocation: {0} GB\\".format(
133  pedeDump.memory)
134  out += r"Total time: {0} h {1} m {2} s\\".format(
135  pedeDump.time[0], pedeDump.time[1], pedeDump.time[2])
136  out += r"Number of records: {0}\\".format(pedeDump.nrec)
137  out += r"Total number of parameters: {0}\\".format(pedeDump.ntgb)
138  out += r"Number of variable parameters: {0}\\".format(pedeDump.nvgb)
139  out += r"Warning:\\"
140  for line in pedeDump.warning:
141 
142  # check if line empty
143  if line.replace(r" ", r""):
144  out += "\\begin{verbatim}\n"
145  out += line + "\n"
146  out += "\\end{verbatim}\n"
147 
148  out += "\section{{Parameter plots}}\n"
149  except Exception as e:
150  logger.error("data not found - {0} {1}".format(type(e), e))
151 
152  # high level structures
153  if config.showhighlevel:
154  big = [x for x in config.outputList if (x.plottype == "big")]
155 
156  if big:
157  out += "\subsection{{High-level parameters}}\n"
158  for i in big:
159  out += "\includegraphics[width=\linewidth]{{{0}/plots/pdf/{1}.pdf}}\n".format(
160  config.outputPath, i.filename)
161 
162  # time (IOV) dependent plots
163  if config.showtime:
164  time = [x for x in config.outputList if (x.plottype == "time")]
165 
166  if time:
167  out += "\subsection{{High-level parameters versus time (IOV)}}\n"
168  # get list with names of the structures
169  for structure in [x.name for x in time if x.parameter == "xyz"]:
170  out += "\subsubsection{{{0}}}\n".format(structure)
171  for mode in ["xyz", "rot"]:
172  if any([x.filename for x in time if (x.parameter == mode and x.name == structure)]):
173  filename = [x.filename for x in time if (x.parameter == mode and x.name == structure)][0]
174  out += "\includegraphics[width=\linewidth]{{{0}/plots/pdf/{1}.pdf}}\n".format(
175  config.outputPath, filename)
176 
177  # hole modules
178  if config.showmodule:
179  # check if there are module plots
180  if any(x for x in config.outputList if (x.plottype == "mod" and x.number == "")):
181  out += "\subsection{{Module-level parameters}}\n"
182 
183  # loop over all structures
184  for moduleName in [x.name for x in alignables.structures]:
185 
186  # check if there is a plot for this module
187  if any(x for x in config.outputList if (x.plottype == "mod" and x.number == "" and x.name == moduleName)):
188  out += "\subsubsection{{{0}}}\n".format(moduleName)
189  # loop over modes
190  for mode in ["xyz", "rot", "dist"]:
191 
192  # get module plot
193  module = [x for x in config.outputList if (
194  x.plottype == "mod" and x.number == "" and x.name == moduleName and x.parameter == mode)]
195  # get list of sub module plots
196  moduleSub = [x for x in config.outputList if (
197  x.plottype == "subMod" and x.number != "" and x.name == moduleName and x.parameter == mode)]
198 
199  # check if plot there is a plot in this mode
200  if module:
201  out += "\includegraphics[width=\linewidth]{{{0}/plots/pdf/{1}.pdf}}\n".format(
202  config.outputPath, module[0].filename)
203  if config.showsubmodule:
204  # loop over submodules
205  for plot in moduleSub:
206  out += "\includegraphics[width=\linewidth]{{{0}/plots/pdf/{1}.pdf}}\n".format(
207  config.outputPath, plot.filename)
208 
209  # plot taken from the millePedeMonitor_merge.root file
210  if config.showmonitor:
211  if any(x for x in config.outputList if x.plottype == "monitor"):
212  out += "\section{{Monitor plots}}\n"
213 
214  lastdataset = ""
215  for plot in [x for x in config.outputList if x.plottype == "monitor"]:
216  # all plots of a dataset together in one section
217  if (lastdataset != plot.name):
218  out += "\subsection{{{0}}}\n".format(plot.name)
219  lastdataset = plot.name
220  out += "\includegraphics[width=\linewidth]{{{0}/plots/pdf/{1}.pdf}}\n".format(
221  config.outputPath, plot.filename)
222 
223  data = data.substitute(out=out)
224 
225  with open(os.path.join(config.outputPath, outputFile), "w") as output:
226  output.write(data)
227  output.close()
228 
229  # TODO run pdflatex
230  for i in range(2):
231  os.system("pdflatex -output-directory={0} {1}/{2}".format(
232  config.outputPath, config.outputPath, outputFile))
FastTimerService_cff.range
range
Definition: FastTimerService_cff.py:34
pdfCreator.create
def create(alignables, pedeDump, additionalData, outputFile, config)
Definition: pdfCreator.py:19
pdfCreator.TexTemplate
Definition: pdfCreator.py:15
cms::dd::split
std::vector< std::string_view > split(std::string_view, const char *)
any
bool any(const std::vector< T > &v, const T &what)
Definition: ECalSD.cc:34
ConfigBuilder.dumpPython
def dumpPython(process, name)
Definition: ConfigBuilder.py:92
format