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, randomWorkdirPart = None):
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  - `randomWorkDirPart`: If this option is ommitted a random number is
28  generated to create unique path names for the
29  individual validation instances.
30  """
31  defaults = {
32  "3DSubdetector1":"1",
33  "3DSubdetector2":"2",
34  "3DTranslationalScaleFactor":"50"
35  }
36  mandatories = ["levels", "dbOutput"]
37  GenericValidation.__init__(self, valName, alignment, config,
38  "compare", addDefaults=defaults,
39  addMandatories = mandatories)
40  if not randomWorkdirPart == None:
41  self.randomWorkdirPart = randomWorkdirPart
42  self.referenceAlignment = referenceAlignment
43  referenceName = "IDEAL"
44  if not self.referenceAlignment == "IDEAL":
45  referenceName = self.referenceAlignment.name
46 
47  allCompares = config.getCompares()
48  self.__compares = {}
49  if valName in allCompares:
50  self.__compares[valName] = allCompares[valName]
51  else:
52  msg = ("Could not find compare section '%s' in '%s'"
53  %(valName, allCompares))
54  raise AllInOneError(msg)
55  self.copyImages = copyImages
56 
57  def getRepMap(self, alignment = None):
58  if alignment == None:
59  alignment = self.alignmentToValidate
60  repMap = GenericValidation.getRepMap( self, alignment )
61  referenceName = "IDEAL"
62  referenceTitle = "IDEAL"
63  if not self.referenceAlignment == "IDEAL":
64  referenceName = self.referenceAlignment.name
65  referenceTitle = self.referenceAlignment.title
66 
67  repMap.update({
68  "comparedGeometry": (".oO[alignmentName]Oo."
69  "ROOTGeometry.root"),
70  "referenceGeometry": "IDEAL", # will be replaced later
71  # if not compared to IDEAL
72  "reference": referenceName,
73  "referenceTitle": referenceTitle,
74  "alignmentTitle": self.alignmentToValidate.title
75  })
76  if not referenceName == "IDEAL":
77  repMap["referenceGeometry"] = (".oO[reference]Oo."
78  "ROOTGeometry.root")
79  repMap["name"] += "_vs_.oO[reference]Oo."
80  return repMap
81 
82  def createConfiguration(self, path ):
83  # self.__compares
84  repMap = self.getRepMap()
85  cfgFileName = "TkAlCompareToNTuple.%s.%s_cfg.py"%(
86  self.alignmentToValidate.name, self.randomWorkdirPart)
87  cfgs = {cfgFileName: configTemplates.intoNTuplesTemplate}
88  repMaps = {cfgFileName: repMap}
89  if not self.referenceAlignment == "IDEAL":
90  referenceRepMap = self.getRepMap( self.referenceAlignment )
91  cfgFileName = "TkAlCompareToNTuple.%s.%s_cfg.py"%(
92  self.referenceAlignment.name, self.randomWorkdirPart )
93  cfgs[cfgFileName] = configTemplates.intoNTuplesTemplate
94  repMaps[cfgFileName] = referenceRepMap
95 
96  cfgSchedule = cfgs.keys()
97  for common in self.__compares:
98  repMap.update({"common": common,
99  "levels": self.__compares[common][0],
100  "dbOutput": self.__compares[common][1]
101  })
102  if self.__compares[common][1].split()[0] == "true":
103  repMap["dbOutputService"] = configTemplates.dbOutputTemplate
104  else:
105  repMap["dbOutputService"] = ""
106  cfgName = replaceByMap(("TkAlCompareCommon.oO[common]Oo.."
107  ".oO[name]Oo._cfg.py"),repMap)
108  cfgs[cfgName] = configTemplates.compareTemplate
109  repMaps[cfgName] = repMap
110 
111  cfgSchedule.append( cfgName )
112  GenericValidation.createConfiguration(self, cfgs, path, cfgSchedule, repMaps = repMaps)
113 
114  def createScript(self, path):
115  repMap = self.getRepMap()
116  repMap["runComparisonScripts"] = ""
117  scriptName = replaceByMap(("TkAlGeomCompare.%s..oO[name]Oo..sh"
118  %self.name), repMap)
119  for name in self.__compares:
120  if '"DetUnit"' in self.__compares[name][0].split(","):
121  repMap["outputFile"] = (".oO[name]Oo..Comparison_common"+name+".root")
122  repMap["nIndex"] = ("")
123  repMap["runComparisonScripts"] += \
124  ("rfcp .oO[CMSSW_BASE]Oo./src/Alignment/OfflineValidation"
125  "/scripts/comparisonScript.C .\n"
126  "rfcp .oO[CMSSW_BASE]Oo./src/Alignment/OfflineValidation"
127  "/scripts/GeometryComparisonPlotter.h .\n"
128  "rfcp .oO[CMSSW_BASE]Oo./src/Alignment/OfflineValidation"
129  "/scripts/GeometryComparisonPlotter.cc .\n"
130  "root -b -q 'comparisonScript.C+(\""
131  ".oO[name]Oo..Comparison_common"+name+".root\",\""
132  "./\")'\n"
133  "rfcp "+path+"/TkAl3DVisualization_.oO[name]Oo..C .\n"
134  "root -l -b -q TkAl3DVisualization_.oO[name]Oo..C+\n")
135  if self.copyImages:
136  repMap["runComparisonScripts"] += \
137  ("rfmkdir -p .oO[datadir]Oo./.oO[name]Oo."
138  ".Comparison_common"+name+"_Images\n")
139  repMap["runComparisonScripts"] += \
140  ("rfmkdir -p .oO[datadir]Oo./.oO[name]Oo."
141  ".Comparison_common"+name+"_Images/Translations\n")
142  repMap["runComparisonScripts"] += \
143  ("rfmkdir -p .oO[datadir]Oo./.oO[name]Oo."
144  ".Comparison_common"+name+"_Images/Rotations\n")
145  repMap["runComparisonScripts"] += \
146  ("rfmkdir -p .oO[datadir]Oo./.oO[name]Oo."
147  ".Comparison_common"+name+"_Images/CrossTalk\n")
148 
149 
150  ### At the moment translations are immages with suffix _1 and _2, rotations _3 and _4, and cross talk _5, _6, _7 and _8
151  ### The numeration depends on the order of the MakePlots(x, y) commands in comparisonScript.C
152  ### If comparisonScript.C is changed, check if the following lines need to be changed as well
153  repMap["runComparisonScripts"] += \
154  ("find . -maxdepth 1 -name \"*_1*\" "
155  "-print | xargs -I {} bash -c \"rfcp {} .oO[datadir]Oo."
156  "/.oO[name]Oo..Comparison_common"+name+"_Images/Translations/\" \n")
157  repMap["runComparisonScripts"] += \
158  ("find . -maxdepth 1 -name \"*_2*\" "
159  "-print | xargs -I {} bash -c \"rfcp {} .oO[datadir]Oo."
160  "/.oO[name]Oo..Comparison_common"+name+"_Images/Translations/\" \n")
161 
162  repMap["runComparisonScripts"] += \
163  ("find . -maxdepth 1 -name \"*_3*\" "
164  "-print | xargs -I {} bash -c \"rfcp {} .oO[datadir]Oo."
165  "/.oO[name]Oo..Comparison_common"+name+"_Images/Rotations/\" \n")
166  repMap["runComparisonScripts"] += \
167  ("find . -maxdepth 1 -name \"*_4*\" "
168  "-print | xargs -I {} bash -c \"rfcp {} .oO[datadir]Oo."
169  "/.oO[name]Oo..Comparison_common"+name+"_Images/Rotations/\" \n")
170 
171  repMap["runComparisonScripts"] += \
172  ("find . -maxdepth 1 -name \"*_5*\" "
173  "-print | xargs -I {} bash -c \"rfcp {} .oO[datadir]Oo."
174  "/.oO[name]Oo..Comparison_common"+name+"_Images/CrossTalk/\" \n")
175  repMap["runComparisonScripts"] += \
176  ("find . -maxdepth 1 -name \"*_6*\" "
177  "-print | xargs -I {} bash -c \"rfcp {} .oO[datadir]Oo."
178  "/.oO[name]Oo..Comparison_common"+name+"_Images/CrossTalk/\" \n")
179  repMap["runComparisonScripts"] += \
180  ("find . -maxdepth 1 -name \"*_7*\" "
181  "-print | xargs -I {} bash -c \"rfcp {} .oO[datadir]Oo."
182  "/.oO[name]Oo..Comparison_common"+name+"_Images/CrossTalk/\" \n")
183  repMap["runComparisonScripts"] += \
184  ("find . -maxdepth 1 -name \"*_8*\" "
185  "-print | xargs -I {} bash -c \"rfcp {} .oO[datadir]Oo."
186  "/.oO[name]Oo..Comparison_common"+name+"_Images/CrossTalk/\" \n")
187 
188  repMap["runComparisonScripts"] += \
189  ("find . -maxdepth 1 -name "
190  "\"TkMap_SurfDeform*.pdf\" -print | xargs -I {} bash -c"
191  " \"rfcp {} .oO[datadir]Oo./.oO[name]Oo."
192  ".Comparison_common"+name+"_Images/\" \n")
193  repMap["runComparisonScripts"] += \
194  ("find . -maxdepth 1 -name "
195  "\"TkMap_SurfDeform*.png\" -print | xargs -I {} bash -c"
196  " \"rfcp {} .oO[datadir]Oo./.oO[name]Oo."
197  ".Comparison_common"+name+"_Images/\" \n")
198  repMap["runComparisonScripts"] += \
199  ("if [[ $HOSTNAME = lxplus[0-9]*\.cern\.ch ]]\n"
200  "then\n"
201  " rfmkdir -p .oO[workdir]Oo./.oO[name]Oo.."+name
202  +"_ArrowPlots\n"
203  "else\n"
204  " mkdir -p $CWD/TkAllInOneTool/.oO[name]Oo.."+name
205  +"_ArrowPlots\n"
206  "fi\n")
207  repMap["runComparisonScripts"] += \
208  ("rfcp .oO[CMSSW_BASE]Oo./src/Alignment"
209  "/OfflineValidation/scripts/makeArrowPlots.C "
210  ".\n"
211  "root -b -q 'makeArrowPlots.C(\""
212  ".oO[name]Oo..Comparison_common"+name
213  +".root\",\".oO[name]Oo.."
214  +name+"_ArrowPlots\")'\n")
215  repMap["runComparisonScripts"] += \
216  ("rfmkdir -p .oO[datadir]Oo./.oO[name]Oo."
217  ".Comparison_common"+name+"_Images/ArrowPlots\n")
218  repMap["runComparisonScripts"] += \
219  ("find .oO[name]Oo.."+name+"_ArrowPlots "
220  "-maxdepth 1 -name \"*.png\" -print | xargs -I {} bash "
221  "-c \"rfcp {} .oO[datadir]Oo./.oO[name]Oo."
222  ".Comparison_common"+name+"_Images/ArrowPlots\"\n")
223  repMap["runComparisonScripts"] += \
224  ("find . "
225  "-maxdepth 1 -name \".oO[name]Oo..Visualization_rotated.gif\" -print | xargs -I {} bash "
226  "-c \"rfcp {} .oO[datadir]Oo./.oO[name]Oo."
227  ".Comparison_common"+name+"_Images/.oO[name]Oo..Visualization.gif\"\n")
228 
229  resultingFile = replaceByMap(("/store/caf/user/$USER/.oO[eosdir]Oo./compared%s_"
230  ".oO[name]Oo..root"%name), repMap)
231  resultingFile = os.path.expandvars( resultingFile )
232  resultingFile = os.path.abspath( resultingFile )
233  repMap["runComparisonScripts"] += \
234  ("cmsStage -f OUTPUT_comparison.root %s\n"
235  %resultingFile)
236  self.filesToCompare[ name ] = resultingFile
237 
238  repMap["CommandLine"]=""
239 
240  for cfg in self.configFiles:
241  # FIXME: produce this line only for enabled dbOutput
242  # postProcess = "rfcp .oO[workdir]Oo./*.db .oO[datadir]Oo.\n"
243  # postProcess = "rfcp *.db .oO[datadir]Oo.\n"
244  postProcess = ""
245  repMap["CommandLine"]+= \
246  repMap["CommandLineTemplate"]%{"cfgFile":cfg,
247  "postProcess":postProcess}
248  repMap["CommandLine"]+= ("# overall postprocessing\n"
249  ".oO[runComparisonScripts]Oo.\n"
250  )
251 
252  #~ print configTemplates.scriptTemplate
253  scripts = {scriptName: replaceByMap( configTemplates.scriptTemplate, repMap )}
254  files = {replaceByMap("TkAl3DVisualization_.oO[name]Oo..C", repMap ): replaceByMap(configTemplates.visualizationTrackerTemplate, repMap )}
255  self.createFiles(files, path)
256  return GenericValidation.createScript(self, scripts, path)
257 
258  def createCrabCfg(self, path):
259  msg = ("Parallelization not supported for geometry comparison. Please "
260  "choose another 'jobmode'.")
261  raise AllInOneError(msg)
def replaceByMap
— Helpers —############################
double split
Definition: MVATrainer.cc:139