-
Notifications
You must be signed in to change notification settings - Fork 1
/
launch.py
136 lines (109 loc) · 4.53 KB
/
launch.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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
import subprocess
import os
import sys
from optparse import OptionParser
eos_dir = "/eos/cms/store/group/dpg_tracker_strip/comm_tracker/Strip/Calibration/calibrationtree/GR18"
#current dir
cwd = os.getcwd()
##################################################
# Parse options
##################################################
def_workdir = "/afs/cern.ch/work/e/echabert/private/SiStrip/StoN"
def_pbs_queue = "1nh"
def_tree="both"
def_runnumber = "321305"
def_script = "demo.sh"
#define the binnings
def_nBinsX = 20
#def_minX = 9000
def_minX = 0
def_maxX = 20000
def_nBinsY = 1000
def_minY = 0
def_maxY = 1000
parser = OptionParser()
#define the options
parser.add_option("-d","--workdir", dest="workdir", help="working directory path where output of jobs will be stored", default=def_workdir)
parser.add_option("-q","--queue", dest="queue", help="pbs queue", default=def_pbs_queue)
parser.add_option("-t","--tree", dest="tree", help="choose input tree(s) - 3 options:\n std_bunch, aag, both", default=def_tree)
parser.add_option("-r","--runs", dest="runs", help="list of run numbers - has to be written in quotes or separated with comma without space ", default=def_runnumber)
parser.add_option("-s","--script", dest="script", help="demo script file - template of job launch", default=def_script)
parser.add_option("--nBinsX", dest="nBinsX", help="number of bins - X axis", default=def_nBinsX)
parser.add_option("--nBinsY", dest="nBinsY", help="number of bins - Y axis", default=def_nBinsY)
parser.add_option("--minX", dest="minX", help="range of X axis: min", default=def_minX)
parser.add_option("--maxX", dest="maxX", help="range of X axis: max", default=def_maxX)
parser.add_option("--minY", dest="minY", help="range of Y axis: min", default=def_minY)
parser.add_option("--maxY", dest="maxY", help="range of Y axis: max", default=def_maxY)
parser.add_option("--maxEvents", dest="maxEvents", help="debug mode - enter max events (default = -1)", default=-1)
(options, args) = parser.parse_args()
##################################################
# Create directories
##################################################
launchdir = options.workdir+str("/launch")
if not os.path.exists(launchdir):
os.makedirs(launchdir)
if not os.path.exists(options.workdir+str("/tmp")):
os.makedirs(options.workdir+str("/tmp"))
if not os.path.exists(options.workdir+str("/tmp/std_bunch")):
os.makedirs(options.workdir+str("/tmp/std_bunch"))
if not os.path.exists(options.workdir+str("/tmp/aag")):
os.makedirs(options.workdir+str("/tmp/aag"))
#f = open("demo.sh")
f = open(options.script)
content = f.read()
##################################################
# Run for aag /std_bunch or both
##################################################
tree_list = []
if options.tree == "both":
tree_list = ["std_bunch","aag"]
if options.tree == "aag":
tree_list = ["aag"]
if options.tree == "std_bunch":
tree_list = ["std_bunch"]
for tree in tree_list:
fulllist = ""
if tree == "std_bunch":
fulllist = subprocess.check_output(['ls',eos_dir])
if tree == "aag":
fulllist = subprocess.check_output(['ls',eos_dir+"_Aag"])
runs = [el for el in options.runs.replace(',',' ').split(' ') if el !=str() ]
calibTreeList = []
for run in runs:
print "RUN = ", run
cList = [ i for i in fulllist.split('\n') if i.find(str(run))>0]
print cList
calibTreeList.extend(cList)
for file in calibTreeList:
#modify content
ocontent = content
theOptions = " --file "+file+str(" -d ")+options.workdir
theOptions+=" -t "+tree
theOptions+=" --maxEvents \""+str(options.maxEvents)+"\""
theOptions+=" --nBinsX "+str(options.nBinsX)
theOptions+=" --nBinsY "+str(options.nBinsY)
theOptions+=" --minX "+str(options.minX)
theOptions+=" --minY "+str(options.minY)
theOptions+=" --maxX "+str(options.maxX)
theOptions+=" --maxY "+str(options.maxY)
ocontent = ocontent.replace("OPTIONS",theOptions)
#create file job
filename = launchdir+"/job_"+file+"_"+tree+"_.sh"
ofile = open(filename,"w")
ofile.write(ocontent)
ofile.close()
#go to the launch directory
os.chdir(launchdir)
#launch the job
#command = ["bsub","-q","8nm",filename]
#mailoption = "-o /dev/null -e /dev/null"
mailoption = ""
#command = ["LSB_JOB_REPORT_MAIL=N","bsub","-q",options.queue,mailoption,filename]
command = ["bsub","-q",options.queue,mailoption,filename]
print command
#subprocess.call(command)
p = subprocess.Popen(["chmod","+x",filename], stdout=subprocess.PIPE)
p = subprocess.Popen(command, stdout=subprocess.PIPE)
print p.communicate()
#go back
os.chdir(cwd)