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  GenericValidation.__init__(self, valName, alignment, config)
32  if not randomWorkdirPart == None:
33  self.randomWorkdirPart = randomWorkdirPart
34  self.referenceAlignment = referenceAlignment
35  try: # try to override 'jobmode' from [general] section
36  self.jobmode = config.get( "compare:"+self.name, "jobmode" )
37  except ConfigParser.NoOptionError:
38  pass
39  referenceName = "IDEAL"
40  if not self.referenceAlignment == "IDEAL":
41  referenceName = self.referenceAlignment.name
42 
43  allCompares = config.getCompares()
44  self.__compares = {}
45  if valName in allCompares:
46  self.__compares[valName] = allCompares[valName]
47  else:
48  msg = ("Could not find compare section '%s' in '%s'"
49  %(valName, allCompares))
50  raise AllInOneError(msg)
51  self.copyImages = copyImages
52 
53  def getRepMap(self, alignment = None):
54  if alignment == None:
55  alignment = self.alignmentToValidate
56  repMap = GenericValidation.getRepMap( self, alignment )
57  referenceName = "IDEAL"
58  if not self.referenceAlignment == "IDEAL":
59  referenceName = self.referenceAlignment.name
60 
61  repMap.update({
62  "comparedGeometry": (".oO[alignmentName]Oo."
63  "ROOTGeometry.root"),
64  "referenceGeometry": "IDEAL", # will be replaced later
65  # if not compared to IDEAL
66  "reference": referenceName
67  })
68  if not referenceName == "IDEAL":
69  repMap["referenceGeometry"] = (".oO[reference]Oo."
70  "ROOTGeometry.root")
71  repMap["name"] += "_vs_.oO[reference]Oo."
72  return repMap
73 
74  def createConfiguration(self, path ):
75  # self.__compares
76  repMap = self.getRepMap()
77  cfgs = { "TkAlCompareToNTuple.%s.%s_cfg.py"%(
78  self.alignmentToValidate.name, self.randomWorkdirPart ):
79  replaceByMap( configTemplates.intoNTuplesTemplate, repMap)}
80  if not self.referenceAlignment == "IDEAL":
81  referenceRepMap = self.getRepMap( self.referenceAlignment )
82  cfgFileName = "TkAlCompareToNTuple.%s.%s_cfg.py"%(
83  self.referenceAlignment.name, self.randomWorkdirPart )
84  cfgs[cfgFileName] = replaceByMap(configTemplates.intoNTuplesTemplate,
85  referenceRepMap)
86 
87  cfgSchedule = cfgs.keys()
88  for common in self.__compares:
89  repMap.update({"common": common,
90  "levels": self.__compares[common][0],
91  "dbOutput": self.__compares[common][1]
92  })
93  if self.__compares[common][1].split()[0] == "true":
94  repMap["dbOutputService"] = configTemplates.dbOutputTemplate
95  else:
96  repMap["dbOutputService"] = ""
97  cfgName = replaceByMap(("TkAlCompareCommon.oO[common]Oo.."
98  ".oO[name]Oo._cfg.py"),repMap)
99  cfgs[cfgName] = replaceByMap(configTemplates.compareTemplate, repMap)
100 
101  cfgSchedule.append( cfgName )
102  GenericValidation.createConfiguration(self, cfgs, path, cfgSchedule)
103 
104  def createScript(self, path):
105  repMap = self.getRepMap()
106  repMap["runComparisonScripts"] = ""
107  scriptName = replaceByMap(("TkAlGeomCompare.%s..oO[name]Oo..sh"
108  %self.name), repMap)
109  for name in self.__compares:
110  if '"DetUnit"' in self.__compares[name][0].split(","):
111  repMap["runComparisonScripts"] += \
112  ("rfcp .oO[CMSSW_BASE]Oo./src/Alignment/OfflineValidation"
113  "/scripts/comparisonScript.C .\n"
114  "rfcp .oO[CMSSW_BASE]Oo./src/Alignment/OfflineValidation"
115  "/scripts/comparisonPlots.h .\n"
116  "rfcp .oO[CMSSW_BASE]Oo./src/Alignment/OfflineValidation"
117  "/scripts/comparisonPlots.cc .\n"
118  "root -b -q 'comparisonScript.C(\""
119  ".oO[name]Oo..Comparison_common"+name+".root\",\""
120  "./\")'\n")
121  if self.copyImages:
122  repMap["runComparisonScripts"] += \
123  ("rfmkdir -p .oO[datadir]Oo./.oO[name]Oo."
124  ".Comparison_common"+name+"_Images\n")
125  repMap["runComparisonScripts"] += \
126  ("find . -maxdepth 1 -name \"plot*.eps\" "
127  "-print | xargs -I {} bash -c \"rfcp {} .oO[datadir]Oo."
128  "/.oO[name]Oo..Comparison_common"+name+"_Images/\" \n")
129  repMap["runComparisonScripts"] += \
130  ("find . -maxdepth 1 -name \"plot*.pdf\" "
131  "-print | xargs -I {} bash -c \"rfcp {} .oO[datadir]Oo."
132  "/.oO[name]Oo..Comparison_common"+name+"_Images/\" \n")
133  repMap["runComparisonScripts"] += \
134  ("find . -maxdepth 1 -name "
135  "\"TkMap_SurfDeform*.pdf\" -print | xargs -I {} bash -c"
136  " \"rfcp {} .oO[datadir]Oo./.oO[name]Oo."
137  ".Comparison_common"+name+"_Images/\" \n")
138  repMap["runComparisonScripts"] += \
139  ("find . -maxdepth 1 -name "
140  "\"TkMap_SurfDeform*.png\" -print | xargs -I {} bash -c"
141  " \"rfcp {} .oO[datadir]Oo./.oO[name]Oo."
142  ".Comparison_common"+name+"_Images/\" \n")
143  repMap["runComparisonScripts"] += \
144  ("if [[ $HOSTNAME = lxplus[0-9]*\.cern\.ch ]]\n"
145  "then\n"
146  " rfmkdir -p .oO[workdir]Oo./.oO[name]Oo.."+name
147  +"_ArrowPlots\n"
148  "else\n"
149  " mkdir -p $CWD/TkAllInOneTool/.oO[name]Oo.."+name
150  +"_ArrowPlots\n"
151  "fi\n")
152  repMap["runComparisonScripts"] += \
153  ("rfcp .oO[CMSSW_BASE]Oo./src/Alignment"
154  "/OfflineValidation/scripts/makeArrowPlots.C "
155  "$CWD/TkAllInOneTool\n"
156  "root -b -q 'makeArrowPlots.C(\""
157  ".oO[name]Oo..Comparison_common"+name
158  +".root\",\".oO[name]Oo.."
159  +name+"_ArrowPlots\")'\n")
160  repMap["runComparisonScripts"] += \
161  ("rfmkdir -p .oO[datadir]Oo./.oO[name]Oo."
162  ".Comparison_common"+name+"_Images/ArrowPlots\n")
163  repMap["runComparisonScripts"] += \
164  ("find .oO[name]Oo.."+name+"_ArrowPlots "
165  "-maxdepth 1 -name \"*.png\" -print | xargs -I {} bash "
166  "-c \"rfcp {} .oO[datadir]Oo./.oO[name]Oo."
167  ".Comparison_common"+name+"_Images/ArrowPlots\"\n")
168 
169  resultingFile = replaceByMap(("/store/caf/user/$USER/.oO[eosdir]Oo./compared%s_"
170  ".oO[name]Oo..root"%name), repMap)
171  resultingFile = os.path.expandvars( resultingFile )
172  resultingFile = os.path.abspath( resultingFile )
173  repMap["runComparisonScripts"] += \
174  ("cmsStage -f OUTPUT_comparison.root %s\n"
175  %resultingFile)
176  self.filesToCompare[ name ] = resultingFile
177 
178  repMap["CommandLine"]=""
179 
180  for cfg in self.configFiles:
181  # FIXME: produce this line only for enabled dbOutput
182  # postProcess = "rfcp .oO[workdir]Oo./*.db .oO[datadir]Oo.\n"
183  postProcess = "rfcp *.db .oO[datadir]Oo.\n"
184  repMap["CommandLine"]+= \
185  repMap["CommandLineTemplate"]%{"cfgFile":cfg,
186  "postProcess":postProcess}
187  repMap["CommandLine"]+= ("# overall postprocessing\n"
188  ".oO[runComparisonScripts]Oo.\n"
189  )
190 
191  scripts = {scriptName: replaceByMap( configTemplates.scriptTemplate, repMap ) }
192  return GenericValidation.createScript(self, scripts, path)
193 
194  def createCrabCfg(self, path):
195  msg = ("Parallelization not supported for geometry comparison. Please "
196  "choose another 'jobmode'.")
197  raise AllInOneError(msg)
def replaceByMap
— Helpers —############################
double split
Definition: MVATrainer.cc:139