ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/rootEWKanalyzer/batch_qsub.py
Revision: 1.1
Committed: Mon Jun 7 14:57:40 2010 UTC (14 years, 10 months ago) by jueugste
Content type: text/x-python
Branch: MAIN
Log Message:
first commit

File Contents

# User Rev Content
1 jueugste 1.1 #! /usr/bin/python
2    
3    
4    
5     # this is a python script to submit the analysis* as
6     # batch jobs on the tier-3
7     #
8     # * this means jobs in the jet met prompt analysis
9     # framework which I adapted to the ewk analysis
10     #
11     # the following variables should be changed/checked
12     # before job submission:
13     # - output
14     # - inputlist
15     # - ijobmax
16    
17     import os
18    
19     ## setup the output dir and input files
20     output = "Data"
21     inputlist = "config/input_Data.txt"
22     ## the cut file (still needed...)
23     settingfile = "config/cutFileExample.txt"
24     ## number of max jobs
25     ijobmax = 10
26    
27     ################################################
28     # to write on local disks
29     ################################################
30    
31     ## name of the directory where the *.root file is stored
32     outputmain = output
33     ## make some directories
34     os.system("mkdir "+output)
35     os.system("mkdir "+output+"/log/")
36     os.system("mkdir "+output+"/input/")
37     os.system("mkdir "+output+"/src/")
38     outputroot = outputmain+"/root/"
39     os.system("mkdir "+outputroot)
40    
41     ################################################
42     #look for the current directory
43     ################################################
44     os.system("\\rm tmp.log")
45     os.system("echo $PWD > tmp.log")
46     tmp = open("tmp.log")
47     pwd = tmp.readline()
48     tmp.close()
49     os.system("\\rm tmp.log")
50     #################################################
51     numfiles = reduce(lambda x,y: x+1, file(inputlist).xreadlines(), 0)
52     filesperjob = numfiles/ijobmax
53     filesperjob = filesperjob
54     extrafiles = numfiles%ijobmax
55     input = open(inputlist)
56     #################################################
57     for ijob in range(ijobmax):
58     # prepare the list file
59     inputfilename = output+"/input/input_"+str(ijob)+".list"
60     inputfile = open(inputfilename,'w')
61     # if it is a normal job get filesperjob lines
62     if ijob != (ijobmax-1):
63     for line in range(filesperjob):
64     ntpfile = input.readline()
65     if ntpfile != '':
66     inputfile.write(ntpfile)
67     continue
68     else:
69     # if it is the last job get ALL remaining lines
70     ntpfile = input.readline()
71     while ntpfile != '':
72     inputfile.write(ntpfile)
73     ntpfile = input.readline()
74     continue
75     inputfile.close()
76    
77     # prepare the script to run
78     outputname = output+"/src/submit_"+str(ijob)+".src"
79     outputfile = open(outputname,'w')
80     outputfile.write('#!/bin/bash\n')
81     outputfile.write('#$ -N '+output+'_'+str(ijob)+'\n')
82     outputfile.write('#$ -l s_rt=00:30:00,h_rt=01:00:00\n')
83     outputfile.write('#$ -q all.q\n')
84     outputfile.write('#$ -cwd\n')
85     outputfile.write('#$ -o /shome/jueugste/CMSSW/CMSSW_3_5_6_7TeV/src/DiLeptonAnalysis/NTupleProducer/test/rootEWKanalyzer/'+output+'/log/\n')
86     outputfile.write('#$ -e /shome/jueugste/CMSSW/CMSSW_3_5_6_7TeV/src/DiLeptonAnalysis/NTupleProducer/test/rootEWKanalyzer/'+output+'/log/\n')
87    
88     outputfile.write('source /swshare/cms/cmsset_default.sh\n')
89     outputfile.write('cd /shome/jueugste/CMSSW/CMSSW_3_5_6_7TeV/src/DiLeptonAnalysis/NTupleProducer/test/rootEWKanalyzer\n')
90     outputfile.write('eval `scramv1 runtime -sh`\n')
91     outputfile.write('export LD_LIBRARY_PATH=/swshare/glite/d-cache/dcap/lib:$LD_LIBRARY_PATH\n')
92     outputfile.write('./main '+inputfilename+' '+settingfile+' analyze/Analysis '+outputroot+output+'_'+str(ijob)+' '+output+"/log/cutEfficiencyFile_"+str(ijob)+"\n")
93     outputfile.close
94     ##os.system('echo qsub '+outputname)
95     ##os.system('qsub '+outputname)
96     ijob = ijob+1
97     continue
98    
99     ## now submit the jobs...
100     for ijob in range(ijobmax):
101     os.system('qsub '+output+'/src/submit_'+str(ijob)+'.src')
102     os.system('echo qsub '+output+'/src/submit_'+str(ijob)+'.src')