CMS 3D CMS Logo

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