ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/cbrown/AnalysisFramework/DistributedModelCalculations/LimitsFromSystematics/RunScanLimits.py
Revision: 1.1
Committed: Mon Oct 24 08:09:44 2011 UTC (13 years, 6 months ago) by buchmann
Content type: text/x-python
Branch: MAIN
CVS Tags: Honeypot
Log Message:
Script for running limit computation based on systematics file on the t3wns

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=""
41 # 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")
42 if result=="":
43 print "You've hit enter! Using the existing version ... ";
44 else:
45 print "You've written \"new\" - creating a new file!";
46 create_config()
47 else:
48 create_config()
49
50 def do_simple_submit():
51 print "Going to submit "+str(sys.argv[1])+" jobs : "
52 fusecommand="hadd -f output/all_limits.root"
53 path=str(os.path.abspath(os.curdir))
54 path=path.replace("/","\/");
55 savearg=(sys.argv[2]).replace("/","\/")
56 confcommand="cat Source/calcLimFromSyst.sh_template | sed 's/SETJZBCUT/"+str(sys.argv[1])+"/' | sed 's/SETSYSTFILE/"+str(savearg)+"/' | sed 's/SETNJOBS/"+str(sys.argv[1])+"/' | sed 's/THISDIR/"+str(path)+"/' > output/calcLimFromSyst.sh"
57 print confcommand
58 commands.getoutput(confcommand)
59 # sys.exit(-1)
60 for ijob in range(0,int(sys.argv[1])):
61 pipe=popen("qsub -q short.q -e /tmp/ -o /tmp/ -N " + "LimCal"+str(ijob)+ " " + os.curdir + "/output/calcLimFromSyst.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!"
83
84 def do_advanced_submit():
85 counter=-2;
86 for argument in sys.argv:
87 counter+=1
88 if counter < 1: continue
89 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"
90 print confcommand
91 commands.getoutput(confcommand)
92
93 def printUsage():
94 print "Please provide the following argument: (total number of jobs) (abs path to syst file)"
95 # 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"
96
97 if(len(sys.argv) < 3 or sys.argv[1] == "-h"):
98 printUsage()
99 sys.exit(-1)
100 else:
101 lay_out_groundwork()
102 print "Will now recompile to account for any possible changes in the configuration (or setup)"
103 # commands.getoutput("make")
104 if(len(sys.argv) ==3):
105 do_simple_submit()
106 else:
107 printUsage()
108 # Note: advanced submitting has not been implemented yet for limit calculations
109 # do_advanced_submit()
110