CMS 3D CMS Logo

geometryComparison.py
Go to the documentation of this file.
1 from __future__ import absolute_import
2 import os
3 import configparser as ConfigParser # needed for exceptions in this module
4 from . import configTemplates
5 from .genericValidation import GenericValidation
6 from .helperFunctions import replaceByMap, getCommandOutput2, cppboolstring, pythonboolstring, clean_name
7 from .TkAlExceptions import AllInOneError
8 
9 
11  """
12  Object representing a geometry comparison job.
13  """
14  defaults = {
15  "3DSubdetector1":"1",
16  "3DSubdetector2":"2",
17  "3DTranslationalScaleFactor":"50",
18  "modulesToPlot":"all",
19  "moduleList": "/store/caf/user/cschomak/emptyModuleList.txt",
20  "useDefaultRange":"false",
21  "plotOnlyGlobal":"true",
22  "plotPng":"true",
23  "makeProfilePlots":"true",
24  "dx_min":"-99999",
25  "dx_max":"-99999",
26  "dy_min":"-99999",
27  "dy_max":"-99999",
28  "dz_min":"-99999",
29  "dz_max":"-99999",
30  "dr_min":"-99999",
31  "dr_max":"-99999",
32  "rdphi_min":"-99999",
33  "rdphi_max":"-99999",
34  "dalpha_min":"-99999",
35  "dalpha_max":"-99999",
36  "dbeta_min":"-99999",
37  "dbeta_max":"-99999",
38  "dgamma_min":"-99999",
39  "dgamma_max":"-99999",
40  "multiIOV":"False",
41  }
42  mandatories = {"levels", "dbOutput"}
43  valType = "compare"
44  def __init__( self, valName, alignment, referenceAlignment,
45  config, copyImages = True):
46  """
47  Constructor of the GeometryComparison class.
48 
49  Arguments:
50  - `valName`: String which identifies individual validation instances
51  - `alignment`: `Alignment` instance to validate
52  - `referenceAlignment`: `Alignment` instance which is compared
53  with `alignment`
54  - `config`: `BetterConfigParser` instance which includes the
55  configuration of the validations
56  - `copyImages`: Boolean which indicates whether png- and pdf-files
57  should be copied back from the batch farm
58  """
59  super(GeometryComparison, self).__init__(valName, alignment, config)
60  self.referenceAlignment = referenceAlignment
61  referenceName = "IDEAL"
62  if not self.referenceAlignment == "IDEAL":
63  referenceName = self.referenceAlignment.name
64 
65  allCompares = config.getCompares()
66  self.__compares = {}
67  self.__filesToCompare = {}
68  if valName in allCompares:
69  self.__compares[valName] = allCompares[valName]
70  else:
71  msg = ("Could not find compare section '%s' in '%s'"
72  %(valName, allCompares))
73  raise AllInOneError(msg)
74  self.copyImages = copyImages
75 
76  for name in "useDefaultRange", "plotOnlyGlobal", "plotPng":
77  self.general[name] = cppboolstring(self.general[name], name)
78 
79 
80  def getRepMap(self, alignment = None):
81  if alignment == None:
82  alignment = self.alignmentToValidate
83  repMap = super(GeometryComparison, self).getRepMap( alignment )
84  referenceName = "IDEAL"
85  referenceTitle = "IDEAL"
86  if not self.referenceAlignment == "IDEAL":
87  referenceName = self.referenceAlignment.name
88  referenceTitle = self.referenceAlignment.title
89 
90  assert len(self.__compares) == 1 #? not sure how it can be anything else, but just in case
91  common = list(self.__compares.keys())[0]
92 
93  repMap.update({
94  "common": clean_name(common),
95  "comparedGeometry": (".oO[alignmentName]Oo."
96  "ROOTGeometry.root"),
97  "referenceGeometry": "IDEAL", # will be replaced later
98  # if not compared to IDEAL
99  "reference": clean_name(referenceName),
100  "referenceTitle": referenceTitle,
101  "alignmentTitle": self.alignmentToValidate.title,
102  "moduleListBase": os.path.basename(repMap["moduleList"]),
103  })
104  if not referenceName == "IDEAL":
105  repMap["referenceGeometry"] = (".oO[reference]Oo."
106  "ROOTGeometry.root")
107  repMap["name"] += "_vs_.oO[reference]Oo."
108  return repMap
109 
110  @property
111  def filesToCompare(self):
112  return self.__filesToCompare
113 
114  def createConfiguration(self, path ):
115  # self.__compares
116  repMap = self.getRepMap()
117  cfgFileName = "TkAlCompareToNTuple.%s_cfg.py"%(
118  self.alignmentToValidate.name)
119  cfgs = {cfgFileName: configTemplates.intoNTuplesTemplate}
120  repMaps = {cfgFileName: repMap}
121  if not self.referenceAlignment == "IDEAL":
122  referenceRepMap = self.getRepMap( self.referenceAlignment )
123  cfgFileName = "TkAlCompareToNTuple.%s_cfg.py"%(
124  self.referenceAlignment.name )
125  cfgs[cfgFileName] = configTemplates.intoNTuplesTemplate
126  repMaps[cfgFileName] = referenceRepMap
127 
128  cfgSchedule = list(cfgs.keys())
129  for common in self.__compares:
130  repMap.update({
131  "levels": self.__compares[common][0],
132  "dbOutput": pythonboolstring(self.__compares[common][1], "dbOutput")
133  })
134  if self.__compares[common][1].split()[0] == "true":
135  repMap["dbOutputService"] = configTemplates.dbOutputTemplate
136  else:
137  repMap["dbOutputService"] = ""
138  cfgName = replaceByMap(("TkAlCompareCommon.oO[common]Oo.."
139  ".oO[name]Oo._cfg.py"),repMap)
140  cfgs[cfgName] = configTemplates.compareTemplate
141  repMaps[cfgName] = repMap
142 
143  cfgSchedule.append( cfgName )
144  super(GeometryComparison, self).createConfiguration(cfgs, path, cfgSchedule, repMaps = repMaps)
145 
146  def createScript(self, path):
147  repMap = self.getRepMap()
148  repMap["runComparisonScripts"] = ""
149  scriptName = replaceByMap(("TkAlGeomCompare.%s..oO[name]Oo..sh"
150  %self.name), repMap)
151 
152  y_ranges = ""
153  plottedDifferences = ["dx","dy","dz","dr","rdphi","dalpha","dbeta","dgamma"]
154  for diff in plottedDifferences:
155  y_ranges += ","+repMap["%s_min"%diff]
156  y_ranges += ","+repMap["%s_max"%diff]
157 
158  for name in self.__compares:
159  if '"DetUnit"' in self.__compares[name][0].split(","):
160  repMap["outputFile"] = (".oO[name]Oo..Comparison_common"+name+".root")
161  repMap["nIndex"] = ("")
162  repMap["runComparisonScripts"] += \
163  ("cp .oO[Alignment/OfflineValidation]Oo."
164  "/scripts/comparisonScript.C .\n"
165  "cp .oO[Alignment/OfflineValidation]Oo."
166  "/scripts/GeometryComparisonPlotter.h .\n"
167  "cp .oO[Alignment/OfflineValidation]Oo."
168  "/scripts/GeometryComparisonPlotter.cc .\n"
169  "root -b -q 'comparisonScript.C+(\""
170  ".oO[name]Oo..Comparison_common"+name+".root\",\""
171  "./\",\".oO[modulesToPlot]Oo.\",\".oO[alignmentName]Oo.\",\".oO[reference]Oo.\",.oO[useDefaultRange]Oo.,.oO[plotOnlyGlobal]Oo.,.oO[plotPng]Oo.,.oO[makeProfilePlots]Oo."+y_ranges+")'\n"
172  "cp "+path+"/TkAl3DVisualization_.oO[common]Oo._.oO[name]Oo..C .\n"
173  "root -l -b -q TkAl3DVisualization_.oO[common]Oo._.oO[name]Oo..C+\n")
174  if self.copyImages:
175  repMap["runComparisonScripts"] += \
176  ("mkdir -p .oO[datadir]Oo./.oO[name]Oo."
177  ".Comparison_common"+name+"_Images/Translations\n")
178  repMap["runComparisonScripts"] += \
179  ("mkdir -p .oO[datadir]Oo./.oO[name]Oo."
180  ".Comparison_common"+name+"_Images/Rotations\n")
181 
182 
183 
186 
187  if repMap["plotPng"] == "true":
188  repMap["runComparisonScripts"] += \
189  ("find . -maxdepth 1 -name \"*_1*\" "
190  "-print | xargs -I {} bash -c \"cp {} .oO[datadir]Oo."
191  "/.oO[name]Oo..Comparison_common"+name+"_Images/Translations/\" \n")
192  repMap["runComparisonScripts"] += \
193  ("find . -maxdepth 1 -name \"*_2*\" "
194  "-print | xargs -I {} bash -c \"cp {} .oO[datadir]Oo."
195  "/.oO[name]Oo..Comparison_common"+name+"_Images/Translations/\" \n")
196 
197  repMap["runComparisonScripts"] += \
198  ("find . -maxdepth 1 -name \"*_3*\" "
199  "-print | xargs -I {} bash -c \"cp {} .oO[datadir]Oo."
200  "/.oO[name]Oo..Comparison_common"+name+"_Images/Rotations/\" \n")
201  repMap["runComparisonScripts"] += \
202  ("find . -maxdepth 1 -name \"*_4*\" "
203  "-print | xargs -I {} bash -c \"cp {} .oO[datadir]Oo."
204  "/.oO[name]Oo..Comparison_common"+name+"_Images/Rotations/\" \n")
205 
206  else:
207  repMap["runComparisonScripts"] += \
208  ("find . -maxdepth 1 -name \"*_1*\" "
209  "-print | xargs -I {} bash -c \"cp {} .oO[datadir]Oo."
210  "/.oO[name]Oo..Comparison_common"+name+"_Images/Translations/\" \n")
211 
212  repMap["runComparisonScripts"] += \
213  ("find . -maxdepth 1 -name \"*_2*\" "
214  "-print | xargs -I {} bash -c \"cp {} .oO[datadir]Oo."
215  "/.oO[name]Oo..Comparison_common"+name+"_Images/Rotations/\" \n")
216 
217  repMap["runComparisonScripts"] += \
218  ("find . -maxdepth 1 -name "
219  "\"*.tex\" -print | xargs -I {} bash -c"
220  " \"cp {} .oO[datadir]Oo./.oO[name]Oo."
221  ".Comparison_common"+name+"_Images/\" \n")
222  repMap["runComparisonScripts"] += \
223  ("find . -maxdepth 1 -name "
224  "\"TkMap_SurfDeform*.pdf\" -print | xargs -I {} bash -c"
225  " \"cp {} .oO[datadir]Oo./.oO[name]Oo."
226  ".Comparison_common"+name+"_Images/\" \n")
227  repMap["runComparisonScripts"] += \
228  ("find . -maxdepth 1 -name "
229  "\"TkMap_SurfDeform*.png\" -print | xargs -I {} bash -c"
230  " \"cp {} .oO[datadir]Oo./.oO[name]Oo."
231  ".Comparison_common"+name+"_Images/\" \n")
232  repMap["runComparisonScripts"] += \
233  ("cp .oO[Alignment/OfflineValidation]Oo."
234  "/macros/makeArrowPlots.C "
235  ".\n"
236  "root -b -q 'makeArrowPlots.C(\""
237  ".oO[name]Oo..Comparison_common"+name
238  +".root\",\".oO[name]Oo.."
239  +name+"_ArrowPlots\")'\n")
240  repMap["runComparisonScripts"] += \
241  ("mkdir -p .oO[datadir]Oo./.oO[name]Oo."
242  ".Comparison_common"+name+"_Images/ArrowPlots\n")
243  repMap["runComparisonScripts"] += \
244  ("find .oO[name]Oo.."+name+"_ArrowPlots "
245  "-maxdepth 1 -name \"*.png\" -print | xargs -I {} bash "
246  "-c \"cp {} .oO[datadir]Oo./.oO[name]Oo."
247  ".Comparison_common"+name+"_Images/ArrowPlots\"\n")
248  repMap["runComparisonScripts"] += \
249  ("find .oO[name]Oo.."+name+"_ArrowPlots "
250  "-maxdepth 1 -name \"*.pdf\" -print | xargs -I {} bash "
251  "-c \"cp {} .oO[datadir]Oo./.oO[name]Oo."
252  ".Comparison_common"+name+"_Images/ArrowPlots\"\n")
253  repMap["runComparisonScripts"] += \
254  ("find . "
255  "-maxdepth 1 -name \".oO[common]Oo._.oO[name]Oo..Visualization_rotated.gif\" -print | xargs -I {} bash "
256  "-c \"cp {} .oO[datadir]Oo./.oO[name]Oo."
257  ".Comparison_common"+name+"_Images/.oO[common]Oo._.oO[name]Oo..Visualization.gif\"\n")
258 
259  resultingFile = replaceByMap(("/store/group/alca_trackeralign/AlignmentValidation/.oO[eosdir]Oo./compared%s_"
260  ".oO[name]Oo..root"%name), repMap)
261  resultingFile = os.path.expandvars( resultingFile )
262  resultingFile = os.path.abspath( resultingFile )
263  resultingFile = "root://eoscms//eos/cms" + resultingFile #needs to be AFTER abspath so that it doesn't eat the //
264  self.__filesToCompare[ name ] = resultingFile
265 
266  else:
267  raise AllInOneError("Need to have DetUnit in levels!")
268 
269  repMap["CommandLine"]=""
270  repMap["CommandLine"]+= \
271  "# copy module list required for comparison script \n"
272  if repMap["moduleList"].startswith("/store"):
273  repMap["CommandLine"]+= \
274  "xrdcp root://eoscms//eos/cms.oO[moduleList]Oo. .\n"
275  elif repMap["moduleList"].startswith("root://"):
276  repMap["CommandLine"]+= \
277  "xrdcp .oO[moduleList]Oo. .\n"
278  else:
279  repMap["CommandLine"]+= \
280  "cp .oO[moduleList]Oo. .\n"
281 
282  try:
283  getCommandOutput2(replaceByMap("cd $(mktemp -d)\n.oO[CommandLine]Oo.\ncat .oO[moduleListBase]Oo.", repMap))
284  except RuntimeError:
285  raise AllInOneError(replaceByMap(".oO[moduleList]Oo. does not exist!", repMap))
286 
287  for cfg in self.configFiles:
288  # FIXME: produce this line only for enabled dbOutput
289  # postProcess = "cp .oO[workdir]Oo./*.db .oO[datadir]Oo.\n"
290  # postProcess = "cp *.db .oO[datadir]Oo.\n"
291  postProcess = ""
292  repMap["CommandLine"]+= \
293  repMap["CommandLineTemplate"]%{"cfgFile":cfg,
294  "postProcess":postProcess}
295  repMap["CommandLine"]+= ("# overall postprocessing\n"
296  ".oO[runComparisonScripts]Oo.\n"
297  )
298 
299  #~ print configTemplates.scriptTemplate
300  scripts = {scriptName: replaceByMap( configTemplates.scriptTemplate, repMap )}
301  files = {replaceByMap("TkAl3DVisualization_.oO[common]Oo._.oO[name]Oo..C", repMap ): replaceByMap(configTemplates.visualizationTrackerTemplate, repMap )}
302  self.createFiles(files, path)
303  return super(GeometryComparison, self).createScript(scripts, path)
304 
305  def createCrabCfg(self, path):
306  msg = ("Parallelization not supported for geometry comparison. Please "
307  "choose another 'jobmode'.")
308  raise AllInOneError(msg)
genericValidation.GenericValidation.configFiles
configFiles
Definition: genericValidation.py:60
geometryComparison.GeometryComparison.copyImages
copyImages
Definition: geometryComparison.py:73
geometryComparison.GeometryComparison.__init__
def __init__(self, valName, alignment, referenceAlignment, config, copyImages=True)
Definition: geometryComparison.py:44
relativeConstraints.keys
keys
Definition: relativeConstraints.py:89
cms::dd::split
std::vector< std::string_view > split(std::string_view, const char *)
helperFunctions.replaceByMap
def replaceByMap(target, the_map)
— Helpers —############################
Definition: helperFunctions.py:13
geometryComparison.GeometryComparison.createConfiguration
def createConfiguration(self, path)
Definition: geometryComparison.py:114
helperFunctions.clean_name
def clean_name(s)
Definition: helperFunctions.py:213
genericValidation.GenericValidation.createFiles
def createFiles(self, fileContents, path, repMap=None, repMaps=None)
Definition: genericValidation.py:193
geometryComparison.GeometryComparison
Definition: geometryComparison.py:10
genericValidation.GenericValidation.general
general
Definition: genericValidation.py:58
helperFunctions.getCommandOutput2
def getCommandOutput2(command)
Definition: helperFunctions.py:52
genericValidation.GenericValidation.alignmentToValidate
alignmentToValidate
Definition: genericValidation.py:57
geometryComparison.GeometryComparison.createScript
def createScript(self, path)
Definition: geometryComparison.py:146
geometryComparison.GeometryComparison.createCrabCfg
def createCrabCfg(self, path)
Definition: geometryComparison.py:305
helperFunctions.cppboolstring
def cppboolstring(string, name)
Definition: helperFunctions.py:194
genericValidation.GenericValidation.name
name
Definition: genericValidation.py:56
genericValidation.GenericValidation.getRepMap
def getRepMap(self, alignment=None)
Definition: genericValidation.py:137
helperFunctions.pythonboolstring
def pythonboolstring(string, name)
Definition: helperFunctions.py:187
geometryComparison.GeometryComparison.filesToCompare
def filesToCompare(self)
Definition: geometryComparison.py:111
geometryComparison.GeometryComparison.getRepMap
def getRepMap(self, alignment=None)
Definition: geometryComparison.py:80
geometryComparison.GeometryComparison.__filesToCompare
__filesToCompare
Definition: geometryComparison.py:66
TkAlExceptions.AllInOneError
Definition: TkAlExceptions.py:1
geometryComparison.GeometryComparison.__compares
__compares
Definition: geometryComparison.py:65
list
How EventSelector::AcceptEvent() decides whether to accept an event for output otherwise it is excluding the probing of A single or multiple positive and the trigger will pass if any such matching triggers are PASS or EXCEPTION[A criterion thatmatches no triggers at all is detected and causes a throw.] A single negative with an expectation of appropriate bit checking in the decision and the trigger will pass if any such matching triggers are FAIL or EXCEPTION A wildcarded negative criterion that matches more than one trigger in the trigger list("!*", "!HLTx*" if it matches 2 triggers or more) will accept the event if all the matching triggers are FAIL. It will reject the event if any of the triggers are PASS or EXCEPTION(this matches the behavior of "!*" before the partial wildcard feature was incorporated). Triggers which are in the READY state are completely ignored.(READY should never be returned since the trigger paths have been run
genericValidation.GenericValidation
Definition: genericValidation.py:42
geometryComparison.GeometryComparison.referenceAlignment
referenceAlignment
Definition: geometryComparison.py:59