Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-11-26 02:34:21

0001 #!/usr/bin/env python
0002 from .Page1Parser import Page1Parser
0003 import sys
0004 import os
0005 import cPickle as pickle
0006 import getopt
0007 from .TablePrint import *
0008 
0009 WBMPageTemplate = "http://cmswbm/cmsdb/servlet/TriggerMode?KEY=l1_hlt_collisions/v%s"
0010 
0011 def usage():
0012     print("%s [Options] KeyVersion" % sys.argv[0])
0013     print("--IgnoreCols=<cols>               List of columns to ignore from the prescale checker (format is 1,2,3,4 etc.)")
0014 
0015     
0016 def main():
0017     try:
0018         opt, args = getopt.getopt(sys.argv[1:],"",["IgnoreCols="])
0019     except getopt.GetoptError as err:
0020         print(str(err))
0021         usage()
0022         sys.exit(2)
0023 
0024     if len(args)<1:
0025         usage()
0026         sys.exit(2)
0027 
0028     IgnoreCols=[]
0029     for o,a in opt:
0030         if o == "--IgnoreCols":
0031             tmp = a.split(',')
0032             try:
0033                 for e in tmp:
0034                     IgnoreCols.append(int(e))
0035             except:
0036                 print("Invalid argument to '--IgnoreCols' ")
0037                 sys.exit(2)
0038         else:
0039             print("Invalid option "+o)
0040             usage()
0041             sys.exit(0)
0042             
0043     WBMPage = WBMPageTemplate % args[0]
0044     ## Parse the key page
0045     Parser = Page1Parser()
0046     Parser._Parse(WBMPage)
0047     Parser.ParseTrigModePage()
0048     Parser.ComputeTotalPrescales()
0049 
0050     Header=["Path Name", "L1 Seed"]+Parser.ColumnLumi
0051     ColWidths=[70,30]+[10]*len(Parser.ColumnLumi)
0052     print("""
0053     TOTAL L1*HLT PRESCALE TABLE:
0054     """)
0055     PrettyPrintTable(Header,Parser.TotalPrescaleTable,ColWidths)
0056     
0057     print("""
0058     Weird Looking L1*HLT Prescales
0059 
0060     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)
0061     """)
0062 
0063     PrettyPrintTable(Header,findAnomalies(Parser.TotalPrescaleTable,IgnoreCols),ColWidths)
0064     ## OK, we need some more checks here, but to first order this is useful
0065 
0066 def TrendingWithLumi(ColLumi,PrescaleTable):
0067     RatioTable=[]
0068     for line in PrescaleTable:
0069         name = line[0]
0070         l1 = line[1]
0071         prescales = line[2:]
0072         ratios=[]
0073         for lumi,ps in zip(ColLumi,prescales):
0074             if ps>0:
0075                 ratios.append(lumi/ps)
0076             else:
0077                 ratios.append(0)
0078         RatioTable.append([name,l1]+ratios)
0079     return RatioTable
0080 
0081 def isMonotonic(array, ignoreCols):  # return 0 if not, 1 if true and 2 if the array is constant
0082     lastEntry = array[0]
0083     returnVal=2
0084     for entry,i in zip(array[0:],range(len(array[0:]))):
0085         if i in ignoreCols:
0086             continue
0087         if lastEntry<entry and lastEntry!=0:
0088             return 0
0089         if lastEntry!=entry:
0090             returnVal=1
0091         lastEntry=entry
0092     return returnVal
0093 
0094 def findAnomalies(PrescaleTable,ignoreCols):
0095     anomalies=[]
0096     for line in PrescaleTable:
0097         ps = line[2:]
0098         if not isMonotonic(ps,ignoreCols):
0099             anomalies.append(line)
0100     return anomalies
0101 if __name__=='__main__':
0102     main()