ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/RateMonShiftTool_dev/ReadConfig.py
Revision: 1.3
Committed: Thu Feb 16 16:38:34 2012 UTC (13 years, 2 months ago) by amott
Content type: text/x-python
Branch: MAIN
CVS Tags: V00-00-08, V00-00-07, V00-00-05
Branch point for: V00-00-06
Changes since 1.2: +13 -1 lines
Log Message:
Update to ReadConfig and added code to point to the PS column

File Contents

# User Rev Content
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 amott 1.3 self.L1Predictions=[]
18 grchrist 1.1 self.MonitorOnly=0
19     self.MonTargetLumi=0
20     self.FindL1Zeros=0
21     self.LSWindow=-1
22     self.CompareReference=0
23 grchrist 1.2 self.ShifterMode=0
24 grchrist 1.1
25     def ReadList(self,filename):
26     filename=self.BasePath+'/'+filename
27     list = []
28     if not os.path.exists(filename):
29     return list
30     f = open(filename)
31     for line in f:
32     if line.startswith('#'):
33     continue
34     if len(line)<3 or line=='\n':
35     continue
36     line = ((line.rstrip('\n')).rstrip(' '))
37     if line.find(':')==-1: # exclude list, no rate estimates
38     list.append( line )
39     else:
40     split = line.split(':')
41     list.append([split[0],split[1],split[2],split[3]])
42     f.close()
43     return list
44    
45     def ReadCFG(self):
46     f=open(self.CFGfile)
47     for line in f:
48     if line.startswith('#'):
49     continue
50     if len(line)<1:
51     continue
52    
53     strippedLine = line.split('#')[0]
54     strippedLine = strippedLine.rstrip('\n').rstrip(' ')
55     if strippedLine=='':
56     continue
57     tok = strippedLine.split('=')
58     par = tok[0].rstrip(' ').lstrip(' ')
59     if len(tok)>=2:
60     arg=tok[1].rstrip('\n').rstrip(' ').lstrip(' ')
61     else:
62     arg=''
63    
64     if par=="ReferenceRun":
65     self.ReferenceRun=arg
66     elif par=="DefaultAllowedRateDiff":
67     self.DefAllowRateDiff=float(arg)
68     elif par=="DefaultIgnoreThreshold":
69     self.DefAllowIgnoreThresh=float(arg)
70     elif par=="ExcludeTriggerList":
71     self.ExcludeList=self.ReadList(arg)
72     elif par=="TriggerToMonitorList":
73     tmp=self.ReadList(arg)
74     for line in tmp:
75     self.MonitorList.append(line[0])
76     self.MonitorIntercept.append(float(line[1]))
77     self.MonitorSlope.append(float(line[2]))
78     self.MonitorQuad.append(float(line[3]))
79 amott 1.3 elif par=="L1CrossSection":
80     self.L1Predictions = self.ReadList(arg)
81 grchrist 1.1 elif par == "MonitorOnlyListed":
82     self.MonitorOnly=int(arg)
83     elif par=="MonitorTargetLumi":
84     self.MonTargetLumi=float(arg)
85     elif par=="FindL1Zeros":
86     self.FindL1Zeros=int(arg)
87     elif par=="LSSlidingWindow":
88     self.LSWindow=int(arg)
89     elif par=="CompareReference":
90     self.CompareReference=int(arg)
91 grchrist 1.2 elif par=="ShifterMode":
92     self.ShifterMode=arg
93    
94 grchrist 1.1 else:
95     print "Invalid Option : "+strippedLine
96     f.close()
97    
98     def AnalyzeTrigger(self,TrigName): ## Have to pass this a version number stripped Trigger
99     if TrigName in self.ExcludeList:
100     return False
101     if self.MonitorOnly and not TrigName in self.MonitorList:
102     return False
103     return True
104    
105     def GetExpectedRate(self,TrigName,lumi):
106     for trig,intercept,slope,quad in zip(self.MonitorList,self.MonitorIntercept,self.MonitorSlope,self.MonitorQuad):
107     if trig==TrigName:
108 grchrist 1.2 #print "mon list",self.MonitorList
109 grchrist 1.1 if lumi:
110     return intercept + lumi*slope/1000 + lumi*lumi*quad/1000000
111     else:
112     return intercept + 3000*slope/1000 + 3000*3000*quad/1000000
113     return -1
114    
115 amott 1.3 def GetExpectedL1Rates(self,lumi):
116     if not lumi:
117     return {}
118     expectedRates = {}
119     for col,inter,slope,quad in self.L1Predictions:
120     try:
121     expectedRates[int(col)] = lumi*(float(inter)+float(slope)*lumi+float(quad)*lumi*lumi)
122     except:
123     return {}
124     return expectedRates
125 grchrist 1.2
126