File indexing completed on 2023-03-17 10:40:24
0001 from __future__ import absolute_import
0002 import os
0003 from . import configTemplates
0004 from . import globalDictionaries
0005 from .genericValidation import GenericValidationData_CTSR, ParallelValidation, ValidationWithComparison, ValidationForPresentation, ValidationWithPlots, ValidationWithPlotsSummary
0006 from .helperFunctions import replaceByMap, addIndex, pythonboolstring
0007 from .presentation import SubsectionFromList, SubsectionOnePage
0008 from .TkAlExceptions import AllInOneError
0009
0010 class OfflineValidation(GenericValidationData_CTSR, ParallelValidation, ValidationWithComparison, ValidationWithPlotsSummary, ValidationForPresentation):
0011 configBaseName = "TkAlOfflineValidation"
0012 scriptBaseName = "TkAlOfflineValidation"
0013 crabCfgBaseName = "TkAlOfflineValidation"
0014 resultBaseName = "AlignmentValidation"
0015 outputBaseName = "AlignmentValidation"
0016 defaults = {
0017 "offlineModuleLevelHistsTransient": "False",
0018 "offlineModuleLevelProfiles": "True",
0019 "stripYResiduals": "False",
0020 "maxtracks": "0",
0021 "chargeCut": "0",
0022 "multiIOV": "False",
0023 }
0024 deprecateddefaults = {
0025 "DMRMethod":"",
0026 "DMRMinimum":"",
0027 "DMROptions":"",
0028 "OfflineTreeBaseDir":"",
0029 "SurfaceShapes":"",
0030 }
0031 defaults.update(deprecateddefaults)
0032 mandatories = {"trackcollection"}
0033 valType = "offline"
0034
0035 def __init__(self, valName, alignment, config):
0036 super(OfflineValidation, self).__init__(valName, alignment, config)
0037
0038 for name in "offlineModuleLevelHistsTransient", "offlineModuleLevelProfiles", "stripYResiduals":
0039 self.general[name] = pythonboolstring(self.general[name], name)
0040
0041 for option in self.deprecateddefaults:
0042 if self.general[option]:
0043 raise AllInOneError("The '%s' option has been moved to the [plots:offline] section. Please specify it there."%option)
0044 del self.general[option]
0045
0046 if self.NJobs > 1 and self.general["offlineModuleLevelHistsTransient"] == "True":
0047 msg = ("To be able to merge results when running parallel jobs,"
0048 " set offlineModuleLevelHistsTransient to false.")
0049 raise AllInOneError(msg)
0050
0051 try:
0052 self.NTracks = int(self.general["maxtracks"])
0053 if self.NTracks < 0: raise ValueError
0054 except ValueError:
0055 raise AllInOneError("maxtracks has to be a positive integer, or 0 for no limit")
0056
0057 if self.NTracks / self.NJobs != float(self.NTracks) / self.NJobs:
0058 raise AllInOneError("maxtracks has to be divisible by parallelJobs")
0059
0060 @property
0061 def ProcessName(self):
0062 return "OfflineValidator"
0063
0064 @property
0065 def ValidationTemplate(self):
0066 return configTemplates.offlineTemplate
0067
0068 @property
0069 def ValidationSequence(self):
0070 return configTemplates.OfflineValidationSequence
0071
0072 @property
0073 def FileOutputTemplate(self):
0074 return configTemplates.offlineFileOutputTemplate
0075
0076 def createScript(self, path):
0077 return super(OfflineValidation, self).createScript(path)
0078
0079 def createCrabCfg(self, path):
0080 return super(OfflineValidation, self).createCrabCfg(path, self.crabCfgBaseName)
0081
0082 def getRepMap(self, alignment = None):
0083 repMap = super(OfflineValidation, self).getRepMap(alignment)
0084 repMap.update({
0085 "nEvents": self.general["maxevents"],
0086 "offlineValidationMode": "Standalone",
0087 "TrackCollection": self.general["trackcollection"],
0088 "filetoplot": "root://eoscms//eos/cms.oO[finalResultFile]Oo.",
0089 })
0090
0091 return repMap
0092
0093 def appendToPlots(self):
0094 return ' p.loadFileList(".oO[filetoplot]Oo.", ".oO[title]Oo.", .oO[color]Oo., .oO[style]Oo.);\n'
0095
0096 @classmethod
0097 def initMerge(cls):
0098 from .plottingOptions import PlottingOptions
0099 outFilePath = replaceByMap(".oO[scriptsdir]Oo./TkAlOfflineJobsMerge.C", PlottingOptions(None, cls.valType))
0100 print("outFilePath")
0101 print(outFilePath)
0102 with open(outFilePath, "w") as theFile:
0103 theFile.write(replaceByMap(configTemplates.mergeOfflineParJobsTemplate, {}))
0104 result = super(OfflineValidation, cls).initMerge()
0105 result += ("cp .oO[Alignment/OfflineValidation]Oo./scripts/merge_TrackerOfflineValidation.C .\n"
0106 "cp .oO[mergeOfflineParJobsScriptPath]Oo. .\n")
0107 return result
0108
0109 def appendToMerge(self):
0110 repMap = self.getRepMap()
0111
0112 parameters = "root://eoscms//eos/cms" + ",root://eoscms//eos/cms".join(repMap["resultFiles"])
0113
0114 mergedoutputfile = "root://eoscms//eos/cms%(finalResultFile)s"%repMap
0115 return ('root -x -b -q -l "TkAlOfflineJobsMerge.C(\\\"'
0116 +parameters+'\\\",\\\"'+mergedoutputfile+'\\\")"')
0117
0118 @classmethod
0119 def plottingscriptname(cls):
0120 return "TkAlExtendedOfflineValidation.C"
0121
0122 @classmethod
0123 def plottingscripttemplate(cls):
0124 return configTemplates.extendedValidationTemplate
0125
0126 @classmethod
0127 def plotsdirname(cls):
0128 return "ExtendedOfflineValidation_Images"
0129
0130 @classmethod
0131 def comparealignmentsname(cls):
0132 return "compareAlignments.cc"
0133
0134 @classmethod
0135 def presentationsubsections(cls):
0136 return [
0137 SubsectionOnePage('chi2', r'$\chi^2$ plots'),
0138 SubsectionSubdetectors('DmedianY*R_[^_]*.eps$', 'DMR'),
0139 SubsectionSubdetectors('DmedianY*R.*plain.eps$', 'DMR'),
0140 SubsectionSubdetectors('DmedianY*R.*split.eps$','Split DMR'),
0141 SubsectionSubdetectors('DrmsNY*R_[^_]*.eps$', 'DRnR'),
0142 SubsectionSubdetectors('DrmsNY*R.*plain.eps$', 'DRnR'),
0143 SubsectionSubdetectors('SurfaceShape', 'Surface Shape'),
0144 ]
0145
0146 class SubsectionSubdetectors(SubsectionFromList):
0147 pageidentifiers = (
0148 ("BPIX", "BPIX"),
0149 ("FPIX", "FPIX"),
0150 ("TIB", "TIB"),
0151 ("TID", "TID"),
0152 ("TOB", "TOB"),
0153 ("TEC", "TEC"),
0154 )
0155
0156 class OfflineValidationDQM(OfflineValidation):
0157 configBaseName = "TkAlOfflineValidationDQM"
0158 def __init__(self, valName, alignment, config):
0159 super(OfflineValidationDQM, self).__init__(valName, alignment, config)
0160 if not config.has_section("DQM"):
0161 msg = "You need to have a DQM section in your configfile!"
0162 raise AllInOneError(msg)
0163
0164 self.__PrimaryDataset = config.get("DQM", "primaryDataset")
0165 self.__firstRun = int(config.get("DQM", "firstRun"))
0166 self.__lastRun = int(config.get("DQM", "lastRun"))
0167
0168 def getRepMap(self, alignment = None):
0169 repMap = super(OfflineValidationDQM, self).getRepMap(alignment)
0170 repMap.update({
0171 "workdir": os.path.expandvars(repMap["workdir"]),
0172 "offlineValidationMode": "Dqm",
0173 "workflow": ("/%s/TkAl%s-.oO[alignmentName]Oo._R%09i_R%09i_"
0174 "ValSkim-v1/ALCARECO"
0175 %(self.__PrimaryDataset,
0176 datetime.datetime.now().strftime("%y"),
0177 self.__firstRun, self.__lastRun)),
0178 "firstRunNumber": "%i"% self.__firstRun
0179 })
0180 if "__" in repMap["workflow"]:
0181 msg = ("the DQM workflow specefication must not contain '__'. "
0182 "it is: %s"%repMap["workflow"])
0183 raise AllInOneError(msg)
0184 return repMap
0185
0186 @property
0187 def FileOutputTemplate(self):
0188 return configTemplates.offlineDqmFileOutputTemplate