forked from cms-tsg-fog/RateMon
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDatabaseParser.py
executable file
·1333 lines (1125 loc) · 56.5 KB
/
DatabaseParser.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/python
import cx_Oracle
import cPickle as pickle
import os
import sys
import time
import re
from colors import *
try: ## set is builtin in python 2.6.4 and sets is deprecated
set
except NameError:
from sets import Set
class DatabaseParser:
def __init__(self):
self.curs = ConnectDB()
##-- Defined in ParsePage1 --##
self.RunNumber = 0
##-- Defined in ParseRunPage --##
self.Date=''
self.L1_HLT_Key=''
self.HLT_Key=''
self.GTRS_Key=''
self.TSC_Key=''
self.GT_Key=''
self.ConfigId=0
##-- Defined in ParseHLTSummaryPage --##
self.HLTRatesByLS = {}
self.HLTPSByLS = {}
self.nAlgoBits=0
self.L1PrescaleTable=[]
self.AvgL1Prescales=[] ## contains the average L1 prescales for the current LS range range
self.HLTList=[]
self.AvgTotalPrescales={}
self.HLTPrescaleTable=[] ## can't fill this yet
self.UnprescaledRates={}
self.PrescaledRates={}
##-- Defined in ParseLumiPage --##
self.LastLSParsed=-1
self.InstLumiByLS = {}
self.DeliveredLumiByLS = {}
self.LiveLumiByLS = {}
self.PSColumnByLS = {}
self.AvInstLumi = 0
self.AvDeliveredLumi = 0
self.AvLiveLumi = 0
self.AvDeadTime = 0
self.LumiInfo = {} ##Returns
self.DeadTime = {}
self.Physics = {}
self.Active = {}
self.B1Pres = {}
self.B2Pres = {}
self.B1Stab = {}
self.B2Stab = {}
self.EBP = {}
self.EBM = {}
self.EEP = {}
self.EEM = {}
self.HBHEA = {}
self.HBHEB = {}
self.HBHEC = {}
self.HF = {}
self.RPC = {}
self.DT0 = {}
self.DTP = {}
self.DTM = {}
self.CSCP = {}
self.CSCM = {}
self.TOB = {}
self.TIBTID= {}
self.TECP = {}
self.TECM = {}
self.BPIX = {}
self.FPIX = {}
self.ESP = {}
self.ESM = {}
self.DeadTimeBeamActive = {}
##-- Defined in ParsePSColumnPage (not currently used) --##
self.PSColumnChanges=[] ##Returns
##-- Defined in ParseTriggerModePage --##
self.L1TriggerMode={} ##
self.HLTTriggerMode={} ##
self.HLTSeed={}
self.HLTSequenceMap=[]
self.TriggerInfo = [] ##Returns
##-- Defined in AssemblePrescaleValues --##
self.L1Prescale={}
self.L1IndexNameMap={}
self.HLTPrescale=[]
self.MissingPrescale=[]
self.PrescaleValues=[] ##Returns
##-- Defined in ComputeTotalPrescales --##
self.TotalPSInfo = [] ##Returns # #collection
##-- Defined in CorrectForPrescaleChange --##
self.CorrectedPSInfo = [] ##Returns
self.HLTPrescaleTable={}
##-- In the current Parser.py philosophy, only RunNumber is set globally
## - LS range is set from the outside for each individual function
#self.FirstLS = -1
#self.LastLS = -1
def GetRunInfo(self):
## This query gets the L1_HLT Key (A), the associated HLT Key (B) and the Config number for that key (C)
KeyQuery = """
SELECT A.TRIGGERMODE, B.HLT_KEY, B.GT_RS_KEY, B.TSC_KEY, C.CONFIGID, D.GT_KEY FROM
CMS_WBM.RUNSUMMARY A, CMS_L1_HLT.L1_HLT_CONF B, CMS_HLT_GDR.U_CONFVERSIONS C, CMS_TRG_L1_CONF.TRIGGERSUP_CONF D WHERE
B.ID = A.TRIGGERMODE AND C.NAME = B.HLT_KEY AND D.TS_Key = B.TSC_Key AND A.RUNNUMBER=%d
""" % (self.RunNumber,)
try:
self.curs.execute(KeyQuery)
self.L1_HLT_Key,self.HLT_Key,self.GTRS_Key,self.TSC_Key,self.ConfigId,self.GT_Key = self.curs.fetchone()
except:
##print "Unable to get L1 and HLT keys for this run"
pass
def UpdateRateTable(self): # lets not rebuild the rate table every time, rather just append new LSs
pass
def GetHLTRates(self,LSRange):
self.GetHLTPrescaleMatrix()
sqlquery = """
SELECT SUM(A.L1PASS),SUM(A.PSPASS),SUM(A.PACCEPT),SUM(A.PEXCEPT), A.LSNUMBER,
(SELECT M.NAME FROM CMS_HLT_GDR.U_PATHS M,CMS_HLT_GDR.U_PATHIDS L WHERE L.PATHID=A.PATHID AND M.ID=L.ID_PATH) PATHNAME FROM
CMS_RUNINFO.HLT_SUPERVISOR_TRIGGERPATHS A WHERE RUNNUMBER=%s AND A.LSNUMBER IN %s GROUP BY A.LSNUMBER,A.PATHID
"""
LSRangeSTR = str(LSRange)
LSRangeSTR = LSRangeSTR.replace("[","(")
LSRangeSTR = LSRangeSTR.replace("]",")")
StartLS = LSRange[0]
EndLS = LSRange[-1]
LSUsed={}
for lumisection in LSRange:
LSUsed[lumisection]=False
AvgL1Prescales = [0]*self.nAlgoBits
#print "Getting HLT Rates for LS from %d to %d" % (LSRange[0],LSRange[-1],)
query = sqlquery % (self.RunNumber,LSRangeSTR)
# print "RUN NUMBER AND LS RANGE ==",self.RunNumber," ",LSRangeSTR
try:
self.curs.execute(query)
except:
print "Unsuccessful db query."
TriggerRates = {}
for L1Pass,PSPass,HLTPass,HLTExcept,LS ,name in self.curs.fetchall():
#if not self.HLTSeed.has_key(name):
# continue
rate = HLTPass/23.3
#print "Trg Name == ",name," rate == ",rate
hltps = 0
if not TriggerRates.has_key(name):
try:
psi = self.PSColumnByLS[LS]
except:
print "HLT in: Cannot figure out PSI for LS "+str(StartLS)+" setting to 0"
print "The value of LSRange[0] is:"
print str(LS)
psi = 0
if psi is None:
psi=0
#if self.HLTPrescaleTable.has_key(name):
try:
hltps = self.HLTPrescaleTable[name][psi]
except:#else:
if PSPass:
hltps = float(L1Pass)/PSPass
hltps = float(hltps)
try:
if self.L1IndexNameMap.has_key(self.HLTSeed[name]):
l1ps = self.L1PrescaleTable[self.L1IndexNameMap[self.HLTSeed[name]]][psi]
else:
AvL1Prescales = self.CalculateAvL1Prescales([LS])
l1ps = self.UnwindORSeed(self.HLTSeed[name],AvL1Prescales)
except:
#print "The path: ",name," does not have a L1 seed"
l1ps =1
ps = l1ps*hltps
###if ps < 1: ### want PS=0 too!
#print "Oops! somehow ps for "+str(name)+" = "+str(ps)+", where L1 PS = "+str(l1ps)+" and HLT PS = "+str(hltps)
# ps = 1
psrate = ps*rate
TriggerRates[name]= [ps,rate,psrate,1]
LSUsed[LS]=True
else:
[ops,orate,opsrate,on] = TriggerRates[name]
try:
psi = self.PSColumnByLS[LSRange[on]]
except:
print "HLT out: Cannot figure out PSI for index "+str(on)+" setting to 0"
print "The value of LSRange[on] is:"
print str(LS)
psi = 0
if psi is None:
psi=3
if self.HLTPrescaleTable.has_key(name):
hltps = self.HLTPrescaleTable[name][psi]
else:
if PSPass:
hltps = float(L1Pass)/PSPass
hltps = float(hltps)
try:
if self.L1IndexNameMap.has_key(self.HLTSeed[name]):
l1ps = self.L1PrescaleTable[self.L1IndexNameMap[self.HLTSeed[name]]][psi]
else:
AvL1Prescales = self.CalculateAvL1Prescales([LS])
l1ps = self.UnwindORSeed(self.HLTSeed[name],AvL1Prescales)
except:
#print "The path: ",name," does not have a L1 seed"
l1ps =1
ps = l1ps*hltps
#if ps < 1: ###want PS=0 too!
##print "Oops! somehow ps for "+str(name)+" = "+str(ps)+", where L1 PS = "+str(l1ps)+" and HLT PS = "+str(hltps)
# ps = 1
psrate = ps*rate
TriggerRates[name]= [ops+ps,orate+rate,opsrate+psrate,on+1]
LSUsed[LS]=True
###check if LS is used above, if not and deadtime is 100% add extra lumi for calculation
lumirange_one=[]
for key in LSUsed.iterkeys():
lumirange_one=[key]##set LSRange equal to one LS so can get deadtime
if LSUsed[key]:
continue
if self.GetDeadTimeBeamActive(lumirange_one)<=0.9999:
##print "LS",key,"gottcha", LSUsed[key]
LSUsed[key]=True
print "Some strange error LS",key, "has deadtime ", self.GetDeadTimeBeamActive(lumirange_one)
else:
print "increasing # LS by one, LS", key, "has 100% deadtime"
for name,val in TriggerRates.iteritems():
[ops,orate,opsrate,on] = TriggerRates[name]
TriggerRates[name]= [ops,orate,opsrate,on+1]
for name,val in TriggerRates.iteritems():
[ps,rate,psrate,n] = val
avps = ps/n
try:
ps = psrate/rate
except:
#print "Rate = 0 for "+str(name)+", setting ps to 1"
ps = avps
TriggerRates[name] = [avps,ps,rate/n,psrate/n]
return TriggerRates
def GetAvgTrigRateInLSRange(self,triggerName,LSRange):
sqlquery = """
SELECT A.PACCEPT
FROM CMS_RUNINFO.HLT_SUPERVISOR_TRIGGERPATHS A, CMS_HLT_GDR.U_PATHS B,CMS_HLT_GDR.U_PATHIDS C
WHERE RUNNUMBER=%s AND B.NAME =\'%s\' AND A.PATHID = C.PATHID AND B.ID=C.ID_PATH AND A.LSNUMBER IN %s
"""
LSRangeSTR = str(LSRange)
LSRangeSTR = LSRangeSTR.replace("[","(")
LSRangeSTR = LSRangeSTR.replace("]",")")
query = sqlquery % (self.RunNumber,triggerName,LSRangeSTR)
self.curs.execute(query)
avg_rate = sum([counts[0] for counts in self.curs.fetchall()])/ (23.3 * len(LSRange))
return avg_rate
def GetTrigRatesInLSRange(self,triggerName,LSRange):
sqlquery = """
SELECT A.LSNUMBER, A.PACCEPT
FROM CMS_RUNINFO.HLT_SUPERVISOR_TRIGGERPATHS A, CMS_HLT_GDR.U_PATHS B,CMS_HLT_GDR.U_PATHIDS C
WHERE RUNNUMBER=%s AND B.NAME =\'%s\' AND A.PATHID = C.PATHID AND B.ID=C.ID_PATH AND A.LSNUMBER IN %s
ORDER BY A.LSNUMBER
"""
LSRangeSTR = str(LSRange)
LSRangeSTR = LSRangeSTR.replace("[","(")
LSRangeSTR = LSRangeSTR.replace("]",")")
query = sqlquery % (self.RunNumber,triggerName,LSRangeSTR)
self.curs.execute(query)
r={}
for ls,accept in self.curs.fetchall():
r[ls] = accept/23.3
return r
def GetStreamRate(self,streamName):
sqlquery="""SELECT EVT_RATE,UPDATE_TIME FROM CMS_STOMGR.VIEW_SM_STREAMS WHERE RUN_NUMBER = \'%s\' AND
STREAM = \'%s\'"""
query = sqlquery % (self.RunNumber,streamName)
self.curs.execute(query)
try:
r,t = self.curs.fetchone()
r = float(r)
return [r,t]
except:
print "Failed to fetch stream ",streamName," rate from db. "
return [0,'UNABLE TO FETCH STREAM RATE FROM DB']
def GetTriggerRatesByLS(self,triggerName):
sqlquery = """
SELECT A.LSNUMBER, A.PACCEPT
FROM CMS_RUNINFO.HLT_SUPERVISOR_TRIGGERPATHS A, CMS_HLT_GDR.U_PATHS B,CMS_HLT_GDR.U_PATHIDS C
WHERE RUNNUMBER=%s AND B.NAME =\'%s\' AND A.PATHID = C.PATHID AND B.ID=C.ID_PATH
ORDER BY A.LSNUMBER
""" % (self.RunNumber,triggerName,)
self.curs.execute(sqlquery)
r={}
for ls,accept in self.curs.fetchall():
r[ls] = accept/23.3
return r
def GetAllTriggerRatesByLS(self):
for hltName in self.HLTSeed:
self.HLTRatesByLS[hltName] = self.GetTriggerRatesByLS(hltName)
def GetPSColumnsInLSRange(self,LSRange):
sqlquery="""SELECT LUMI_SECTION,PRESCALE_INDEX FROM
CMS_GT_MON.LUMI_SECTIONS B WHERE B.RUN_NUMBER=%s AND B.LUMI_SECTION IN %s"""
LSRangeSTR = str(LSRange)
LSRangeSTR = LSRangeSTR.replace("[","(")
LSRangeSTR = LSRangeSTR.replace("]",")")
query = sqlquery % (self.RunNumber,LSRangeSTR)
self.curs.execute(query)
ps_columns={}
for ls, ps_index in self.curs.fetchall():
ps_columns[ls] = ps_index
return ps_columns
def GetAvDeliveredLumi(self,LSRange):
sqlquery="""SELECT DELIVLUMI FROM
CMS_RUNTIME_LOGGER.LUMI_SECTIONS A WHERE A.RUNNUMBER=%s AND A.LUMISECTION IN %s"""
LSRangeSTR = str(LSRange)
LSRangeSTR = LSRangeSTR.replace("[","(")
LSRangeSTR = LSRangeSTR.replace("]",")")
query = sqlquery % (self.RunNumber,LSRangeSTR)
self.curs.execute(query)
delivered = [val[0] for val in self.curs.fetchall()]
avg_delivered = sum(delivered)/len(LSRange)
return avg_delivered
def GetLumiInfo(self):
sqlquery="""SELECT RUNNUMBER,LUMISECTION,PRESCALE_INDEX,INSTLUMI,LIVELUMI,DELIVLUMI,DEADTIME
,DCSSTATUS,PHYSICS_FLAG,CMS_ACTIVE
FROM CMS_RUNTIME_LOGGER.LUMI_SECTIONS A,CMS_GT_MON.LUMI_SECTIONS B WHERE A.RUNNUMBER=%s
AND B.RUN_NUMBER(+)=A.RUNNUMBER AND B.LUMI_SECTION(+)=A.LUMISECTION AND A.LUMISECTION > %d
ORDER BY A.RUNNUMBER,A.LUMISECTION"""
## Get the lumi information for the run, just update the table, don't rebuild it every time
query = sqlquery % (self.RunNumber,self.LastLSParsed)
self.curs.execute(query)
pastLSCol=-1
for run,ls,psi,inst,live,dlive,dt,dcs,phys,active in self.curs.fetchall():
if psi is None:
psi = GetLastKnownPSIndex(self.PSColumnByLS)
self.PSColumnByLS[ls]=psi
self.InstLumiByLS[ls]=inst
self.LiveLumiByLS[ls]=live
self.DeliveredLumiByLS[ls]=dlive
self.DeadTime[ls]=dt
self.Physics[ls]=phys
self.Active[ls]=active
if pastLSCol!=-1 and ls!=pastLSCol:
self.PSColumnChanges.append([ls,psi])
pastLSCol=ls
if ls>self.LastLSParsed:
self.LastLSParsed=ls
self.LumiInfo = [self.PSColumnByLS, self.InstLumiByLS, self.DeliveredLumiByLS, self.LiveLumiByLS, self.DeadTime, self.Physics, self.Active]
return self.LumiInfo
def GetMoreLumiInfo(self):
sqlquery="""SELECT RUNNUMBER,LUMISECTION,BEAM1_PRESENT, BEAM2_PRESENT, BEAM1_STABLE, BEAM2_STABLE, EBP_READY,EBM_READY,EEP_READY,EEM_READY,HBHEA_READY,HBHEB_READY,HBHEC_READY,HF_READY,RPC_READY,DT0_READY,DTP_READY,DTM_READY,CSCP_READY,CSCM_READY,TOB_READY,TIBTID_READY,TECP_READY,TECM_READY,BPIX_READY,FPIX_READY,ESP_READY,ESM_READY
FROM CMS_RUNTIME_LOGGER.LUMI_SECTIONS A,CMS_GT_MON.LUMI_SECTIONS B WHERE A.RUNNUMBER=%s
AND B.RUN_NUMBER(+)=A.RUNNUMBER AND B.LUMI_SECTION(+)=A.LUMISECTION AND A.LUMISECTION > %d
ORDER BY A.RUNNUMBER,A.LUMISECTION"""
## Get the lumi information for the run, just update the table, don't rebuild it every time
query = sqlquery % (self.RunNumber,self.LastLSParsed)
self.curs.execute(query)
pastLSCol=-1
for run,ls,b1pres,b2pres,b1stab,b2stab,ebp,ebm,eep,eem,hbhea,hbheb,hbhec,hf,rpc,dt0,dtp,dtm,cscp,cscm,tob,tibtid,tecp,tecm,bpix,fpix,esp,esm in self.curs.fetchall():
self.B1Pres[ls]=b1pres
self.B2Pres[ls]=b2pres
self.B1Stab[ls]=b1stab
self.B2Stab[ls]=b2stab
self.EBP[ls]= ebp
self.EBM[ls] = ebm
self.EEP[ls] = eep
self.EEM[ls] = eem
self.HBHEA[ls] = hbhea
self.HBHEB[ls] = hbheb
self.HBHEC[ls] = hbhec
self.HF[ls] = hf
self.RPC[ls] = rpc
self.DT0[ls] = dt0
self.DTP[ls] = dtp
self.DTM[ls] = dtm
self.CSCP[ls] = cscp
self.CSCM[ls] = cscm
self.TOB[ls] = tob
self.TIBTID[ls]= tibtid
self.TECP[ls] = tecp
self.TECM[ls] = tecm
self.BPIX[ls] = bpix
self.FPIX[ls] = fpix
self.ESP[ls] = esp
self.ESM[ls] = esm
pastLSCol=ls
if ls>self.LastLSParsed:
self.LastLSParsed=ls
self.MoreLumiInfo ={'b1pres':self.B1Pres,'b2pres':self.B2Pres,'b1stab':self.B1Stab,'b2stab':self.B2Stab,'ebp':self.EBP,'ebm':self.EBM,'eep':self.EEP,'eem':self.EEM,'hbhea':self.HBHEA,'hbheb':self.HBHEB,'hbhec':self.HBHEC,'hf':self.HF,'rpc':self.RPC,'dt0':self.DT0,'dtp':self.DTP,'dtm':self.DTM,'cscp':self.CSCP,'cscm':self.CSCM,'tob':self.TOB,'tibtid':self.TIBTID,'tecp':self.TECP,'tecm':self.TECM,'bpix':self.BPIX,'fpix':self.FPIX,'esp':self.ESP,'esm':self.ESM}
return self.MoreLumiInfo
def GetL1HLTseeds(self):
#print self.HLTSeed
L1HLTseeds={}
for HLTkey in self.HLTSeed.iterkeys():
#print HLTkey, self.HLTSeed[HLTkey]
dummy=str(self.HLTSeed[HLTkey])
if dummy.find(" OR ") == -1:
dummylist=[]
dummylist.append(dummy)
L1HLTseeds[StripVersion(HLTkey)]=dummylist
continue # Not an OR of seeds
seedList = dummy.split(" OR ")
#print seedList
L1HLTseeds[StripVersion(HLTkey)]=seedList
if len(seedList)==1:
print "error: zero length L1 seed"
continue #shouldn't get here
#print L1HLTseeds
return L1HLTseeds
def GetDeadTimeBeamActive(self,LSRange):
sqlquery=""" select FRACTION
from
CMS_GT_MON.V_SCALERS_TCS_DEADTIME
where
RUN_NUMBER=%s and
LUMI_SECTION in %s and
SCALER_NAME='DeadtimeBeamActive'"""
LSRangeSTR = str(LSRange)
LSRangeSTR = LSRangeSTR.replace("[","(")
LSRangeSTR = LSRangeSTR.replace("]",")")
query=sqlquery %(self.RunNumber,LSRangeSTR)
#print query
self.curs.execute(query)
deadtimeba_sum=0
ii=0
for deadtimebeamactive in self.curs.fetchall():
try:
deadtimeba_sum=deadtimeba_sum+deadtimebeamactive[0]
except:
##print "no dtba for run ",self.RunNumber, ", ls ",LSRange[ii], "using dt"
deadtimeba_sum=deadtimeba_sum+self.GetDeadTime(LSRange[ii])
ii=ii+1
deadtimeba_av=deadtimeba_sum/len(LSRange)
return deadtimeba_av
def GetDeadTime(self,LS):
sqlquery=""" select FRACTION
from
CMS_GT_MON.V_SCALERS_TCS_DEADTIME
where
RUN_NUMBER=%s and
LUMI_SECTION=%s and
SCALER_NAME='Deadtime'"""
query=sqlquery %(self.RunNumber,LS)
#print query
self.curs.execute(query)
dt=1.0
for deadtime in self.curs.fetchall():
try:
dt=deadtime[0]
#print "dt=",dt
except:
print "no dt for run ",self.RunNumber, ", ls ",LS
dt=1.0
return dt
def GetAvLumiInfo(self,LSRange):
nLS=0;
AvInstLumi=0
try:
StartLS = LSRange[0]
EndLS = LSRange[-1]
#print "startls=",StartLS, "endls=",EndLS
try: ## Cosmics won't have lumi info
maxlive = self.LiveLumiByLS[EndLS]
maxdelivered = self.DeliveredLumiByLS[EndLS]
for iterator in LSRange:
if self.LiveLumiByLS[iterator] > maxlive:
maxlive = self.LiveLumiByLS[iterator]
if self.DeliveredLumiByLS[iterator] > maxdelivered:
maxdelivered = self.DeliveredLumiByLS[iterator]
AvLiveLumi=maxlive-self.LiveLumiByLS[StartLS]
AvDeliveredLumi=maxdelivered-self.DeliveredLumiByLS[StartLS]
except:
AvLiveLumi=0
AvDeliveredLumi=0
if AvDeliveredLumi > 0:
AvDeadTime = 1 - AvLiveLumi/AvDeliveredLumi
else:
if AvLiveLumi > 0:
print "Live Lumi > 0 but Delivered <= 0: problem"
AvDeadTime = 0.0
PSCols=[]
for ls in LSRange:
try:
try:
AvInstLumi+=self.InstLumiByLS[ls]
except:
pass
PSCols.append(self.PSColumnByLS[ls])
nLS+=1
except:
print "ERROR: Lumi section "+str(ls)+" not in bounds"
return [0.,0.,0.,0.,[]]
return [AvInstLumi/nLS,(1000.0/23.3)*AvLiveLumi/(EndLS-StartLS),(1000.0/23.3)*AvDeliveredLumi/(EndLS-StartLS), AvDeadTime,PSCols]
except:
if LSRange[0] == LSRange[-1]:
AvInstLumi = self.InstLumiByLS[StartLS]
try:
AvLiveLumi = self.LiveLumiByLS[StartLS]-self.LiveLumiByLS[StartLS-1]
AvDeliveredLumi = self.DeliveredLumiByLS[StartLS]-self.DeliveredLumiByLS[StartLS-1]
except:
try:
AvLiveLumi = self.LiveLumiByLS[StartLS+1]-self.LiveLumiByLS[StartLS]
AvDeliveredLumi = self.DeliveredLumiByLS[StartLS+1]-self.DeliveredLumiByLS[StartLS]
except:
print "missing live/delivered run ",self.RunNumber, "ls ",LSRange
AvLiveLumi = 0
AvDeliveredLumi = 0
if AvDeliveredLumi > 0:
AvDeadTime = 1 - AvLiveLumi/AvDeliveredLumi
elif AvLiveLumi > 0:
print "Live Lumi > 0 but Delivered <= 0: problem run ",self.RunNumber, " ls ",LSRange
AvDeadTime = 1.0
else:
AvDeadTime=1.0
PSCols = [self.PSColumnByLS[StartLS]]
return [AvInstLumi,(1000.0/23.3)*AvLiveLumi,(1000.0/23.3)*AvDeliveredLumi,AvDeadTime,PSCols]
else:
return [0.,0.,0.,0.,[]]
def ParsePSColumnPage(self): ## this is now done automatically when we read the db
pass
def GetL1NameIndexAssoc(self):
## get the L1 algo names associated with each algo bit
AlgoNameQuery = """SELECT ALGO_INDEX, ALIAS FROM CMS_GT.L1T_MENU_ALGO_VIEW
WHERE MENU_IMPLEMENTATION IN (SELECT L1T_MENU_FK FROM CMS_GT.GT_SETUP WHERE ID='%s')
ORDER BY ALGO_INDEX""" % (self.GT_Key,)
self.curs.execute(AlgoNameQuery)
for index,name in self.curs.fetchall():
self.L1IndexNameMap[name] = index
def GetL1AlgoPrescales(self):
L1PrescalesQuery= """
SELECT
PRESCALE_FACTOR_ALGO_000,PRESCALE_FACTOR_ALGO_001,PRESCALE_FACTOR_ALGO_002,PRESCALE_FACTOR_ALGO_003,PRESCALE_FACTOR_ALGO_004,PRESCALE_FACTOR_ALGO_005,
PRESCALE_FACTOR_ALGO_006,PRESCALE_FACTOR_ALGO_007,PRESCALE_FACTOR_ALGO_008,PRESCALE_FACTOR_ALGO_009,PRESCALE_FACTOR_ALGO_010,PRESCALE_FACTOR_ALGO_011,
PRESCALE_FACTOR_ALGO_012,PRESCALE_FACTOR_ALGO_013,PRESCALE_FACTOR_ALGO_014,PRESCALE_FACTOR_ALGO_015,PRESCALE_FACTOR_ALGO_016,PRESCALE_FACTOR_ALGO_017,
PRESCALE_FACTOR_ALGO_018,PRESCALE_FACTOR_ALGO_019,PRESCALE_FACTOR_ALGO_020,PRESCALE_FACTOR_ALGO_021,PRESCALE_FACTOR_ALGO_022,PRESCALE_FACTOR_ALGO_023,
PRESCALE_FACTOR_ALGO_024,PRESCALE_FACTOR_ALGO_025,PRESCALE_FACTOR_ALGO_026,PRESCALE_FACTOR_ALGO_027,PRESCALE_FACTOR_ALGO_028,PRESCALE_FACTOR_ALGO_029,
PRESCALE_FACTOR_ALGO_030,PRESCALE_FACTOR_ALGO_031,PRESCALE_FACTOR_ALGO_032,PRESCALE_FACTOR_ALGO_033,PRESCALE_FACTOR_ALGO_034,PRESCALE_FACTOR_ALGO_035,
PRESCALE_FACTOR_ALGO_036,PRESCALE_FACTOR_ALGO_037,PRESCALE_FACTOR_ALGO_038,PRESCALE_FACTOR_ALGO_039,PRESCALE_FACTOR_ALGO_040,PRESCALE_FACTOR_ALGO_041,
PRESCALE_FACTOR_ALGO_042,PRESCALE_FACTOR_ALGO_043,PRESCALE_FACTOR_ALGO_044,PRESCALE_FACTOR_ALGO_045,PRESCALE_FACTOR_ALGO_046,PRESCALE_FACTOR_ALGO_047,
PRESCALE_FACTOR_ALGO_048,PRESCALE_FACTOR_ALGO_049,PRESCALE_FACTOR_ALGO_050,PRESCALE_FACTOR_ALGO_051,PRESCALE_FACTOR_ALGO_052,PRESCALE_FACTOR_ALGO_053,
PRESCALE_FACTOR_ALGO_054,PRESCALE_FACTOR_ALGO_055,PRESCALE_FACTOR_ALGO_056,PRESCALE_FACTOR_ALGO_057,PRESCALE_FACTOR_ALGO_058,PRESCALE_FACTOR_ALGO_059,
PRESCALE_FACTOR_ALGO_060,PRESCALE_FACTOR_ALGO_061,PRESCALE_FACTOR_ALGO_062,PRESCALE_FACTOR_ALGO_063,PRESCALE_FACTOR_ALGO_064,PRESCALE_FACTOR_ALGO_065,
PRESCALE_FACTOR_ALGO_066,PRESCALE_FACTOR_ALGO_067,PRESCALE_FACTOR_ALGO_068,PRESCALE_FACTOR_ALGO_069,PRESCALE_FACTOR_ALGO_070,PRESCALE_FACTOR_ALGO_071,
PRESCALE_FACTOR_ALGO_072,PRESCALE_FACTOR_ALGO_073,PRESCALE_FACTOR_ALGO_074,PRESCALE_FACTOR_ALGO_075,PRESCALE_FACTOR_ALGO_076,PRESCALE_FACTOR_ALGO_077,
PRESCALE_FACTOR_ALGO_078,PRESCALE_FACTOR_ALGO_079,PRESCALE_FACTOR_ALGO_080,PRESCALE_FACTOR_ALGO_081,PRESCALE_FACTOR_ALGO_082,PRESCALE_FACTOR_ALGO_083,
PRESCALE_FACTOR_ALGO_084,PRESCALE_FACTOR_ALGO_085,PRESCALE_FACTOR_ALGO_086,PRESCALE_FACTOR_ALGO_087,PRESCALE_FACTOR_ALGO_088,PRESCALE_FACTOR_ALGO_089,
PRESCALE_FACTOR_ALGO_090,PRESCALE_FACTOR_ALGO_091,PRESCALE_FACTOR_ALGO_092,PRESCALE_FACTOR_ALGO_093,PRESCALE_FACTOR_ALGO_094,PRESCALE_FACTOR_ALGO_095,
PRESCALE_FACTOR_ALGO_096,PRESCALE_FACTOR_ALGO_097,PRESCALE_FACTOR_ALGO_098,PRESCALE_FACTOR_ALGO_099,PRESCALE_FACTOR_ALGO_100,PRESCALE_FACTOR_ALGO_101,
PRESCALE_FACTOR_ALGO_102,PRESCALE_FACTOR_ALGO_103,PRESCALE_FACTOR_ALGO_104,PRESCALE_FACTOR_ALGO_105,PRESCALE_FACTOR_ALGO_106,PRESCALE_FACTOR_ALGO_107,
PRESCALE_FACTOR_ALGO_108,PRESCALE_FACTOR_ALGO_109,PRESCALE_FACTOR_ALGO_110,PRESCALE_FACTOR_ALGO_111,PRESCALE_FACTOR_ALGO_112,PRESCALE_FACTOR_ALGO_113,
PRESCALE_FACTOR_ALGO_114,PRESCALE_FACTOR_ALGO_115,PRESCALE_FACTOR_ALGO_116,PRESCALE_FACTOR_ALGO_117,PRESCALE_FACTOR_ALGO_118,PRESCALE_FACTOR_ALGO_119,
PRESCALE_FACTOR_ALGO_120,PRESCALE_FACTOR_ALGO_121,PRESCALE_FACTOR_ALGO_122,PRESCALE_FACTOR_ALGO_123,PRESCALE_FACTOR_ALGO_124,PRESCALE_FACTOR_ALGO_125,
PRESCALE_FACTOR_ALGO_126,PRESCALE_FACTOR_ALGO_127
FROM CMS_GT.GT_FDL_PRESCALE_FACTORS_ALGO A, CMS_GT.GT_RUN_SETTINGS_PRESC_VIEW B
WHERE A.ID=B.PRESCALE_FACTORS_ALGO_FK AND B.ID='%s'
""" % (self.GTRS_Key,)
self.curs.execute(L1PrescalesQuery)
## This is pretty horrible, but this how you get them!!
tmp = self.curs.fetchall()
self.L1PrescaleTable = []
for ps in tmp[0]: #build the prescale table initially
self.L1PrescaleTable.append([ps])
for line in tmp[1:]: # now fill it
for ps,index in zip(line,range(len(line))):
self.L1PrescaleTable[index].append(ps)
self.nAlgoBits=128
def GetHLTIndex(self,name):
for i,n in enumerate(self.HLTList):
if n.find(name)!=-1:
return i
#print name
return -1
def GetHLTPrescaleMatrix(self):
tmp_curs = ConnectDB('hlt')
configIDQuery = "SELECT CONFIGID FROM CMS_HLT_GDR.U_CONFVERSIONS WHERE NAME='%s'" % (self.HLT_Key)
tmp_curs.execute(configIDQuery)
ConfigId, = tmp_curs.fetchone()
SequencePathQuery ="""
SELECT prescale_sequence , triggername FROM ( SELECT J.ID, J.NAME, LAG(J.ORD,1,0) OVER (order by J.ID) PRESCALE_SEQUENCE, J.VALUE TRIGGERNAME, trim('{' from trim('}' from LEAD(J.VALUE,1,0) OVER (order by J.ID))) as PRESCALE_INDEX FROM CMS_HLT_GDR.U_CONFVERSIONS A, CMS_HLT_GDR.U_CONF2SRV S, CMS_HLT_GDR.U_SERVICES B, CMS_HLT_GDR.U_SRVTEMPLATES C, CMS_HLT_GDR.U_SRVELEMENTS J WHERE A.CONFIGID=%s AND A.ID=S.ID_CONFVER AND S.ID_SERVICE=B.ID AND C.ID=B.ID_TEMPLATE AND C.NAME='PrescaleService' AND J.ID_SERVICE=B.ID )Q WHERE NAME='pathName'
""" % (ConfigId,)
tmp_curs.execute(SequencePathQuery)
HLTSequenceMap = {}
for seq,name in tmp_curs.fetchall():
name = name.lstrip('"').rstrip('"')
HLTSequenceMap[seq]=name
SequencePrescaleQuery="""
with pq as ( SELECT Q.* FROM ( SELECT J.ID, J.NAME, LAG(J.ORD,1,0) OVER (order by J.ID) PRESCALE_SEQUENCE, J.VALUE TRIGGERNAME, trim('{' from trim('}' from LEAD(J.VALUE,1,0) OVER (order by J.ID))) as PRESCALE_INDEX FROM CMS_HLT_GDR.U_CONFVERSIONS A, CMS_HLT_GDR.U_CONF2SRV S, CMS_HLT_GDR.U_SERVICES B, CMS_HLT_GDR.U_SRVTEMPLATES C, CMS_HLT_GDR.U_SRVELEMENTS J WHERE A.CONFIGID=%s AND A.ID=S.ID_CONFVER AND S.ID_SERVICE=B.ID AND C.ID=B.ID_TEMPLATE AND C.NAME='PrescaleService' AND J.ID_SERVICE=B.ID )Q WHERE NAME='pathName' ) select prescale_sequence , MYINDEX , regexp_substr (prescale_index, '[^,]+', 1, rn) mypsnum from pq cross join (select rownum rn, mod(rownum -1, level) MYINDEX from (select max (length (regexp_replace (prescale_index, '[^,]+'))) + 1 mx from pq ) connect by level <= mx ) where regexp_substr (prescale_index, '[^,]+', 1, rn) is not null order by prescale_sequence, myindex
""" % (ConfigId,)
tmp_curs.execute(SequencePrescaleQuery)
lastIndex=-1
lastSeq=-1
row = []
for seq,index,val in tmp_curs.fetchall():
if lastIndex!=index-1:
self.HLTPrescaleTable[HLTSequenceMap[seq-1]] = row
row=[]
lastSeq=seq
lastIndex=index
row.append(val)
def GetHLTSeeds(self):
## This is a rather delicate query, but it works!
## Essentially get a list of paths associated with the config, then find the module of type HLTLevel1GTSeed associated with the path
## Then find the parameter with field name L1SeedsLogicalExpression and look at the value
##
## NEED TO BE LOGGED IN AS CMS_HLT_R
tmpcurs = ConnectDB('hlt')
sqlquery ="""
select s.name, d.value from cms_hlt_gdr.u_confversions h, cms_hlt_gdr.u_pathid2conf a, cms_hlt_gdr.u_pathid2pae n, cms_hlt_gdr.u_paelements b, cms_hlt_gdr.u_pae2moe c, cms_hlt_gdr.u_moelements d, cms_hlt_gdr.u_mod2templ e,cms_hlt_gdr.u_moduletemplates f, cms_hlt_gdr.u_pathids p, cms_hlt_gdr.u_paths s where h.name='%s' and a.id_confver=h.id and n.id_pathid=a.id_pathid and b.id=n.id_pae and c.id_pae=b.id and d.id=c.id_moe and d.name='L1SeedsLogicalExpression' and e.id_pae=b.id and f.id=e.id_templ and f.name='HLTLevel1GTSeed' and p.id=n.id_pathid and s.id=p.id_path order by value
""" % (self.HLT_Key,)
tmpcurs.execute(sqlquery)
for HLTPath,L1Seed in tmpcurs.fetchall():
if not self.HLTSeed.has_key(HLTPath): ## this should protect us from L1_SingleMuOpen
self.HLTSeed[HLTPath] = L1Seed.lstrip('"').rstrip('"')
#self.GetHLTPrescaleMatrix(tmpcurs)
def ParseRunSetup(self):
#queries that need to be run only once per run
self.GetRunInfo()
self.GetL1NameIndexAssoc()
self.GetL1AlgoPrescales()
self.GetHLTSeeds()
self.GetLumiInfo()
self.LastLSParsed=-1
self.GetMoreLumiInfo()
#self.GetDeadTimeBeamActive()
def UpdateRun(self,LSRange):
self.GetLumiInfo()
TriggerRates = self.GetHLTRates(LSRange)
#L1Prescales = self.CalculateAvL1Prescales(LSRange)
#TotalPrescales = self.CalculateTotalPrescales(TriggerRates,L1Prescales)
#UnprescaledRates = self.UnprescaleRates(TriggerRates,TotalPrescales)
#return [UnprescaledRates, TotalPrescales, L1Prescales, TriggerRates]
return TriggerRates
def GetLSRange(self,StartLS, NLS,reqPhysics=True):
"""
returns an array of valid LumiSections
if NLS < 0, count backwards from StartLS
"""
self.GetLumiInfo()
LS=[]
curLS=StartLS
step = NLS/abs(NLS)
NLS=abs(NLS)
while len(LS)<NLS:
if (curLS<0 and step<0) or (curLS>=self.LastLSParsed and step>0):
break
if curLS>=0 and curLS<self.LastLSParsed-1:
if (not self.Physics.has_key(curLS) or not self.Active.has_key(curLS)) and reqPhysics:
break
if not reqPhysics or (self.Physics[curLS] and self.Active[curLS]):
if step>0:
LS.append(curLS)
else:
LS.insert(0,curLS)
curLS += step
return LS
def GetLastLS(self,phys=False):
self.GetLumiInfo()
try:
if not phys:
maxLS=-1
for ls, active in self.Active.iteritems():
if active and ls>maxLS:
maxLS=ls
if maxLS==-1:
return 0
else:
return maxLS
else:
maxLS=-1
for ls,phys in self.Physics.iteritems():
if phys and self.Active[ls] and ls > maxLS:
maxLS=ls
if maxLS==-1:
return 0
else:
return maxLS
except:
return 0
def CalculateAvL1Prescales(self,LSRange):
AvgL1Prescales = [0]*self.nAlgoBits
for index in LSRange:
psi = self.PSColumnByLS[index]
if not psi:
#print "L1: Cannot figure out PSI for LS "+str(index)+" setting to 0"
psi = 0
for algo in range(self.nAlgoBits):
AvgL1Prescales[algo]+=self.L1PrescaleTable[algo][psi]
for i in range(len(AvgL1Prescales)):
try:
AvgL1Prescales[i] = AvgL1Prescales[i]/len(LSRange)
except:
AvgL1Prescales[i] = AvgL1Prescales[i]
return AvgL1Prescales
def CalculateTotalPrescales(self,TriggerRates, L1Prescales):
AvgTotalPrescales={}
for hltName,v in TriggerRates.iteritems():
if not self.HLTSeed.has_key(hltName):
continue
hltPS=0
if len(v)>0:
hltPS = v[0]
l1Index=-1
if self.L1IndexNameMap.has_key(self.HLTSeed[hltName]):
l1Index = self.L1IndexNameMap[self.HLTSeed[hltName]]
l1PS=0
if l1Index==-1:
l1PS = self.UnwindORSeed(self.HLTSeed[hltName],L1Prescales)
else:
l1PS = L1Prescales[l1Index]
AvgTotalPrescales[hltName]=l1PS*hltPS
return AvgTotalPrescales
def UnwindORSeed(self,expression,L1Prescales):
"""
Figures out the effective prescale for the OR of several seeds
we take this to be the *LOWEST* prescale of the included seeds
"""
if expression.find(" OR ") == -1:
return -1 # Not an OR of seeds
seedList = expression.split(" OR ")
if len(seedList)==1:
return -1 # Not an OR of seeds, really shouldn't get here...
minPS = 99999999999
for seed in seedList:
if not self.L1IndexNameMap.has_key(seed):
continue
ps = L1Prescales[self.L1IndexNameMap[seed]]
if ps:
minPS = min(ps,minPS)
if minPS==99999999999:
return 0
else:
return minPS
def UnprescaleRates(self,TriggerRates,TotalPrescales):
UnprescaledRates = {}
for hltName,v in TriggerRates.iteritems():
if TotalPrescales.has_key(hltName):
ps = TotalPrescales[hltName]
if ps:
UnprescaledRates[hltName] = v[1]*ps
else:
UnprescaledRates[hltName] = v[1]
else:
UnprescaledRates[hltName] = v[1]
return UnprescaledRates
def GetTotalL1Rates(self):
query = "SELECT RUNNUMBER, LUMISEGMENTNR, L1ASPHYSICS/23.3 FROM CMS_WBM.LEVEL1_TRIGGER_CONDITIONS WHERE RUNNUMBER=%s" % self.RunNumber
self.curs.execute(query)
L1Rate = {}
for LS,rate in self.curs.fetchall():
psi = self.PSColumnByLS.get(LS,0)
lumi = self.InstLumiByLS.get(LS,0)
L1Rate[LS] = [rate,psi,lumi]
return L1Rate
def GetL1RatesALL(self,LSRange,isPreDT=False):
##ANCIENT COMMANDS THAT DO WHO KNOWS WHAT
##sqlquery = "SELECT RUN_NUMBER, LUMI_SECTION, RATE_HZ, SCALER_INDEX FROM CMS_GT_MON.V_SCALERS_TCS_TRIGGER WHERE RUN_NUMBER=%s AND LUMI_SECTION IN %s and SCALER_INDEX=9"
##sqlquery = "SELECT RUN_NUMBER, LUMI_SECTION, RATE_HZ, SCALER_INDEX FROM CMS_GT_MON.V_SCALERS_FDL_ALGO WHERE RUN_NUMBER=%s AND LUMI_SECTION IN %s and SCALER_INDEX IN (9,13, 71)"
if isPreDT:
##OLD VERSION THAT GETS PRE-DT RATE (used before 16/11/2012)
sqlquery = "SELECT RUN_NUMBER, LUMI_SECTION, RATE_HZ, SCALER_INDEX FROM CMS_GT_MON.V_SCALERS_FDL_ALGO WHERE RUN_NUMBER=%s AND LUMI_SECTION IN %s"
else:
##NEW VERSION THAT GETS POST-DT RATE (implemented 16/11/2012)
sqlquery = "SELECT RUN_NUMBER, LUMI_SECTION, COUNT/23.3, BIT FROM (SELECT MOD(ROWNUM - 1, 128) BIT , TO_CHAR(A.MODIFICATIONTIME, 'YYYY.MM.DD HH24:MI:SS') TIME, C.COLUMN_VALUE COUNT, A.RUNNUMBER RUN_NUMBER, A.LSNUMBER LUMI_SECTION FROM CMS_RUNINFO.HLT_SUPERVISOR_L1_SCALARS A ,TABLE(A.DECISION_ARRAY) C WHERE A.RUNNUMBER = %s AND A.LSNUMBER IN %s )"
LSRangeSTR = str(LSRange)
LSRangeSTR = LSRangeSTR.replace("[","(")
LSRangeSTR = LSRangeSTR.replace("]",")")
query= sqlquery %(self.RunNumber,LSRangeSTR)
self.curs.execute(query)
L1RateAll=self.curs.fetchall()
L1RatesBits={}
###initialize dict of L1 bits
for L1seed in sorted(self.L1IndexNameMap.iterkeys()):
L1RatesBits[self.L1IndexNameMap[L1seed]]=0
###sum dict of L1 bits
for line in L1RateAll:
#if line[3] in self.L1IndexNameMap: ##do not fill if empty L1 key
try:
L1RatesBits[line[3]]=line[2]+L1RatesBits[line[3]]
except:
pass
#print "not filling bit",line[3]
###divide by number of LS
for name in self.L1IndexNameMap.iterkeys():
L1RatesBits[self.L1IndexNameMap[name]]=L1RatesBits[self.L1IndexNameMap[name]]/len(LSRange)
###total L1 PS table
L1PSdict={}
counter=0
for line in self.L1PrescaleTable:
L1PSdict[counter]=line
counter=counter+1
for LS in LSRange:
#self.PSColumnByLS[LS]
try: #FIXME
self.PSColumnByLS[LS]
except:
print "No prescale column detected for LS", LS
###av ps dict
L1PSbits={}
for bit in L1PSdict.iterkeys():
L1PSbits[bit]=0
for bit in L1PSdict.iterkeys():
for LS in LSRange:
try:
pscol = self.PSColumnByLS[LS]
L1PSbits[bit]=L1PSbits[bit]+L1PSdict[bit][pscol]
except:
pass
for bit in L1PSdict.iterkeys():
L1PSbits[bit]=L1PSbits[bit]/len(LSRange)
###convert dict of L1 bits to dict of L1 names
L1RatesNames={}
for name in self.L1IndexNameMap.iterkeys():
dummy=[]
dummy.append(L1PSbits[self.L1IndexNameMap[name]])
dummy.append(L1PSbits[self.L1IndexNameMap[name]])
dummy.append(L1RatesBits[self.L1IndexNameMap[name]])
dummy.append(L1RatesBits[self.L1IndexNameMap[name]]*L1PSbits[self.L1IndexNameMap[name]])
L1RatesNames[name+'_v1']=dummy
return L1RatesNames
def GetL1PSbyseed(self):
#for name in self.L1IndexNameMap.iterkeys():
# print name, self.L1IndexNameMap[name], self.L1PrescaleTable[self.L1IndexNameMap[name]]
#self.HLTSeed[name]
#for name in self.HLTSeed:
# print name, self.HLTSeed[name]
#self.L1PrescaleTable[self.L1IndexNameMap[self.HLTSeed[name]]][psi]
L1HLTSeeds=self.GetL1HLTseeds()
HLTL1PS={}
for HLTkey in L1HLTSeeds.iterkeys():
#print HLTkey, L1HLTSeeds[HLTkey]
dict={}
for L1seed in L1HLTSeeds[HLTkey]:
#try:
# print L1seed, L1HLTSeeds[HLTkey], self.L1PrescaleTable[self.L1IndexNameMap[L1seed]]
#except:
# print 'fail'
try:
dict[L1seed]=self.L1PrescaleTable[self.L1IndexNameMap[L1seed]]
except:
dummylist=[]
for i in range(0,len(self.L1PrescaleTable[0])):
dummylist.append(1)
dict[L1seed]=dummylist
#exit(2)
#print HLTkey, dict
HLTL1PS[HLTkey]=dict
#for HLTkey in HLTL1PS.iterkeys():
# print HLTkey, HLTL1PS[HLTkey]
return HLTL1PS
def GetL1Rates(self,LSRange):
sqlquery = "SELECT RUN_NUMBER, LUMI_SECTION, SCALER_NAME, RATE_HZ FROM CMS_GT_MON.V_SCALERS_TCS_TRIGGER WHERE RUN_NUMBER=%s and SCALER_NAME='L1AsPhysics' and LUMI_SECTION in %s"
LSRangeSTR = str(LSRange)
LSRangeSTR = LSRangeSTR.replace("[","(")
LSRangeSTR = LSRangeSTR.replace("]",")")
query=sqlquery %(self.RunNumber, LSRangeSTR)
#print query
self.curs.execute(query)
L1Rate=self.curs.fetchall()