ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/cbrown/Development/DistributedModelCalculations/Efficiency/RunScanEfficiency.py
Revision: 1.1
Committed: Mon Jan 30 15:25:01 2012 UTC (13 years, 3 months ago) by buchmann
Content type: text/x-python
Branch: MAIN
CVS Tags: HEAD
Error occurred while calculating annotation data.
Log Message:
Initial commit of Ice Cream versions

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 purge_output():
25 print "Purging previous output files ... "
26 dirList=os.listdir(os.getcwd()+"/output/")
27 for fname in dirList:
28 if fname.find("Distributed")>-1 and fname.find(".root")>-1:
29 os.remove(os.getcwd()+"/output/"+fname)
30 print " Removed "+fname
31 print "Done purging!"
32
33 def create_config():
34 command="../../Plotting/Create_All_Plots.exec 1" #this is the command to give us the configuration file :-)
35 print "Creating the configuration"
36 pipe=popen(command)
37 print "Everything is sent up. Your jobs will be submitted in a minute!"
38
39 def lay_out_groundwork():
40 if os.path.isfile("../last_configuration.C"):
41 result="fff"
42 while(result!="" and result!="new"):
43 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 existent one please either hit enter: \n")
44 if result=="":
45 print "You've hit enter! Using the existing version ... ";
46 else:
47 print "You've written \"new\" - creating a new file!";
48 create_config()
49 else:
50 create_config()
51
52 def printUsage():
53 print "Please provide the following argument: (number of jobs)"
54
55 if(len(sys.argv) != 2 or sys.argv[1] == "-h"):
56 printUsage()
57 sys.exit(-1)
58 else:
59 lay_out_groundwork()
60 print "Will now recompile to account for any possible changes in the configuration (or setup)"
61 commands.getoutput("make")
62 print "Going to submit "+str(sys.argv[1])+" jobs : "
63 fusecommand="hadd -f output/all_efficiencies.root"
64 path=str(os.path.abspath(os.curdir))
65 path=path.replace("/","\/");
66 confcommand="cat Sources/calcEff.sh_template | sed 's/SETJZBCUT/"+str(sys.argv[1])+"/' | sed 's/SETNJOBS/"+str(sys.argv[1])+"/' | sed 's/THISDIR/"+path+"/' > output/calcEff.sh"
67 commands.getoutput(confcommand)
68 for ijob in range(0,int(sys.argv[1])):
69 pipe=popen("qsub -e /tmp/ -o /tmp/ -N " + "EffCalc"+str(ijob)+ " " + os.curdir + "/output/calcEff.sh"+ " "+str(ijob))
70 for l in pipe.readlines():
71 if l.find("Your job")>-1:
72 thisjobnumber=int(l[l.index('job ')+4:l.index(' (')])
73 print ": Submitted job "+str(ijob)+" with job number: "+str(thisjobnumber)
74 jobnumbers.append(thisjobnumber)
75 fusecommand=fusecommand+" output/DistributedEfficiencies_job"+str(ijob)+"_of_"+str(sys.argv[1])+".root"
76 counter=0
77 while(len(jobnumbers)>0 and counter<300) :
78 counter+=1
79 currlist=[]
80 pipe=popen("qstat | grep `whoami` | awk '{print $1}'")
81 for line in pipe.readlines():
82 currlist.append(int(line))
83 checklist(jobnumbers,currlist)
84 time.sleep(60)
85 print "All jobs have finished - need to merge everything and place it in your scratch directory!"
86 print commands.getoutput(fusecommand)
87 process_command="./produce_plots.exec output/all_efficiencies.root"
88 commands.getoutput(process_command)
89 print "All done!"