ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/cbrown/AnalysisFramework/DistributedModelCalculations/Systematics/RunScanSystematics.py
Revision: 1.8
Committed: Thu Oct 27 10:14:51 2011 UTC (13 years, 6 months ago) by buchmann
Content type: text/x-python
Branch: MAIN
CVS Tags: cbaf_4_98ifb_paper, cbaf_4p7ifb, HEAD
Changes since 1.7: +11 -2 lines
Log Message:
Permitting fine tuning to submit to short.q

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