1 |
muell149 |
1.1 |
#!/usr/bin/env python
|
2 |
|
|
import sys
|
3 |
|
|
import os
|
4 |
awoodard |
1.3 |
import string
|
5 |
muell149 |
1.1 |
import subprocess
|
6 |
|
|
import getopt
|
7 |
|
|
import pickle
|
8 |
|
|
import re
|
9 |
|
|
import csv
|
10 |
|
|
|
11 |
|
|
#########################################################################################
|
12 |
muell149 |
1.2 |
#### This file uses: DatabaseRatePredictor.py
|
13 |
|
|
#### DatabaseRateMonitor.py
|
14 |
|
|
#### to compare rates across hlt menus.
|
15 |
|
|
####
|
16 |
|
|
#### Instructions: https://twiki.cern.ch/twiki/bin/viewauth/CMS/MenuComparison_Tutorial
|
17 |
|
|
####
|
18 |
muell149 |
1.1 |
#### Charlie Mueller 8/8/2012
|
19 |
|
|
#########################################################################################
|
20 |
|
|
def usage():
|
21 |
|
|
print "This tool compares old menu rates to new menu rates in addition to googledoc and TMD predicions"
|
22 |
|
|
print "EXAMPLE: python MenuCompare.py --TriggerList=monitorlist_all_v4.list --json=Cert_190456-199429_8TeV_PromptReco_Collisions12_JSON.txt --oldMenu=199318-199429 --LS1=2 --nLS1=23 --newMenu=199751-199754 --LS2=54 --nLS2=20 --googleDoc=googledoc_7e33_v3.csv --TMDpred=TMDpred_7e33_v4.csv "
|
23 |
|
|
print "the only optional argument is '--json='"
|
24 |
|
|
|
25 |
|
|
def main():
|
26 |
|
|
try:
|
27 |
|
|
try:
|
28 |
|
|
opt,args = getopt.getopt(sys.argv[1:],"",["TriggerList=","json=","oldMenu=","LS1=","nLS1=","newMenu=","LS2=","nLS2=","scaleFac=","googleDoc=","TMDpred="])
|
29 |
|
|
except getopt.GetoptError, err:
|
30 |
|
|
print "Error"
|
31 |
|
|
usage()
|
32 |
|
|
sys.exit(2)
|
33 |
|
|
|
34 |
|
|
#init inputs
|
35 |
|
|
triggerlist = ""
|
36 |
|
|
json = ""
|
37 |
|
|
LS1 = ""
|
38 |
|
|
LS2 = ""
|
39 |
|
|
nLS1 = ""
|
40 |
|
|
nLS2 = ""
|
41 |
|
|
gDoc = ""
|
42 |
|
|
TMDpred = ""
|
43 |
|
|
for o,a in opt:
|
44 |
|
|
if o == "--TriggerList":
|
45 |
|
|
triggerlist = a
|
46 |
|
|
elif o =="--json":
|
47 |
|
|
json = a
|
48 |
|
|
elif o =="--oldMenu":
|
49 |
|
|
oldMenu = a
|
50 |
|
|
elif o =="--LS1":
|
51 |
|
|
LS1 = a
|
52 |
|
|
elif o =="--nLS1":
|
53 |
|
|
nLS1 = a
|
54 |
|
|
elif o =="--newMenu":
|
55 |
|
|
newMenu = a
|
56 |
|
|
elif o =="--LS2":
|
57 |
|
|
LS2 = a
|
58 |
|
|
elif o =="--nLS2":
|
59 |
|
|
nLS2 = a
|
60 |
|
|
elif o =="--googleDoc":
|
61 |
|
|
gDoc = a
|
62 |
|
|
elif o =="--TMDpred":
|
63 |
|
|
TMDpred = a
|
64 |
|
|
elif o =="--scaleFac":
|
65 |
|
|
scaleFac = float(a)
|
66 |
|
|
|
67 |
|
|
if oldMenu.find('-') != -1:#oldMenu is a run range
|
68 |
|
|
rrangeOld = oldMenu.split('-')
|
69 |
|
|
if newMenu.find('-') != -1:#newMenu is a run range
|
70 |
|
|
rrangeNew = newMenu.split('-')
|
71 |
|
|
|
72 |
|
|
run1 = rrangeOld[0]
|
73 |
|
|
run2 = rrangeOld[1]
|
74 |
|
|
run3 = rrangeNew[0]
|
75 |
|
|
run4 = rrangeNew[1]
|
76 |
|
|
|
77 |
|
|
save_string = "MenuComparison_"+run2+"-"+run4+".csv"
|
78 |
|
|
trigger_string = "--TriggerList="+triggerlist
|
79 |
|
|
|
80 |
|
|
if json == "":
|
81 |
|
|
json_string = json
|
82 |
|
|
else:
|
83 |
|
|
json_string = "--json="+json
|
84 |
|
|
|
85 |
muell149 |
1.2 |
print " "
|
86 |
muell149 |
1.1 |
cmd1 = "env DISPLAY= python DatabaseRatePredictor.py --makeFits "+trigger_string+" --NoVersion "+json_string+" --maxdt=0.10 "+oldMenu
|
87 |
|
|
cmd2 = "sed -i '/TriggerToMonitorList=/ c\TriggerToMonitorList="+triggerlist+"' defaults.cfg"
|
88 |
|
|
cmd3 = "sed -i '/FitFileName=/ c\FitFileName=Fits/2012/Fit_HLT_NoV_10LS_Run"+run1+"to"+run2+".pkl' defaults.cfg"
|
89 |
awoodard |
1.3 |
cmd4 = "sed -i '/prettyCSVwriter(/ c\ prettyCSVwriter(\"rateMon_oldmenu.csv\",[80,10,10,10,10,20,20],Header,core_data,Warn)' DatabaseRateMonitor.py"
|
90 |
muell149 |
1.2 |
cmd5 = "python DatabaseRateMonitor.py --write --CompareRun="+run2+" --FirstLS="+LS1+" --NumberLS="+nLS1
|
91 |
muell149 |
1.1 |
cmd6 = "env DISPLAY= python DatabaseRatePredictor.py --makeFits "+trigger_string+" --NoVersion --maxdt=0.10 "+newMenu
|
92 |
|
|
cmd7 = "sed -i '/FitFileName=/ c\FitFileName=Fits/2012/Fit_HLT_NoV_10LS_Run"+run3+"to"+run4+".pkl' defaults.cfg"
|
93 |
awoodard |
1.3 |
cmd8 = "sed -i '/prettyCSVwriter(/ c\ prettyCSVwriter(\"rateMon_newmenu.csv\",[80,10,10,10,10,20,20],Header,core_data,Warn)' DatabaseRateMonitor.py"
|
94 |
muell149 |
1.2 |
cmd9 = "python DatabaseRateMonitor.py --write --CompareRun="+run4+" --FirstLS="+LS2+" --NumberLS="+nLS2
|
95 |
muell149 |
1.1 |
cmds = [cmd1,cmd2,cmd3,cmd4,cmd5,cmd6,cmd7,cmd8,cmd9]
|
96 |
|
|
for cmd in cmds:
|
97 |
|
|
try:
|
98 |
|
|
subprocess.call(cmd, shell=True)
|
99 |
|
|
except:
|
100 |
|
|
print "Command Error:",cmd
|
101 |
|
|
sys.exit(2)
|
102 |
|
|
|
103 |
|
|
compareFiles("rateMon_newmenu.csv","rateMon_oldmenu.csv",TMDpred,gDoc,scaleFac,save_string)
|
104 |
|
|
|
105 |
|
|
except KeyboardInterrupt:
|
106 |
|
|
print "Exiting..."
|
107 |
|
|
|
108 |
|
|
|
109 |
|
|
def StripVersion(name):
|
110 |
|
|
if re.match('.*_v[0-9]+',name):
|
111 |
|
|
name = name[:name.rfind('_')]
|
112 |
awoodard |
1.3 |
name = string.strip(name)
|
113 |
muell149 |
1.1 |
return name
|
114 |
|
|
|
115 |
|
|
def StripPm(name1):
|
116 |
|
|
if re.match('.*[+-]',name1):
|
117 |
|
|
name1 = name1[:name1.rfind('+-')]
|
118 |
|
|
return name1
|
119 |
|
|
|
120 |
|
|
def compareFiles(new,old,tmd,gdoct,scaler,save_file):
|
121 |
|
|
f1 = open(new,"rU")#new menu, the order is important!
|
122 |
|
|
f2 = open(old,"rU")#old menu
|
123 |
|
|
f3 = open(tmd,"rU")#TMD
|
124 |
|
|
f4 = open(gdoct,"rU")#gDoc
|
125 |
|
|
saveF = open(save_file,"wb")
|
126 |
|
|
r1 = csv.reader(f1)
|
127 |
|
|
r2 = csv.reader(f2)
|
128 |
|
|
r3 = csv.reader(f3)
|
129 |
|
|
r4 = csv.reader(f4)
|
130 |
|
|
w1 = csv.writer(saveF)
|
131 |
|
|
|
132 |
|
|
w1.writerow(["Trigger","Old Menu Rate (Actual)"," Old Menu Rate (Expected)","Old Menu PS","New Menu Rate (Actual)","New Menu Rate (Expected)","New Menu PS","Google Doc Rate","TMD Pred Rate","contact"])
|
133 |
|
|
|
134 |
|
|
list2 = [iter2 for iter2 in r2]
|
135 |
|
|
list3 = [iter3 for iter3 in r3]
|
136 |
|
|
list4 = [iter4 for iter4 in r4]
|
137 |
|
|
|
138 |
|
|
#row1 = newmenu
|
139 |
|
|
#row2 = oldmenu
|
140 |
|
|
#row3 = TMD
|
141 |
|
|
#row4 = googledoc
|
142 |
|
|
|
143 |
|
|
for row1 in r1:
|
144 |
|
|
for row2 in list2:
|
145 |
awoodard |
1.3 |
if StripVersion(str(row1[0])) == StripVersion(str(row2[0])):#new and old menu trigs match
|
146 |
muell149 |
1.1 |
for row3 in list3:
|
147 |
awoodard |
1.3 |
if StripVersion(str(row3[0])) == StripVersion(str(row2[0])):#TMD and old menu trigs match
|
148 |
muell149 |
1.1 |
row_write = False
|
149 |
|
|
for row4 in list4:
|
150 |
awoodard |
1.3 |
if (StripVersion(str(row4[0])) == StripVersion(str(row3[0]))) and not row_write:
|
151 |
muell149 |
1.1 |
w1.writerow([str(row1[0]),str(float(row2[1])*scaler),str(float(row2[2])*scaler),str(row2[5]),str(float(row1[1])*scaler),str(float(row1[2])*scaler),str(row1[5]),str(row4[3]),str(row3[4]),str(row4[32])])
|
152 |
|
|
row_write = True
|
153 |
|
|
break
|
154 |
|
|
|
155 |
|
|
if row_write == False: #if no gDoc match
|
156 |
|
|
w1.writerow([str(row1[0]),str(float(row2[1])*scaler),str(float(row2[2])*scaler),str(row2[5]),str(float(row1[1])*scaler),str(float(row1[2])*scaler),str(row1[5]),"none",str(row3[4]),"none"])
|
157 |
|
|
|
158 |
|
|
|
159 |
|
|
f1.close()
|
160 |
|
|
f2.close()
|
161 |
|
|
f3.close()
|
162 |
|
|
f4.close()
|
163 |
|
|
print "output comparison file is ",save_file
|
164 |
|
|
saveF.close()
|
165 |
|
|
|
166 |
|
|
|
167 |
|
|
if __name__=='__main__':
|
168 |
|
|
main()
|