CMS 3D CMS Logo

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