CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_6_1_2_SLHC4_patch1/src/HLTrigger/Tools/python/OnlinePrescaleChecker/PrescaleChecker.py

Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 from Page1Parser import Page1Parser
00003 import sys
00004 import os
00005 import cPickle as pickle
00006 import getopt
00007 from TablePrint import *
00008 
00009 WBMPageTemplate = "http://cmswbm/cmsdb/servlet/TriggerMode?KEY=l1_hlt_collisions/v%s"
00010 
00011 def usage():
00012     print "%s [Options] KeyVersion" % sys.argv[0]
00013     print "--IgnoreCols=<cols>               List of columns to ignore from the prescale checker (format is 1,2,3,4 etc.)"
00014 
00015     
00016 def main():
00017     try:
00018         opt, args = getopt.getopt(sys.argv[1:],"",["IgnoreCols="])
00019     except getopt.GetoptError, err:
00020         print str(err)
00021         usage()
00022         sys.exit(2)
00023 
00024     if len(args)<1:
00025         usage()
00026         sys.exit(2)
00027 
00028     IgnoreCols=[]
00029     for o,a in opt:
00030         if o == "--IgnoreCols":
00031             tmp = a.split(',')
00032             try:
00033                 for e in tmp:
00034                     IgnoreCols.append(int(e))
00035             except:
00036                 print "Invalid argument to '--IgnoreCols' "
00037                 sys.exit(2)
00038         else:
00039             print "Invalid option "+o
00040             usage()
00041             sys.exit(0)
00042             
00043     WBMPage = WBMPageTemplate % args[0]
00044     ## Parse the key page
00045     Parser = Page1Parser()
00046     Parser._Parse(WBMPage)
00047     Parser.ParseTrigModePage()
00048     Parser.ComputeTotalPrescales()
00049 
00050     Header=["Path Name", "L1 Seed"]+Parser.ColumnLumi
00051     ColWidths=[70,30]+[10]*len(Parser.ColumnLumi)
00052     print """
00053     TOTAL L1*HLT PRESCALE TABLE:
00054     """
00055     PrettyPrintTable(Header,Parser.TotalPrescaleTable,ColWidths)
00056     
00057     print """
00058     Weird Looking L1*HLT Prescales
00059 
00060     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)
00061     """
00062 
00063     PrettyPrintTable(Header,findAnomalies(Parser.TotalPrescaleTable,IgnoreCols),ColWidths)
00064     ## OK, we need some more checks here, but to first order this is useful
00065 
00066 def TrendingWithLumi(ColLumi,PrescaleTable):
00067     RatioTable=[]
00068     for line in PrescaleTable:
00069         name = line[0]
00070         l1 = line[1]
00071         prescales = line[2:]
00072         ratios=[]
00073         for lumi,ps in zip(ColLumi,prescales):
00074             if ps>0:
00075                 ratios.append(lumi/ps)
00076             else:
00077                 ratios.append(0)
00078         RatioTable.append([name,l1]+ratios)
00079     return RatioTable
00080 
00081 def isMonotonic(array, ignoreCols):  # return 0 if not, 1 if true and 2 if the array is constant
00082     lastEntry = array[0]
00083     returnVal=2
00084     for entry,i in zip(array[0:],range(len(array[0:]))):
00085         if i in ignoreCols:
00086             continue
00087         if lastEntry<entry and lastEntry!=0:
00088             return 0
00089         if lastEntry!=entry:
00090             returnVal=1
00091         lastEntry=entry
00092     return returnVal
00093 
00094 def findAnomalies(PrescaleTable,ignoreCols):
00095     anomalies=[]
00096     for line in PrescaleTable:
00097         ps = line[2:]
00098         if not isMonotonic(ps,ignoreCols):
00099             anomalies.append(line)
00100     return anomalies
00101 if __name__=='__main__':
00102     main()