ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/cbrown/AnalysisFramework/DistributedModelCalculations/Limits/RunScanLimits.py
Revision: 1.10
Committed: Fri Aug 19 20:58:46 2011 UTC (13 years, 8 months ago) by buchmann
Content type: text/x-python
Branch: MAIN
Changes since 1.9: +4 -2 lines
Log Message:
Improving the 'user experience'

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