CMS 3D CMS Logo

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

Functions

def main
 

Function Documentation

def mps_validate.main ( )

Definition at line 36 of file mps_validate.py.

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