Go to the documentation of this file.00001 import os
00002 import ConfigParser
00003 import configTemplates
00004 from genericValidation import GenericValidation
00005 from helperFunctions import replaceByMap
00006 from TkAlExceptions import AllInOneError
00007
00008
00009 class GeometryComparison(GenericValidation):
00010 """
00011 Object representing a geometry comparison job.
00012 """
00013 def __init__( self, valName, alignment, referenceAlignment,
00014 config, copyImages = True, randomWorkdirPart = None):
00015 """
00016 Constructor of the GeometryComparison class.
00017
00018 Arguments:
00019 - `valName`: String which identifies individual validation instances
00020 - `alignment`: `Alignment` instance to validate
00021 - `referenceAlignment`: `Alignment` instance which is compared
00022 with `alignment`
00023 - `config`: `BetterConfigParser` instance which includes the
00024 configuration of the validations
00025 - `copyImages`: Boolean which indicates whether png- and pdf-files
00026 should be copied back from the batch farm
00027 - `randomWorkDirPart`: If this option is ommitted a random number is
00028 generated to create unique path names for the
00029 individual validation instances.
00030 """
00031 GenericValidation.__init__(self, valName, alignment, config)
00032 if not randomWorkdirPart == None:
00033 self.randomWorkdirPart = randomWorkdirPart
00034 self.referenceAlignment = referenceAlignment
00035 try:
00036 self.jobmode = config.get( "compare:"+self.name, "jobmode" )
00037 except ConfigParser.NoOptionError:
00038 pass
00039 referenceName = "IDEAL"
00040 if not self.referenceAlignment == "IDEAL":
00041 referenceName = self.referenceAlignment.name
00042
00043 allCompares = config.getCompares()
00044 self.__compares = {}
00045 if valName in allCompares:
00046 self.__compares[valName] = allCompares[valName]
00047 else:
00048 msg = ("Could not find compare section '%s' in '%s'"
00049 %(valName, allCompares))
00050 raise AllInOneError(msg)
00051 self.copyImages = copyImages
00052
00053 def getRepMap(self, alignment = None):
00054 if alignment == None:
00055 alignment = self.alignmentToValidate
00056 repMap = GenericValidation.getRepMap( self, alignment )
00057 referenceName = "IDEAL"
00058 if not self.referenceAlignment == "IDEAL":
00059 referenceName = self.referenceAlignment.name
00060
00061 repMap.update({
00062 "comparedGeometry": (".oO[alignmentName]Oo."
00063 "ROOTGeometry.root"),
00064 "referenceGeometry": "IDEAL",
00065
00066 "reference": referenceName
00067 })
00068 if not referenceName == "IDEAL":
00069 repMap["referenceGeometry"] = (".oO[reference]Oo."
00070 "ROOTGeometry.root")
00071 repMap["name"] += "_vs_.oO[reference]Oo."
00072 return repMap
00073
00074 def createConfiguration(self, path ):
00075
00076 repMap = self.getRepMap()
00077 cfgs = { "TkAlCompareToNTuple.%s.%s_cfg.py"%(
00078 self.alignmentToValidate.name, self.randomWorkdirPart ):
00079 replaceByMap( configTemplates.intoNTuplesTemplate, repMap)}
00080 if not self.referenceAlignment == "IDEAL":
00081 referenceRepMap = self.getRepMap( self.referenceAlignment )
00082 cfgFileName = "TkAlCompareToNTuple.%s.%s_cfg.py"%(
00083 self.referenceAlignment.name, self.randomWorkdirPart )
00084 cfgs[cfgFileName] = replaceByMap(configTemplates.intoNTuplesTemplate,
00085 referenceRepMap)
00086
00087 cfgSchedule = cfgs.keys()
00088 for common in self.__compares:
00089 repMap.update({"common": common,
00090 "levels": self.__compares[common][0],
00091 "dbOutput": self.__compares[common][1]
00092 })
00093 if self.__compares[common][1].split()[0] == "true":
00094 repMap["dbOutputService"] = configTemplates.dbOutputTemplate
00095 else:
00096 repMap["dbOutputService"] = ""
00097 cfgName = replaceByMap(("TkAlCompareCommon.oO[common]Oo.."
00098 ".oO[name]Oo._cfg.py"),repMap)
00099 cfgs[cfgName] = replaceByMap(configTemplates.compareTemplate, repMap)
00100
00101 cfgSchedule.append( cfgName )
00102 GenericValidation.createConfiguration(self, cfgs, path, cfgSchedule)
00103
00104 def createScript(self, path):
00105 repMap = self.getRepMap()
00106 repMap["runComparisonScripts"] = ""
00107 scriptName = replaceByMap(("TkAlGeomCompare.%s..oO[name]Oo..sh"
00108 %self.name), repMap)
00109 for name in self.__compares:
00110 if '"DetUnit"' in self.__compares[name][0].split(","):
00111 repMap["runComparisonScripts"] += \
00112 ("rfcp .oO[CMSSW_BASE]Oo./src/Alignment/OfflineValidation"
00113 "/scripts/comparisonScript.C .\n"
00114 "rfcp .oO[CMSSW_BASE]Oo./src/Alignment/OfflineValidation"
00115 "/scripts/comparisonPlots.h .\n"
00116 "rfcp .oO[CMSSW_BASE]Oo./src/Alignment/OfflineValidation"
00117 "/scripts/comparisonPlots.cc .\n"
00118 "root -b -q 'comparisonScript.C(\""
00119 ".oO[name]Oo..Comparison_common"+name+".root\",\""
00120 "./\")'\n")
00121 if self.copyImages:
00122 repMap["runComparisonScripts"] += \
00123 ("rfmkdir -p .oO[datadir]Oo./.oO[name]Oo."
00124 ".Comparison_common"+name+"_Images\n")
00125 repMap["runComparisonScripts"] += \
00126 ("find . -maxdepth 1 -name \"plot*.eps\" "
00127 "-print | xargs -I {} bash -c \"rfcp {} .oO[datadir]Oo."
00128 "/.oO[name]Oo..Comparison_common"+name+"_Images/\" \n")
00129 repMap["runComparisonScripts"] += \
00130 ("find . -maxdepth 1 -name \"plot*.pdf\" "
00131 "-print | xargs -I {} bash -c \"rfcp {} .oO[datadir]Oo."
00132 "/.oO[name]Oo..Comparison_common"+name+"_Images/\" \n")
00133 repMap["runComparisonScripts"] += \
00134 ("find . -maxdepth 1 -name "
00135 "\"TkMap_SurfDeform*.pdf\" -print | xargs -I {} bash -c"
00136 " \"rfcp {} .oO[datadir]Oo./.oO[name]Oo."
00137 ".Comparison_common"+name+"_Images/\" \n")
00138 repMap["runComparisonScripts"] += \
00139 ("find . -maxdepth 1 -name "
00140 "\"TkMap_SurfDeform*.png\" -print | xargs -I {} bash -c"
00141 " \"rfcp {} .oO[datadir]Oo./.oO[name]Oo."
00142 ".Comparison_common"+name+"_Images/\" \n")
00143 repMap["runComparisonScripts"] += \
00144 ("if [[ $HOSTNAME = lxplus[0-9]*\.cern\.ch ]]\n"
00145 "then\n"
00146 " rfmkdir -p .oO[workdir]Oo./.oO[name]Oo.."+name
00147 +"_ArrowPlots\n"
00148 "else\n"
00149 " mkdir -p $CWD/TkAllInOneTool/.oO[name]Oo.."+name
00150 +"_ArrowPlots\n"
00151 "fi\n")
00152 repMap["runComparisonScripts"] += \
00153 ("rfcp .oO[CMSSW_BASE]Oo./src/Alignment"
00154 "/OfflineValidation/scripts/makeArrowPlots.C "
00155 "$CWD/TkAllInOneTool\n"
00156 "root -b -q 'makeArrowPlots.C(\""
00157 ".oO[name]Oo..Comparison_common"+name
00158 +".root\",\".oO[name]Oo.."
00159 +name+"_ArrowPlots\")'\n")
00160 repMap["runComparisonScripts"] += \
00161 ("rfmkdir -p .oO[datadir]Oo./.oO[name]Oo."
00162 ".Comparison_common"+name+"_Images/ArrowPlots\n")
00163 repMap["runComparisonScripts"] += \
00164 ("find .oO[name]Oo.."+name+"_ArrowPlots "
00165 "-maxdepth 1 -name \"*.png\" -print | xargs -I {} bash "
00166 "-c \"rfcp {} .oO[datadir]Oo./.oO[name]Oo."
00167 ".Comparison_common"+name+"_Images/ArrowPlots\"\n")
00168
00169 resultingFile = replaceByMap(("/store/caf/user/$USER/.oO[eosdir]Oo./compared%s_"
00170 ".oO[name]Oo..root"%name), repMap)
00171 resultingFile = os.path.expandvars( resultingFile )
00172 resultingFile = os.path.abspath( resultingFile )
00173 repMap["runComparisonScripts"] += \
00174 ("cmsStage -f OUTPUT_comparison.root %s\n"
00175 %resultingFile)
00176 self.filesToCompare[ name ] = resultingFile
00177
00178 repMap["CommandLine"]=""
00179
00180 for cfg in self.configFiles:
00181
00182
00183 postProcess = "rfcp *.db .oO[datadir]Oo.\n"
00184 repMap["CommandLine"]+= \
00185 repMap["CommandLineTemplate"]%{"cfgFile":cfg,
00186 "postProcess":postProcess}
00187 repMap["CommandLine"]+= ("# overall postprocessing\n"
00188 ".oO[runComparisonScripts]Oo.\n"
00189 )
00190
00191 scripts = {scriptName: replaceByMap( configTemplates.scriptTemplate, repMap ) }
00192 return GenericValidation.createScript(self, scripts, path)
00193
00194 def createCrabCfg(self, path):
00195 msg = ("Parallelization not supported for geometry comparison. Please "
00196 "choose another 'jobmode'.")
00197 raise AllInOneError(msg)