-
Notifications
You must be signed in to change notification settings - Fork 7
/
submit.py
88 lines (68 loc) · 2.85 KB
/
submit.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
import sys, os, pwd, commands
#from tqdm import tqdm
from subprocess import *
import optparse, shlex, re
sys.path.append("inputs/")
from binning import binning
def parseOptions():
global opt, args, runAllSteps
usage = ('usage: %prog [options]\n'
+ '%prog -h for help')
parser = optparse.OptionParser(usage)
# input options
parser.add_option('', '--year', dest='YEAR', type='string',default='Full', help='Year -> 2016 or 2017 or 2018 or Full')
parser.add_option('', '--submit', action='store_true', dest='SUBMIT', default=False, help='Do only scripts')
parser.add_option('', '--unblind', action='store_true', dest='UNBLIND', default=False, help='Use real data')
parser.add_option('', '--fitOnly', action='store_true', dest='FITONLY', default=False, help='Run only fit')
parser.add_option('', '--myID', dest='MYID', type='string', default='', help='Your CERN ID')
# store options and arguments as global variables
global opt, args
(opt, args) = parser.parse_args()
# Define function for processing of os command
def processCmd(cmd, quiet = 0):
output = "\n"
p = Popen(cmd, shell=True, stdout=PIPE, stderr=STDOUT, bufsize=-1)
for line in iter(p.stdout.readline, ""):
output=output+str(line)
print line,
p.stdout.close()
if p.wait() != 0:
raise RuntimeError("%r failed, exit status: %d" % (cmd, p.returncode))
return output
# parse the arguments and options
global opt, args, runAllSteps
parseOptions()
year = str(opt.YEAR)
unblind = opt.UNBLIND
fitOnly = opt.FITONLY
submit = opt.SUBMIT
my_id = opt.MYID
def prepareScript(obs_name, obs_bin, name):
scriptName = './scripts/script_'+name+'.sh'
with open(scriptName, 'w') as f:
f.write('export VO_CMS_SW_DIR=/cvmfs/cms.cern.ch \n')
f.write('source $VO_CMS_SW_DIR/cmsset_default.sh \n')
f.write('echo $MYPSW | /opt/exp_soft/cms/t3/eos-login -keytab -init -username ' + my_id + '\n')
f.write('/opt/exp_soft/cms/t3/eos-login -init -username ' + my_id + '\n')
f.write('cmsenv \n')
pipeline = 'python pipeline.py --obsName "' + obs_name + '" --obsBins "' + obs_bin + '" --year "' + year + '"'
if unblind:
pipeline += " --unblind True"
if fitOnly:
pipeline += " --fitOnly True"
f.write(pipeline)
processCmd('chmod 0744 ' + scriptName)
return scriptName
for key in binning:
_bin = binning[key]
_obs_name = key
_screen_name = key
if ' vs ' in key:
first = key.split(' vs ')[0]
second = key.split(' vs ')[1]
_screen_name = first + '_' + second
_scriptName = prepareScript(_obs_name, _bin, _screen_name)
if submit:
cmd = "screen -dmS "+ _screen_name + " '" + _scriptName + "'"
print(cmd)
processCmd(cmd)