Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleanup after switch to input args #8885

Closed
wants to merge 20 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 32 additions & 24 deletions scripts/CMSRunAnalysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -286,11 +286,10 @@ def handleException(exitAcronym, exitCode, exitMsg):

def parseArgs():
parser = PassThroughOptionParser()
parser.add_option('--jobId', dest='jobId', type='string')
parser.add_option('--json', dest='jsonArgFile', type='string')
parser.add_option('-a', dest='archiveJob', type='string')
parser.add_option('-o', dest='outFiles', type='string')
parser.add_option('--inputFile', dest='inputFile', type='string')
parser.add_option('--sourceURL', dest='sourceURL', type='string')
parser.add_option('--userSandbox', dest='userSandbox', type='string')
parser.add_option('--inputFileList', dest='inputFileList', type='string')
parser.add_option('--jobNumber', dest='jobNumber', type='string')
parser.add_option('--cmsswVersion', dest='cmsswVersion', type='string')
parser.add_option('--scramArch', dest='scramArch', type='string')
Expand Down Expand Up @@ -319,9 +318,32 @@ def parseArgs():
if value == 'None':
setattr(opts, name, None)

# allow for most input arguments to be passed via a JSON file
# in this case only -r and --JobNumber need to be present as arguments
# allow for arguments simply be the jobId (a string because automtic splitting has format like N-M
if getattr(opts, 'jobId', None):
arguments = {}
with open('input_args.json', 'r', encoding='UTF-8') as fh:
allArgs = json.load(fh) # read file prepared by DagmanCreator
for args in allArgs:
if args['CRAB_Id'] == opts.jobId:
arguments = args # pick the arguments for this job
break
if not arguments:
raise Exception("input jobId not found in input_args.json")
for key, value in arguments.items():
setattr(opts, key, value)

# remap key in input_args.json to the argument names required by CMSRunAnalysis.py
# use as : value_of_argument_name = inputArgs[argMap[argument_name]]
# to ease transition to cleaner code the new key are only added if missing
argMap = {
}
for key, value in argMap.items():
if not getattr(opts, key, None):
setattr(opts, key, arguments[value]) # assign to our variables

# allow for most input arguments to be passed via a (job specific) JSON file
if getattr(opts, 'jsonArgFile', None):
arguments = {}
with open(opts.jsonArgFile, 'r', encoding='UTF-8') as fh:
arguments = json.load(fh)
for key, value in arguments.items():
Expand All @@ -338,13 +360,11 @@ def parseArgs():

try:
print(f"==== Parameters Dump at {UTCNow()} ===")
print("archiveJob: ", opts.archiveJob)
print("sourceURL: ", opts.sourceURL)
print("userSandbox: ", opts.userSandbox)
print("jobNumber: ", opts.jobNumber)
print("cmsswVersion: ", opts.cmsswVersion)
print("scramArch: ", opts.scramArch)
print("inputFile ", opts.inputFile)
print("outFiles: ", opts.outFiles)
print("inputFileList ", opts.inputFileList)
print("runAndLumis: ", opts.runAndLumis)
print("lheInputFiles: ", opts.lheInputFiles)
print("firstEvent: ", opts.firstEvent)
Expand Down Expand Up @@ -669,7 +689,7 @@ def compareBrachListWithReference(branchList, tier):
print(f"==== SCRAM Obj INITIALIZED at {UTCNow()} ====")

print("==== Extract user sandbox in top and CMSSW directory ====")
extractUserSandbox(options.archiveJob)
extractUserSandbox(options.userSandbox)

#Multi-microarch env: Setting cmssw env after extracting the sandbox
print(f"==== SCRAM runtime environment CREATED at {UTCNow()} ====")
Expand Down Expand Up @@ -873,19 +893,7 @@ def compareBrachListWithReference(branchList, tier):
mintime()
sys.exit(EC_ReportHandlingErr)

# rename output files. Doing this after checksums otherwise outfile is not found.
if jobExitCode == 0:
try:
oldName = 'UNKNOWN'
newName = 'UNKNOWN'
for oldName, newName in literal_eval(options.outFiles).items():
os.rename(oldName, newName)
except Exception as ex: # pylint: disable=broad-except
handleException("FAILED", EC_MoveOutErr, f"Exception while renaming file {oldName} to {newName}.")
mintime()
sys.exit(EC_MoveOutErr)
else:
mintime()
mintime()

print(f"==== CMSRunAnalysis.py FINISHED at {UTCNow()} ====")
print(f"Local time : {time.ctime()}")
Expand Down
4 changes: 2 additions & 2 deletions scripts/TweakPSet.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,8 @@ def createScriptLines(opts, pklIn):
if opts.runAndLumis:
runAndLumis = readFileFromTarball(opts.runAndLumis, 'run_and_lumis.tar.gz')
inputFiles = {}
if opts.inputFile:
inputFiles = readFileFromTarball(opts.inputFile, 'input_files.tar.gz')
if opts.inputFileList:
inputFiles = readFileFromTarball(opts.inputFileList, 'input_files.tar.gz')

# build a tweak object with the needed changes to be applied to PSet
tweak = PSetTweak()
Expand Down
Loading