ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/cbrown/AnalysisFramework/DistributedModelCalculations/Limits/RunScanLimits.py
Revision: 1.4
Committed: Tue Jul 26 13:33:35 2011 UTC (13 years, 9 months ago) by buchmann
Content type: text/x-python
Branch: MAIN
Changes since 1.3: +7 -7 lines
Log Message:
Updated script to run manager a bit (to use produce_limit_plots.exec)

File Contents

# Content
1 #!/usr/bin/python
2
3 # System libraries to interact with the shell
4 import sys
5 import os
6 from os import popen
7 import commands
8 import time
9
10 jobnumbers=[]
11 totaljobnumber=0
12
13 def checklist(joblist,currlist):
14 jobfinished=[]
15 for i in joblist:
16 if i in currlist: ## if the job is still active
17 currlist.remove(int(i))## we don't need this anymore on the list of currently running jobs (we already know it's running)
18 else:#job is finished
19 jobfinished.append(int(i))
20 for job in jobfinished:
21 joblist.remove(int(job))
22 print "Jobs left:"+str(len(joblist))+" / "+str(len(jobnumbers))
23
24 def printUsage():
25 print "Please provide the following two arguments: (JZB cut) and (number of jobs)"
26
27 if(len(sys.argv) != 3 or sys.argv[1] == "-h"):
28 printUsage()
29 sys.exit(-1)
30 else:
31 print "Going to submit "+str(sys.argv[2])+" jobs : "
32 fusecommand="hadd -f output/all_limits.root"
33 path=str(os.path.abspath(os.curdir))
34 path=path.replace("/","\/");
35 confcommand="cat Source/calcLim.sh_template | sed 's/SETJZBCUT/"+str(sys.argv[1])+"/' | sed 's/SETNJOBS/"+str(sys.argv[2])+"/' | sed 's/THISDIR/"+str(path)+"/' > output/calcLim.sh"
36 commands.getoutput(confcommand)
37 for ijob in range(0,int(sys.argv[2])):
38 pipe=popen("qsub -e /tmp/ -o /tmp/ -N " + "EffCalc"+str(ijob)+ " " + os.curdir + "/output/calcLim.sh"+ " "+str(ijob))
39 for l in pipe.readlines():
40 if l.find("Your job")>-1:
41 thisjobnumber=int(l[l.index('job ')+4:l.index(' (')])
42 print ": Submitted job "+str(ijob)+" with job number: "+str(thisjobnumber)
43 jobnumbers.append(thisjobnumber)
44 fusecommand=fusecommand+" output/DistributedLimits_job"+str(ijob)+"_of_"+str(sys.argv[2])+".root"
45 counter=0
46 while(len(jobnumbers)>0 and counter<300) :
47 counter+=1
48 currlist=[]
49 pipe=popen("qstat | grep `whoami` | awk '{print $1}'")
50 for line in pipe.readlines():
51 currlist.append(int(line))
52 checklist(jobnumbers,currlist)
53 time.sleep(60)
54 print "All jobs have finished - need to merge everything and place it in your scratch directory!"
55 print commands.getoutput(fusecommand)
56 process_command="./produce_limit_plots.exec output/all_limits.root"
57 commands.getoutput(process_command)
58 print "All done!"