File indexing completed on 2024-04-06 11:56:36
0001
0002
0003
0004
0005
0006
0007
0008
0009 import argparse
0010 import glob
0011 import logging
0012 import os
0013 import shutil
0014 import sys
0015
0016 import ROOT
0017 ROOT.PyConfig.IgnoreCommandLineOptions = True
0018 ROOT.gROOT.SetBatch()
0019
0020 import Alignment.MillePedeAlignmentAlgorithm.mpsvalidate.style as mpsv_style
0021 import Alignment.MillePedeAlignmentAlgorithm.mpsvalidate.geometry as mpsv_geometry
0022 import Alignment.MillePedeAlignmentAlgorithm.mpsvalidate.bigModule as mpsv_bigModule
0023 import Alignment.MillePedeAlignmentAlgorithm.mpsvalidate.iniparser as mpsv_iniparser
0024 import Alignment.MillePedeAlignmentAlgorithm.mpsvalidate.dumpparser as mpsv_dumpparser
0025 import Alignment.MillePedeAlignmentAlgorithm.mpsvalidate.pdfCreator as mpsv_pdfCreator
0026 import Alignment.MillePedeAlignmentAlgorithm.mpsvalidate.htmlCreator as mpsv_htmlCreator
0027 import Alignment.MillePedeAlignmentAlgorithm.mpsvalidate.monitorPlot as mpsv_monitorPlot
0028 import Alignment.MillePedeAlignmentAlgorithm.mpsvalidate.trackerTree as mpsv_trackerTree
0029 import Alignment.MillePedeAlignmentAlgorithm.mpsvalidate.bigStructure as mpsv_bigStructure
0030 import Alignment.MillePedeAlignmentAlgorithm.mpsvalidate.beamerCreator as mpsv_beamerCreator
0031 import Alignment.MillePedeAlignmentAlgorithm.mpsvalidate.timeStructure as mpsv_timeStructure
0032 import Alignment.MillePedeAlignmentAlgorithm.mpsvalidate.additionalparser as mpsv_additionalparser
0033
0034
0035
0036 def main():
0037
0038 logging.basicConfig(level=logging.INFO, format="%(levelname)s %(asctime)s (%(pathname)s line %(lineno)d): %(message)s", datefmt="%H:%M:%S")
0039 logger = logging.getLogger("mpsvalidate")
0040
0041
0042 parser = argparse.ArgumentParser(description="Validate your Alignment.")
0043 parser.add_argument(
0044 "-j", "--job", help="chose jobmX directory (default: ini-file)", default=-1, type=int)
0045 parser.add_argument(
0046 "-t", "--time", help="chose MillePedeUser_X Tree (default: ini-file)", default=-1, type=int)
0047 parser.add_argument("-i", "--ini", help="specify a ini file")
0048 parser.add_argument("-m", "--message",
0049 help="identification on every plot", default="")
0050 parser.add_argument("-p", "--jobdatapath",
0051 help="path to the jobm directory", default="")
0052 parser.add_argument("-o", "--outputpath",
0053 help="outputpath", default="")
0054 parser.add_argument("-l", "--logging",
0055 help="if this argument is given a logging file (validation.log) is saved in the current directory", action="store_true")
0056 parser.add_argument("-c", "--copy",
0057 help="creates a copy of the validation_user.ini file in the current directory", action="store_true")
0058 args = parser.parse_args()
0059
0060
0061 config = mpsv_iniparser.ConfigData()
0062
0063
0064 if args.logging:
0065 handler = logging.FileHandler("validation.log", mode="w")
0066 handler.setLevel(logging.DEBUG)
0067 formatter = logging.Formatter("%(levelname)s %(asctime)s (%(pathname)s line %(lineno)d): %(message)s",
0068 datefmt="%H:%M:%S")
0069 handler.setFormatter(formatter)
0070 logger.addHandler(handler)
0071
0072
0073 logger.info("start to parse the default.ini")
0074 config.parseConfig(os.path.join(config.mpspath, "templates",
0075 "mpsvalidate_default.ini"))
0076
0077
0078 if args.copy:
0079 logger.info("create copy of validation_user.ini in current directory")
0080 shutil.copy2(os.path.join(config.mpspath, "templates", "mpsvalidate_default.ini"),
0081 "validation_user.ini")
0082 sys.exit()
0083
0084
0085
0086 if args.ini != None:
0087 logger.info("start to parse the user ini: {0}".format(args.ini))
0088 config.parseConfig(args.ini)
0089
0090
0091 config.parseParameter(args)
0092
0093
0094 logger.info("create the output directories")
0095 if not os.path.exists(os.path.join(config.outputPath, "plots/pdf")):
0096 os.makedirs(os.path.join(config.outputPath, "plots/pdf"))
0097 if not os.path.exists(os.path.join(config.outputPath, "plots/png")):
0098 os.makedirs(os.path.join(config.outputPath, "plots/png"))
0099
0100
0101 logger.info("try to open the root file: {0}".format(os.path.join(config.jobDataPath, "treeFile_merge.root")))
0102 treeFile = ROOT.TFile(os.path.join(config.jobDataPath, "treeFile_merge.root"))
0103 MillePedeUser = treeFile.Get("MillePedeUser_{0}".format(config.jobTime))
0104 if not MillePedeUser:
0105 logger.error("Could not open TTree File MillePedeUser_{0} in {1}".format(
0106 config.jobTime, os.path.join(config.jobDataPath, "treeFile_merge.root")))
0107 return
0108
0109
0110 mpsv_style.setgstyle()
0111
0112
0113 alignables = mpsv_geometry.Alignables(config)
0114
0115
0116 mpsv_trackerTree.check(config)
0117
0118
0119
0120
0121
0122 if config.showmonitor:
0123 try:
0124 logger.info("start to collect the plots of the millePedeMonitor_merge.root file")
0125 mpsv_monitorPlot.plot(config)
0126 except Exception as e:
0127 logging.error("millePedeMonitor_merge.root failure - {0} {1}".format(type(e), e))
0128 raise
0129
0130
0131
0132
0133
0134 if config.showadditional:
0135 logger.info("start to parse the alignment_merge.py file")
0136 try:
0137 additionalData = mpsv_additionalparser.AdditionalData()
0138 additionalData.parse(
0139 config, os.path.join(config.jobDataPath, "alignment_merge.py"))
0140 except Exception as e:
0141 logging.error("alignment_merge.py parser failure - {0} {1}".format(type(e), e))
0142 raise
0143
0144
0145
0146
0147
0148 if config.showdump:
0149 try:
0150 logger.info("start to parse the pede.dump.gz file")
0151 pedeDump = mpsv_dumpparser.parse(
0152 os.path.join(config.jobDataPath, "pede.dump.gz"), config)
0153 except Exception as e:
0154 logging.error("pede.dump.gz parser failure - {0} {1}".format(type(e), e))
0155 raise
0156
0157
0158
0159
0160
0161 if config.showtime:
0162 try:
0163 logger.info("create the time dependent plots")
0164 mpsv_timeStructure.plot(treeFile, alignables, config)
0165 except Exception as e:
0166 logging.error("time dependent plots failure - {0} {1}".format(type(e), e))
0167 raise
0168
0169
0170
0171
0172
0173 if config.showhighlevel:
0174 try:
0175 logger.info("create the high level plots")
0176 mpsv_bigStructure.plot(MillePedeUser, alignables, config)
0177 except Exception as e:
0178 logging.error("high level plots failure - {0} {1}".format(type(e), e))
0179 raise
0180
0181
0182
0183
0184
0185
0186 if config.showmodule:
0187 try:
0188 logger.info("create the module plots")
0189 mpsv_bigModule.plot(MillePedeUser, alignables, config)
0190 except Exception as e:
0191 logging.error("module plots failure - {0} {1}".format(type(e), e))
0192 raise
0193
0194
0195
0196
0197
0198 if config.showtex:
0199 try:
0200 logger.info("create the latex file")
0201 mpsv_pdfCreator.create(alignables, pedeDump, additionalData,
0202 config.latexfile, config)
0203 except Exception as e:
0204 logging.error("latex creation failure - {0} {1}".format(type(e), e))
0205 raise
0206
0207 if config.showbeamer:
0208 try:
0209 logger.info("create the latex beamer file")
0210 mpsv_beamerCreator.create(alignables, pedeDump, additionalData,
0211 "beamer.tex", config)
0212 except Exception as e:
0213 logging.error("beamer latex failure - {0} {1}".format(type(e), e))
0214 raise
0215
0216
0217 for extension in ["aux", "log", "nav", "out", "snm", "toc"]:
0218 extension = "*." + extension
0219 pattern = os.path.join(config.outputPath, extension)
0220 logger.info("Remove temporary latex files: "+pattern)
0221 map(os.remove, glob.glob(pattern))
0222
0223 if config.showhtml:
0224 try:
0225 logger.info("create the HTML file")
0226 mpsv_htmlCreator.create(alignables, pedeDump, additionalData,
0227 "html_file.html", config)
0228 except Exception as e:
0229 logging.error("HTML creation failure - {0} {1}".format(type(e), e))
0230 raise
0231
0232 if __name__ == "__main__":
0233 main()