CMS 3D CMS Logo

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