test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros 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 22 of file pdfCreator.py.

References any().

Referenced by mps_validate.main().

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