285 if(len(validations) == 0):
286 raise AllInOneError(
"Cowardly refusing to merge nothing!")
288 config = validations[0].config
289 repMap = config.getGeneral()
292 "CompareAlignments":
"",
293 "RunValidationPlots":
"",
294 "CMSSW_BASE": os.environ[
"CMSSW_BASE"],
295 "SCRAM_ARCH": os.environ[
"SCRAM_ARCH"],
296 "CMSSW_RELEASE_BASE": os.environ[
"CMSSW_RELEASE_BASE"],
300 for validation
in validations:
301 for referenceName
in validation.filesToCompare:
302 validationtype = type(validation)
303 if issubclass(validationtype, PreexistingValidation):
305 for parentclass
in validationtype.mro():
306 if not issubclass(parentclass, PreexistingValidation):
307 validationtype = parentclass
309 key = (validationtype, referenceName)
310 if key
in comparisonLists:
311 comparisonLists[key].
append(validation)
313 comparisonLists[key] = [validation]
317 repMap[
"doMerge"] =
"mergeRetCode=0\n" 318 repMap[
"rmUnmerged"] = (
"if [[ mergeRetCode -eq 0 ]]; then\n" 319 " echo -e \\n\"Merging succeeded, removing original files.\"\n")
320 repMap[
"beforeMerge"] =
"" 321 repMap[
"mergeParallelFilePrefixes"] =
"" 322 repMap[
"createResultsDirectory"]=
"" 329 if options.mergeOfflineParallel:
330 parallelMergeObjects={}
331 for (validationType, referencename), validations
in six.iteritems(comparisonLists):
332 for validation
in validations:
334 if (isinstance(validation, PreexistingValidation)
335 or validation.NJobs == 1
336 or not isinstance(validation, ParallelValidation)):
338 if options.mergeOfflineParallel
and validationType.valType==
'offline' and validation.jobmode.split(
",")[0]==
"lxBatch":
339 repMapTemp=repMap.copy()
340 if validationType
not in anythingToMerge:
341 anythingToMerge += [validationType]
343 fileName=
"TkAlMergeInit" 344 filePath = os.path.join(path, fileName+
".sh")
345 theFile = open( filePath,
"w" )
346 repMapTemp[
"createResultsDirectory"]=
"#!/bin/bash" 347 repMapTemp[
"createResultsDirectory"]+=
replaceByMap(configTemplates.createResultsDirectoryTemplate, repMapTemp)
348 theFile.write(
replaceByMap( configTemplates.createResultsDirectoryTemplate, repMapTemp ) )
350 os.chmod(filePath,0o755)
354 repMapTemp[
"createResultsDirectory"]=
"" 358 repMapTemp[
"beforeMerge"] += validationType.doInitMerge()
359 repMapTemp[
"doMerge"] +=
'\n\n\n\necho -e "\n\nMerging results from %s jobs with alignment %s"\n\n' % (validationType.valType,validation.alignmentToValidate.name)
360 repMapTemp[
"doMerge"] += validation.doMerge()
361 for f
in validation.getRepMap()[
"outputFiles"]:
362 longName = os.path.join(
"/eos/cms/store/caf/user/$USER/",
363 validation.getRepMap()[
"eosdir"], f)
364 repMapTemp[
"rmUnmerged"] +=
" rm "+longName+
"\n" 366 repMapTemp[
"rmUnmerged"] += (
"else\n" 367 " echo -e \\n\"WARNING: Merging failed, unmerged" 368 " files won't be deleted.\\n" 369 "(Ignore this warning if merging was done earlier)\"\n" 373 repMapTemp[
"DownloadData"] =
replaceByMap( configTemplates.mergeParallelResults, repMapTemp )
375 repMapTemp[
"RunValidationPlots"] = validationType.doRunPlots(validations)
378 fileName=
"TkAlMerge"+validation.alignmentToValidate.name
379 filePath = os.path.join(path, fileName+
".sh")
380 theFile = open( filePath,
"w" )
381 theFile.write(
replaceByMap( configTemplates.mergeParallelOfflineTemplate, repMapTemp ) )
383 os.chmod(filePath,0o755)
385 if "parallel" in parallelMergeObjects:
393 if validationType
not in anythingToMerge:
394 anythingToMerge += [validationType]
395 repMap[
"doMerge"] +=
'\n\n\n\necho -e "\n\nMerging results from %s jobs"\n\n' % validationType.valType
396 repMap[
"beforeMerge"] += validationType.doInitMerge()
397 repMap[
"doMerge"] += validation.doMerge()
398 for f
in validation.getRepMap()[
"outputFiles"]:
399 longName = os.path.join(
"/eos/cms/store/caf/user/$USER/",
400 validation.getRepMap()[
"eosdir"], f)
401 repMap[
"rmUnmerged"] +=
" rm "+longName+
"\n" 405 repMap[
"rmUnmerged"] += (
"else\n" 406 " echo -e \\n\"WARNING: Merging failed, unmerged" 407 " files won't be deleted.\\n" 408 "(Ignore this warning if merging was done earlier)\"\n" 414 repMap[
"DownloadData"] +=
replaceByMap( configTemplates.mergeParallelResults, repMap )
416 repMap[
"DownloadData"] =
"" 418 repMap[
"RunValidationPlots"] =
"" 419 for (validationType, referencename), validations
in six.iteritems(comparisonLists):
420 if issubclass(validationType, ValidationWithPlots):
421 repMap[
"RunValidationPlots"] += validationType.doRunPlots(validations)
423 repMap[
"CompareAlignments"] =
"#run comparisons" 424 for (validationType, referencename), validations
in six.iteritems(comparisonLists):
425 if issubclass(validationType, ValidationWithComparison):
426 repMap[
"CompareAlignments"] += validationType.doComparison(validations)
429 if options.mergeOfflineParallel
and parallelMergeObjects!={}:
430 parallelMergeObjects[
"continue"]=
ParallelMergeJob(
"TkAlMergeFinal",os.path.join(path,
"TkAlMergeFinal.sh"),[])
431 filePath = os.path.join(path,
"TkAlMergeFinal.sh")
434 repMap[
"createResultsDirectory"]=
replaceByMap(configTemplates.createResultsDirectoryTemplate, repMap)
435 filePath = os.path.join(path,
"TkAlMerge.sh")
439 theFile = open( filePath,
"w" )
440 theFile.write(
replaceByMap( configTemplates.mergeTemplate, repMap ) )
442 os.chmod(filePath,0o755)
444 if options.mergeOfflineParallel:
445 return {
'TkAlMerge.sh':filePath,
'parallelMergeObjects':parallelMergeObjects}
def createMergeScript(path, validations, options)
— Classes —############################
def replaceByMap(target, the_map)
— Helpers —############################