1 |
amott |
1.1 |
import cx_Oracle
|
2 |
|
|
import cPickle as pickle
|
3 |
|
|
import os, sys
|
4 |
|
|
import time
|
5 |
|
|
|
6 |
|
|
class DatabaseParser:
|
7 |
|
|
|
8 |
|
|
def __init__(self):
|
9 |
|
|
cmd='cat ~centraltspro/secure/cms_trg_r.txt'
|
10 |
|
|
line=os.popen(cmd).readlines()
|
11 |
|
|
magic = line[0].rstrip("\n\r")
|
12 |
|
|
connect= 'cms_trg_r/' + magic + '@cms_omds_lb'
|
13 |
|
|
# connect to the DB
|
14 |
|
|
self.orcl = cx_Oracle.connect(connect)
|
15 |
|
|
self.curs = self.orcl.cursor()
|
16 |
|
|
|
17 |
|
|
##-- Defined in ParsePage1 --##
|
18 |
|
|
self.RunNumber = 0
|
19 |
|
|
|
20 |
|
|
##-- Defined in ParseRunPage --##
|
21 |
|
|
self.Date=''
|
22 |
|
|
self.L1_HLT_Key=''
|
23 |
|
|
self.HLT_Key=''
|
24 |
|
|
self.GTRS_Key=''
|
25 |
|
|
self.TSC_Key=''
|
26 |
|
|
self.GT_Key=''
|
27 |
|
|
self.ConfigId=0
|
28 |
|
|
|
29 |
|
|
##-- Defined in ParseHLTSummaryPage --##
|
30 |
|
|
self.TriggerRates = [] ## contains the HLT rates for the current LS range
|
31 |
|
|
self.RateTable = [] ## Rates per LS, useful but maybe enormous!
|
32 |
|
|
|
33 |
|
|
self.L1PrescaleTable=[]
|
34 |
|
|
self.AvgL1Prescales=[] ## contains the average L1 prescales for the current LS range range
|
35 |
|
|
self.HLTList=[]
|
36 |
|
|
self.AvgTotalPrescales=[]
|
37 |
|
|
self.HLTPrescaleTable=[] ## can't fill this yet
|
38 |
|
|
self.UnprescaledRates=[]
|
39 |
|
|
self.PrescaledRates=[]
|
40 |
|
|
##-- Defined in ParseLumiPage --##
|
41 |
|
|
self.LastLSParsed=-1
|
42 |
|
|
self.LSByLS = []
|
43 |
|
|
self.InstLumiByLS = []
|
44 |
|
|
self.DeliveredLumiByLS = []
|
45 |
|
|
self.LiveLumiByLS = []
|
46 |
|
|
self.PSColumnByLS = []
|
47 |
|
|
self.AvInstLumi = 0
|
48 |
|
|
self.AvDeliveredLumi = 0
|
49 |
|
|
self.AvLiveLumi = 0
|
50 |
|
|
self.LumiInfo = [] ##Returns
|
51 |
|
|
self.DeadTime = []
|
52 |
|
|
self.Physics = []
|
53 |
|
|
|
54 |
|
|
|
55 |
|
|
##-- Defined in ParseL1Page (not currently used) --##
|
56 |
|
|
self.L1Rates={} ##Returns
|
57 |
|
|
|
58 |
|
|
##-- Defined in ParsePSColumnPage (not currently used) --##
|
59 |
|
|
self.PSColumnChanges=[] ##Returns
|
60 |
|
|
|
61 |
|
|
##-- Defined in ParseTriggerModePage --##
|
62 |
|
|
self.L1TriggerMode={}
|
63 |
|
|
self.HLTTriggerMode={}
|
64 |
|
|
self.HLTSeed=[]
|
65 |
|
|
self.HLTSequenceMap=[]
|
66 |
|
|
self.TriggerInfo = [] ##Returns
|
67 |
|
|
|
68 |
|
|
##-- Defined in AssemblePrescaleValues --##
|
69 |
|
|
self.L1Prescale=[]
|
70 |
|
|
self.L1IndexNameMap=[]
|
71 |
|
|
self.HLTPrescale=[]
|
72 |
|
|
self.MissingPrescale=[]
|
73 |
|
|
self.PrescaleValues=[] ##Returns
|
74 |
|
|
|
75 |
|
|
##-- Defined in ComputeTotalPrescales --##
|
76 |
|
|
self.TotalPSInfo = [] ##Returns
|
77 |
|
|
|
78 |
|
|
##-- Defined in CorrectForPrescaleChange --##
|
79 |
|
|
self.CorrectedPSInfo = [] ##Returns
|
80 |
|
|
|
81 |
|
|
##-- In the current Parser.py philosophy, only RunNumber is set globally
|
82 |
|
|
## - LS range is set from the outside for each individual function
|
83 |
|
|
#self.FirstLS = -1
|
84 |
|
|
#self.LastLS = -1
|
85 |
|
|
|
86 |
|
|
def GetRunInfo(self):
|
87 |
|
|
## This query gets the L1_HLT Key (A), the associated HLT Key (B) and the Config number for that key (C)
|
88 |
|
|
KeyQuery = """
|
89 |
|
|
SELECT A.TRIGGERMODE, B.HLT_KEY, B.GT_RS_KEY, B.TSC_KEY, C.CONFIGID, D.GT_KEY FROM
|
90 |
|
|
CMS_WBM.RUNSUMMARY A, CMS_L1_HLT.L1_HLT_CONF B, CMS_HLT.CONFIGURATIONS C, CMS_TRG_L1_CONF.TRIGGERSUP_CONF D WHERE
|
91 |
|
|
B.ID = A.TRIGGERMODE AND C.CONFIGDESCRIPTOR = B.HLT_KEY AND D.TS_Key = B.TSC_Key AND A.RUNNUMBER=%d
|
92 |
|
|
""" % (self.RunNumber,)
|
93 |
|
|
self.curs.execute(KeyQuery)
|
94 |
|
|
self.L1_HLT_Key,self.HLT_Key,self.GTRS_Key,self.TSC_Key,self.ConfigId,self.GT_Key = self.curs.fetchone()
|
95 |
|
|
|
96 |
|
|
def UpdateRateTable(self): # lets not rebuild the rate table every time, rather just append new LSs
|
97 |
|
|
pass
|
98 |
|
|
|
99 |
|
|
def GetHLTRates(self,StartLS,EndLS):
|
100 |
|
|
sqlquery = """SELECT SUM(A.L1PASS),SUM(A.PSPASS),SUM(A.PACCEPT)
|
101 |
|
|
,SUM(A.PEXCEPT),(SELECT L.NAME FROM CMS_HLT.PATHS L WHERE L.PATHID=A.PATHID) PATHNAME
|
102 |
|
|
FROM CMS_RUNINFO.HLT_SUPERVISOR_TRIGGERPATHS A WHERE RUNNUMBER=%s AND A.LSNUMBER>=%d AND A.LSNUMBER<%d
|
103 |
|
|
GROUP BY A.LSNUMBER,A.PATHID"""
|
104 |
|
|
|
105 |
|
|
query = sqlquery % (self.RunNumber,StartLS,EndLS)
|
106 |
|
|
self.curs.execute(query)
|
107 |
|
|
self.TriggerRates=['']*len(self.HLTList)
|
108 |
|
|
for L1Pass,PSPass,HLTPass,HLTExcept,name in self.curs.fetchall():
|
109 |
|
|
rate = HLTPass/23.3
|
110 |
|
|
ps = 0
|
111 |
|
|
if PSPass:
|
112 |
|
|
ps = float(L1Pass)/PSPass
|
113 |
|
|
if not [name] in self.RateTable:
|
114 |
|
|
continue
|
115 |
|
|
nameI = self.GetHLTIndex(name) #self.RateTable.index([name])
|
116 |
|
|
if nameI==-1:
|
117 |
|
|
continue
|
118 |
|
|
self.RateTable[nameI].append([ps,rate])
|
119 |
|
|
self.TriggerRates[nameI]= [rate,L1Pass,PSPass,ps,StartLS,EndLS]
|
120 |
|
|
##self.RateTable
|
121 |
|
|
return self.TriggerRates
|
122 |
|
|
|
123 |
|
|
|
124 |
|
|
def GetLumiInfo(self):
|
125 |
|
|
sqlquery="""SELECT RUNNUMBER,LUMISECTION,PRESCALE_INDEX,INSTLUMI,LIVELUMI,DELIVLUMISECTION,DEADTIME
|
126 |
|
|
,DCSSTATUS,PHYSICS_FLAG
|
127 |
|
|
FROM CMS_RUNTIME_LOGGER.LUMI_SECTIONS A,CMS_GT_MON.LUMI_SECTIONS B WHERE A.RUNNUMBER=%s
|
128 |
|
|
AND B.RUN_NUMBER(+)=A.RUNNUMBER AND B.LUMI_SECTION(+)=A.LUMISECTION AND A.LUMISECTION > %d
|
129 |
|
|
ORDER BY A.RUNNUMBER,A.LUMISECTION"""
|
130 |
|
|
|
131 |
|
|
## Get the lumi information for the run, just update the table, don't rebuild it every time
|
132 |
|
|
query = sqlquery % (self.RunNumber,self.LastLSParsed)
|
133 |
|
|
self.curs.execute(query)
|
134 |
|
|
pastLSCol=-1
|
135 |
|
|
for run,ls,psi,inst,live,dlive,dt,dcs,phys in self.curs.fetchall():
|
136 |
|
|
self.LSByLS.append(ls)
|
137 |
|
|
self.PSColumnByLS.append(psi)
|
138 |
|
|
self.InstLumiByLS.append(inst)
|
139 |
|
|
self.LiveLumiByLS.append(inst)
|
140 |
|
|
self.DeliveredLumiByLS.append(inst)
|
141 |
|
|
self.DeadTime.append(dt)
|
142 |
|
|
self.Physics.append(phys)
|
143 |
|
|
if pastLSCol!=-1 and ls!=pastLSCol:
|
144 |
|
|
self.PSColumnChanges.append([ls,psi])
|
145 |
|
|
pastLSCol=ls
|
146 |
|
|
if ls>self.LastLSParsed:
|
147 |
|
|
self.LastLSParsed=ls
|
148 |
|
|
|
149 |
|
|
def FillLumiInfo(self,StartLS,EndLS):
|
150 |
|
|
if EndLS <= StartLS:
|
151 |
|
|
print "In ParseLumiPage, EndLS <= StartLS"
|
152 |
|
|
|
153 |
|
|
print "In ParseLumiPage, StartLS = "+str(StartLS)+" and EndLS = "+str(EndLS)
|
154 |
|
|
|
155 |
|
|
self.AvLiveLumi = 1000*(self.LiveLumiByLS[EndLS] - self.LiveLumiByLS[StartLS])/(23.3*(EndLS-StartLS))
|
156 |
|
|
self.AvDeliveredLumi = 1000*(self.DeliveredLumiByLS[EndLS] - self.DeliveredLumiByLS[StartLS])/(23.3*(EndLS-StartLS))
|
157 |
|
|
value_iterator = 0
|
158 |
|
|
for value in self.LSByLS:
|
159 |
|
|
if value >= StartLS and value <= EndLS:
|
160 |
|
|
self.AvInstLumi+=self.InstLumiByLS[value]
|
161 |
|
|
value_iterator+=1
|
162 |
|
|
self.AvInstLumi = self.AvInstLumi / value_iterator
|
163 |
|
|
|
164 |
|
|
self.LumiInfo = [self.LSByLS, self.PSColumnByLS, self.InstLumiByLS, self.DeliveredLumiByLS, self.LiveLumiByLS, self.AvInstLumi, self.AvDeliveredLumi, self.AvLiveLumi]
|
165 |
|
|
|
166 |
|
|
return [self.LumiInfo,StartLS,EndLS]
|
167 |
|
|
|
168 |
|
|
|
169 |
|
|
def ParsePSColumnPage(self): ## this is now done automatically when we read the db
|
170 |
|
|
pass
|
171 |
|
|
|
172 |
|
|
def GetL1NameIndexAssoc(self):
|
173 |
|
|
## get the L1 algo names associated with each algo bit
|
174 |
|
|
AlgoNameQuery = """SELECT ALGO_INDEX, ALIAS FROM CMS_GT.L1T_MENU_ALGO_VIEW
|
175 |
|
|
WHERE MENU_IMPLEMENTATION IN (SELECT L1T_MENU_FK FROM CMS_GT.GT_SETUP WHERE ID='%s')
|
176 |
|
|
ORDER BY ALGO_INDEX""" % (self.GT_Key,)
|
177 |
|
|
self.curs.execute(AlgoNameQuery)
|
178 |
|
|
nextIndex=0
|
179 |
|
|
for index,name in self.curs.fetchall():
|
180 |
|
|
while nextIndex<index:
|
181 |
|
|
self.L1IndexNameMap.append('')
|
182 |
|
|
nextIndex+=1 ## skips empty seeds
|
183 |
|
|
self.L1IndexNameMap.append(name)
|
184 |
|
|
nextIndex+=1
|
185 |
|
|
|
186 |
|
|
def GetL1AlgoPrescales(self):
|
187 |
|
|
L1PrescalesQuery= """
|
188 |
|
|
SELECT
|
189 |
|
|
PRESCALE_FACTOR_ALGO_000,PRESCALE_FACTOR_ALGO_001,PRESCALE_FACTOR_ALGO_002,PRESCALE_FACTOR_ALGO_003,PRESCALE_FACTOR_ALGO_004,PRESCALE_FACTOR_ALGO_005,
|
190 |
|
|
PRESCALE_FACTOR_ALGO_006,PRESCALE_FACTOR_ALGO_007,PRESCALE_FACTOR_ALGO_008,PRESCALE_FACTOR_ALGO_009,PRESCALE_FACTOR_ALGO_010,PRESCALE_FACTOR_ALGO_011,
|
191 |
|
|
PRESCALE_FACTOR_ALGO_012,PRESCALE_FACTOR_ALGO_013,PRESCALE_FACTOR_ALGO_014,PRESCALE_FACTOR_ALGO_015,PRESCALE_FACTOR_ALGO_016,PRESCALE_FACTOR_ALGO_017,
|
192 |
|
|
PRESCALE_FACTOR_ALGO_018,PRESCALE_FACTOR_ALGO_019,PRESCALE_FACTOR_ALGO_020,PRESCALE_FACTOR_ALGO_021,PRESCALE_FACTOR_ALGO_022,PRESCALE_FACTOR_ALGO_023,
|
193 |
|
|
PRESCALE_FACTOR_ALGO_024,PRESCALE_FACTOR_ALGO_025,PRESCALE_FACTOR_ALGO_026,PRESCALE_FACTOR_ALGO_027,PRESCALE_FACTOR_ALGO_028,PRESCALE_FACTOR_ALGO_029,
|
194 |
|
|
PRESCALE_FACTOR_ALGO_030,PRESCALE_FACTOR_ALGO_031,PRESCALE_FACTOR_ALGO_032,PRESCALE_FACTOR_ALGO_033,PRESCALE_FACTOR_ALGO_034,PRESCALE_FACTOR_ALGO_035,
|
195 |
|
|
PRESCALE_FACTOR_ALGO_036,PRESCALE_FACTOR_ALGO_037,PRESCALE_FACTOR_ALGO_038,PRESCALE_FACTOR_ALGO_039,PRESCALE_FACTOR_ALGO_040,PRESCALE_FACTOR_ALGO_041,
|
196 |
|
|
PRESCALE_FACTOR_ALGO_042,PRESCALE_FACTOR_ALGO_043,PRESCALE_FACTOR_ALGO_044,PRESCALE_FACTOR_ALGO_045,PRESCALE_FACTOR_ALGO_046,PRESCALE_FACTOR_ALGO_047,
|
197 |
|
|
PRESCALE_FACTOR_ALGO_048,PRESCALE_FACTOR_ALGO_049,PRESCALE_FACTOR_ALGO_050,PRESCALE_FACTOR_ALGO_051,PRESCALE_FACTOR_ALGO_052,PRESCALE_FACTOR_ALGO_053,
|
198 |
|
|
PRESCALE_FACTOR_ALGO_054,PRESCALE_FACTOR_ALGO_055,PRESCALE_FACTOR_ALGO_056,PRESCALE_FACTOR_ALGO_057,PRESCALE_FACTOR_ALGO_058,PRESCALE_FACTOR_ALGO_059,
|
199 |
|
|
PRESCALE_FACTOR_ALGO_060,PRESCALE_FACTOR_ALGO_061,PRESCALE_FACTOR_ALGO_062,PRESCALE_FACTOR_ALGO_063,PRESCALE_FACTOR_ALGO_064,PRESCALE_FACTOR_ALGO_065,
|
200 |
|
|
PRESCALE_FACTOR_ALGO_066,PRESCALE_FACTOR_ALGO_067,PRESCALE_FACTOR_ALGO_068,PRESCALE_FACTOR_ALGO_069,PRESCALE_FACTOR_ALGO_070,PRESCALE_FACTOR_ALGO_071,
|
201 |
|
|
PRESCALE_FACTOR_ALGO_072,PRESCALE_FACTOR_ALGO_073,PRESCALE_FACTOR_ALGO_074,PRESCALE_FACTOR_ALGO_075,PRESCALE_FACTOR_ALGO_076,PRESCALE_FACTOR_ALGO_077,
|
202 |
|
|
PRESCALE_FACTOR_ALGO_078,PRESCALE_FACTOR_ALGO_079,PRESCALE_FACTOR_ALGO_080,PRESCALE_FACTOR_ALGO_081,PRESCALE_FACTOR_ALGO_082,PRESCALE_FACTOR_ALGO_083,
|
203 |
|
|
PRESCALE_FACTOR_ALGO_084,PRESCALE_FACTOR_ALGO_085,PRESCALE_FACTOR_ALGO_086,PRESCALE_FACTOR_ALGO_087,PRESCALE_FACTOR_ALGO_088,PRESCALE_FACTOR_ALGO_089,
|
204 |
|
|
PRESCALE_FACTOR_ALGO_090,PRESCALE_FACTOR_ALGO_091,PRESCALE_FACTOR_ALGO_092,PRESCALE_FACTOR_ALGO_093,PRESCALE_FACTOR_ALGO_094,PRESCALE_FACTOR_ALGO_095,
|
205 |
|
|
PRESCALE_FACTOR_ALGO_096,PRESCALE_FACTOR_ALGO_097,PRESCALE_FACTOR_ALGO_098,PRESCALE_FACTOR_ALGO_099,PRESCALE_FACTOR_ALGO_100,PRESCALE_FACTOR_ALGO_101,
|
206 |
|
|
PRESCALE_FACTOR_ALGO_102,PRESCALE_FACTOR_ALGO_103,PRESCALE_FACTOR_ALGO_104,PRESCALE_FACTOR_ALGO_105,PRESCALE_FACTOR_ALGO_106,PRESCALE_FACTOR_ALGO_107,
|
207 |
|
|
PRESCALE_FACTOR_ALGO_108,PRESCALE_FACTOR_ALGO_109,PRESCALE_FACTOR_ALGO_110,PRESCALE_FACTOR_ALGO_111,PRESCALE_FACTOR_ALGO_112,PRESCALE_FACTOR_ALGO_113,
|
208 |
|
|
PRESCALE_FACTOR_ALGO_114,PRESCALE_FACTOR_ALGO_115,PRESCALE_FACTOR_ALGO_116,PRESCALE_FACTOR_ALGO_117,PRESCALE_FACTOR_ALGO_118,PRESCALE_FACTOR_ALGO_119,
|
209 |
|
|
PRESCALE_FACTOR_ALGO_120,PRESCALE_FACTOR_ALGO_121,PRESCALE_FACTOR_ALGO_122,PRESCALE_FACTOR_ALGO_123,PRESCALE_FACTOR_ALGO_124,PRESCALE_FACTOR_ALGO_125,
|
210 |
|
|
PRESCALE_FACTOR_ALGO_126,PRESCALE_FACTOR_ALGO_127
|
211 |
|
|
FROM CMS_GT.GT_FDL_PRESCALE_FACTORS_ALGO A, CMS_GT.GT_RUN_SETTINGS_PRESC_VIEW B
|
212 |
|
|
WHERE A.ID=B.PRESCALE_FACTORS_ALGO_FK AND B.ID='%s'
|
213 |
|
|
""" % (self.GTRS_Key,)
|
214 |
|
|
self.curs.execute(L1PrescalesQuery)
|
215 |
|
|
## This is pretty horrible, but this how you get them!!
|
216 |
|
|
tmp = self.curs.fetchall()
|
217 |
|
|
for ps in tmp[0]: #build the prescale table initially
|
218 |
|
|
self.L1PrescaleTable.append([ps])
|
219 |
|
|
for line in tmp[1:]: # now fill it
|
220 |
|
|
for ps,index in zip(line,range(len(line))):
|
221 |
|
|
self.L1PrescaleTable[index].append(ps)
|
222 |
|
|
|
223 |
|
|
def GetHLTIndex(self,name):
|
224 |
|
|
for i,n in enumerate(self.HLTList):
|
225 |
|
|
if n.find(name)!=-1:
|
226 |
|
|
return i
|
227 |
|
|
print name
|
228 |
|
|
return -1
|
229 |
|
|
|
230 |
|
|
def GetL1Index(self,name):
|
231 |
|
|
for i,n in enumerate(self.L1IndexNameMap):
|
232 |
|
|
if n==name:
|
233 |
|
|
return i
|
234 |
|
|
print name
|
235 |
|
|
return -1
|
236 |
|
|
|
237 |
|
|
def GetHLTPrescaleMatrix(self,cursor):
|
238 |
|
|
##NOT WORKING 1/19/2012
|
239 |
|
|
return
|
240 |
|
|
SequencePathQuery ="""
|
241 |
|
|
SELECT F.SEQUENCENB,J.VALUE TRIGGERNAME
|
242 |
|
|
FROM CMS_HLT.CONFIGURATIONSERVICEASSOC A
|
243 |
|
|
, CMS_HLT.SERVICES B
|
244 |
|
|
, CMS_HLT.SERVICETEMPLATES C
|
245 |
|
|
, CMS_HLT.SUPERIDVECPARAMSETASSOC D
|
246 |
|
|
, CMS_HLT.VECPARAMETERSETS E
|
247 |
|
|
, CMS_HLT.SUPERIDPARAMSETASSOC F
|
248 |
|
|
, CMS_HLT.PARAMETERSETS G
|
249 |
|
|
, CMS_HLT.SUPERIDPARAMETERASSOC H
|
250 |
|
|
, CMS_HLT.PARAMETERS I
|
251 |
|
|
, CMS_HLT.STRINGPARAMVALUES J
|
252 |
|
|
WHERE A.CONFIGID= %d
|
253 |
|
|
AND A.SERVICEID=B.SUPERID
|
254 |
|
|
AND B.TEMPLATEID=C.SUPERID
|
255 |
|
|
AND C.NAME='PrescaleService'
|
256 |
|
|
AND B.SUPERID=D.SUPERID
|
257 |
|
|
AND D.VPSETID=E.SUPERID
|
258 |
|
|
AND E.NAME='prescaleTable'
|
259 |
|
|
AND D.VPSETID=F.SUPERID
|
260 |
|
|
AND F.PSETID=G.SUPERID
|
261 |
|
|
AND G.SUPERID=H.SUPERID
|
262 |
|
|
AND I.PARAMID=H.PARAMID
|
263 |
|
|
AND I.NAME='pathName'
|
264 |
|
|
AND J.PARAMID=H.PARAMID
|
265 |
|
|
ORDER BY F.SEQUENCENB
|
266 |
|
|
""" % (self.ConfigId,)
|
267 |
|
|
|
268 |
|
|
cursor.execute(SequencePathQuery)
|
269 |
|
|
self.HLTSequenceMap = [0]*len(self.HLTList)
|
270 |
|
|
for seq,name in cursor.fetchall():
|
271 |
|
|
name = name.lstrip('"').rstrip('"')
|
272 |
|
|
try:
|
273 |
|
|
self.HLTSequenceMap[self.GetHLTIndex(name)]=seq
|
274 |
|
|
except:
|
275 |
|
|
print "couldn't find "+name
|
276 |
|
|
|
277 |
|
|
for i,seq in enumerate(self.HLTSequenceMap):
|
278 |
|
|
if seq==0:
|
279 |
|
|
print self.HLTList[i]
|
280 |
|
|
|
281 |
|
|
SequencePrescaleQuery="""
|
282 |
|
|
SELECT F.SEQUENCENB,J.SEQUENCENB,J.VALUE
|
283 |
|
|
FROM CMS_HLT.CONFIGURATIONSERVICEASSOC A
|
284 |
|
|
, CMS_HLT.SERVICES B
|
285 |
|
|
, CMS_HLT.SERVICETEMPLATES C
|
286 |
|
|
, CMS_HLT.SUPERIDVECPARAMSETASSOC D
|
287 |
|
|
, CMS_HLT.VECPARAMETERSETS E
|
288 |
|
|
, CMS_HLT.SUPERIDPARAMSETASSOC F
|
289 |
|
|
, CMS_HLT.PARAMETERSETS G
|
290 |
|
|
, CMS_HLT.SUPERIDPARAMETERASSOC H
|
291 |
|
|
, CMS_HLT.PARAMETERS I
|
292 |
|
|
, CMS_HLT.VUINT32PARAMVALUES J
|
293 |
|
|
WHERE A.CONFIGID=%d
|
294 |
|
|
AND A.SERVICEID=B.SUPERID
|
295 |
|
|
AND B.TEMPLATEID=C.SUPERID
|
296 |
|
|
AND C.NAME='PrescaleService'
|
297 |
|
|
AND B.SUPERID=D.SUPERID
|
298 |
|
|
AND D.VPSETID=E.SUPERID
|
299 |
|
|
AND E.NAME='prescaleTable'
|
300 |
|
|
AND D.VPSETID=F.SUPERID
|
301 |
|
|
AND F.PSETID=G.SUPERID
|
302 |
|
|
AND G.SUPERID=H.SUPERID
|
303 |
|
|
AND I.PARAMID=H.PARAMID
|
304 |
|
|
AND I.NAME='prescales'
|
305 |
|
|
AND J.PARAMID=H.PARAMID
|
306 |
|
|
ORDER BY F.SEQUENCENB,J.SEQUENCENB
|
307 |
|
|
""" % (self.ConfigId,)
|
308 |
|
|
|
309 |
|
|
print self.HLTSequenceMap
|
310 |
|
|
cursor.execute(SequencePrescaleQuery)
|
311 |
|
|
self.HLTPrescaleTable=[ [] ]*len(self.HLTList)
|
312 |
|
|
lastIndex=-1
|
313 |
|
|
lastSeq=-1
|
314 |
|
|
row = []
|
315 |
|
|
for seq,index,val in cursor.fetchall():
|
316 |
|
|
if lastIndex!=index-1:
|
317 |
|
|
self.HLTPrescaleTable[self.HLTSequenceMap.index(lastSeq)].append(row)
|
318 |
|
|
row=[]
|
319 |
|
|
lastSeq=seq
|
320 |
|
|
lastIndex=index
|
321 |
|
|
row.append(val)
|
322 |
|
|
|
323 |
|
|
def GetHLTSeeds(self):
|
324 |
|
|
## This is a rather delicate query, but it works!
|
325 |
|
|
## Essentially get a list of paths associated with the config, then find the module of type HLTLevel1GTSeed associated with the path
|
326 |
|
|
## Then find the parameter with field name L1SeedsLogicalExpression and look at the value
|
327 |
|
|
##
|
328 |
|
|
## NEED TO BE LOGGED IN AS CMS_HLT_R
|
329 |
|
|
cmd='cat ~hltpro/secure/cms_hlt_r.txt'
|
330 |
|
|
line=os.popen(cmd).readlines()
|
331 |
|
|
magic = line[0].rstrip("\n\r")
|
332 |
|
|
connect= 'cms_hlt_r/' + magic + '@cms_omds_lb'
|
333 |
|
|
# connect to the DB
|
334 |
|
|
tmporcl = cx_Oracle.connect(connect)
|
335 |
|
|
tmpcurs = tmporcl.cursor()
|
336 |
|
|
sqlquery ="""
|
337 |
|
|
SELECT I.NAME,A.VALUE
|
338 |
|
|
FROM
|
339 |
|
|
CMS_HLT.STRINGPARAMVALUES A,
|
340 |
|
|
CMS_HLT.PARAMETERS B,
|
341 |
|
|
CMS_HLT.SUPERIDPARAMETERASSOC C,
|
342 |
|
|
CMS_HLT.MODULETEMPLATES D,
|
343 |
|
|
CMS_HLT.MODULES E,
|
344 |
|
|
CMS_HLT.PATHMODULEASSOC F,
|
345 |
|
|
CMS_HLT.CONFIGURATIONPATHASSOC G,
|
346 |
|
|
CMS_HLT.CONFIGURATIONS H,
|
347 |
|
|
CMS_HLT.PATHS I
|
348 |
|
|
WHERE
|
349 |
|
|
A.PARAMID = C.PARAMID AND
|
350 |
|
|
B.PARAMID = C.PARAMID AND
|
351 |
|
|
B.NAME = 'L1SeedsLogicalExpression' AND
|
352 |
|
|
C.SUPERID = F.MODULEID AND
|
353 |
|
|
D.NAME = 'HLTLevel1GTSeed' AND
|
354 |
|
|
E.TEMPLATEID = D.SUPERID AND
|
355 |
|
|
F.MODULEID = E.SUPERID AND
|
356 |
|
|
F.PATHID=G.PATHID AND
|
357 |
|
|
I.PATHID=G.PATHID AND
|
358 |
|
|
G.CONFIGID=H.CONFIGID AND
|
359 |
|
|
H.CONFIGDESCRIPTOR='%s'
|
360 |
|
|
""" % (self.HLT_Key,)
|
361 |
|
|
tmpcurs.execute(sqlquery)
|
362 |
|
|
for HLTPath,L1Seed in tmpcurs.fetchall():
|
363 |
|
|
self.HLTList.append(HLTPath)
|
364 |
|
|
self.HLTSeed.append([HLTPath,L1Seed])
|
365 |
|
|
self.TriggerRates.append([HLTPath])
|
366 |
|
|
self.RateTable.append([HLTPath])
|
367 |
|
|
#self.GetHLTPrescaleMatrix(tmpcurs)
|
368 |
|
|
|
369 |
|
|
def ParseRunSetup(self):
|
370 |
|
|
#queries that need to be run only once per run
|
371 |
|
|
self.GetRunInfo()
|
372 |
|
|
self.GetL1NameIndexAssoc()
|
373 |
|
|
self.GetL1AlgoPrescales()
|
374 |
|
|
self.GetHLTSeeds()
|
375 |
|
|
|
376 |
|
|
def UpdateRun(self,StartLS,EndLS):
|
377 |
|
|
if EndLS<StartLS:
|
378 |
|
|
print "Invalid Lumi Section Range"
|
379 |
|
|
return
|
380 |
|
|
self.GetLumiInfo()
|
381 |
|
|
if StartLS < 0:
|
382 |
|
|
EndLS = max(self.LSByLS) - 1
|
383 |
|
|
StartLS = EndLS + StartLS
|
384 |
|
|
if StartLS < 2: #The parser does not parse the first LS
|
385 |
|
|
StartLS = 2
|
386 |
|
|
if StartLS == 999999:
|
387 |
|
|
StartLS = min(self.LSByLS)
|
388 |
|
|
if EndLS == 111111:
|
389 |
|
|
EndLS = max(self.LSByLS)
|
390 |
|
|
if EndLS>self.LastLSParsed:
|
391 |
|
|
print "EndLS out of range"
|
392 |
|
|
return
|
393 |
|
|
self.FillLumiInfo(StartLS,EndLS)
|
394 |
|
|
self.GetHLTRates(StartLS,EndLS)
|
395 |
|
|
self.CalculateAvL1Prescales(StartLS,EndLS)
|
396 |
|
|
self.CalculateTotalPrescales()
|
397 |
|
|
self.UnprescaleRates()
|
398 |
|
|
|
399 |
|
|
def CalculateAvL1Prescales(self,StartLS,EndLS):
|
400 |
|
|
self.AvgL1Prescales=[0]*len(self.L1IndexNameMap) ## make it an array of 0s of the right length (should be 128, but don't assume)
|
401 |
|
|
for index in range(StartLS,EndLS+1):
|
402 |
|
|
psi = self.PSColumnByLS[index]
|
403 |
|
|
if not psi:
|
404 |
|
|
print "Cannot figure out PSI for LS "+str(index)
|
405 |
|
|
continue
|
406 |
|
|
for algo in range(len(self.L1IndexNameMap)):
|
407 |
|
|
self.AvgL1Prescales[algo]+=self.L1PrescaleTable[algo][psi]
|
408 |
|
|
for i in range(len(self.AvgL1Prescales)):
|
409 |
|
|
self.AvgL1Prescales[i] = self.AvgL1Prescales[i]/(EndLS-StartLS+1)
|
410 |
|
|
|
411 |
|
|
def CalculateTotalPrescales(self):
|
412 |
|
|
self.AvgTotalPrescales=[]
|
413 |
|
|
for i,n in enumerate(self.HLTList):
|
414 |
|
|
hltPS=0
|
415 |
|
|
if len(self.TriggerRates[i])>0:
|
416 |
|
|
hltPS = self.TriggerRates[i][3]
|
417 |
|
|
l1Index = self.GetL1Index(self.HLTSeed[i][1].lstrip('"').rstrip('"'))
|
418 |
|
|
l1PS=0
|
419 |
|
|
if l1Index==-1:
|
420 |
|
|
print "Could not find prescale for seed "+self.HLTSeed[i][1]
|
421 |
|
|
else:
|
422 |
|
|
l1PS = self.AvgL1Prescales[l1Index]
|
423 |
|
|
#print hltPS+" "+l1PS
|
424 |
|
|
self.AvgTotalPrescales.append(hltPS*l1PS)
|
425 |
|
|
|
426 |
|
|
|
427 |
|
|
def UnprescaleRates(self):
|
428 |
|
|
self.PrescaledRates=[]
|
429 |
|
|
self.UnprescaledRates=[]
|
430 |
|
|
for i,n in enumerate(self.HLTList):
|
431 |
|
|
psRate=0
|
432 |
|
|
if len(self.TriggerRates[i])>0:
|
433 |
|
|
psRate = self.TriggerRates[i][0]
|
434 |
|
|
totalPS = self.AvgTotalPrescales[i]
|
435 |
|
|
unpsRate = psRate
|
436 |
|
|
if totalPS:
|
437 |
|
|
unpsRate = psRate*totalPS
|
438 |
|
|
self.PrescaledRates.append(psRate)
|
439 |
|
|
self.UnprescaledRates.append(unpsRate)
|
440 |
|
|
|
441 |
|
|
def AssemblePrescaleValues(self): ##Depends on output from ParseLumiPage and ParseTriggerModePage
|
442 |
|
|
return ## WHAT DOES THIS FUNCTION DO???
|
443 |
|
|
MissingName = "Nemo"
|
444 |
|
|
for key in self.L1TriggerMode:
|
445 |
|
|
self.L1Prescale[key] = {}
|
446 |
|
|
for n in range(min(self.LSByLS),max(self.LSByLS)+1): #"range()" excludes the last element
|
447 |
|
|
try:
|
448 |
|
|
self.L1Prescale[key][n] = self.L1TriggerMode[key][self.PSColumnByLS[n]]
|
449 |
|
|
except:
|
450 |
|
|
if not key == MissingName:
|
451 |
|
|
self.MissingPrescale.append(key)
|
452 |
|
|
MissingName = key
|
453 |
|
|
if not n < 2:
|
454 |
|
|
print "LS "+str(n)+" of key "+str(key)+" is missing from the LumiSections page"
|
455 |
|
|
|
456 |
|
|
for key in self.HLTTriggerMode:
|
457 |
|
|
self.HLTPrescale[key] = {}
|
458 |
|
|
for n in range(min(self.LSByLS),max(self.LSByLS)+1): #"range" excludes the last element
|
459 |
|
|
try:
|
460 |
|
|
self.HLTPrescale[key][n] = self.HLTTriggerMode[key][self.PSColumnByLS[n]]
|
461 |
|
|
except:
|
462 |
|
|
if not key == MissingName:
|
463 |
|
|
self.MissingPrescale.append(key)
|
464 |
|
|
MissingName = key
|
465 |
|
|
if not n < 2:
|
466 |
|
|
print "LS "+str(n)+" of key "+str(key)+" is missing from the LumiSections page"
|
467 |
|
|
|
468 |
|
|
self.PrescaleValues = [self.L1Prescale,self.HLTPrescale,self.MissingPrescale]
|
469 |
|
|
return self.PrescaleValues
|
470 |
|
|
|
471 |
|
|
def ComputeTotalPrescales(self,StartLS,EndLS):
|
472 |
|
|
return ## WHAT DOES THIS FUNCTION DO??
|
473 |
|
|
IdealHLTPrescale = {}
|
474 |
|
|
IdealPrescale = {}
|
475 |
|
|
L1_zero = {}
|
476 |
|
|
HLT_zero = {}
|
477 |
|
|
n1 = {}
|
478 |
|
|
n2 = {}
|
479 |
|
|
L1 = {}
|
480 |
|
|
L2 = {}
|
481 |
|
|
H1 = {}
|
482 |
|
|
H2 = {}
|
483 |
|
|
InitialColumnIndex = self.PSColumnByLS[int(StartLS)]
|
484 |
|
|
|
485 |
|
|
for key in self.HLTTriggerMode:
|
486 |
|
|
try:
|
487 |
|
|
DoesThisPathHaveAValidL1SeedWithPrescale = self.L1Prescale[self.HLTSeed[key]][StartLS]
|
488 |
|
|
except:
|
489 |
|
|
L1_zero[key] = True
|
490 |
|
|
HLT_zero[key] = False
|
491 |
|
|
continue
|
492 |
|
|
|
493 |
|
|
IdealHLTPrescale[key] = 0.0
|
494 |
|
|
IdealPrescale[key] = 0.0
|
495 |
|
|
n1[key] = 0
|
496 |
|
|
L1_zero[key] = False
|
497 |
|
|
HLT_zero[key] = False
|
498 |
|
|
|
499 |
|
|
for LSIterator in range(StartLS,EndLS+1): #"range" excludes the last element
|
500 |
|
|
if self.L1Prescale[self.HLTSeed[key]][LSIterator] > 0 and self.HLTPrescale[key][LSIterator] > 0:
|
501 |
|
|
IdealPrescale[key]+=1.0/(self.L1Prescale[self.HLTSeed[key]][LSIterator]*self.HLTPrescale[key][LSIterator])
|
502 |
|
|
else:
|
503 |
|
|
IdealPrescale[key]+=1.0 ##To prevent a divide by 0 error later
|
504 |
|
|
if self.L1Prescale[self.HLTSeed[key]][LSIterator] < 0.1:
|
505 |
|
|
L1_zero[key] = True
|
506 |
|
|
if self.HLTPrescale[key][LSIterator] < 0.1:
|
507 |
|
|
HLT_zero[key] = True
|
508 |
|
|
if self.PSColumnByLS[LSIterator] == InitialColumnIndex:
|
509 |
|
|
n1[key]+=1
|
510 |
|
|
|
511 |
|
|
if L1_zero[key] == True or HLT_zero[key] == True:
|
512 |
|
|
continue
|
513 |
|
|
|
514 |
|
|
IdealPrescale[key] = (EndLS + 1 - StartLS)/IdealPrescale[key]
|
515 |
|
|
|
516 |
|
|
n2[key] = float(EndLS + 1 - StartLS - n1[key])
|
517 |
|
|
L1[key] = float(self.L1Prescale[self.HLTSeed[key]][StartLS])
|
518 |
|
|
L2[key] = float(self.L1Prescale[self.HLTSeed[key]][EndLS])
|
519 |
|
|
H1[key] = float(self.HLTPrescale[key][StartLS])
|
520 |
|
|
H2[key] = float(self.HLTPrescale[key][EndLS])
|
521 |
|
|
|
522 |
|
|
IdealHLTPrescale[key] = ((n1[key]/L1[key])+(n2[key]/L2[key]))/((n1[key]/(L1[key]*H1[key]))+(n2[key]/(L2[key]*H2[key])))
|
523 |
|
|
|
524 |
|
|
self.TotalPSInfo = [L1_zero,HLT_zero,IdealPrescale,IdealHLTPrescale,n1,n2,L1,L2,H1,H2]
|
525 |
|
|
|
526 |
|
|
return self.TotalPSInfo
|
527 |
|
|
|
528 |
|
|
|
529 |
|
|
def CorrectForPrescaleChange(self,StartLS,EndLS):
|
530 |
|
|
[L1_zero,HLT_zero,IdealPrescale,IdealHLTPrescale,n1,n2,L1,L2,H1,H2] = self.TotalPSInfo
|
531 |
|
|
xLS = {}
|
532 |
|
|
RealPrescale = {}
|
533 |
|
|
|
534 |
|
|
for key in self.HLTTriggerMode:
|
535 |
|
|
if L1_zero[key] == True or HLT_zero[key] == True:
|
536 |
|
|
continue
|
537 |
|
|
[TriggerRate,L1Pass,PSPass,PS,Seed,StartLS,EndLS] = self.TriggerRates[key]
|
538 |
|
|
if PS > 0.95 * IdealHLTPrescale[key] and PS < 1.05 * IdealHLTPrescale[key]:
|
539 |
|
|
RealPrescale[key] = IdealPrescale[key]
|
540 |
|
|
continue
|
541 |
|
|
|
542 |
|
|
if H1[key] == H2[key] and L1[key] == L2[key] and not EndLS > max(self.LSByLS) - 1: ##Look for prescale change into the next LS
|
543 |
|
|
H2[key] = float(self.HLTPrescale[key][EndLS+1])
|
544 |
|
|
L2[key] = float(self.L1Prescale[self.HLTSeed[key]][EndLS+1])
|
545 |
|
|
if H1[key] == H2[key] and L1[key] == L2[key] and not StartLS < 3:
|
546 |
|
|
H1[key] = float(self.HLTPrescale[key][StartLS-1])
|
547 |
|
|
L1[key] = float(self.L1Prescale[self.HLTSeed[key]][StartLS-1])
|
548 |
|
|
if H1[key] == H2[key]:
|
549 |
|
|
xLS[key] = 0
|
550 |
|
|
else:
|
551 |
|
|
xLS[key] = ((-(PS/IdealHLTPrescale[key])*(L2[key]*n1[key]+L1[key]*n2[key])*(H2[key]*L2[key]*n1[key]+H1[key]*L1[key]*n2[key]))+((H2[key]*L2[key]*n1[key]+H1[key]*L1[key]*n2[key])*(L2[key]*n1[key]+L1[key]*n2[key])))/(((PS/IdealHLTPrescale[key])*(L2[key]*n1[key]+L1[key]*n2[key])*(H1[key]*L1[key]-H2[key]*L2[key]))+((H2[key]*L2[key]*n1[key]+H1[key]*L1[key]*n2[key])*(L2[key]-L1[key])))
|
552 |
|
|
|
553 |
|
|
if xLS[key] > 1:
|
554 |
|
|
xLS[key] = 1
|
555 |
|
|
if xLS[key] < -1:
|
556 |
|
|
xLS[key] = -1
|
557 |
|
|
RealPrescale[key] = (n1[key] + n2[key])/(((n1[key] - xLS[key])/(H1[key]*L1[key]))+(n2[key]+xLS[key])/(H2[key]*L2[key]))
|
558 |
|
|
|
559 |
|
|
self.CorrectedPSInfo = [RealPrescale,xLS,L1,L2,H1,H2]
|
560 |
|
|
|
561 |
|
|
return self.CorrectedPSInfo
|
562 |
|
|
|
563 |
|
|
def Save(self, fileName):
|
564 |
|
|
dir = os.path.dirname(fileName)
|
565 |
|
|
if not os.path.exists(dir):
|
566 |
|
|
os.makedirs(dir)
|
567 |
|
|
pickle.dump( self, open( fileName, 'w' ) )
|
568 |
|
|
|
569 |
|
|
def Load(self, fileName):
|
570 |
|
|
self = pickle.load( open( fileName ) )
|