CMS 3D CMS Logo

PrescaleChecker.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 from __future__ import print_function
3 from __future__ import absolute_import
4 from .Page1Parser import Page1Parser
5 import sys
6 import os
7 import cPickle as pickle
8 import getopt
9 from .TablePrint import *
10 
11 WBMPageTemplate = "http://cmswbm/cmsdb/servlet/TriggerMode?KEY=l1_hlt_collisions/v%s"
12 
13 def usage():
14  print("%s [Options] KeyVersion" % sys.argv[0])
15  print("--IgnoreCols=<cols> List of columns to ignore from the prescale checker (format is 1,2,3,4 etc.)")
16 
17 
18 def main():
19  try:
20  opt, args = getopt.getopt(sys.argv[1:],"",["IgnoreCols="])
21  except getopt.GetoptError as err:
22  print(str(err))
23  usage()
24  sys.exit(2)
25 
26  if len(args)<1:
27  usage()
28  sys.exit(2)
29 
30  IgnoreCols=[]
31  for o,a in opt:
32  if o == "--IgnoreCols":
33  tmp = a.split(',')
34  try:
35  for e in tmp:
36  IgnoreCols.append(int(e))
37  except:
38  print("Invalid argument to '--IgnoreCols' ")
39  sys.exit(2)
40  else:
41  print("Invalid option "+o)
42  usage()
43  sys.exit(0)
44 
45  WBMPage = WBMPageTemplate % args[0]
46  ## Parse the key page
47  Parser = Page1Parser()
48  Parser._Parse(WBMPage)
49  Parser.ParseTrigModePage()
50  Parser.ComputeTotalPrescales()
51 
52  Header=["Path Name", "L1 Seed"]+Parser.ColumnLumi
53  ColWidths=[70,30]+[10]*len(Parser.ColumnLumi)
54  print("""
55  TOTAL L1*HLT PRESCALE TABLE:
56  """)
57  PrettyPrintTable(Header,Parser.TotalPrescaleTable,ColWidths)
58 
59  print("""
60  Weird Looking L1*HLT Prescales
61 
62  WARNING: paths seeded by the OR of several L1 bits may not be calculated properly (they assume an L1 prescale of 1 in all columns)
63  """)
64 
65  PrettyPrintTable(Header,findAnomalies(Parser.TotalPrescaleTable,IgnoreCols),ColWidths)
66  ## OK, we need some more checks here, but to first order this is useful
67 
68 def TrendingWithLumi(ColLumi,PrescaleTable):
69  RatioTable=[]
70  for line in PrescaleTable:
71  name = line[0]
72  l1 = line[1]
73  prescales = line[2:]
74  ratios=[]
75  for lumi,ps in zip(ColLumi,prescales):
76  if ps>0:
77  ratios.append(lumi/ps)
78  else:
79  ratios.append(0)
80  RatioTable.append([name,l1]+ratios)
81  return RatioTable
82 
83 def isMonotonic(array, ignoreCols): # return 0 if not, 1 if true and 2 if the array is constant
84  lastEntry = array[0]
85  returnVal=2
86  for entry,i in zip(array[0:],range(len(array[0:]))):
87  if i in ignoreCols:
88  continue
89  if lastEntry<entry and lastEntry!=0:
90  return 0
91  if lastEntry!=entry:
92  returnVal=1
93  lastEntry=entry
94  return returnVal
95 
96 def findAnomalies(PrescaleTable,ignoreCols):
97  anomalies=[]
98  for line in PrescaleTable:
99  ps = line[2:]
100  if not isMonotonic(ps,ignoreCols):
101  anomalies.append(line)
102  return anomalies
103 if __name__=='__main__':
104  main()
def findAnomalies(PrescaleTable, ignoreCols)
def isMonotonic(array, ignoreCols)
def TrendingWithLumi(ColLumi, PrescaleTable)
S & print(S &os, JobReport::InputFile const &f)
Definition: JobReport.cc:66
OutputIterator zip(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, InputIterator2 last2, OutputIterator result, Compare comp)
def PrettyPrintTable(Headers, Data, ColWidths, WarningCol=[], border='*')
Definition: TablePrint.py:7
Definition: main.py:1
#define str(s)