ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/VHbb/python/submitThem.py
Revision: 1.9
Committed: Fri Sep 28 14:15:01 2012 UTC (12 years, 7 months ago) by peller
Content type: text/x-python
Branch: MAIN
Changes since 1.8: +32 -20 lines
Log Message:
added options to submit script

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     help="Mass for DC or Plots, 110...135")
15 nmohr 1.6
16     (opts, args) = parser.parse_args(sys.argv)
17     if opts.tag == "":
18     print "Please provide tag to run the analysis with, example '-T 8TeV' uses config8TeV and pathConfig8TeV to run the analysis."
19     sys.exit(123)
20 peller 1.9
21     if opts.task == "":
22     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"
23     sys.exit(123)
24    
25 nmohr 1.6 en = opts.tag
26     configs = ['config%s'%(en),'pathConfig%s'%(en)]
27     print configs
28     config = BetterConfigParser()
29     config.read(configs)
30 nmohr 1.7 btagLibrary = config.get('BTagReshaping','library')
31     submitDir = os.getcwd()
32     os.chdir(os.path.dirname(btagLibrary))
33     if not os.path.exists(btagLibrary):
34     ROOT.gROOT.LoadMacro('%s+'%btagLibrary.replace('_h.so','.h'))
35     shutil.copyfile(os.path.basename(btagLibrary),'/scratch/%s/%s'%(getpass.getuser(),os.path.basename(btagLibrary)))
36     shutil.copyfile('/scratch/%s/%s'%(getpass.getuser(),os.path.basename(btagLibrary)),btagLibrary)
37     os.chdir(submitDir)
38 nmohr 1.6 logPath = config.get("Directories","logpath")
39     repDict = {'en':en,'logpath':logPath,'job':''}
40     def submit(job,repDict):
41     repDict['job'] = job
42 peller 1.9 command = 'qsub -V -cwd -q all.q -N %(job)s_%(en)s -o %(logpath)s/%(job)s_%(en)s.out -e %(logpath)s/%(job)s_%(en)s.err runAll.sh %(job)s %(en)s ' %(repDict) + opts.task
43 nmohr 1.1 print command
44     subprocess.call([command], shell=True)
45    
46 peller 1.9 if opts.task == 'dc':
47     DC_vars = config.items('Limit')
48     if opts.task == 'plot':
49     Plot_vars= config.items('Plot')
50 peller 1.8
51 nmohr 1.6 path = config.get("Directories","samplepath")
52     infofile = open(path+'/env/samples.info','r')
53     info = pickle.load(infofile)
54     infofile.close()
55 nmohr 1.1
56 peller 1.8
57 peller 1.9 if opts.task == 'plot':
58     for item in Plot_vars:
59     if 'ZH%s'%opts.mass in item[0]:
60     submit(item[0],repDict)
61     elif opts.mass == '' and 'ZH' in item[0]:
62     submit(item[0],repDict)
63    
64     elif opts.task == 'dc':
65     for item in DC_vars:
66     if 'ZH%s'%opts.mass in item[0] and opts.tag in item[0]:
67     submit(item[0],repDict)
68     elif 'ZH' in item[0] and opts.tag in item[0] and opts.mass == '*':
69     submit(item[0],repDict)
70     elif opts.task == 'prep':
71     submit('prepare',repDict)
72    
73     elif opts.task == 'eval' or opts.task == 'sys':
74     for job in info:
75 peller 1.8 submit(job.name,repDict)