File indexing completed on 2024-11-25 02:29:58
0001
0002
0003 from builtins import range
0004 import sys, os, string
0005 import time
0006
0007 import FWCore.ParameterSet.Config as cms
0008 from .hcalLaserEventFilter_cfi import hcalLaserEventFilter
0009
0010 ''' Program reads existing bad run/event list from hcalLaserEventFilter_cfi.py, and an (optional) new list from a text file. If a text file is specified, this is assumed to be the desired new bad list, and its output will be sent to badEvents.py in the form needed by the cfi file.
0011
0012 If no text file is provided, then the current bad events in the .py file will be displayed.
0013 '''
0014
0015
0016 def MakePair(startlist):
0017 dict={}
0018 for i in range(0,len(startlist),2):
0019 key1=startlist[i]
0020 key2=startlist[i+1]
0021 runevent=(key1,key2)
0022 dict[runevent]="%s,%s,"%(key1,key2)
0023 return dict
0024
0025 def ReadNewList(newlist):
0026 ''' Read a new list of bad runs from an input file, and
0027 creates a new list of output keys for the bad run/events.
0028 '''
0029 outlist=[]
0030 for i in newlist:
0031 temp=string.strip(i)
0032
0033 if temp.find(",")>-1:
0034 temp=string.split(temp,",")
0035
0036 else:
0037 temp=string.split(temp)
0038
0039
0040 if len(temp)==3:
0041 try:
0042 run=string.atoi(temp[0])
0043 evt=string.atoi(temp[2])
0044 except:
0045 print("Could not parse line '%s'"%i)
0046
0047 elif len(temp)==2:
0048 try:
0049 run=string.atoi(temp[0])
0050 evt=string.atoi(temp[1])
0051 except:
0052 print("Could not parse line '%s'"%i)
0053 else:
0054 print("Cannot parse line! ('%s')"%i)
0055 continue
0056 outlist.append(run)
0057 outlist.append(evt)
0058 outDict=MakePair(outlist)
0059 return outDict
0060
0061
0062
0063
0064 if __name__=="__main__":
0065 defaultList=hcalLaserEventFilter.BadRunEventNumbers
0066 defaultDict=MakePair(defaultList)
0067 keys=sorted(defaultDict.keys())
0068 if len(sys.argv)==1:
0069 print("Default bad (run,events) are:")
0070 for i in keys:
0071 print(i)
0072 print("\nA total of %i bad events"%len(keys))
0073 sys.exit()
0074 newlines=[]
0075 for i in sys.argv[1:]:
0076 if not os.path.isfile(i):
0077 print("Error, file '%s' does not exist"%i)
0078 continue
0079 lines=open(i,'r').readlines()
0080 for i in lines:
0081 newlines.append(i)
0082 newBadDict=ReadNewList(newlines)
0083
0084
0085
0086 newkeys=newBadDict.keys()
0087 newkeys.sort()
0088 notInOld={}
0089 notInNew={}
0090
0091 out=open("badEvents.py",'w')
0092
0093 thistime=time.time()
0094 thistime=time.strftime("%H:%M:%S %d %h %Y")
0095 out.write("# File last updated on %s\n"%thistime)
0096 out.write("# A total of %i bad events\n\n"%len(newkeys))
0097
0098 out.write("badEvents=[\n")
0099 for i in newkeys:
0100
0101 out.write("%s\n"%newBadDict[i])
0102 if i not in keys:
0103 notInOld[i]=newBadDict[i]
0104 out.write("]\n")
0105 out.close()
0106
0107
0108 for i in keys:
0109 if i not in newkeys:
0110 notInNew[i]=defaultDict[i]
0111
0112
0113 print("Total bad events in new file = ",len(newkeys))
0114
0115 if len(notInOld)>0:
0116 print()
0117 print("A total of %i bad events found"%len(notInOld))
0118 for k in notInOld.keys():
0119 print(k)
0120
0121 if len(notInNew)>0:
0122 print()
0123 print("A total of %i events aren't in NEW list!"%len(notInNew))
0124 for k in notInNew.keys():
0125 print(k)