290 if(len(validations) == 0):
291 raise AllInOneError(
"Cowardly refusing to merge nothing!")
293 config = validations[0].config
294 repMap = config.getGeneral()
297 "CompareAlignments":
"",
298 "RunValidationPlots":
"",
299 "CMSSW_BASE": os.environ[
"CMSSW_BASE"],
300 "SCRAM_ARCH": os.environ[
"SCRAM_ARCH"],
301 "CMSSW_RELEASE_BASE": os.environ[
"CMSSW_RELEASE_BASE"],
305 for validation
in validations:
306 for referenceName
in validation.filesToCompare:
307 validationtype = type(validation)
308 if issubclass(validationtype, PreexistingValidation):
310 for parentclass
in validationtype.mro():
311 if not issubclass(parentclass, PreexistingValidation):
312 validationtype = parentclass
314 key = (validationtype, referenceName)
315 if key
in comparisonLists:
316 comparisonLists[key].
append(validation)
318 comparisonLists[key] = [validation]
322 repMap[
"doMerge"] =
"mergeRetCode=0\n" 323 repMap[
"rmUnmerged"] = (
"if [[ mergeRetCode -eq 0 ]]; then\n" 324 " echo -e \\n\"Merging succeeded, removing original files.\"\n")
325 repMap[
"beforeMerge"] =
"" 326 repMap[
"mergeParallelFilePrefixes"] =
"" 327 repMap[
"createResultsDirectory"]=
"" 334 if options.mergeOfflineParallel:
335 parallelMergeObjects={}
336 for (validationType, referencename), validations
in six.iteritems(comparisonLists):
337 for validation
in validations:
339 if (isinstance(validation, PreexistingValidation)
340 or validation.NJobs == 1
341 or not isinstance(validation, ParallelValidation)):
343 if options.mergeOfflineParallel
and validationType.valType==
'offline' and validation.jobmode.split(
",")[0]==
"lxBatch":
344 repMapTemp=repMap.copy()
345 if validationType
not in anythingToMerge:
346 anythingToMerge += [validationType]
348 fileName=
"TkAlMergeInit" 349 filePath = os.path.join(path, fileName+
".sh")
350 theFile = open( filePath,
"w" )
351 repMapTemp[
"createResultsDirectory"]=
"#!/bin/bash" 352 repMapTemp[
"createResultsDirectory"]+=
replaceByMap(configTemplates.createResultsDirectoryTemplate, repMapTemp)
353 theFile.write(
replaceByMap( configTemplates.createResultsDirectoryTemplate, repMapTemp ) )
355 os.chmod(filePath,0o755)
359 repMapTemp[
"createResultsDirectory"]=
"" 363 repMapTemp[
"beforeMerge"] += validationType.doInitMerge()
364 repMapTemp[
"doMerge"] +=
'\n\n\n\necho -e "\n\nMerging results from %s jobs with alignment %s"\n\n' % (validationType.valType,validation.alignmentToValidate.name)
365 repMapTemp[
"doMerge"] += validation.doMerge()
366 for f
in validation.getRepMap()[
"outputFiles"]:
367 longName = os.path.join(
"/eos/cms/store/group/alca_trackeralign/AlignmentValidation/",
368 validation.getRepMap()[
"eosdir"], f)
369 repMapTemp[
"rmUnmerged"] +=
" rm "+longName+
"\n" 371 repMapTemp[
"rmUnmerged"] += (
"else\n" 372 " echo -e \\n\"WARNING: Merging failed, unmerged" 373 " files won't be deleted.\\n" 374 "(Ignore this warning if merging was done earlier)\"\n" 378 repMapTemp[
"DownloadData"] =
replaceByMap( configTemplates.mergeParallelResults, repMapTemp )
380 repMapTemp[
"RunValidationPlots"] = validationType.doRunPlots(validations)
383 fileName=
"TkAlMergeOfflineValidation"+validation.name+validation.alignmentToValidate.name
384 filePath = os.path.join(path, fileName+
".sh")
385 theFile = open( filePath,
"w" )
386 theFile.write(
replaceByMap( configTemplates.mergeParallelOfflineTemplate, repMapTemp ) )
388 os.chmod(filePath,0o755)
390 if "parallel" in parallelMergeObjects:
398 if validationType
not in anythingToMerge:
399 anythingToMerge += [validationType]
400 repMap[
"doMerge"] +=
'\n\n\n\necho -e "\n\nMerging results from %s jobs"\n\n' % validationType.valType
401 repMap[
"beforeMerge"] += validationType.doInitMerge()
402 repMap[
"doMerge"] += validation.doMerge()
403 for f
in validation.getRepMap()[
"outputFiles"]:
404 longName = os.path.join(
"/eos/cms/store/group/alca_trackeralign/AlignmentValidation/",
405 validation.getRepMap()[
"eosdir"], f)
406 repMap[
"rmUnmerged"] +=
" rm "+longName+
"\n" 410 repMap[
"rmUnmerged"] += (
"else\n" 411 " echo -e \\n\"WARNING: Merging failed, unmerged" 412 " files won't be deleted.\\n" 413 "(Ignore this warning if merging was done earlier)\"\n" 419 repMap[
"DownloadData"] +=
replaceByMap( configTemplates.mergeParallelResults, repMap )
421 repMap[
"DownloadData"] =
"" 423 repMap[
"RunValidationPlots"] =
"" 424 for (validationType, referencename), validations
in six.iteritems(comparisonLists):
425 if issubclass(validationType, ValidationWithPlots):
426 repMap[
"RunValidationPlots"] += validationType.doRunPlots(validations)
428 repMap[
"CompareAlignments"] =
"#run comparisons" 429 for (validationType, referencename), validations
in six.iteritems(comparisonLists):
430 if issubclass(validationType, ValidationWithComparison):
431 repMap[
"CompareAlignments"] += validationType.doComparison(validations)
434 if options.mergeOfflineParallel
and parallelMergeObjects!={}:
435 parallelMergeObjects[
"continue"]=
ParallelMergeJob(
"TkAlMergeFinal",os.path.join(path,
"TkAlMergeFinal.sh"),[])
436 filePath = os.path.join(path,
"TkAlMergeFinal.sh")
439 repMap[
"createResultsDirectory"]=
replaceByMap(configTemplates.createResultsDirectoryTemplate, repMap)
440 filePath = os.path.join(path,
"TkAlMerge.sh")
444 theFile = open( filePath,
"w" )
445 theFile.write(
replaceByMap( configTemplates.mergeTemplate, repMap ) )
447 os.chmod(filePath,0o755)
449 if options.mergeOfflineParallel:
450 return {
'TkAlMerge.sh':filePath,
'parallelMergeObjects':parallelMergeObjects}
def createMergeScript(path, validations, options)
— Classes —############################
def replaceByMap(target, the_map)
— Helpers —############################