-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSubmitCondorJob.py
executable file
·100 lines (80 loc) · 2.58 KB
/
SubmitCondorJob.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#!/bin/env python
import os
import sys
import argparse
import importlib
CMSSW_BASE = os.environ['CMSSW_BASE']
sub ="""
executable = {0}/src/CPVAnalysis/SentJob.sh
arguments = $(cmd) $(opt) $(ClusterID) $(ProcId)
output = /afs/cern.ch/user/p/pusheng/condor/output/{1}.$(ClusterID).$(ProcId).out
error = /afs/cern.ch/user/p/pusheng/condor/error/{1}.$(ClusterID).$(ProcId).err
log = /afs/cern.ch/user/p/pusheng/condor/log/{1}.$(ClusterID).$(ProcId).log
requirements = (OpSysAndVer =?= "CentOS7")
+JobFlavour = "longlunch"
queue cmd,opt from job.dat
"""
def MakeName( cmd, trailer ):
for t in trailer.split(' '):
if "--" in t:
cmd += "_" + t[2:]
elif "-" in t:
pass
else:
cmd += "_" + t
return cmd
def main(args):
parser = argparse.ArgumentParser(
"Submit jobs for commands"
)
parser.add_argument(
'-C', '--Command',
help='Main command',
type=str,
required=True
)
parser.add_argument(
'-T', '--Trailer',
help='Trailer command line',
type=str,
default=""
)
parser.add_argument(
'-S', '--Samplelst',
help='Input sample list',
type=str
)
parser.add_argument(
'--test',
help='test',
action='store_true'
)
try:
opt = parser.parse_args(args[1:])
except:
parser.print_help()
raise
if opt.Command in ("PreCut", "FullCut") :
subdir = "CPVAnalysis.BaseLineSelector."
elif opt.Command in ("MakeHist") :
subdir = "CPVAnalysis.CompareDataMC."
samplelst = importlib.import_module( subdir + opt.Command )
if opt.test:
for sample in getattr( samplelst, opt.Samplelst ):
trailer = "{} -s {}".format( opt.Trailer, sample )
os.system("{} {}".format( opt.Command, trailer ) )
return
# writing dat file
output_dat = open( "job.dat", 'w' )
for sample in getattr( samplelst, opt.Samplelst ):
trailer = "{} -s {}".format( opt.Trailer, sample )
output_dat.write( '{0}, {1}\n'.format( opt.Command, trailer ) )
output_dat.close()
output_sub = open( "job.sub", 'w' )
output_sub.write( sub.format( CMSSW_BASE, MakeName( opt.Command, opt.Trailer ) ) )
output_sub.close()
os.system( "condor_submit {}".format( "job.sub" ) )
os.system( "rm job.sub" )
os.system( "rm job.dat" )
if __name__ == '__main__':
main(sys.argv)