ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/VHbb/python/submitThem.py
Revision: 1.24
Committed: Wed Jan 16 16:22:47 2013 UTC (12 years, 3 months ago) by peller
Content type: text/x-python
Branch: MAIN
Changes since 1.23: +4 -7 lines
Log Message:
reorganized the whole repository. Macros im myutils, config files in subdirectories. Config file split in parts. Path config file restructured. Moved all path options to the path config. Changed the code accordingly.

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 nmohr 1.7 import getpass
5 peller 1.24 from myutils import BetterConfigParser, sample, parse_info
6 nmohr 1.7
7 nmohr 1.6 parser = OptionParser()
8     parser.add_option("-T", "--tag", dest="tag", default="",
9     help="Tag to run the analysis with, example '8TeV' uses config8TeV and pathConfig8TeV to run the analysis")
10 peller 1.9 parser.add_option("-J", "--task", dest="task", default="",
11 nmohr 1.19 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 (or 'syseval' for both). ")
12 peller 1.9 parser.add_option("-M", "--mass", dest="mass", default="125",
13 bortigno 1.10 help="Mass for DC or Plots, 110...135")
14     parser.add_option("-S","--samples",dest="samples",default="",
15     help="samples you want to run on")
16    
17 nmohr 1.6
18     (opts, args) = parser.parse_args(sys.argv)
19     if opts.tag == "":
20     print "Please provide tag to run the analysis with, example '-T 8TeV' uses config8TeV and pathConfig8TeV to run the analysis."
21     sys.exit(123)
22 peller 1.9
23     if opts.task == "":
24     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"
25     sys.exit(123)
26    
27 bortigno 1.11 #create the list with the samples to run over
28     samplesList=opts.samples.split(",")
29 bortigno 1.10
30 nmohr 1.6 en = opts.tag
31 peller 1.24 #configs = ['config%s'%(en),'pathConfig%s'%(en)]
32     configs = ['#sconfig/general'%(en),'#sconfig/paths'%(en),'#sconfig/plots'%(en),'#sconfig/training'%(en),'#sconfig/datacards'%(en),'#sconfig/cuts'%(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.14 #check if the logPath exist. If not exit
47     if( not os.path.isdir(logPath) ):
48     print 'ERROR: ' + logPath + ': dir not found.'
49     print 'ERROR: Create it before submitting '
50     print 'Exit'
51     sys.exit(-1)
52    
53 nmohr 1.16 repDict = {'en':en,'logpath':logPath,'job':'','task':opts.task,'queue': 'all.q'}
54 nmohr 1.6 def submit(job,repDict):
55     repDict['job'] = job
56 nmohr 1.16 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
57 nmohr 1.1 print command
58     subprocess.call([command], shell=True)
59    
60 peller 1.9 if opts.task == 'dc':
61 peller 1.18 #DC_vars = config.items('Limit')
62     DC_vars= (config.get('LimitGeneral','List')).split(',')
63     print DC_vars
64    
65 peller 1.9 if opts.task == 'plot':
66 peller 1.15 Plot_vars= (config.get('Plot_general','List')).split(',')
67 peller 1.8
68 peller 1.12 if not opts.task == 'prep':
69     path = config.get("Directories","samplepath")
70 nmohr 1.21 samplesinfo = config.get("Directories","samplesinfo")
71 peller 1.24 info = parse_info(samplesinfo,path)
72 peller 1.8
73 peller 1.9 if opts.task == 'plot':
74 peller 1.23 repDict['queue'] = 'all.q'
75 peller 1.9 for item in Plot_vars:
76 peller 1.15 submit(item,repDict)
77 peller 1.9
78     elif opts.task == 'dc':
79 peller 1.23 repDict['queue'] = 'all.q'
80 peller 1.9 for item in DC_vars:
81 peller 1.22 if 'ZH%s'%opts.mass in item:
82 peller 1.18 submit(item,repDict)
83 peller 1.22 elif 'ZH' in item and opts.mass == 'all':
84 peller 1.18 submit(item,repDict)
85 peller 1.17
86 peller 1.9 elif opts.task == 'prep':
87     submit('prepare',repDict)
88    
89 nmohr 1.19 elif opts.task == 'eval' or opts.task == 'sys' or opts.task == 'syseval':
90 bortigno 1.10 if ( opts.samples == ""):
91     for job in info:
92     submit(job.name,repDict)
93     else:
94 bortigno 1.11 for sample in samplesList:
95 bortigno 1.10 submit(sample,repDict)
96 peller 1.20
97     os.system('qstat')