ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/cbrown/AnalysisFramework/DistributedModelCalculations/Limits/RunScanLimits.py
Revision: 1.11
Committed: Tue Aug 30 16:16:49 2011 UTC (13 years, 8 months ago) by buchmann
Content type: text/x-python
Branch: MAIN
CVS Tags: cbaf_4_98ifb_paper, cbaf_4p7ifb, Honeypot, cbaf_2p1ifb, HEAD
Changes since 1.10: +33 -11 lines
Log Message:
Now permitting multiple users to contribute in limit setting (i.e. each one sends in a couple of hundred jobs)

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 try:
11 import ROOT
12 except:
13 print "ROOT cannot be loaded, you won't get a timeline histo after running ... "
14
15 jobnumbers=[]
16 totaljobnumber=0
17 totjobs=0;
18
19 def checklist(joblist,currlist):
20 jobfinished=[]
21 for i in joblist:
22 if i in currlist: ## if the job is still active
23 currlist.remove(int(i))## we don't need this anymore on the list of currently running jobs (we already know it's running)
24 else:#job is finished
25 jobfinished.append(int(i))
26 for job in jobfinished:
27 joblist.remove(int(job))
28 print "Jobs left:"+str(len(joblist))+" / "+str(totjobs)
29
30 def create_config():
31 command="../../Plotting/Create_All_Plots.exec 1" #this is the command to give us the configuration file :-)
32 print "Creating the configuration"
33 pipe=popen(command)
34 print "Everything is sent up. Your jobs will be submitted in a minute!"
35
36 def lay_out_groundwork():
37 if os.path.isfile("../last_configuration.C"):
38 result="fff"
39 while(result!="" and result!="new"):
40 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")
41 if result=="":
42 print "You've hit enter! Using the existing version ... ";
43 else:
44 print "You've written \"new\" - creating a new file!";
45 create_config()
46 else:
47 create_config()
48
49 def do_simple_submit():
50 print "Going to submit "+str(sys.argv[1])+" jobs : "
51 fusecommand="hadd -f output/all_limits.root"
52 path=str(os.path.abspath(os.curdir))
53 path=path.replace("/","\/");
54 confcommand="cat Source/calcLim.sh_template | sed 's/SETJZBCUT/"+str(sys.argv[1])+"/' | sed 's/SETNJOBS/"+str(sys.argv[1])+"/' | sed 's/THISDIR/"+str(path)+"/' > output/calcLim.sh"
55 commands.getoutput(confcommand)
56 for ijob in range(0,int(sys.argv[1])):
57 pipe=popen("qsub -e /tmp/ -o /tmp/ -N " + "LimCalc"+str(ijob)+ " " + os.curdir + "/output/calcLim.sh"+ " "+str(ijob))
58 for l in pipe.readlines():
59 if l.find("Your job")>-1:
60 thisjobnumber=int(l[l.index('job ')+4:l.index(' (')])
61 print ": Submitted job "+str(ijob)+" with job number: "+str(thisjobnumber)
62 jobnumbers.append(thisjobnumber)
63 fusecommand=fusecommand+" output/DistributedLimits_job"+str(ijob)+"_of_"+str(sys.argv[1])+".root"
64 counter=0
65 totjobs=sys.argv[1]
66 while(len(jobnumbers)>0 and counter<300) :
67 counter+=1
68 currlist=[]
69 pipe=popen("qstat | grep `whoami` | awk '{print $1}'")
70 for line in pipe.readlines():
71 currlist.append(int(line))
72 checklist(jobnumbers,currlist)
73 time.sleep(60)
74 print "All jobs have finished - need to merge everything and place it in your scratch directory!"
75 print commands.getoutput(fusecommand)
76 process_command="./produce_limit_plots.exec output/all_limits.root"
77 commands.getoutput(process_command)
78 print "All done!"
79
80 def do_advanced_submit():
81 counter=-2;
82 for argument in sys.argv:
83 counter+=1
84 if counter < 1: continue
85 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"
86 print confcommand
87 commands.getoutput(confcommand)
88
89 def printUsage():
90 print "Please provide the following argument: total number of jobs"
91 print "You can also, on top of the number of jobs, provide a list of names (e.g. Adam Barbara Carl Debra ... ) to share the computational load"
92
93 if(len(sys.argv) < 2 or sys.argv[1] == "-h"):
94 printUsage()
95 sys.exit(-1)
96 else:
97 lay_out_groundwork()
98 print "Will now recompile to account for any possible changes in the configuration (or setup)"
99 commands.getoutput("make")
100 if(len(sys.argv) ==2):
101 do_simple_submit()
102 else:
103 do_advanced_submit()
104