ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/cbrown/Development/DistributedModelCalculations/ShapeLimits/RunScanLimits.py
Revision: 1.3
Committed: Thu May 17 19:58:09 2012 UTC (12 years, 11 months ago) by buchmann
Content type: text/x-python
Branch: MAIN
CVS Tags: HEAD
Changes since 1.2: +2 -4 lines
Log Message:
Submitting to short queue again after implementing significant efficiency gains; cout and cerr redirects to /tmp/ have been removed to avoid problems; os.curdir was replaced with os.getcwd

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
11 jobnumbers=[]
12 totaljobnumber=0
13 totjobs=0;
14
15 def checklist(joblist,currlist):
16 jobfinished=[]
17 for i in joblist:
18 if i in currlist: ## if the job is still active
19 currlist.remove(int(i))## we don't need this anymore on the list of currently running jobs (we already know it's running)
20 else:#job is finished
21 jobfinished.append(int(i))
22 for job in jobfinished:
23 joblist.remove(int(job))
24 print "Jobs left:"+str(len(joblist))+" / "+str(totjobs)
25
26 def create_config():
27 command="../../Plotting/Create_All_Plots.exec 1" #this is the command to give us the configuration file :-)
28 print "Creating the configuration"
29 pipe=popen(command)
30 print "Everything is sent up. Your jobs will be submitted in a minute!"
31
32 def lay_out_groundwork():
33 if os.path.isfile("../last_configuration.C") and os.path.isfile("../StoredShapes.root"):
34 result="fff"
35 while(result!="" and result!="new"):
36 result=""
37 result=raw_input("Configuration file exists - would you like to use this one or create a new one? if you want to create a new one, please write new, if you want to use the existing one please either hit enter\n new = generate a new file \n [ENTER] = use existing file: \n")
38 if result=="":
39 print "You've hit enter! Using the existing version ... ";
40 else:
41 print "You've written \"new\" - creating a new file!";
42 create_config()
43 else:
44 create_config()
45
46 def do_simple_submit():
47 print "Going to submit "+str(sys.argv[1])+" jobs : "
48 fusecommand="hadd -f output/Shape_N_CnC_Limits.root"
49 path=str(os.path.abspath(os.getcwd()))
50 path=path.replace("/","\/");
51 confcommand="cat Source/ShapeLimWorker.sh_template | sed 's/SETJZBCUT/"+str(sys.argv[1])+"/' | sed 's/SETNJOBS/"+str(sys.argv[1])+"/' | sed 's/THISDIR/"+str(path)+"/' > output/ShapeLimWorker.sh"
52 commands.getoutput(confcommand)
53 for ijob in range(0,int(sys.argv[1])):
54 pipe=popen("qsub -q short.q -e /dev/null -o /dev/null -N " + "ShaLimA"+str(ijob)+ " " + os.getcwd() + "/output/ShapeLimWorker.sh"+ " "+str(ijob))
55 for l in pipe.readlines():
56 if l.find("Your job")>-1:
57 thisjobnumber=int(l[l.index('job ')+4:l.index(' (')])
58 print ": Submitted job "+str(ijob)+" with job number: "+str(thisjobnumber)
59 jobnumbers.append(thisjobnumber)
60 fusecommand=fusecommand+" output/DistributedLimits_job"+str(ijob)+"_of_"+str(sys.argv[1])+".root"
61 counter=0
62 totjobs=sys.argv[1]
63 while(len(jobnumbers)>0) :
64 counter+=1
65 currlist=[]
66 pipe=popen("qstat | grep `whoami` | awk '{print $1}'")
67 for line in pipe.readlines():
68 currlist.append(int(line))
69 checklist(jobnumbers,currlist)
70 time.sleep(60)
71 print "All jobs have finished - going to merge them, and pick points to do full fledged limit setting"
72 Asymptotic_Limits
73 commands.getoutput("python Utilities/DoFullLimits.py "+str(os.path.abspath(os.curdir))+"/output/Asymptotic_Limits.root")
74 print "All done!"
75
76 def do_advanced_submit():
77 counter=-2;
78 for argument in sys.argv:
79 counter+=1
80 if counter < 1: continue
81 confcommand="cat basic_sender.py | sed 's/nPEOPLE/"+str(int(len(sys.argv)-2))+"/' | sed 's/nJOBS/"+str(sys.argv[1])+"/' | sed 's/iPEOPLE/"+str(counter)+"/' > distributed_"+argument+".py"
82 print confcommand
83 commands.getoutput(confcommand)
84
85 def printUsage():
86 print "Please provide the following argument: (total number of jobs)"
87
88
89 if(len(sys.argv) < 2 or len(sys.argv) > 2 or sys.argv[1] == "-h"):
90 printUsage()
91 sys.exit(-1)
92 else:
93 lay_out_groundwork()
94 print "Will now recompile to account for any possible changes in the configuration (or setup)"
95 # commands.getoutput("make")
96 do_simple_submit()
97