Classes | |
class | Alignment |
class | BetterConfigParser |
--- Classes ---############################ More... | |
class | GenericValidation |
class | GeometryComparison |
class | MonteCarloValidation |
class | OfflineValidation |
class | OfflineValidationDQM |
class | OfflineValidationParallel |
class | TrackSplittingValidation |
class | ValidationJob |
class | ZMuMuValidation |
Functions | |
def | castorDirExists |
def | createCrabScript |
def | createExtendedValidationScript |
def | createMergeScript |
def | createOfflineJobsMergeScript |
def | createParallelMergeScript |
def | getCommandOutput2 |
def | loadTemplates |
def | main |
--- Main ---############################ | |
def | replaceByMap |
--- Helpers ---############################ replaces .oO[id]Oo. | |
Variables | |
dictionary | alignRandDict = {} |
def validateAlignments::castorDirExists | ( | path | ) |
Definition at line 44 of file validateAlignments.py.
00045 : 00046 if path[-1] == "/": 00047 path = path[:-1] 00048 containingPath = os.path.join( *path.split("/")[:-1] ) 00049 dirInQuestion = path.split("/")[-1] 00050 try: 00051 rawLines =getCommandOutput2("rfdir /"+containingPath).splitlines() 00052 except RuntimeError: 00053 return False 00054 for line in rawLines: 00055 if line.split()[0][0] == "d": 00056 if line.split()[8] == dirInQuestion: 00057 return True 00058 return False
def validateAlignments::createCrabScript | ( | path, | |
validations | |||
) |
Definition at line 1108 of file validateAlignments.py.
01109 : 01110 repMap = {"crabCommand": "", 01111 "crabBaseDir": path, 01112 "useCshell": "" 01113 } 01114 for validation in validations: 01115 if validation.jobmode.split( ',' )[0] == 'crab': 01116 valRepMap = {"crabWorkingDir": validation.crabWorkingDir, 01117 "crabCfgName": validation.crabWorkingDir + ".cfg" 01118 } 01119 repMap["crabCommand"] += replaceByMap( configTemplates.crabCommandTemplate, 01120 valRepMap ) 01121 if len( repMap["crabCommand"] ) == 0: 01122 return None 01123 crabShScriptPath = os.path.join( path, 'TkAlRunCrab.sh' ) 01124 crabShScript = open( crabShScriptPath, 'w' ) 01125 crabShScript.write( replaceByMap( configTemplates.crabShellScriptTemplate, 01126 repMap ) ) 01127 crabShScript.close() 01128 repMap["useCshell"] = "c" 01129 crabCshScriptPath = os.path.join( path, 'TkAlRunCrab.csh' ) 01130 crabCshScript = open( crabCshScriptPath, 'w' ) 01131 crabCshScript.write( replaceByMap( configTemplates.crabShellScriptTemplate, 01132 repMap ) ) 01133 crabCshScript.close() 01134 return crabShScriptPath, crabCshScriptPath
def validateAlignments::createExtendedValidationScript | ( | offlineValidationList, | |
outFilePath | |||
) |
Definition at line 1147 of file validateAlignments.py.
01148 : 01149 repMap = offlineValidationList[0].getRepMap() # bit ugly since some special features are filled 01150 repMap[ "extendedInstantiation" ] = "" #give it a "" at first in order to get the initialisation back 01151 01152 for validation in offlineValidationList: 01153 repMap[ "extendedInstantiation" ] = validation.appendToExtendedValidation( repMap[ "extendedInstantiation" ] ) 01154 01155 theFile = open( outFilePath, "w" ) 01156 theFile.write( replaceByMap( configTemplates.extendedValidationTemplate ,repMap ) ) 01157 theFile.close()
def validateAlignments::createMergeScript | ( | path, | |
validations | |||
) |
Definition at line 1158 of file validateAlignments.py.
01159 : 01160 if( len(validations) == 0 ): 01161 raise StandardError, "cowardly refusing to merge nothing!" 01162 01163 repMap = validations[0].getRepMap() #FIXME - not nice this way 01164 repMap.update({ 01165 "DownloadData":"", 01166 "CompareAllignments":"", 01167 "RunExtendedOfflineValidation":"" 01168 }) 01169 01170 comparisonLists = {} # directory of lists containing the validations that are comparable 01171 for validation in validations: 01172 for referenceName in validation.filesToCompare: 01173 validationName = "%s.%s"%(validation.__class__.__name__, referenceName) 01174 validationName = validationName.split(".%s"%GenericValidation.defaultReferenceName )[0] 01175 if validationName in comparisonLists: 01176 comparisonLists[ validationName ].append( validation ) 01177 else: 01178 comparisonLists[ validationName ] = [ validation ] 01179 01180 if "OfflineValidation" in comparisonLists: 01181 repMap["extendeValScriptPath"] = os.path.join(path, "TkAlExtendedOfflineValidation.C") 01182 createExtendedValidationScript( comparisonLists["OfflineValidation"], repMap["extendeValScriptPath"] ) 01183 repMap["RunExtendedOfflineValidation"] = replaceByMap(configTemplates.extendedValidationExecution, repMap) 01184 01185 repMap["CompareAllignments"] = "#run comparisons" 01186 for validationId in comparisonLists: 01187 compareStrings = [ val.getCompareStrings(validationId) for val in comparisonLists[validationId] ] 01188 01189 repMap.update({"validationId": validationId, 01190 "compareStrings": " , ".join(compareStrings) }) 01191 01192 repMap["CompareAllignments"] += replaceByMap( configTemplates.compareAlignmentsExecution, repMap ) 01193 01194 filePath = os.path.join(path, "TkAlMerge.sh") 01195 theFile = open( filePath, "w" ) 01196 theFile.write( replaceByMap( configTemplates.mergeTemplate, repMap ) ) 01197 theFile.close() 01198 os.chmod(filePath,0755) 01199 01200 return filePath
def validateAlignments::createOfflineJobsMergeScript | ( | offlineValidationList, | |
outFilePath | |||
) |
Definition at line 1135 of file validateAlignments.py.
01136 : 01137 repMap = offlineValidationList[0].getRepMap() # bit ugly since some special features are filled 01138 repMap[ "mergeOfflinParJobsInstantiation" ] = "" #give it a "" at first in order to get the initialisation back 01139 01140 for validation in offlineValidationList: 01141 repMap[ "mergeOfflinParJobsInstantiation" ] = validation.appendToMergeParJobs( repMap[ "mergeOfflinParJobsInstantiation" ] ) 01142 # validationsSoFar = 'PlotAlignmentValidation p("%(resultFile)s", "%(name)s", %(color)s, %(style)s);\n'%repMap 01143 01144 theFile = open( outFilePath, "w" ) 01145 theFile.write( replaceByMap( configTemplates.mergeOfflineParJobsTemplate ,repMap ) ) 01146 theFile.close()
def validateAlignments::createParallelMergeScript | ( | path, | |
validations | |||
) |
Definition at line 1201 of file validateAlignments.py.
01202 : 01203 if( len(validations) == 0 ): 01204 raise StandardError, "cowardly refusing to merge nothing!" 01205 01206 repMap = validations[0].getRepMap() #FIXME - not nice this way 01207 repMap.update({ 01208 "DownloadData":"", 01209 "CompareAllignments":"", 01210 "RunExtendedOfflineValidation":"" 01211 }) 01212 01213 comparisonLists = {} # directory of lists containing the validations that are comparable 01214 for validation in validations: 01215 for referenceName in validation.filesToCompare: 01216 validationName = "%s.%s"%(validation.__class__.__name__, referenceName) 01217 validationName = validationName.split(".%s"%GenericValidation.defaultReferenceName )[0] 01218 if validationName in comparisonLists: 01219 comparisonLists[ validationName ].append( validation ) 01220 else: 01221 comparisonLists[ validationName ] = [ validation ] 01222 01223 if "OfflineValidationParallel" in comparisonLists: 01224 repMap["extendeValScriptPath"] = os.path.join(path, "TkAlExtendedOfflineValidation.C") 01225 createExtendedValidationScript( comparisonLists["OfflineValidationParallel"], repMap["extendeValScriptPath"] ) 01226 repMap["mergeOfflineParJobsScriptPath"] = os.path.join(path, "TkAlOfflineJobsMerge.C") 01227 createOfflineJobsMergeScript( comparisonLists["OfflineValidationParallel"], repMap["mergeOfflineParJobsScriptPath"] ) 01228 repMap["RunExtendedOfflineValidation"] = replaceByMap(configTemplates.extendedValidationExecution, repMap) 01229 # DownloadData is the section which merges output files from parallel jobs 01230 # it uses the file TkAlOfflineJobsMerge.C 01231 repMap["DownloadData"] += replaceByMap( configTemplates.mergeOfflineParallelResults, repMap ) 01232 01233 repMap["CompareAllignments"] = "#run comparisons" 01234 for validationId in comparisonLists: 01235 compareStrings = [ val.getCompareStrings(validationId) for val in comparisonLists[validationId] ] 01236 01237 repMap.update({"validationId": validationId, 01238 "compareStrings": " , ".join(compareStrings) }) 01239 01240 repMap["CompareAllignments"] += replaceByMap( configTemplates.compareAlignmentsExecution, repMap ) 01241 01242 filePath = os.path.join(path, "TkAlMerge.sh") 01243 theFile = open( filePath, "w" ) 01244 theFile.write( replaceByMap( configTemplates.mergeTemplate, repMap ) ) 01245 theFile.close() 01246 os.chmod(filePath,0755) 01247 01248 return filePath
def validateAlignments::getCommandOutput2 | ( | command | ) |
Definition at line 35 of file validateAlignments.py.
def validateAlignments::loadTemplates | ( | config | ) |
Definition at line 1249 of file validateAlignments.py.
01250 : 01251 if config.has_section("alternateTemplates"): 01252 for templateName in config.options("alternateTemplates"): 01253 newTemplateName = config.get("alternateTemplates", templateName ) 01254 #print "replacing default %s template by %s"%( templateName, newTemplateName) 01255 configTemplates.alternateTemplate(templateName, newTemplateName)
def validateAlignments::main | ( | argv = None | ) |
--- Main ---############################
Definition at line 1257 of file validateAlignments.py.
01258 : 01259 if argv == None: 01260 argv = sys.argv[1:] 01261 optParser = optparse.OptionParser() 01262 optParser.description = """ all-in-one alignment Validation 01263 This will run various validation procedures either on batch queues or interactviely. 01264 01265 If no name is given (-N parameter) a name containing time and date is created automatically 01266 01267 To merge the outcome of all validation procedures run TkAlMerge.sh in your validation's directory. 01268 """ 01269 optParser.add_option("-n", "--dryRun", dest="dryRun", action="store_true", default=False, 01270 help="create all scripts and cfg File but do not start jobs (default=False)") 01271 optParser.add_option( "--getImages", dest="getImages", action="store_true", default=False, 01272 help="get all Images created during the process (default= False)") 01273 optParser.add_option("-c", "--config", dest="config", 01274 help="configuration to use (default compareConfig.ini) this can be a comma-seperated list of all .ini file you want to merge", metavar="CONFIG") 01275 optParser.add_option("-N", "--Name", dest="Name", 01276 help="Name of this validation (default: alignmentValidation_DATE_TIME)", metavar="NAME") 01277 optParser.add_option("-r", "--restrictTo", dest="restrictTo", 01278 help="restrict validations to given modes (comma seperated) (default: no restriction)", metavar="RESTRICTTO") 01279 01280 (options, args) = optParser.parse_args(argv) 01281 01282 if not options.restrictTo == None: 01283 options.restrictTo = options.restrictTo.split(",") 01284 if options.config == None: 01285 options.config = "compareConfig.ini" 01286 else: 01287 options.config = options.config.split(",") 01288 result = [] 01289 for iniFile in options.config: 01290 result.append( os.path.abspath(iniFile) ) 01291 options.config = result 01292 config = BetterConfigParser() 01293 config.read( options.config ) 01294 01295 if options.Name == None: 01296 options.Name = "alignmentValidation_%s"%(datetime.datetime.now().strftime("%y%m%d_%H%M%S")) 01297 01298 outPath = os.path.abspath( options.Name ) 01299 general = config.getGeneral() 01300 config.set("general","workdir",os.path.join(general["workdir"],options.Name) ) 01301 config.set("general","datadir",os.path.join(general["datadir"],options.Name) ) 01302 config.set("general","logdir",os.path.join(general["logdir"],options.Name) ) 01303 01304 # clean up of log directory to avoid cluttering with files with different 01305 # random numbers for geometry comparison 01306 if os.path.isdir( config.getGeneral()["logdir"] ): 01307 shutil.rmtree( config.getGeneral()["logdir"] ) 01308 01309 if not os.path.exists( outPath ): 01310 os.makedirs( outPath ) 01311 elif not os.path.isdir( outPath ): 01312 raise StandardError,"the file %s is in the way rename the Job or move it away"%outPath 01313 01314 #replace default templates by the once specified in the "alternateTemplates" section 01315 loadTemplates( config ) 01316 01317 #save backup configuration file 01318 backupConfigFile = open( os.path.join( outPath, "usedConfiguration.ini" ) , "w" ) 01319 config.write( backupConfigFile ) 01320 01321 jobs = [ ValidationJob( validation, config, options) \ 01322 for validation in config.items( "validation" ) ] 01323 map( lambda job: job.createJob(), jobs ) 01324 validations = [ job.getValidation() for job in jobs ] 01325 01326 if "OfflineValidationParallel" not in [val.__class__.__name__ for val in validations]: 01327 createMergeScript( outPath, validations ) 01328 else: 01329 createParallelMergeScript( outPath, validations ) 01330 crabScript = createCrabScript( outPath, validations ) 01331 01332 map( lambda job: job.runJob(), jobs ) 01333 if crabScript != None: 01334 print 01335 print "="*80 01336 print "To start parallel validation please type:" 01337 print "source "+outPath+"/TkAlRunCrab.sh" 01338 print "\t<or>" 01339 print "source "+outPath+"/TkAlRunCrab.csh" 01340 print "="*80 01341 print 01342
def validateAlignments::replaceByMap | ( | target, | |
map | |||
) |
--- Helpers ---############################ replaces .oO[id]Oo.
by map[id] in target
Definition at line 15 of file validateAlignments.py.
00016 : 00017 result = target 00018 for id in map: 00019 #print " "+id+": "+map[id] 00020 lifeSaver = 10e3 00021 iteration = 0 00022 while ".oO[" in result and "]Oo." in result: 00023 for id in map: 00024 result = result.replace(".oO["+id+"]Oo.",map[id]) 00025 iteration += 1 00026 if iteration > lifeSaver: 00027 problematicLines = "" 00028 print map.keys() 00029 for line in result.splitlines(): 00030 if ".oO[" in result and "]Oo." in line: 00031 problematicLines += "%s\n"%line 00032 raise StandardError, "Oh Dear, there seems to be an endless loop in replaceByMap!!\n%s\nrepMap"%problematicLines 00033 return result 00034 #excute [command] and return output
dictionary validateAlignments::alignRandDict = {} |
Definition at line 962 of file validateAlignments.py.