CMS 3D CMS Logo

offlineValidation.py
Go to the documentation of this file.
1 from __future__ import absolute_import
2 import os
3 from . import configTemplates
4 from . import globalDictionaries
5 from .genericValidation import GenericValidationData_CTSR, ParallelValidation, ValidationWithComparison, ValidationForPresentation, ValidationWithPlots, ValidationWithPlotsSummary
6 from .helperFunctions import replaceByMap, addIndex, pythonboolstring
7 from .presentation import SubsectionFromList, SubsectionOnePage
8 from .TkAlExceptions import AllInOneError
9 
11  configBaseName = "TkAlOfflineValidation"
12  scriptBaseName = "TkAlOfflineValidation"
13  crabCfgBaseName = "TkAlOfflineValidation"
14  resultBaseName = "AlignmentValidation"
15  outputBaseName = "AlignmentValidation"
16  defaults = {
17  "offlineModuleLevelHistsTransient": "False",
18  "offlineModuleLevelProfiles": "True",
19  "stripYResiduals": "False",
20  "maxtracks": "0",
21  "chargeCut": "0",
22  }
23  deprecateddefaults = {
24  "DMRMethod":"",
25  "DMRMinimum":"",
26  "DMROptions":"",
27  "OfflineTreeBaseDir":"",
28  "SurfaceShapes":"",
29  }
30  defaults.update(deprecateddefaults)
31  mandatories = {"trackcollection"}
32  valType = "offline"
33 
34  def __init__(self, valName, alignment, config):
35  super(OfflineValidation, self).__init__(valName, alignment, config)
36 
37  for name in "offlineModuleLevelHistsTransient", "offlineModuleLevelProfiles", "stripYResiduals":
38  self.general[name] = pythonboolstring(self.general[name], name)
39 
40  for option in self.deprecateddefaults:
41  if self.general[option]:
42  raise AllInOneError("The '%s' option has been moved to the [plots:offline] section. Please specify it there."%option)
43  del self.general[option]
44 
45  if self.NJobs > 1 and self.general["offlineModuleLevelHistsTransient"] == "True":
46  msg = ("To be able to merge results when running parallel jobs,"
47  " set offlineModuleLevelHistsTransient to false.")
48  raise AllInOneError(msg)
49 
50  try:
51  self.NTracks = int(self.general["maxtracks"])
52  if self.NTracks < 0: raise ValueError
53  except ValueError:
54  raise AllInOneError("maxtracks has to be a positive integer, or 0 for no limit")
55 
56  if self.NTracks / self.NJobs != float(self.NTracks) / self.NJobs:
57  raise AllInOneError("maxtracks has to be divisible by parallelJobs")
58 
59  @property
60  def ProcessName(self):
61  return "OfflineValidator"
62 
63  @property
64  def ValidationTemplate(self):
65  return configTemplates.offlineTemplate
66 
67  @property
68  def ValidationSequence(self):
69  return configTemplates.OfflineValidationSequence
70 
71  @property
72  def FileOutputTemplate(self):
73  return configTemplates.offlineFileOutputTemplate
74 
75  def createScript(self, path):
76  return super(OfflineValidation, self).createScript(path)
77 
78  def createCrabCfg(self, path):
79  return super(OfflineValidation, self).createCrabCfg(path, self.crabCfgBaseName)
80 
81  def getRepMap(self, alignment = None):
82  repMap = super(OfflineValidation, self).getRepMap(alignment)
83  repMap.update({
84  "nEvents": self.general["maxevents"],
85  "offlineValidationMode": "Standalone",
86  "TrackCollection": self.general["trackcollection"],
87  "filetoplot": "root://eoscms//eos/cms.oO[finalResultFile]Oo.",
88  })
89 
90  return repMap
91 
92  def appendToPlots(self):
93  return ' p.loadFileList(".oO[filetoplot]Oo.", ".oO[title]Oo.", .oO[color]Oo., .oO[style]Oo.);\n'
94 
95  @classmethod
96  def initMerge(cls):
97  from .plottingOptions import PlottingOptions
98  outFilePath = replaceByMap(".oO[scriptsdir]Oo./TkAlOfflineJobsMerge.C", PlottingOptions(None, cls.valType))
99  with open(outFilePath, "w") as theFile:
100  theFile.write(replaceByMap(configTemplates.mergeOfflineParJobsTemplate, {}))
101  result = super(OfflineValidation, cls).initMerge()
102  result += ("cp .oO[Alignment/OfflineValidation]Oo./scripts/merge_TrackerOfflineValidation.C .\n"
103  "rfcp .oO[mergeOfflineParJobsScriptPath]Oo. .\n")
104  return result
105 
106  def appendToMerge(self):
107  repMap = self.getRepMap()
108 
109  parameters = "root://eoscms//eos/cms" + ",root://eoscms//eos/cms".join(repMap["resultFiles"])
110 
111  mergedoutputfile = "root://eoscms//eos/cms%(finalResultFile)s"%repMap
112  return ('root -x -b -q -l "TkAlOfflineJobsMerge.C(\\\"'
113  +parameters+'\\\",\\\"'+mergedoutputfile+'\\\")"')
114 
115  @classmethod
117  return "TkAlExtendedOfflineValidation.C"
118 
119  @classmethod
121  return configTemplates.extendedValidationTemplate
122 
123  @classmethod
124  def plotsdirname(cls):
125  return "ExtendedOfflineValidation_Images"
126 
127  @classmethod
129  return "compareAlignments.cc"
130 
131  @classmethod
133  return [
134  SubsectionOnePage('chi2', r'$\chi^2$ plots'),
135  SubsectionSubdetectors('DmedianY*R_[^_]*.eps$', 'DMR'),
136  SubsectionSubdetectors('DmedianY*R.*plain.eps$', 'DMR'),
137  SubsectionSubdetectors('DmedianY*R.*split.eps$','Split DMR'),
138  SubsectionSubdetectors('DrmsNY*R_[^_]*.eps$', 'DRnR'),
139  SubsectionSubdetectors('DrmsNY*R.*plain.eps$', 'DRnR'),
140  SubsectionSubdetectors('SurfaceShape', 'Surface Shape'),
141  ]
142 
144  pageidentifiers = (
145  ("BPIX", "BPIX"),
146  ("FPIX", "FPIX"),
147  ("TIB", "TIB"),
148  ("TID", "TID"),
149  ("TOB", "TOB"),
150  ("TEC", "TEC"),
151  )
152 
154  configBaseName = "TkAlOfflineValidationDQM"
155  def __init__(self, valName, alignment, config):
156  super(OfflineValidationDQM, self).__init__(valName, alignment, config)
157  if not config.has_section("DQM"):
158  msg = "You need to have a DQM section in your configfile!"
159  raise AllInOneError(msg)
160 
161  self.__PrimaryDataset = config.get("DQM", "primaryDataset")
162  self.__firstRun = int(config.get("DQM", "firstRun"))
163  self.__lastRun = int(config.get("DQM", "lastRun"))
164 
165  def getRepMap(self, alignment = None):
166  repMap = super(OfflineValidationDQM, self).getRepMap(alignment)
167  repMap.update({
168  "workdir": os.path.expandvars(repMap["workdir"]),
169  "offlineValidationMode": "Dqm",
170  "workflow": ("/%s/TkAl%s-.oO[alignmentName]Oo._R%09i_R%09i_"
171  "ValSkim-v1/ALCARECO"
172  %(self.__PrimaryDataset,
173  datetime.datetime.now().strftime("%y"),
174  self.__firstRun, self.__lastRun)),
175  "firstRunNumber": "%i"% self.__firstRun
176  })
177  if "__" in repMap["workflow"]:
178  msg = ("the DQM workflow specefication must not contain '__'. "
179  "it is: %s"%repMap["workflow"])
180  raise AllInOneError(msg)
181  return repMap
182 
183  @property
185  return configTemplates.offlineDqmFileOutputTemplate
def getRepMap(self, alignment=None)
def pythonboolstring(string, name)
def __init__(self, valName, alignment, config)
def PlottingOptions(config, valType)
def replaceByMap(target, the_map)
— Helpers —############################
static std::string join(char **cmd)
Definition: RemoteFile.cc:18
def __init__(self, valName, alignment, config)
def getRepMap(self, alignment=None)