CMS 3D CMS Logo

mps_validate.py
Go to the documentation of this file.
1 #!/usr/bin/env python3
2 
3 
8 
9 import argparse
10 import glob
11 import logging
12 import os
13 import shutil
14 import sys
15 
16 import ROOT
17 ROOT.PyConfig.IgnoreCommandLineOptions = True
18 ROOT.gROOT.SetBatch()
19 
20 import Alignment.MillePedeAlignmentAlgorithm.mpsvalidate.style as mpsv_style
21 import Alignment.MillePedeAlignmentAlgorithm.mpsvalidate.geometry as mpsv_geometry
22 import Alignment.MillePedeAlignmentAlgorithm.mpsvalidate.bigModule as mpsv_bigModule
23 import Alignment.MillePedeAlignmentAlgorithm.mpsvalidate.iniparser as mpsv_iniparser
24 import Alignment.MillePedeAlignmentAlgorithm.mpsvalidate.dumpparser as mpsv_dumpparser
25 import Alignment.MillePedeAlignmentAlgorithm.mpsvalidate.pdfCreator as mpsv_pdfCreator
26 import Alignment.MillePedeAlignmentAlgorithm.mpsvalidate.htmlCreator as mpsv_htmlCreator
27 import Alignment.MillePedeAlignmentAlgorithm.mpsvalidate.monitorPlot as mpsv_monitorPlot
28 import Alignment.MillePedeAlignmentAlgorithm.mpsvalidate.trackerTree as mpsv_trackerTree
29 import Alignment.MillePedeAlignmentAlgorithm.mpsvalidate.bigStructure as mpsv_bigStructure
30 import Alignment.MillePedeAlignmentAlgorithm.mpsvalidate.beamerCreator as mpsv_beamerCreator
31 import Alignment.MillePedeAlignmentAlgorithm.mpsvalidate.timeStructure as mpsv_timeStructure
32 import Alignment.MillePedeAlignmentAlgorithm.mpsvalidate.additionalparser as mpsv_additionalparser
33 
34 
35 
36 def main():
37  # config logging module
38  logging.basicConfig(level=logging.INFO, format="%(levelname)s %(asctime)s (%(pathname)s line %(lineno)d): %(message)s", datefmt="%H:%M:%S")
39  logger = logging.getLogger("mpsvalidate")
40 
41  # ArgumentParser
42  parser = argparse.ArgumentParser(description="Validate your Alignment.")
43  parser.add_argument(
44  "-j", "--job", help="chose jobmX directory (default: ini-file)", default=-1, type=int)
45  parser.add_argument(
46  "-t", "--time", help="chose MillePedeUser_X Tree (default: ini-file)", default=-1, type=int)
47  parser.add_argument("-i", "--ini", help="specify a ini file")
48  parser.add_argument("-m", "--message",
49  help="identification on every plot", default="")
50  parser.add_argument("-p", "--jobdatapath",
51  help="path to the jobm directory", default="")
52  parser.add_argument("-o", "--outputpath",
53  help="outputpath", default="")
54  parser.add_argument("-l", "--logging",
55  help="if this argument is given a logging file (validation.log) is saved in the current directory", action="store_true")
56  parser.add_argument("-c", "--copy",
57  help="creates a copy of the validation_user.ini file in the current directory", action="store_true")
58  args = parser.parse_args()
59 
60  # create config object
61  config = mpsv_iniparser.ConfigData()
62 
63  # create logging handler
64  if args.logging:
65  handler = logging.FileHandler("validation.log", mode="w")
66  handler.setLevel(logging.DEBUG)
67  formatter = logging.Formatter("%(levelname)s %(asctime)s (%(pathname)s line %(lineno)d): %(message)s",
68  datefmt="%H:%M:%S")
69  handler.setFormatter(formatter)
70  logger.addHandler(handler)
71 
72  # parse default ini file
73  logger.info("start to parse the default.ini")
74  config.parseConfig(os.path.join(config.mpspath, "templates",
75  "mpsvalidate_default.ini"))
76 
77  # copy of ini file in current directory
78  if args.copy:
79  logger.info("create copy of validation_user.ini in current directory")
80  shutil.copy2(os.path.join(config.mpspath, "templates", "mpsvalidate_default.ini"),
81  "validation_user.ini")
82  sys.exit()
83 
84 
85  # parse user ini file
86  if args.ini != None:
87  logger.info("start to parse the user ini: {0}".format(args.ini))
88  config.parseConfig(args.ini)
89 
90  # override ini configs with consol parameter
91  config.parseParameter(args)
92 
93  # create output directories
94  logger.info("create the output directories")
95  if not os.path.exists(os.path.join(config.outputPath, "plots/pdf")):
96  os.makedirs(os.path.join(config.outputPath, "plots/pdf"))
97  if not os.path.exists(os.path.join(config.outputPath, "plots/png")):
98  os.makedirs(os.path.join(config.outputPath, "plots/png"))
99 
100  # open root file and get TTree MillePedeUser_X
101  logger.info("try to open the root file: {0}".format(os.path.join(config.jobDataPath, "treeFile_merge.root")))
102  treeFile = ROOT.TFile(os.path.join(config.jobDataPath, "treeFile_merge.root"))
103  MillePedeUser = treeFile.Get("MillePedeUser_{0}".format(config.jobTime))
104  if not MillePedeUser:
105  logger.error("Could not open TTree File MillePedeUser_{0} in {1}".format(
106  config.jobTime, os.path.join(config.jobDataPath, "treeFile_merge.root")))
107  return
108 
109  # set gStyle
110  mpsv_style.setgstyle()
111 
112  # create alignables object
113  alignables = mpsv_geometry.Alignables(config)
114 
115  # check if there is the TrackerTree.root file and if not create it
116  mpsv_trackerTree.check(config)
117 
118 
121 
122  if config.showmonitor:
123  try:
124  logger.info("start to collect the plots of the millePedeMonitor_merge.root file")
125  mpsv_monitorPlot.plot(config)
126  except Exception as e:
127  logging.error("millePedeMonitor_merge.root failure - {0} {1}".format(type(e), e))
128  raise
129 
130 
133 
134  if config.showadditional:
135  logger.info("start to parse the alignment_merge.py file")
136  try:
137  additionalData = mpsv_additionalparser.AdditionalData()
138  additionalData.parse(
139  config, os.path.join(config.jobDataPath, "alignment_merge.py"))
140  except Exception as e:
141  logging.error("alignment_merge.py parser failure - {0} {1}".format(type(e), e))
142  raise
143 
144 
147 
148  if config.showdump:
149  try:
150  logger.info("start to parse the pede.dump.gz file")
151  pedeDump = mpsv_dumpparser.parse(
152  os.path.join(config.jobDataPath, "pede.dump.gz"), config)
153  except Exception as e:
154  logging.error("pede.dump.gz parser failure - {0} {1}".format(type(e), e))
155  raise
156 
157 
160 
161  if config.showtime:
162  try:
163  logger.info("create the time dependent plots")
164  mpsv_timeStructure.plot(treeFile, alignables, config)
165  except Exception as e:
166  logging.error("time dependent plots failure - {0} {1}".format(type(e), e))
167  raise
168 
169 
172 
173  if config.showhighlevel:
174  try:
175  logger.info("create the high level plots")
176  mpsv_bigStructure.plot(MillePedeUser, alignables, config)
177  except Exception as e:
178  logging.error("high level plots failure - {0} {1}".format(type(e), e))
179  raise
180 
181 
185 
186  if config.showmodule:
187  try:
188  logger.info("create the module plots")
189  mpsv_bigModule.plot(MillePedeUser, alignables, config)
190  except Exception as e:
191  logging.error("module plots failure - {0} {1}".format(type(e), e))
192  raise
193 
194 
197 
198  if config.showtex:
199  try:
200  logger.info("create the latex file")
201  mpsv_pdfCreator.create(alignables, pedeDump, additionalData,
202  config.latexfile, config)
203  except Exception as e:
204  logging.error("latex creation failure - {0} {1}".format(type(e), e))
205  raise
206 
207  if config.showbeamer:
208  try:
209  logger.info("create the latex beamer file")
210  mpsv_beamerCreator.create(alignables, pedeDump, additionalData,
211  "beamer.tex", config)
212  except Exception as e:
213  logging.error("beamer latex failure - {0} {1}".format(type(e), e))
214  raise
215 
216  # delete latex temporary files
217  for extension in ["aux", "log", "nav", "out", "snm", "toc"]:
218  extension = "*." + extension
219  pattern = os.path.join(config.outputPath, extension)
220  logger.info("Remove temporary latex files: "+pattern)
221  map(os.remove, glob.glob(pattern))
222 
223  if config.showhtml:
224  try:
225  logger.info("create the HTML file")
226  mpsv_htmlCreator.create(alignables, pedeDump, additionalData,
227  "html_file.html", config)
228  except Exception as e:
229  logging.error("HTML creation failure - {0} {1}".format(type(e), e))
230  raise
231 
232 if __name__ == "__main__":
233  main()
main
Definition: main.py:1
format
mps_validate.main
def main()
Definition: mps_validate.py:36
genParticles_cff.map
map
Definition: genParticles_cff.py:11