Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:18:46

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