ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/RateMonShiftTool_dev/MenuCompare.py
Revision: 1.2
Committed: Thu Aug 9 14:08:54 2012 UTC (12 years, 8 months ago) by muell149
Content type: text/x-python
Branch: MAIN
CVS Tags: V00-01-10, V-00-01-10, V00-01-09, V00-01-08
Changes since 1.1: +9 -6 lines
Log Message:
updated due to writing changes in DatbaseRateMonitor.py

File Contents

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