ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/RateMonShiftTool_dev/ReadConfig.py
Revision: 1.24
Committed: Tue Nov 20 13:30:27 2012 UTC (12 years, 5 months ago) by awoodard
Content type: text/x-python
Branch: MAIN
Changes since 1.23: +2 -3 lines
Log Message:
bug fix

File Contents

# User Rev Content
1 grchrist 1.1 #!/usr/bin/env python
2     import os
3 abrinke1 1.4 import cPickle as pickle
4     import math
5 grchrist 1.8 from DatabaseParser import *
6 grchrist 1.1
7     class RateMonConfig:
8    
9     def __init__(self,path='./'):
10     self.CFGfile=path+"/defaults.cfg"
11     self.BasePath=path
12     self.ReferenceRun=""
13 awoodard 1.15 self.DefAllowRatePercDiff=0.0
14     self.DefAllowRateSigmaDiff=0.0
15 grchrist 1.1 self.DefAllowIgnoreThresh=0.0
16     self.ExcludeList=[]
17     self.MonitorList=[]
18     self.MonitorIntercept=[]
19     self.MonitorSlope=[]
20     self.MonitorQuad=[]
21 amott 1.3 self.L1Predictions=[]
22 awoodard 1.22 self.ListIgnoredPaths=0
23 grchrist 1.1 self.MonTargetLumi=0
24     self.FindL1Zeros=0
25     self.LSWindow=-1
26     self.CompareReference=0
27 grchrist 1.2 self.ShifterMode=0
28 grchrist 1.10 self.NoVersion=0
29 amott 1.5 self.MaxExpressRate=999
30 amott 1.12 self.ForbiddenCols=[]
31 grchrist 1.14 self.CirculatingBeamsColumn=9
32     self.MaxLogMonRate=10
33 awoodard 1.16 self.DefWarnOnSigmaDiff=1
34 awoodard 1.17 self.DefShowSigmaAndPercDiff=0
35 grchrist 1.20 self.DoL1=0
36 awoodard 1.22 self.DefaultMaxBadRatesToShow=500
37 grchrist 1.23 self.L1SeedChangeFit=0
38 awoodard 1.15
39 grchrist 1.1 def ReadList(self,filename):
40     filename=self.BasePath+'/'+filename
41     list = []
42     if not os.path.exists(filename):
43     return list
44     f = open(filename)
45     for line in f:
46     if line.startswith('#'):
47     continue
48     if len(line)<3 or line=='\n':
49     continue
50     line = ((line.rstrip('\n')).rstrip(' '))
51     if line.find(':')==-1: # exclude list, no rate estimates
52     list.append( line )
53     else:
54     split = line.split(':')
55 grchrist 1.9 list.append(split[0])
56     ##list.append([split[0],split[1],split[2],split[3]])
57 grchrist 1.1 f.close()
58     return list
59    
60     def ReadCFG(self):
61     f=open(self.CFGfile)
62     for line in f:
63     if line.startswith('#'):
64     continue
65     if len(line)<1:
66     continue
67    
68     strippedLine = line.split('#')[0]
69     strippedLine = strippedLine.rstrip('\n').rstrip(' ')
70     if strippedLine=='':
71     continue
72     tok = strippedLine.split('=')
73     par = tok[0].rstrip(' ').lstrip(' ')
74     if len(tok)>=2:
75     arg=tok[1].rstrip('\n').rstrip(' ').lstrip(' ')
76     else:
77     arg=''
78    
79     if par=="ReferenceRun":
80     self.ReferenceRun=arg
81 awoodard 1.17 elif par=="ShowSigmaAndPercDiff":
82     self.DefShowSigmaAndPercDiff=float(arg)
83 awoodard 1.15 elif par=="DefaultAllowedRatePercDiff":
84     self.DefAllowRatePercDiff=float(arg)
85     elif par=="DefaultAllowedRateSigmaDiff":
86     self.DefAllowRateSigmaDiff=float(arg)
87 grchrist 1.1 elif par=="DefaultIgnoreThreshold":
88     self.DefAllowIgnoreThresh=float(arg)
89     elif par=="ExcludeTriggerList":
90     self.ExcludeList=self.ReadList(arg)
91     elif par=="TriggerToMonitorList":
92     tmp=self.ReadList(arg)
93     for line in tmp:
94 grchrist 1.8 self.MonitorList.append(line)
95     #self.MonitorIntercept.append(float(line[1]))
96     #self.MonitorSlope.append(float(line[2]))
97     #self.MonitorQuad.append(float(line[3]))
98 amott 1.12 elif par=="ForbiddenColumns":
99     tmp=arg.split(',')
100     for line in tmp:
101     try:
102     self.ForbiddenCols.append(int(line))
103     except:
104     print "Cannot parse Forbidden Cols parameter"
105 amott 1.3 elif par=="L1CrossSection":
106     self.L1Predictions = self.ReadList(arg)
107 awoodard 1.22 elif par =="ListIgnoredPaths":
108     self.ListIgnoredPaths=int(arg)
109 grchrist 1.1 elif par=="MonitorTargetLumi":
110     self.MonTargetLumi=float(arg)
111     elif par=="FindL1Zeros":
112     self.FindL1Zeros=int(arg)
113     elif par=="LSSlidingWindow":
114     self.LSWindow=int(arg)
115     elif par=="CompareReference":
116     self.CompareReference=int(arg)
117 grchrist 1.2 elif par=="ShifterMode":
118     self.ShifterMode=arg
119 amott 1.5 elif par=="MaxExpressRate":
120     self.MaxExpressRate=float(arg)
121 grchrist 1.6 elif par=="MaxStreamARate":
122     self.MaxStreamARate=float(arg)
123 grchrist 1.7 elif par=="FitFileName":
124     self.FitFileName=arg
125 grchrist 1.10 elif par=="NoVersion":
126     self.NoVersion=int(arg)
127 grchrist 1.14 elif par=="CirculatingBeamsColumn":
128     self.CircBeamCol=int(arg)
129     elif par=="MaxLogMonRate":
130     self.MaxLogMonRate=float(arg)
131 awoodard 1.16 elif par=="WarnOnSigmaDiff":
132     self.DefWarnOnSigmaDiff=float(arg)
133 grchrist 1.20 elif par=="DoL1":
134     self.DoL1=int(arg)
135 awoodard 1.22 elif par=="DefaultMaxBadRatesToShow":
136     self.DefaultMaxBadRatesToShow=int(arg)
137 grchrist 1.23 elif par=="L1SeedChangeFit":
138     self.L1SeedChangeFit=int(arg)
139 grchrist 1.1 else:
140     print "Invalid Option : "+strippedLine
141     f.close()
142    
143     def AnalyzeTrigger(self,TrigName): ## Have to pass this a version number stripped Trigger
144     if TrigName in self.ExcludeList:
145     return False
146     if self.MonitorOnly and not TrigName in self.MonitorList:
147     return False
148     return True
149    
150 grchrist 1.10 def GetExpectedRate(self,TrigName,Input,Rates,live,delivered,deadtime):
151 abrinke1 1.4 RefRun = False
152 grchrist 1.10 #replaced live/delivered with deadtimebeamactive
153     if self.NoVersion:
154     TrigName=StripVersion(TrigName)
155     if TrigName not in Input.keys():
156 awoodard 1.22 return [0.0,0.0,"No prediction (fit missing)"]
157    
158 abrinke1 1.4 try:
159 awoodard 1.18 sigma = Input[TrigName][5]
160 grchrist 1.21 except:
161 awoodard 1.22 if Input[TrigName][0] == "fit failed":
162     return [0.0,0.0,"No prediction (fit missing)"]
163     else:
164     return [0.0,0.0,"Exception error"]
165    
166 awoodard 1.24 try:
167     if Input[TrigName][0] == "line" or Input[TrigName][0] == "quad" or Input[TrigName][0] == "cube":
168 awoodard 1.22 return [(1-deadtime)*(Input[TrigName][1]+Input[TrigName][2]*delivered+Input[TrigName][3]*delivered*delivered+Input[TrigName][4]*delivered*delivered*delivered), sigma,""]
169     elif Input[TrigName][0] == "expo":
170     return [(1-deadtime)*(Input[TrigName][1]+Input[TrigName][2]*math.exp(Input[TrigName][3]+Input[TrigName][4]*delivered)), sigma,""]
171 abrinke1 1.4 except:
172 awoodard 1.22 return [0.0,0.0,"Exception error"]
173    
174 abrinke1 1.4 if RefRun:
175     num_compare = 0
176     pred_rate = 0
177     for iterator in range(len(Rates[TrigName]["rate"])):
178     delivered_lumi = Rates[TrigName]["delivered_lumi"][iterator]
179     if delivered_lumi > delivered - 100 and delivered_lumi < delivered + 100:
180     live_lumi = Rates[TrigName]["live_lumi"][iterator]
181     rate = Rates[TrigName]["rate"][iterator]
182     pred_rate += (live/delivered)*rate*(delivered_lumi/live_lumi)
183     num_compare += 1
184    
185     pred_rate = pred_rate/num_compare
186     Chi2 = pred_rate/math.sqrt(num_compare)
187     return [pred_rate, Chi2]
188    
189 grchrist 1.1 return -1
190 abrinke1 1.4
191    
192 grchrist 1.9 ## def GetExpectedL1Rates(self,lumi):
193     ## if not lumi:
194     ## return {}
195     ## expectedRates = {}
196     ## for col,inter,slope,quad in self.L1Predictions:
197     ## try:
198     ## expectedRates[int(col)] = lumi*(float(inter)+float(slope)*lumi+float(quad)*lumi*lumi)
199     ## except:
200     ## return {}
201     ## return expectedRates
202 grchrist 1.2
203