1 |
grchrist |
1.1 |
#!/usr/bin/env python
|
2 |
|
|
import os
|
3 |
|
|
|
4 |
|
|
class RateMonConfig:
|
5 |
|
|
|
6 |
|
|
def __init__(self,path='./'):
|
7 |
|
|
self.CFGfile=path+"/defaults.cfg"
|
8 |
|
|
self.BasePath=path
|
9 |
|
|
self.ReferenceRun=""
|
10 |
|
|
self.DefAllowRateDiff=0.0
|
11 |
|
|
self.DefAllowIgnoreThresh=0.0
|
12 |
|
|
self.ExcludeList=[]
|
13 |
|
|
self.MonitorList=[]
|
14 |
|
|
self.MonitorIntercept=[]
|
15 |
|
|
self.MonitorSlope=[]
|
16 |
|
|
self.MonitorQuad=[]
|
17 |
|
|
self.MonitorOnly=0
|
18 |
|
|
self.MonTargetLumi=0
|
19 |
|
|
self.FindL1Zeros=0
|
20 |
|
|
self.LSWindow=-1
|
21 |
|
|
self.CompareReference=0
|
22 |
|
|
|
23 |
|
|
def ReadList(self,filename):
|
24 |
|
|
filename=self.BasePath+'/'+filename
|
25 |
|
|
list = []
|
26 |
|
|
if not os.path.exists(filename):
|
27 |
|
|
return list
|
28 |
|
|
f = open(filename)
|
29 |
|
|
for line in f:
|
30 |
|
|
if line.startswith('#'):
|
31 |
|
|
continue
|
32 |
|
|
if len(line)<3 or line=='\n':
|
33 |
|
|
continue
|
34 |
|
|
line = ((line.rstrip('\n')).rstrip(' '))
|
35 |
|
|
if line.find(':')==-1: # exclude list, no rate estimates
|
36 |
|
|
list.append( line )
|
37 |
|
|
else:
|
38 |
|
|
split = line.split(':')
|
39 |
|
|
list.append([split[0],split[1],split[2],split[3]])
|
40 |
|
|
f.close()
|
41 |
|
|
return list
|
42 |
|
|
|
43 |
|
|
def ReadCFG(self):
|
44 |
|
|
f=open(self.CFGfile)
|
45 |
|
|
for line in f:
|
46 |
|
|
if line.startswith('#'):
|
47 |
|
|
continue
|
48 |
|
|
if len(line)<1:
|
49 |
|
|
continue
|
50 |
|
|
|
51 |
|
|
strippedLine = line.split('#')[0]
|
52 |
|
|
strippedLine = strippedLine.rstrip('\n').rstrip(' ')
|
53 |
|
|
if strippedLine=='':
|
54 |
|
|
continue
|
55 |
|
|
tok = strippedLine.split('=')
|
56 |
|
|
par = tok[0].rstrip(' ').lstrip(' ')
|
57 |
|
|
if len(tok)>=2:
|
58 |
|
|
arg=tok[1].rstrip('\n').rstrip(' ').lstrip(' ')
|
59 |
|
|
else:
|
60 |
|
|
arg=''
|
61 |
|
|
|
62 |
|
|
if par=="ReferenceRun":
|
63 |
|
|
self.ReferenceRun=arg
|
64 |
|
|
elif par=="DefaultAllowedRateDiff":
|
65 |
|
|
self.DefAllowRateDiff=float(arg)
|
66 |
|
|
elif par=="DefaultIgnoreThreshold":
|
67 |
|
|
self.DefAllowIgnoreThresh=float(arg)
|
68 |
|
|
elif par=="ExcludeTriggerList":
|
69 |
|
|
self.ExcludeList=self.ReadList(arg)
|
70 |
|
|
elif par=="TriggerToMonitorList":
|
71 |
|
|
tmp=self.ReadList(arg)
|
72 |
|
|
for line in tmp:
|
73 |
|
|
self.MonitorList.append(line[0])
|
74 |
|
|
self.MonitorIntercept.append(float(line[1]))
|
75 |
|
|
self.MonitorSlope.append(float(line[2]))
|
76 |
|
|
self.MonitorQuad.append(float(line[3]))
|
77 |
|
|
elif par == "MonitorOnlyListed":
|
78 |
|
|
self.MonitorOnly=int(arg)
|
79 |
|
|
elif par=="MonitorTargetLumi":
|
80 |
|
|
self.MonTargetLumi=float(arg)
|
81 |
|
|
elif par=="FindL1Zeros":
|
82 |
|
|
self.FindL1Zeros=int(arg)
|
83 |
|
|
elif par=="LSSlidingWindow":
|
84 |
|
|
self.LSWindow=int(arg)
|
85 |
|
|
elif par=="CompareReference":
|
86 |
|
|
self.CompareReference=int(arg)
|
87 |
|
|
else:
|
88 |
|
|
print "Invalid Option : "+strippedLine
|
89 |
|
|
f.close()
|
90 |
|
|
|
91 |
|
|
def AnalyzeTrigger(self,TrigName): ## Have to pass this a version number stripped Trigger
|
92 |
|
|
if TrigName in self.ExcludeList:
|
93 |
|
|
return False
|
94 |
grchrist |
1.2 |
|
95 |
grchrist |
1.1 |
if self.MonitorOnly and not TrigName in self.MonitorList:
|
96 |
|
|
return False
|
97 |
grchrist |
1.2 |
|
98 |
grchrist |
1.1 |
return True
|
99 |
|
|
|
100 |
|
|
def GetExpectedRate(self,TrigName,lumi):
|
101 |
grchrist |
1.2 |
try:
|
102 |
|
|
for trig,intercept,slope,quad in zip(self.MonitorList,self.MonitorIntercept,self.MonitorSlope,self.MonitorQuad):
|
103 |
|
|
if trig==TrigName:
|
104 |
|
|
if lumi:
|
105 |
|
|
return intercept + lumi*slope/1000 + lumi*lumi*quad/1000000
|
106 |
|
|
else:
|
107 |
|
|
return intercept + 3000*slope/1000 + 3000*3000*quad/1000000
|
108 |
|
|
return -1
|
109 |
grchrist |
1.1 |
|
110 |
grchrist |
1.2 |
except:
|
111 |
|
|
print "error getting expected rate"
|
112 |
|
|
sys.exit(1)
|