ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/VHbb/python/submitThem.py
Revision: 1.13
Committed: Mon Oct 1 11:33:24 2012 UTC (12 years, 7 months ago) by bortigno
Content type: text/x-python
Branch: MAIN
Changes since 1.12: +2 -2 lines
Log Message:
log files separated by task

File Contents

# User Rev Content
1 nmohr 1.1 #! /usr/bin/env python
2 nmohr 1.7 import os,shutil,sys,pickle,subprocess,ROOT
3 nmohr 1.6 from optparse import OptionParser
4     from BetterConfigParser import BetterConfigParser
5     from samplesclass import sample
6 nmohr 1.7 import getpass
7    
8 nmohr 1.6 parser = OptionParser()
9     parser.add_option("-T", "--tag", dest="tag", default="",
10     help="Tag to run the analysis with, example '8TeV' uses config8TeV and pathConfig8TeV to run the analysis")
11 peller 1.9 parser.add_option("-J", "--task", dest="task", default="",
12     help="Task to be done, i.e. 'dc' for Datacards, 'prep' for preparation of Trees, 'plot' to produce plots or 'eval' to write the MVA output or 'sys' to write regression and systematics. ")
13     parser.add_option("-M", "--mass", dest="mass", default="125",
14 bortigno 1.10 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    
18 nmohr 1.6
19     (opts, args) = parser.parse_args(sys.argv)
20     if opts.tag == "":
21     print "Please provide tag to run the analysis with, example '-T 8TeV' uses config8TeV and pathConfig8TeV to run the analysis."
22     sys.exit(123)
23 peller 1.9
24     if opts.task == "":
25     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"
26     sys.exit(123)
27    
28 bortigno 1.11 #create the list with the samples to run over
29     samplesList=opts.samples.split(",")
30 bortigno 1.10
31 nmohr 1.6 en = opts.tag
32     configs = ['config%s'%(en),'pathConfig%s'%(en)]
33 bortigno 1.10
34 nmohr 1.6 print configs
35     config = BetterConfigParser()
36     config.read(configs)
37 nmohr 1.7 btagLibrary = config.get('BTagReshaping','library')
38     submitDir = os.getcwd()
39     os.chdir(os.path.dirname(btagLibrary))
40     if not os.path.exists(btagLibrary):
41     ROOT.gROOT.LoadMacro('%s+'%btagLibrary.replace('_h.so','.h'))
42     shutil.copyfile(os.path.basename(btagLibrary),'/scratch/%s/%s'%(getpass.getuser(),os.path.basename(btagLibrary)))
43     shutil.copyfile('/scratch/%s/%s'%(getpass.getuser(),os.path.basename(btagLibrary)),btagLibrary)
44     os.chdir(submitDir)
45 nmohr 1.6 logPath = config.get("Directories","logpath")
46 bortigno 1.13 repDict = {'en':en,'logpath':logPath,'job':'','task':opts.task}
47 nmohr 1.6 def submit(job,repDict):
48     repDict['job'] = job
49 bortigno 1.13 command = 'qsub -V -cwd -q all.q -N %(job)s_%(en)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
50 nmohr 1.1 print command
51     subprocess.call([command], shell=True)
52    
53 peller 1.9 if opts.task == 'dc':
54     DC_vars = config.items('Limit')
55     if opts.task == 'plot':
56     Plot_vars= config.items('Plot')
57 peller 1.8
58 peller 1.12 if not opts.task == 'prep':
59     path = config.get("Directories","samplepath")
60     infofile = open(path+'/env/samples.info','r')
61     info = pickle.load(infofile)
62     infofile.close()
63 nmohr 1.1
64 peller 1.8
65 peller 1.9 if opts.task == 'plot':
66     for item in Plot_vars:
67     if 'ZH%s'%opts.mass in item[0]:
68     submit(item[0],repDict)
69     elif opts.mass == '' and 'ZH' in item[0]:
70     submit(item[0],repDict)
71    
72     elif opts.task == 'dc':
73     for item in DC_vars:
74     if 'ZH%s'%opts.mass in item[0] and opts.tag in item[0]:
75     submit(item[0],repDict)
76     elif 'ZH' in item[0] and opts.tag in item[0] and opts.mass == '*':
77     submit(item[0],repDict)
78     elif opts.task == 'prep':
79     submit('prepare',repDict)
80    
81     elif opts.task == 'eval' or opts.task == 'sys':
82 bortigno 1.10 if ( opts.samples == ""):
83     for job in info:
84     submit(job.name,repDict)
85     else:
86 bortigno 1.11 for sample in samplesList:
87 bortigno 1.10 submit(sample,repDict)
88