286 if(len(validations) == 0):
287 raise AllInOneError(
"Cowardly refusing to merge nothing!")
289 config = validations[0].config
290 repMap = config.getGeneral()
293 "CompareAlignments":
"",
294 "RunValidationPlots":
"",
295 "CMSSW_BASE": os.environ[
"CMSSW_BASE"],
296 "SCRAM_ARCH": os.environ[
"SCRAM_ARCH"],
297 "CMSSW_RELEASE_BASE": os.environ[
"CMSSW_RELEASE_BASE"],
301 for validation
in validations:
302 for referenceName
in validation.filesToCompare:
303 validationtype = type(validation)
304 if issubclass(validationtype, PreexistingValidation):
306 for parentclass
in validationtype.mro():
307 if not issubclass(parentclass, PreexistingValidation):
308 validationtype = parentclass
310 key = (validationtype, referenceName)
311 if key
in comparisonLists:
312 comparisonLists[key].
append(validation)
314 comparisonLists[key] = [validation]
318 repMap[
"doMerge"] =
"mergeRetCode=0\n" 319 repMap[
"rmUnmerged"] = (
"if [[ mergeRetCode -eq 0 ]]; then\n" 320 " echo -e \\n\"Merging succeeded, removing original files.\"\n")
321 repMap[
"beforeMerge"] =
"" 322 repMap[
"mergeParallelFilePrefixes"] =
"" 323 repMap[
"createResultsDirectory"]=
"" 330 if options.mergeOfflineParallel:
331 parallelMergeObjects={}
332 for (validationType, referencename), validations
in six.iteritems(comparisonLists):
333 for validation
in validations:
335 if (isinstance(validation, PreexistingValidation)
336 or validation.NJobs == 1
337 or not isinstance(validation, ParallelValidation)):
339 if options.mergeOfflineParallel
and validationType.valType==
'offline' and validation.jobmode.split(
",")[0]==
"lxBatch":
340 repMapTemp=repMap.copy()
341 if validationType
not in anythingToMerge:
342 anythingToMerge += [validationType]
344 fileName=
"TkAlMergeInit" 345 filePath = os.path.join(path, fileName+
".sh")
346 theFile = open( filePath,
"w" )
347 repMapTemp[
"createResultsDirectory"]=
"#!/bin/bash" 348 repMapTemp[
"createResultsDirectory"]+=
replaceByMap(configTemplates.createResultsDirectoryTemplate, repMapTemp)
349 theFile.write(
replaceByMap( configTemplates.createResultsDirectoryTemplate, repMapTemp ) )
351 os.chmod(filePath,0o755)
355 repMapTemp[
"createResultsDirectory"]=
"" 359 repMapTemp[
"beforeMerge"] += validationType.doInitMerge()
360 repMapTemp[
"doMerge"] +=
'\n\n\n\necho -e "\n\nMerging results from %s jobs with alignment %s"\n\n' % (validationType.valType,validation.alignmentToValidate.name)
361 repMapTemp[
"doMerge"] += validation.doMerge()
362 for f
in validation.getRepMap()[
"outputFiles"]:
363 longName = os.path.join(
"/eos/cms/store/group/alca_trackeralign/AlignmentValidation/",
364 validation.getRepMap()[
"eosdir"], f)
365 repMapTemp[
"rmUnmerged"] +=
" rm "+longName+
"\n" 367 repMapTemp[
"rmUnmerged"] += (
"else\n" 368 " echo -e \\n\"WARNING: Merging failed, unmerged" 369 " files won't be deleted.\\n" 370 "(Ignore this warning if merging was done earlier)\"\n" 374 repMapTemp[
"DownloadData"] =
replaceByMap( configTemplates.mergeParallelResults, repMapTemp )
376 repMapTemp[
"RunValidationPlots"] = validationType.doRunPlots(validations)
379 fileName=
"TkAlMergeOfflineValidation"+validation.name+validation.alignmentToValidate.name
380 filePath = os.path.join(path, fileName+
".sh")
381 theFile = open( filePath,
"w" )
382 theFile.write(
replaceByMap( configTemplates.mergeParallelOfflineTemplate, repMapTemp ) )
384 os.chmod(filePath,0o755)
386 if "parallel" in parallelMergeObjects:
394 if validationType
not in anythingToMerge:
395 anythingToMerge += [validationType]
396 repMap[
"doMerge"] +=
'\n\n\n\necho -e "\n\nMerging results from %s jobs"\n\n' % validationType.valType
397 repMap[
"beforeMerge"] += validationType.doInitMerge()
398 repMap[
"doMerge"] += validation.doMerge()
399 for f
in validation.getRepMap()[
"outputFiles"]:
400 longName = os.path.join(
"/eos/cms/store/group/alca_trackeralign/AlignmentValidation/",
401 validation.getRepMap()[
"eosdir"], f)
402 repMap[
"rmUnmerged"] +=
" rm "+longName+
"\n" 406 repMap[
"rmUnmerged"] += (
"else\n" 407 " echo -e \\n\"WARNING: Merging failed, unmerged" 408 " files won't be deleted.\\n" 409 "(Ignore this warning if merging was done earlier)\"\n" 415 repMap[
"DownloadData"] +=
replaceByMap( configTemplates.mergeParallelResults, repMap )
417 repMap[
"DownloadData"] =
"" 419 repMap[
"RunValidationPlots"] =
"" 420 for (validationType, referencename), validations
in six.iteritems(comparisonLists):
421 if issubclass(validationType, ValidationWithPlots):
422 repMap[
"RunValidationPlots"] += validationType.doRunPlots(validations)
424 repMap[
"CompareAlignments"] =
"#run comparisons" 425 for (validationType, referencename), validations
in six.iteritems(comparisonLists):
426 if issubclass(validationType, ValidationWithComparison):
427 repMap[
"CompareAlignments"] += validationType.doComparison(validations)
430 if options.mergeOfflineParallel
and parallelMergeObjects!={}:
431 parallelMergeObjects[
"continue"]=
ParallelMergeJob(
"TkAlMergeFinal",os.path.join(path,
"TkAlMergeFinal.sh"),[])
432 filePath = os.path.join(path,
"TkAlMergeFinal.sh")
435 repMap[
"createResultsDirectory"]=
replaceByMap(configTemplates.createResultsDirectoryTemplate, repMap)
436 filePath = os.path.join(path,
"TkAlMerge.sh")
440 theFile = open( filePath,
"w" )
441 theFile.write(
replaceByMap( configTemplates.mergeTemplate, repMap ) )
443 os.chmod(filePath,0o755)
445 if options.mergeOfflineParallel:
446 return {
'TkAlMerge.sh':filePath,
'parallelMergeObjects':parallelMergeObjects}
def createMergeScript(path, validations, options)
— Classes —############################
def replaceByMap(target, the_map)
— Helpers —############################