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  "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 
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
offlineValidation.OfflineValidationDQM.__firstRun
__firstRun
Definition: offlineValidation.py:165
offlineValidation.OfflineValidation.FileOutputTemplate
def FileOutputTemplate(self)
Definition: offlineValidation.py:73
dqmMemoryStats.float
float
Definition: dqmMemoryStats.py:127
offlineValidation.OfflineValidation.ValidationSequence
def ValidationSequence(self)
Definition: offlineValidation.py:69
genericValidation.ValidationWithPlotsSummary
Definition: genericValidation.py:747
offlineValidation.OfflineValidationDQM.FileOutputTemplate
def FileOutputTemplate(self)
Definition: offlineValidation.py:187
offlineValidation.SubsectionSubdetectors
Definition: offlineValidation.py:146
offlineValidation.OfflineValidation
Definition: offlineValidation.py:10
offlineValidation.OfflineValidation.NTracks
NTracks
Definition: offlineValidation.py:52
join
static std::string join(char **cmd)
Definition: RemoteFile.cc:17
genericValidation.ValidationForPresentation
Definition: genericValidation.py:791
offlineValidation.OfflineValidation.plottingscripttemplate
def plottingscripttemplate(cls)
Definition: offlineValidation.py:123
offlineValidation.OfflineValidationDQM
Definition: offlineValidation.py:156
offlineValidation.OfflineValidationDQM.__lastRun
__lastRun
Definition: offlineValidation.py:166
helperFunctions.replaceByMap
def replaceByMap(target, the_map)
— Helpers —############################
Definition: helperFunctions.py:12
offlineValidation.OfflineValidation.comparealignmentsname
def comparealignmentsname(cls)
Definition: offlineValidation.py:131
plottingOptions.PlottingOptions
def PlottingOptions(config, valType)
Definition: plottingOptions.py:239
genericValidation.GenericValidationData_CTSR
Definition: genericValidation.py:509
offlineValidation.OfflineValidation.getRepMap
def getRepMap(self, alignment=None)
Definition: offlineValidation.py:82
genericValidation.GenericValidation.NJobs
NJobs
Definition: genericValidation.py:68
offlineValidation.OfflineValidation.crabCfgBaseName
string crabCfgBaseName
Definition: offlineValidation.py:13
genericValidation.GenericValidation.general
general
Definition: genericValidation.py:57
offlineValidation.OfflineValidationDQM.__init__
def __init__(self, valName, alignment, config)
Definition: offlineValidation.py:158
genericValidation.ValidationWithComparison
Definition: genericValidation.py:771
offlineValidation.OfflineValidation.appendToPlots
def appendToPlots(self)
Definition: offlineValidation.py:93
print
void print(TMatrixD &m, const char *label=nullptr, bool mathematicaFormat=false)
Definition: Utilities.cc:46
offlineValidation.OfflineValidation.initMerge
def initMerge(cls)
Definition: offlineValidation.py:97
offlineValidation.OfflineValidation.valType
string valType
Definition: offlineValidation.py:33
offlineValidation.OfflineValidation.plottingscriptname
def plottingscriptname(cls)
Definition: offlineValidation.py:119
createfilelist.int
int
Definition: createfilelist.py:10
genericValidation.ParallelValidation
Definition: genericValidation.py:571
offlineValidation.OfflineValidation.__init__
def __init__(self, valName, alignment, config)
Definition: offlineValidation.py:35
offlineValidation.OfflineValidation.ProcessName
def ProcessName(self)
Definition: offlineValidation.py:61
genericValidation.GenericValidation.getRepMap
def getRepMap(self, alignment=None)
Definition: genericValidation.py:136
helperFunctions.pythonboolstring
def pythonboolstring(string, name)
Definition: helperFunctions.py:186
offlineValidation.OfflineValidation.appendToMerge
def appendToMerge(self)
Definition: offlineValidation.py:109
offlineValidation.OfflineValidationDQM.getRepMap
def getRepMap(self, alignment=None)
Definition: offlineValidation.py:168
offlineValidation.OfflineValidation.presentationsubsections
def presentationsubsections(cls)
Definition: offlineValidation.py:135
offlineValidation.OfflineValidation.createCrabCfg
def createCrabCfg(self, path)
Definition: offlineValidation.py:79
TkAlExceptions.AllInOneError
Definition: TkAlExceptions.py:1
offlineValidation.OfflineValidation.plotsdirname
def plotsdirname(cls)
Definition: offlineValidation.py:127
offlineValidation.OfflineValidation.deprecateddefaults
dictionary deprecateddefaults
Definition: offlineValidation.py:24
offlineValidation.OfflineValidationDQM.__PrimaryDataset
__PrimaryDataset
Definition: offlineValidation.py:164
presentation.SubsectionOnePage
Definition: presentation.py:108
presentation.SubsectionFromList
Definition: presentation.py:115
offlineValidation.OfflineValidation.createScript
def createScript(self, path)
Definition: offlineValidation.py:76
offlineValidation.OfflineValidation.ValidationTemplate
def ValidationTemplate(self)
Definition: offlineValidation.py:65