Belle II Software development
submitJobs.py
1#!/usr/bin/env python3
2
3
10
11# This script submit jobs getting the jobs details (runNo, expNo etc)
12# from a look-up table which should already exist
13
14import os
15import sys
16import csv
17
18
19def submit_job(listArgs, logDir, myCmd):
20 print(listArgs)
21 # end of file name for log files
22 filenameEnd = '_'.join(listArgs)
23
24 # job submission with arguments
25 os.system('bsub ' +
26 ' -q l' +
27 ' -oo ' + logDir + '/' + 'out_' + filenameEnd +
28 ' -eo ' + logDir + '/' + 'err_' + filenameEnd +
29 ' -N' +
30 ' \" ' + myCmd +
31 ' ' + sys.argv[2].lower() + ' ' +
32 ' '.join(listArgs) +
33 '\"')
34
35 # summary
36 print('Submitted job for: ' + ' '.join(listArgs))
37
38
39if len(sys.argv) != 3:
40 sys.exit('Need two arguments: 1) path of look up table, 2) mc or data')
41
42# yourWorkingDirectoryPath = '.'
43# logDir = yourWorkingDirectoryPath + '/analysisLog/'
44
45lookUpTablePath = sys.argv[1]
46
47mc_or_data = sys.argv[2].lower()
48isMC = {"mc": True, "data": False}.get(mc_or_data, None)
49if isMC is None:
50 sys.exit(
51 'Second parameter must be "mc" or "data" to indicate whether we run on MC or real data')
52
53# the job we are submitting
54# myCmd = yourWorkingDirectoryPath + '/analysisJob.sh'
55myCmd = './analysisJob.sh'
56logDir = './analysisLog'
57
58# ================================= Submit jobs ! ========================
59print('Jobs submission ..')
60
61# open look up table
62with open(lookUpTablePath) as f:
63
64 reader = csv.reader(f, delimiter='\t')
65
66 # submit one job for each line , for each streamNo
67 for row in reader:
68 if isMC:
69 print(row)
70 expNo = int(row[0])
71
72 if expNo in range(7, 28):
73 streamNoList = range(10, 20)
74 elif expNo in range(31, 66):
75 streamNoList = range(0, 10)
76
77 for streamNo in streamNoList:
78 # removing empty element at end of line
79 row = row[:-1]
80 # adding streamNo
81 row.append(str(streamNo))
82 submit_job(row, logDir, myCmd)
83 else:
84 # removing empty element at end of line
85 submit_job(row[:-1], logDir, myCmd)