ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/VHbb/python/submitThem.py
(Generate patch)

Comparing UserCode/VHbb/python/submitThem.py (file contents):
Revision 1.10 by bortigno, Sun Sep 30 17:36:39 2012 UTC vs.
Revision 1.26 by bortigno, Wed Jan 23 13:25:16 2013 UTC

# Line 1 | Line 1
1   #! /usr/bin/env python
2 import os,shutil,sys,pickle,subprocess,ROOT
2   from optparse import OptionParser
3 < from BetterConfigParser import BetterConfigParser
5 < from samplesclass import sample
6 < import getpass
3 > import sys
4  
5   parser = OptionParser()
6   parser.add_option("-T", "--tag", dest="tag", default="",
7                        help="Tag to run the analysis with, example '8TeV' uses config8TeV and pathConfig8TeV to run the analysis")
8   parser.add_option("-J", "--task", dest="task", default="",
9 <                      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. ")
9 >                      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). ")
10   parser.add_option("-M", "--mass", dest="mass", default="125",
11                        help="Mass for DC or Plots, 110...135")
12   parser.add_option("-S","--samples",dest="samples",default="",
13                        help="samples you want to run on")
14  
18
15   (opts, args) = parser.parse_args(sys.argv)
16 +
17 + import os,shutil,pickle,subprocess,ROOT
18 + from myutils import BetterConfigParser, sample, parse_info
19 + import getpass
20 +
21   if opts.tag == "":
22          print "Please provide tag to run the analysis with, example '-T 8TeV' uses config8TeV and pathConfig8TeV to run the analysis."
23          sys.exit(123)
# Line 25 | Line 26 | if opts.task == "":
26      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"
27      sys.exit(123)
28  
29 < #create the dictionary with the samples to run over
30 < samplesDict=opts.samples.split(",")
29 > #create the list with the samples to run over
30 > samplesList=opts.samples.split(",")
31  
32   en = opts.tag
33 < configs = ['config%s'%(en),'pathConfig%s'%(en)]
33 > configs = ['%sconfig/general'%(en),'%sconfig/paths'%(en),'%sconfig/plots'%(en),'%sconfig/training'%(en),'%sconfig/datacards'%(en),'%sconfig/cuts'%(en)]
34          
35   print configs
36   config = BetterConfigParser()
# Line 43 | Line 44 | shutil.copyfile(os.path.basename(btagLib
44   shutil.copyfile('/scratch/%s/%s'%(getpass.getuser(),os.path.basename(btagLibrary)),btagLibrary)
45   os.chdir(submitDir)
46   logPath = config.get("Directories","logpath")
47 < repDict = {'en':en,'logpath':logPath,'job':''}
47 > #check if the logPath exist. If not exit
48 > if( not os.path.isdir(logPath) ):
49 >        print 'ERROR: ' + logPath + ': dir not found.'
50 >        print 'ERROR: Create it before submitting '
51 >        print 'Exit'
52 >        sys.exit(-1)
53 >
54 > repDict = {'en':en,'logpath':logPath,'job':'','task':opts.task,'queue': 'all.q'}
55   def submit(job,repDict):
56          repDict['job'] = job
57 <        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
57 >        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
58          print command
59          subprocess.call([command], shell=True)
60  
61   if opts.task == 'dc':
62 <    DC_vars = config.items('Limit')
63 < if opts.task == 'plot':
64 <    Plot_vars= config.items('Plot')
62 >    #DC_vars = config.items('Limit')
63 >    DC_vars= (config.get('LimitGeneral','List')).split(',')
64 >    print DC_vars
65  
66 < path = config.get("Directories","samplepath")
67 < infofile = open(path+'/env/samples.info','r')
60 < info = pickle.load(infofile)
61 < infofile.close()
66 > if opts.task == 'plot':
67 >    Plot_vars= (config.get('Plot_general','List')).split(',')
68  
69 + if not opts.task == 'prep':
70 +    path = config.get("Directories","samplepath")
71 +    samplesinfo = config.get("Directories","samplesinfo")
72 +    info = parse_info(samplesinfo,path)
73  
74   if opts.task == 'plot':
75 +    repDict['queue'] = 'all.q'
76      for item in Plot_vars:
77 <        if 'ZH%s'%opts.mass in item[0]:
67 <            submit(item[0],repDict)
68 <        elif opts.mass == '' and 'ZH' in item[0]:
69 <            submit(item[0],repDict)
77 >        submit(item,repDict)
78  
79   elif opts.task == 'dc':
80 +    repDict['queue'] = 'all.q'
81      for item in DC_vars:
82 <        if 'ZH%s'%opts.mass in item[0] and opts.tag in item[0]:
83 <            submit(item[0],repDict)
84 <        elif 'ZH' in item[0] and opts.tag in item[0] and opts.mass == '*':
85 <            submit(item[0],repDict)
82 >        if 'ZH%s'%opts.mass in item:
83 >            submit(item,repDict)
84 >        elif 'ZH' in item and opts.mass == 'all':
85 >            submit(item,repDict)
86 >            
87   elif opts.task == 'prep':
88      submit('prepare',repDict)
89  
90 < elif opts.task == 'eval' or opts.task == 'sys':
90 > elif opts.task == 'eval' or opts.task == 'sys' or opts.task == 'syseval':
91      if ( opts.samples == ""):
92          for job in info:
93              submit(job.name,repDict)
94      else:
95 <        for sample in samplesDict:
95 >        for sample in samplesList:
96              submit(sample,repDict)
97 <            
97 >
98 > os.system('qstat')

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines