CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
Classes | Functions
pdfCreator Namespace Reference

Classes

class  TexTemplate
 

Functions

def create
 

Function Documentation

def pdfCreator.create (   alignables,
  pedeDump,
  additionalData,
  outputFile,
  config 
)

Definition at line 19 of file pdfCreator.py.

References any(), ConfigBuilder.dumpPython(), sistrip::SpyUtilities.range(), and submitPVValidationJobs.split().

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