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