CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
geometryComparison.py
Go to the documentation of this file.
1 import os
2 import ConfigParser # needed for exceptions in this module
3 import configTemplates
4 from genericValidation import GenericValidation
5 from helperFunctions import replaceByMap
6 from TkAlExceptions import AllInOneError
7 
8 
10  """
11  Object representing a geometry comparison job.
12  """
13  def __init__( self, valName, alignment, referenceAlignment,
14  config, copyImages = True):
15  """
16  Constructor of the GeometryComparison class.
17 
18  Arguments:
19  - `valName`: String which identifies individual validation instances
20  - `alignment`: `Alignment` instance to validate
21  - `referenceAlignment`: `Alignment` instance which is compared
22  with `alignment`
23  - `config`: `BetterConfigParser` instance which includes the
24  configuration of the validations
25  - `copyImages`: Boolean which indicates whether png- and pdf-files
26  should be copied back from the batch farm
27  """
28  defaults = {
29  "3DSubdetector1":"1",
30  "3DSubdetector2":"2",
31  "3DTranslationalScaleFactor":"50",
32  "modulesToPlot":"all",
33  "moduleList": "/store/caf/user/cschomak/emptyModuleList.txt",
34  "useDefaultRange":"false",
35  "plotOnlyGlobal":"false",
36  "plotPng":"true",
37  "dx_min":"-99999",
38  "dx_max":"-99999",
39  "dy_min":"-99999",
40  "dy_max":"-99999",
41  "dz_min":"-99999",
42  "dz_max":"-99999",
43  "dr_min":"-99999",
44  "dr_max":"-99999",
45  "rdphi_min":"-99999",
46  "rdphi_max":"-99999",
47  "dalpha_min":"-99999",
48  "dalpha_max":"-99999",
49  "dbeta_min":"-99999",
50  "dbeta_max":"-99999",
51  "dgamma_min":"-99999",
52  "dgamma_max":"-99999",
53  }
54  mandatories = ["levels", "dbOutput"]
55  GenericValidation.__init__(self, valName, alignment, config,
56  "compare", addDefaults=defaults,
57  addMandatories = mandatories)
58  self.referenceAlignment = referenceAlignment
59  referenceName = "IDEAL"
60  if not self.referenceAlignment == "IDEAL":
61  referenceName = self.referenceAlignment.name
62 
63  allCompares = config.getCompares()
64  self.__compares = {}
65  if valName in allCompares:
66  self.__compares[valName] = allCompares[valName]
67  else:
68  msg = ("Could not find compare section '%s' in '%s'"
69  %(valName, allCompares))
70  raise AllInOneError(msg)
71  self.copyImages = copyImages
72 
73  def getRepMap(self, alignment = None):
74  if alignment == None:
75  alignment = self.alignmentToValidate
76  repMap = GenericValidation.getRepMap( self, alignment )
77  referenceName = "IDEAL"
78  referenceTitle = "IDEAL"
79  if not self.referenceAlignment == "IDEAL":
80  referenceName = self.referenceAlignment.name
81  referenceTitle = self.referenceAlignment.title
82 
83  repMap.update({
84  "comparedGeometry": (".oO[alignmentName]Oo."
85  "ROOTGeometry.root"),
86  "referenceGeometry": "IDEAL", # will be replaced later
87  # if not compared to IDEAL
88  "reference": referenceName,
89  "referenceTitle": referenceTitle,
90  "alignmentTitle": self.alignmentToValidate.title
91  })
92  if not referenceName == "IDEAL":
93  repMap["referenceGeometry"] = (".oO[reference]Oo."
94  "ROOTGeometry.root")
95  repMap["name"] += "_vs_.oO[reference]Oo."
96  return repMap
97 
98  def createConfiguration(self, path ):
99  # self.__compares
100  repMap = self.getRepMap()
101  cfgFileName = "TkAlCompareToNTuple.%s_cfg.py"%(
102  self.alignmentToValidate.name)
103  cfgs = {cfgFileName: configTemplates.intoNTuplesTemplate}
104  repMaps = {cfgFileName: repMap}
105  if not self.referenceAlignment == "IDEAL":
106  referenceRepMap = self.getRepMap( self.referenceAlignment )
107  cfgFileName = "TkAlCompareToNTuple.%s_cfg.py"%(
108  self.referenceAlignment.name )
109  cfgs[cfgFileName] = configTemplates.intoNTuplesTemplate
110  repMaps[cfgFileName] = referenceRepMap
111 
112  cfgSchedule = cfgs.keys()
113  for common in self.__compares:
114  repMap.update({"common": common,
115  "levels": self.__compares[common][0],
116  "dbOutput": self.__compares[common][1]
117  })
118  if self.__compares[common][1].split()[0] == "true":
119  repMap["dbOutputService"] = configTemplates.dbOutputTemplate
120  else:
121  repMap["dbOutputService"] = ""
122  cfgName = replaceByMap(("TkAlCompareCommon.oO[common]Oo.."
123  ".oO[name]Oo._cfg.py"),repMap)
124  cfgs[cfgName] = configTemplates.compareTemplate
125  repMaps[cfgName] = repMap
126 
127  cfgSchedule.append( cfgName )
128  GenericValidation.createConfiguration(self, cfgs, path, cfgSchedule, repMaps = repMaps)
129 
130  def createScript(self, path):
131  repMap = self.getRepMap()
132  repMap["runComparisonScripts"] = ""
133  scriptName = replaceByMap(("TkAlGeomCompare.%s..oO[name]Oo..sh"
134  %self.name), repMap)
135 
136  y_ranges = ""
137  plottedDifferences = ["dx","dy","dz","dr","rdphi","dalpha","dbeta","dgamma"]
138  for diff in plottedDifferences:
139  y_ranges += ","+repMap["%s_min"%diff]
140  y_ranges += ","+repMap["%s_max"%diff]
141 
142  for name in self.__compares:
143  if '"DetUnit"' in self.__compares[name][0].split(","):
144  repMap["outputFile"] = (".oO[name]Oo..Comparison_common"+name+".root")
145  repMap["nIndex"] = ("")
146  repMap["runComparisonScripts"] += \
147  ("rfcp .oO[CMSSW_BASE]Oo./src/Alignment/OfflineValidation"
148  "/scripts/comparisonScript.C .\n"
149  "rfcp .oO[CMSSW_BASE]Oo./src/Alignment/OfflineValidation"
150  "/scripts/GeometryComparisonPlotter.h .\n"
151  "rfcp .oO[CMSSW_BASE]Oo./src/Alignment/OfflineValidation"
152  "/scripts/GeometryComparisonPlotter.cc .\n"
153  "root -b -q 'comparisonScript.C+(\""
154  ".oO[name]Oo..Comparison_common"+name+".root\",\""
155  "./\",\".oO[modulesToPlot]Oo.\",\".oO[alignmentName]Oo.\",\".oO[reference]Oo.\",\".oO[useDefaultRange]Oo.\",\".oO[plotOnlyGlobal]Oo.\",\".oO[plotPng]Oo.\""+y_ranges+")'\n"
156  "rfcp "+path+"/TkAl3DVisualization_.oO[name]Oo..C .\n"
157  "root -l -b -q TkAl3DVisualization_.oO[name]Oo..C+\n")
158  if self.copyImages:
159  repMap["runComparisonScripts"] += \
160  ("rfmkdir -p .oO[datadir]Oo./.oO[name]Oo."
161  ".Comparison_common"+name+"_Images\n")
162  repMap["runComparisonScripts"] += \
163  ("rfmkdir -p .oO[datadir]Oo./.oO[name]Oo."
164  ".Comparison_common"+name+"_Images/Translations\n")
165  repMap["runComparisonScripts"] += \
166  ("rfmkdir -p .oO[datadir]Oo./.oO[name]Oo."
167  ".Comparison_common"+name+"_Images/Rotations\n")
168 
169 
170  ### At the moment translations are images with suffix _1 and _2, rotations _3 and _4
171  ### The numeration depends on the order of the MakePlots(x, y) commands in comparisonScript.C
172  ### If comparisonScript.C is changed, check if the following lines need to be changed as well
173 
174  if repMap["plotPng"] == "true":
175  repMap["runComparisonScripts"] += \
176  ("find . -maxdepth 1 -name \"*_1*\" "
177  "-print | xargs -I {} bash -c \"rfcp {} .oO[datadir]Oo."
178  "/.oO[name]Oo..Comparison_common"+name+"_Images/Translations/\" \n")
179  repMap["runComparisonScripts"] += \
180  ("find . -maxdepth 1 -name \"*_2*\" "
181  "-print | xargs -I {} bash -c \"rfcp {} .oO[datadir]Oo."
182  "/.oO[name]Oo..Comparison_common"+name+"_Images/Translations/\" \n")
183 
184  repMap["runComparisonScripts"] += \
185  ("find . -maxdepth 1 -name \"*_3*\" "
186  "-print | xargs -I {} bash -c \"rfcp {} .oO[datadir]Oo."
187  "/.oO[name]Oo..Comparison_common"+name+"_Images/Rotations/\" \n")
188  repMap["runComparisonScripts"] += \
189  ("find . -maxdepth 1 -name \"*_4*\" "
190  "-print | xargs -I {} bash -c \"rfcp {} .oO[datadir]Oo."
191  "/.oO[name]Oo..Comparison_common"+name+"_Images/Rotations/\" \n")
192 
193  else:
194  repMap["runComparisonScripts"] += \
195  ("find . -maxdepth 1 -name \"*_1*\" "
196  "-print | xargs -I {} bash -c \"rfcp {} .oO[datadir]Oo."
197  "/.oO[name]Oo..Comparison_common"+name+"_Images/Translations/\" \n")
198 
199  repMap["runComparisonScripts"] += \
200  ("find . -maxdepth 1 -name \"*_2*\" "
201  "-print | xargs -I {} bash -c \"rfcp {} .oO[datadir]Oo."
202  "/.oO[name]Oo..Comparison_common"+name+"_Images/Rotations/\" \n")
203 
204  repMap["runComparisonScripts"] += \
205  ("find . -maxdepth 1 -name "
206  "\"TkMap_SurfDeform*.pdf\" -print | xargs -I {} bash -c"
207  " \"rfcp {} .oO[datadir]Oo./.oO[name]Oo."
208  ".Comparison_common"+name+"_Images/\" \n")
209  repMap["runComparisonScripts"] += \
210  ("find . -maxdepth 1 -name "
211  "\"TkMap_SurfDeform*.png\" -print | xargs -I {} bash -c"
212  " \"rfcp {} .oO[datadir]Oo./.oO[name]Oo."
213  ".Comparison_common"+name+"_Images/\" \n")
214  repMap["runComparisonScripts"] += \
215  ("if [[ $HOSTNAME = lxplus[0-9]*\.cern\.ch ]]\n"
216  "then\n"
217  " rfmkdir -p .oO[workdir]Oo./.oO[name]Oo.."+name
218  +"_ArrowPlots\n"
219  "else\n"
220  " mkdir -p $CWD/TkAllInOneTool/.oO[name]Oo.."+name
221  +"_ArrowPlots\n"
222  "fi\n")
223  repMap["runComparisonScripts"] += \
224  ("rfcp .oO[CMSSW_BASE]Oo./src/Alignment"
225  "/OfflineValidation/scripts/makeArrowPlots.C "
226  ".\n"
227  "root -b -q 'makeArrowPlots.C(\""
228  ".oO[name]Oo..Comparison_common"+name
229  +".root\",\".oO[name]Oo.."
230  +name+"_ArrowPlots\")'\n")
231  repMap["runComparisonScripts"] += \
232  ("rfmkdir -p .oO[datadir]Oo./.oO[name]Oo."
233  ".Comparison_common"+name+"_Images/ArrowPlots\n")
234  repMap["runComparisonScripts"] += \
235  ("find .oO[name]Oo.."+name+"_ArrowPlots "
236  "-maxdepth 1 -name \"*.png\" -print | xargs -I {} bash "
237  "-c \"rfcp {} .oO[datadir]Oo./.oO[name]Oo."
238  ".Comparison_common"+name+"_Images/ArrowPlots\"\n")
239  repMap["runComparisonScripts"] += \
240  ("find . "
241  "-maxdepth 1 -name \".oO[name]Oo..Visualization_rotated.gif\" -print | xargs -I {} bash "
242  "-c \"rfcp {} .oO[datadir]Oo./.oO[name]Oo."
243  ".Comparison_common"+name+"_Images/.oO[name]Oo..Visualization.gif\"\n")
244 
245  resultingFile = replaceByMap(("/store/caf/user/$USER/.oO[eosdir]Oo./compared%s_"
246  ".oO[name]Oo..root"%name), repMap)
247  resultingFile = os.path.expandvars( resultingFile )
248  resultingFile = os.path.abspath( resultingFile )
249  resultingFile = "root://eoscms//eos/cms" + resultingFile #needs to be AFTER abspath so that it doesn't eat the //
250  repMap["runComparisonScripts"] += \
251  ("xrdcp -f OUTPUT_comparison.root %s\n"
252  %resultingFile)
253  self.filesToCompare[ name ] = resultingFile
254 
255  repMap["CommandLine"]=""
256  repMap["CommandLine"]+= \
257  ("# copy module list required for comparison script \n"
258  "rfcp .oO[moduleList]Oo. .\n")
259 
260  for cfg in self.configFiles:
261  # FIXME: produce this line only for enabled dbOutput
262  # postProcess = "rfcp .oO[workdir]Oo./*.db .oO[datadir]Oo.\n"
263  # postProcess = "rfcp *.db .oO[datadir]Oo.\n"
264  postProcess = ""
265  repMap["CommandLine"]+= \
266  repMap["CommandLineTemplate"]%{"cfgFile":cfg,
267  "postProcess":postProcess}
268  repMap["CommandLine"]+= ("# overall postprocessing\n"
269  ".oO[runComparisonScripts]Oo.\n"
270  )
271 
272  #~ print configTemplates.scriptTemplate
273  scripts = {scriptName: replaceByMap( configTemplates.scriptTemplate, repMap )}
274  files = {replaceByMap("TkAl3DVisualization_.oO[name]Oo..C", repMap ): replaceByMap(configTemplates.visualizationTrackerTemplate, repMap )}
275  self.createFiles(files, path)
276  return GenericValidation.createScript(self, scripts, path)
277 
278  def createCrabCfg(self, path):
279  msg = ("Parallelization not supported for geometry comparison. Please "
280  "choose another 'jobmode'.")
281  raise AllInOneError(msg)
def replaceByMap
— Helpers —############################
double split
Definition: MVATrainer.cc:139