Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 12:45:14

0001 ##########################################################################
0002 
0003 # Read the ini data which is passed to the function and return the
0004 # data as a configData object. If a parameter is given the function
0005 # parseParameter will override the config values.
0006 ##
0007 
0008 import configparser as ConfigParser
0009 import logging
0010 import os
0011 
0012 from Alignment.MillePedeAlignmentAlgorithm.alignmentsetup.helper \
0013     import checked_out_MPS
0014 
0015 
0016 class ConfigData:
0017     """ stores the config data of the ini files or the console parameters
0018     """
0019 
0020     def __init__(self):
0021         # get path to modules, defaut ini and templates
0022         self.mpspath = os.path.join(os.environ["CMSSW_BASE"]
0023                                     if checked_out_MPS()[0]
0024                                     else os.environ["CMSSW_RELEASE_BASE"], "src",
0025                                     "Alignment", "MillePedeAlignmentAlgorithm")
0026 
0027         # General
0028         # jobmX dir
0029         self.jobNumber = -1
0030         # MillePedeUser_X time
0031         self.jobTime = -1
0032         # ./jobData/jobmX path
0033         self.jobDataPath = ""
0034         # base outputpath
0035         self.outputPath = ""
0036         # latex file name
0037         self.latexfile = ""
0038         # identification in every plot (e.g. mp1885)
0039         self.message = ""
0040         # limits for warning dict with keys xyz, rot, dist
0041         # arguments must be given in this order
0042         self.limit = {}
0043         # statboxsize
0044         self.statboxsize = -1
0045         # global tag
0046         self.globalTag = None
0047         # first run to pick for the geometry in self.globalTag
0048         self.firstRun = None
0049 
0050         # what should be created
0051         self.showmonitor    = False
0052         self.showadditional = False
0053         self.showdump       = False
0054         self.showtime       = False
0055         self.showhighlevel  = False
0056         self.showmodule     = False
0057         self.showsubmodule  = False
0058         self.showtex        = False
0059         self.showbeamer     = False
0060         self.showhtml       = False
0061 
0062         # MODULEPLOTS
0063         # number of bins after shrinking
0064         self.numberofbins = -1
0065         # definition of sharp peak; max_outlier / StdDev > X
0066         self.defpeak = -1
0067         # new histogram width in units of StdDev
0068         self.widthstddev = -1
0069         # every parameter (e.g. xyz) with same range
0070         self.samerange = False
0071         # rangemode "stddev" = multiple of StdDev, "all" = show all, "given" =
0072         # use given ranges
0073         self.rangemode = -1
0074         # ranges
0075         self.rangexyzM = []
0076         self.rangerotM = []
0077         self.rangedistM = []
0078 
0079         # HIGHLEVELPLOTS
0080         # given ranges
0081         self.rangexyzHL = []
0082         self.rangerotHL = []
0083         # every parameter (e.g. xyz) with same range
0084         self.samerangeHL = False
0085         # rangemode "all" = show all, "given" = use given ranges
0086         self.rangemodeHL = -1
0087 
0088         # Time dependent
0089         self.firsttree = -1
0090 
0091         # list with the plots for the output
0092         self.outputList = []
0093 
0094     def parseConfig(self, path):
0095         logger = logging.getLogger("mpsvalidate")
0096 
0097         # create ConfigParser object
0098         parser = ConfigParser.ConfigParser()
0099 
0100         # read ini file
0101         if (parser.read(path) == []):
0102             logger.error("Could not open ini-file: {0}".format(path))
0103 
0104         # collect data and process it
0105         try:
0106             self.jobNumber = parser.getint("GENERAL", "job")
0107         except (ConfigParser.NoSectionError, ConfigParser.NoOptionError):
0108             pass
0109 
0110         try:
0111             self.jobDataPath = parser.get("GENERAL", "jobdatapath")
0112         except (ConfigParser.NoSectionError, ConfigParser.NoOptionError):
0113             pass
0114 
0115         # if jobData path is given
0116         if self.jobDataPath != "":
0117             self.outputPath = "validation_output"
0118 
0119         # set jobDataPath if job number is given and if path is not given
0120         if self.jobNumber != -1 and self.jobDataPath == "":
0121             if self.jobNumber == 0:
0122                 self.jobDataPath = "jobData/jobm"
0123             else:
0124                 self.jobDataPath = "jobData/jobm{0}".format(self.jobNumber)
0125             self.outputPath = os.path.join(self.jobDataPath, "validation_output")
0126 
0127         # set outputpath
0128         try:
0129             if parser.get("GENERAL", "outputpath"):
0130                 self.outputPath = parser.get("GENERAL", "outputpath")
0131         except (ConfigParser.NoSectionError, ConfigParser.NoOptionError):
0132             pass
0133 
0134 
0135         # data which could be stored directly
0136         try:
0137             self.jobTime = parser.getint("GENERAL", "time")
0138         except (ConfigParser.NoSectionError, ConfigParser.NoOptionError):
0139             pass
0140 
0141         try:
0142             self.latexfile = parser.get("GENERAL", "latexfile")
0143         except (ConfigParser.NoSectionError, ConfigParser.NoOptionError):
0144             pass
0145 
0146         try:
0147             self.limit = parser.get("GENERAL", "limit")
0148             self.limit = map(float, "".join(self.limit.split()).split(","))
0149             # make a dict to lookup by mode
0150             self.limit = dict(zip(["xyz", "rot", "dist"], self.limit))
0151         except (ConfigParser.NoSectionError, ConfigParser.NoOptionError):
0152             pass
0153 
0154         try:
0155             self.statboxsize = parser.getfloat("GENERAL", "statboxsize")
0156         except (ConfigParser.NoSectionError, ConfigParser.NoOptionError):
0157             pass
0158 
0159 
0160         # MODULEPLOTS
0161 
0162         # integers
0163         for par in ("numberofbins", "defpeak", "widthstddev"):
0164             try:
0165                 setattr(self, par, parser.getint("MODULEPLOTS", par))
0166             except (ConfigParser.NoSectionError, ConfigParser.NoOptionError):
0167                 pass
0168 
0169         # booleans
0170         try:
0171             self.samerange = parser.getboolean("MODULEPLOTS", "samerange")
0172         except (ConfigParser.NoSectionError, ConfigParser.NoOptionError):
0173             pass
0174 
0175         # strings
0176         try:
0177             self.rangemode = parser.get("MODULEPLOTS", "rangemode")
0178         except (ConfigParser.NoSectionError, ConfigParser.NoOptionError):
0179             pass
0180 
0181         # ranges
0182         for r in ("rangexyz", "rangerot", "rangedist"):
0183             try:
0184                 setattr(self, r+"M", parser.get("MODULEPLOTS", r))
0185                 setattr(self, r+"M",
0186                         sorted(map(float, "".join(getattr(self, r+"M").split()).split(","))))
0187             except (ConfigParser.NoSectionError, ConfigParser.NoOptionError):
0188                 pass
0189 
0190 
0191         # HIGHLEVELPLOTS
0192 
0193         # booleans
0194         try:
0195             self.samerangeHL = parser.getboolean("HIGHLEVELPLOTS", "samerange")
0196         except (ConfigParser.NoSectionError, ConfigParser.NoOptionError):
0197             pass
0198 
0199         # strings
0200         try:
0201             self.rangemodeHL = parser.get("HIGHLEVELPLOTS", "rangemode")
0202         except (ConfigParser.NoSectionError, ConfigParser.NoOptionError):
0203             pass
0204 
0205         # ranges
0206         for r in ("rangexyz", "rangerot"):
0207             try:
0208                 setattr(self, r+"HL", parser.get("HIGHLEVELPLOTS", r))
0209                 setattr(self, r+"HL",
0210                         sorted(map(float, "".join(getattr(self, r+"HL").split()).split(","))))
0211             except (ConfigParser.NoSectionError, ConfigParser.NoOptionError):
0212                 pass
0213 
0214 
0215         # TIMEPLOTS
0216 
0217         try:
0218             self.firsttree = parser.getint("TIMEPLOTS", "firsttree")
0219         except (ConfigParser.NoSectionError, ConfigParser.NoOptionError):
0220             pass
0221 
0222         # SHOW
0223         for boolean in ("showmonitor", "showadditional", "showdump", "showtime",
0224                         "showhighlevel", "showmodule", "showsubmodule",
0225                         "showtex", "showbeamer", "showhtml"):
0226             try:
0227                 setattr(self, boolean, parser.getboolean("SHOW", boolean))
0228             except (ConfigParser.NoSectionError, ConfigParser.NoOptionError):
0229                 pass
0230 
0231 
0232     def parseParameter(self, args):
0233         logger = logging.getLogger("mpsvalidate")
0234 
0235         # check if parameter is given and override the config data
0236         if args.time != -1:
0237             self.jobTime = args.time
0238 
0239         if args.job != -1:
0240             self.jobNumber = args.job
0241 
0242             # set jobDataPath
0243             if self.jobNumber == 0:
0244                 self.jobDataPath = "jobData/jobm"
0245             else:
0246                 self.jobDataPath = "jobData/jobm{0}".format(self.jobNumber)
0247             self.outputPath = os.path.join(self.jobDataPath, "validation_output")
0248 
0249         if args.jobdatapath != "":
0250             self.jobDataPath = args.jobdatapath
0251 
0252         if args.message != "":
0253             self.message = args.message
0254 
0255         # if path is given put the output in the current directory
0256         if args.jobdatapath:
0257             self.outputPath = "validation_output"
0258 
0259         if args.outputpath:
0260             self.outputPath = args.outputpath
0261