282 if(len(validations) == 0):
283 raise AllInOneError(
"Cowardly refusing to merge nothing!")
285 config = validations[0].config
286 repMap = config.getGeneral()
289 "CompareAlignments":
"",
290 "RunValidationPlots":
"",
291 "CMSSW_BASE": os.environ[
"CMSSW_BASE"],
292 "SCRAM_ARCH": os.environ[
"SCRAM_ARCH"],
293 "CMSSW_RELEASE_BASE": os.environ[
"CMSSW_RELEASE_BASE"],
297 for validation
in validations:
298 for referenceName
in validation.filesToCompare:
299 validationtype = type(validation)
300 if isinstance(validationtype, PreexistingValidation):
302 for parentclass
in validationtype.mro():
303 if not issubclass(parentclass, PreexistingValidation):
304 validationtype = parentclass
306 key = (validationtype, referenceName)
307 if key
in comparisonLists:
308 comparisonLists[key].
append(validation)
310 comparisonLists[key] = [validation]
314 repMap[
"doMerge"] =
"mergeRetCode=0\n" 315 repMap[
"rmUnmerged"] = (
"if [[ mergeRetCode -eq 0 ]]; then\n" 316 " echo -e \\n\"Merging succeeded, removing original files.\"\n")
317 repMap[
"beforeMerge"] =
"" 318 repMap[
"mergeParallelFilePrefixes"] =
"" 319 repMap[
"createResultsDirectory"]=
"" 326 if options.mergeOfflineParallel:
327 parallelMergeObjects={}
328 for (validationType, referencename), validations
in comparisonLists.iteritems():
329 for validation
in validations:
331 if (isinstance(validation, PreexistingValidation)
332 or validation.NJobs == 1
333 or not isinstance(validation, ParallelValidation)):
335 if options.mergeOfflineParallel
and validationType.valType==
'offline' and validation.jobmode.split(
",")[0]==
"lxBatch":
336 repMapTemp=repMap.copy()
337 if validationType
not in anythingToMerge:
338 anythingToMerge += [validationType]
340 fileName=
"TkAlMergeInit" 341 filePath = os.path.join(path, fileName+
".sh")
342 theFile = open( filePath,
"w" )
343 repMapTemp[
"createResultsDirectory"]=
"#!/bin/bash" 344 repMapTemp[
"createResultsDirectory"]+=
replaceByMap(configTemplates.createResultsDirectoryTemplate, repMapTemp)
345 theFile.write(
replaceByMap( configTemplates.createResultsDirectoryTemplate, repMapTemp ) )
347 os.chmod(filePath,0o755)
351 repMapTemp[
"createResultsDirectory"]=
"" 355 repMapTemp[
"beforeMerge"] += validationType.doInitMerge()
356 repMapTemp[
"doMerge"] +=
'\n\n\n\necho -e "\n\nMerging results from %s jobs with alignment %s"\n\n' % (validationType.valType,validation.alignmentToValidate.name)
357 repMapTemp[
"doMerge"] += validation.doMerge()
358 for f
in validation.getRepMap()[
"outputFiles"]:
359 longName = os.path.join(
"/eos/cms/store/caf/user/$USER/",
360 validation.getRepMap()[
"eosdir"], f)
361 repMapTemp[
"rmUnmerged"] +=
" rm "+longName+
"\n" 363 repMapTemp[
"rmUnmerged"] += (
"else\n" 364 " echo -e \\n\"WARNING: Merging failed, unmerged" 365 " files won't be deleted.\\n" 366 "(Ignore this warning if merging was done earlier)\"\n" 370 repMapTemp[
"DownloadData"] =
replaceByMap( configTemplates.mergeParallelResults, repMapTemp )
372 repMapTemp[
"RunValidationPlots"] = validationType.doRunPlots(validations)
375 fileName=
"TkAlMerge"+validation.alignmentToValidate.name
376 filePath = os.path.join(path, fileName+
".sh")
377 theFile = open( filePath,
"w" )
378 theFile.write(
replaceByMap( configTemplates.mergeParallelOfflineTemplate, repMapTemp ) )
380 os.chmod(filePath,0o755)
382 if "parallel" in parallelMergeObjects:
390 if validationType
not in anythingToMerge:
391 anythingToMerge += [validationType]
392 repMap[
"doMerge"] +=
'\n\n\n\necho -e "\n\nMerging results from %s jobs"\n\n' % validationType.valType
393 repMap[
"beforeMerge"] += validationType.doInitMerge()
394 repMap[
"doMerge"] += validation.doMerge()
395 for f
in validation.getRepMap()[
"outputFiles"]:
396 longName = os.path.join(
"/eos/cms/store/caf/user/$USER/",
397 validation.getRepMap()[
"eosdir"], f)
398 repMap[
"rmUnmerged"] +=
" rm "+longName+
"\n" 402 repMap[
"rmUnmerged"] += (
"else\n" 403 " echo -e \\n\"WARNING: Merging failed, unmerged" 404 " files won't be deleted.\\n" 405 "(Ignore this warning if merging was done earlier)\"\n" 411 repMap[
"DownloadData"] +=
replaceByMap( configTemplates.mergeParallelResults, repMap )
413 repMap[
"DownloadData"] =
"" 415 repMap[
"RunValidationPlots"] =
"" 416 for (validationType, referencename), validations
in comparisonLists.iteritems():
417 if issubclass(validationType, ValidationWithPlots):
418 repMap[
"RunValidationPlots"] += validationType.doRunPlots(validations)
420 repMap[
"CompareAlignments"] =
"#run comparisons" 421 for (validationType, referencename), validations
in comparisonLists.iteritems():
422 if issubclass(validationType, ValidationWithComparison):
423 repMap[
"CompareAlignments"] += validationType.doComparison(validations)
426 if options.mergeOfflineParallel
and parallelMergeObjects!={}:
427 parallelMergeObjects[
"continue"]=
ParallelMergeJob(
"TkAlMergeFinal",os.path.join(path,
"TkAlMergeFinal.sh"),[])
428 filePath = os.path.join(path,
"TkAlMergeFinal.sh")
431 repMap[
"createResultsDirectory"]=
replaceByMap(configTemplates.createResultsDirectoryTemplate, repMap)
432 filePath = os.path.join(path,
"TkAlMerge.sh")
436 theFile = open( filePath,
"w" )
437 theFile.write(
replaceByMap( configTemplates.mergeTemplate, repMap ) )
439 os.chmod(filePath,0o755)
441 if options.mergeOfflineParallel:
442 return {
'TkAlMerge.sh':filePath,
'parallelMergeObjects':parallelMergeObjects}
def createMergeScript(path, validations, options)
— Classes —############################
def replaceByMap(target, the_map)
— Helpers —############################