283 if(len(validations) == 0):
284 raise AllInOneError(
"Cowardly refusing to merge nothing!")
286 config = validations[0].config
287 repMap = config.getGeneral()
290 "CompareAlignments":
"",
291 "RunValidationPlots":
"",
292 "CMSSW_BASE": os.environ[
"CMSSW_BASE"],
293 "SCRAM_ARCH": os.environ[
"SCRAM_ARCH"],
294 "CMSSW_RELEASE_BASE": os.environ[
"CMSSW_RELEASE_BASE"],
298 for validation
in validations:
299 for referenceName
in validation.filesToCompare:
300 validationtype = type(validation)
301 if issubclass(validationtype, PreexistingValidation):
303 for parentclass
in validationtype.mro():
304 if not issubclass(parentclass, PreexistingValidation):
305 validationtype = parentclass
307 key = (validationtype, referenceName)
308 if key
in comparisonLists:
309 comparisonLists[key].
append(validation)
311 comparisonLists[key] = [validation]
315 repMap[
"doMerge"] =
"mergeRetCode=0\n" 316 repMap[
"rmUnmerged"] = (
"if [[ mergeRetCode -eq 0 ]]; then\n" 317 " echo -e \\n\"Merging succeeded, removing original files.\"\n")
318 repMap[
"beforeMerge"] =
"" 319 repMap[
"mergeParallelFilePrefixes"] =
"" 320 repMap[
"createResultsDirectory"]=
"" 327 if options.mergeOfflineParallel:
328 parallelMergeObjects={}
329 for (validationType, referencename), validations
in six.iteritems(comparisonLists):
330 for validation
in validations:
332 if (isinstance(validation, PreexistingValidation)
333 or validation.NJobs == 1
334 or not isinstance(validation, ParallelValidation)):
336 if options.mergeOfflineParallel
and validationType.valType==
'offline' and validation.jobmode.split(
",")[0]==
"lxBatch":
337 repMapTemp=repMap.copy()
338 if validationType
not in anythingToMerge:
339 anythingToMerge += [validationType]
341 fileName=
"TkAlMergeInit" 342 filePath = os.path.join(path, fileName+
".sh")
343 theFile = open( filePath,
"w" )
344 repMapTemp[
"createResultsDirectory"]=
"#!/bin/bash" 345 repMapTemp[
"createResultsDirectory"]+=
replaceByMap(configTemplates.createResultsDirectoryTemplate, repMapTemp)
346 theFile.write(
replaceByMap( configTemplates.createResultsDirectoryTemplate, repMapTemp ) )
348 os.chmod(filePath,0o755)
352 repMapTemp[
"createResultsDirectory"]=
"" 356 repMapTemp[
"beforeMerge"] += validationType.doInitMerge()
357 repMapTemp[
"doMerge"] +=
'\n\n\n\necho -e "\n\nMerging results from %s jobs with alignment %s"\n\n' % (validationType.valType,validation.alignmentToValidate.name)
358 repMapTemp[
"doMerge"] += validation.doMerge()
359 for f
in validation.getRepMap()[
"outputFiles"]:
360 longName = os.path.join(
"/eos/cms/store/caf/user/$USER/",
361 validation.getRepMap()[
"eosdir"], f)
362 repMapTemp[
"rmUnmerged"] +=
" rm "+longName+
"\n" 364 repMapTemp[
"rmUnmerged"] += (
"else\n" 365 " echo -e \\n\"WARNING: Merging failed, unmerged" 366 " files won't be deleted.\\n" 367 "(Ignore this warning if merging was done earlier)\"\n" 371 repMapTemp[
"DownloadData"] =
replaceByMap( configTemplates.mergeParallelResults, repMapTemp )
373 repMapTemp[
"RunValidationPlots"] = validationType.doRunPlots(validations)
376 fileName=
"TkAlMerge"+validation.alignmentToValidate.name
377 filePath = os.path.join(path, fileName+
".sh")
378 theFile = open( filePath,
"w" )
379 theFile.write(
replaceByMap( configTemplates.mergeParallelOfflineTemplate, repMapTemp ) )
381 os.chmod(filePath,0o755)
383 if "parallel" in parallelMergeObjects:
391 if validationType
not in anythingToMerge:
392 anythingToMerge += [validationType]
393 repMap[
"doMerge"] +=
'\n\n\n\necho -e "\n\nMerging results from %s jobs"\n\n' % validationType.valType
394 repMap[
"beforeMerge"] += validationType.doInitMerge()
395 repMap[
"doMerge"] += validation.doMerge()
396 for f
in validation.getRepMap()[
"outputFiles"]:
397 longName = os.path.join(
"/eos/cms/store/caf/user/$USER/",
398 validation.getRepMap()[
"eosdir"], f)
399 repMap[
"rmUnmerged"] +=
" rm "+longName+
"\n" 403 repMap[
"rmUnmerged"] += (
"else\n" 404 " echo -e \\n\"WARNING: Merging failed, unmerged" 405 " files won't be deleted.\\n" 406 "(Ignore this warning if merging was done earlier)\"\n" 412 repMap[
"DownloadData"] +=
replaceByMap( configTemplates.mergeParallelResults, repMap )
414 repMap[
"DownloadData"] =
"" 416 repMap[
"RunValidationPlots"] =
"" 417 for (validationType, referencename), validations
in six.iteritems(comparisonLists):
418 if issubclass(validationType, ValidationWithPlots):
419 repMap[
"RunValidationPlots"] += validationType.doRunPlots(validations)
421 repMap[
"CompareAlignments"] =
"#run comparisons" 422 for (validationType, referencename), validations
in six.iteritems(comparisonLists):
423 if issubclass(validationType, ValidationWithComparison):
424 repMap[
"CompareAlignments"] += validationType.doComparison(validations)
427 if options.mergeOfflineParallel
and parallelMergeObjects!={}:
428 parallelMergeObjects[
"continue"]=
ParallelMergeJob(
"TkAlMergeFinal",os.path.join(path,
"TkAlMergeFinal.sh"),[])
429 filePath = os.path.join(path,
"TkAlMergeFinal.sh")
432 repMap[
"createResultsDirectory"]=
replaceByMap(configTemplates.createResultsDirectoryTemplate, repMap)
433 filePath = os.path.join(path,
"TkAlMerge.sh")
437 theFile = open( filePath,
"w" )
438 theFile.write(
replaceByMap( configTemplates.mergeTemplate, repMap ) )
440 os.chmod(filePath,0o755)
442 if options.mergeOfflineParallel:
443 return {
'TkAlMerge.sh':filePath,
'parallelMergeObjects':parallelMergeObjects}
def createMergeScript(path, validations, options)
— Classes —############################
def replaceByMap(target, the_map)
— Helpers —############################