1 |
|
#! /usr/bin/env python |
2 |
– |
import os,shutil,sys,pickle,subprocess,ROOT |
2 |
|
from optparse import OptionParser |
3 |
< |
from BetterConfigParser import BetterConfigParser |
4 |
< |
from samplesclass import sample |
5 |
< |
import getpass |
3 |
> |
import sys |
4 |
> |
import time |
5 |
> |
import os |
6 |
> |
import shutil |
7 |
|
|
8 |
|
parser = OptionParser() |
9 |
|
parser.add_option("-T", "--tag", dest="tag", default="", |
14 |
|
help="Mass for DC or Plots, 110...135") |
15 |
|
parser.add_option("-S","--samples",dest="samples",default="", |
16 |
|
help="samples you want to run on") |
17 |
+ |
parser.add_option("-F", "--folderTag", dest="ftag", default="", |
18 |
+ |
help="Creats a new folder structure for outputs or uses an existing one with the given name") |
19 |
+ |
(opts, args) = parser.parse_args(sys.argv) |
20 |
|
|
21 |
+ |
import os,shutil,pickle,subprocess,ROOT |
22 |
+ |
ROOT.gROOT.SetBatch(True) |
23 |
+ |
from myutils import BetterConfigParser, Sample, ParseInfo |
24 |
+ |
import getpass |
25 |
|
|
19 |
– |
(opts, args) = parser.parse_args(sys.argv) |
26 |
|
if opts.tag == "": |
27 |
|
print "Please provide tag to run the analysis with, example '-T 8TeV' uses config8TeV and pathConfig8TeV to run the analysis." |
28 |
|
sys.exit(123) |
31 |
|
print "Please provide a task.\n-J prep:\tpreparation of Trees\n-J sys:\t\twrite regression and systematics\n-J eval:\tcreate MVA output\n-J plot:\tproduce Plots\n-J dc:\t\twrite workspaces and datacards" |
32 |
|
sys.exit(123) |
33 |
|
|
34 |
+ |
|
35 |
+ |
en = opts.tag |
36 |
+ |
|
37 |
|
#create the list with the samples to run over |
38 |
|
samplesList=opts.samples.split(",") |
39 |
|
|
40 |
< |
en = opts.tag |
41 |
< |
configs = ['config%s'%(en),'pathConfig%s'%(en)] |
42 |
< |
|
40 |
> |
timestamp = time.asctime().replace(' ','_').replace(':','-') |
41 |
> |
|
42 |
> |
configs = ['%sconfig/general'%(en),'%sconfig/paths'%(en),'%sconfig/plots'%(en),'%sconfig/training'%(en),'%sconfig/datacards'%(en),'%sconfig/cuts'%(en)] |
43 |
> |
|
44 |
> |
pathconfig = BetterConfigParser() |
45 |
> |
pathconfig.read('%sconfig/paths'%(en)) |
46 |
> |
|
47 |
> |
if not opts.ftag == '': |
48 |
> |
tagDir = pathconfig.get('Directories','tagDir') |
49 |
> |
DirStruct={'tagDir':tagDir,'ftagdir':'%s/%s/'%(tagDir,opts.ftag),'logpath':'%s/%s/%s/'%(tagDir,opts.ftag,'Logs'),'plotpath':'%s/%s/%s/'%(tagDir,opts.ftag,'Plots'),'limitpath':'%s/%s/%s/'%(tagDir,opts.ftag,'Limits'),'confpath':'%s/%s/%s/'%(tagDir,opts.ftag,'config') } |
50 |
> |
|
51 |
> |
for keys in ['tagDir','ftagdir','logpath','plotpath','limitpath','confpath']: |
52 |
> |
try: |
53 |
> |
os.stat(DirStruct[keys]) |
54 |
> |
except: |
55 |
> |
os.mkdir(DirStruct[keys]) |
56 |
> |
|
57 |
> |
pathfile = open('%sconfig/paths'%(en)) |
58 |
> |
buffer = pathfile.readlines() |
59 |
> |
pathfile.close() |
60 |
> |
os.rename('%sconfig/paths'%(en),'%sconfig/paths.bkp'%(en)) |
61 |
> |
pathfile = open('%sconfig/paths'%(en),'w') |
62 |
> |
for line in buffer: |
63 |
> |
if line.startswith('plotpath'): |
64 |
> |
line = 'plotpath: %s\n'%DirStruct['plotpath'] |
65 |
> |
elif line.startswith('logpath'): |
66 |
> |
line = 'logpath: %s\n'%DirStruct['logpath'] |
67 |
> |
elif line.startswith('limits'): |
68 |
> |
line = 'limits: %s\n'%DirStruct['limitpath'] |
69 |
> |
pathfile.write(line) |
70 |
> |
pathfile.close() |
71 |
> |
|
72 |
> |
#copy config files |
73 |
> |
for item in configs: |
74 |
> |
shutil.copyfile(item,'%s/%s/%s'%(tagDir,opts.ftag,item.strip(en))) |
75 |
> |
|
76 |
> |
|
77 |
|
print configs |
78 |
|
config = BetterConfigParser() |
79 |
|
config.read(configs) |
80 |
+ |
|
81 |
|
btagLibrary = config.get('BTagReshaping','library') |
82 |
|
submitDir = os.getcwd() |
83 |
|
os.chdir(os.path.dirname(btagLibrary)) |
94 |
|
print 'Exit' |
95 |
|
sys.exit(-1) |
96 |
|
|
97 |
< |
repDict = {'en':en,'logpath':logPath,'job':'','task':opts.task,'queue': 'all.q'} |
97 |
> |
repDict = {'en':en,'logpath':logPath,'job':'','task':opts.task,'queue': 'all.q','timestamp':timestamp} |
98 |
|
def submit(job,repDict): |
99 |
|
repDict['job'] = job |
100 |
< |
command = 'qsub -V -cwd -q %(queue)s -N %(job)s_%(en)s%(task)s -o %(logpath)s/%(job)s_%(en)s_%(task)s.out -e %(logpath)s/%(job)s_%(en)s_%(task)s.err runAll.sh %(job)s %(en)s ' %(repDict) + opts.task |
100 |
> |
command = 'qsub -V -cwd -q %(queue)s -l h_vmem=6G -N %(job)s_%(en)s%(task)s -o %(logpath)s/%(timestamp)s_%(job)s_%(en)s_%(task)s.out -e %(logpath)s/%(timestamp)s_%(job)s_%(en)s_%(task)s.err runAll.sh %(job)s %(en)s ' %(repDict) + opts.task |
101 |
|
print command |
102 |
|
subprocess.call([command], shell=True) |
103 |
|
|
112 |
|
if not opts.task == 'prep': |
113 |
|
path = config.get("Directories","samplepath") |
114 |
|
samplesinfo = config.get("Directories","samplesinfo") |
115 |
< |
infofile = open(samplesinfo,'r') |
72 |
< |
info = pickle.load(infofile) |
73 |
< |
infofile.close() |
74 |
< |
|
115 |
> |
info = ParseInfo(samplesinfo,path) |
116 |
|
|
117 |
|
if opts.task == 'plot': |
118 |
< |
repDict['queue'] = 'short.q' |
118 |
> |
repDict['queue'] = 'all.q' |
119 |
|
for item in Plot_vars: |
120 |
|
submit(item,repDict) |
121 |
|
|
122 |
|
elif opts.task == 'dc': |
123 |
< |
repDict['queue'] = 'short.q' |
123 |
> |
repDict['queue'] = 'all.q' |
124 |
|
for item in DC_vars: |
125 |
|
if 'ZH%s'%opts.mass in item: |
126 |
|
submit(item,repDict) |
139 |
|
submit(sample,repDict) |
140 |
|
|
141 |
|
os.system('qstat') |
142 |
+ |
os.system('./qstat.py') |