Go to the documentation of this file.00001
00002
00003
00004 import csv
00005 import re
00006 def is_intstr(s):
00007 try:
00008 int(s)
00009 return True
00010 except ValueError:
00011 return False
00012 class csvLumibyLSParser(object):
00013 def __init__(self,filename):
00014 self.__result={}
00015 self.__strresult={}
00016 self.__filename=filename
00017 csvReader=csv.reader(open(filename),delimiter=',')
00018 oldRun=0
00019 runnumber=0
00020 ldict = {}
00021 llist = []
00022 NonValidLumi = 0
00023 lastLumi = 0
00024 for row in csvReader:
00025 field0=str(row[0]).strip()
00026 fieldsplit=re.split(':',field0)
00027 runstring = fieldsplit[0]
00028 try:
00029 field1=str(row[1]).strip()
00030 fieldsplit=re.split(':',field1)
00031 lsstring = fieldsplit[0]
00032 except Exception,e:
00033 lsstring='1'
00034 if not is_intstr(runstring) or not is_intstr(lsstring):
00035 continue
00036 runnumber=int(runstring)
00037 lsnumber=int(lsstring)
00038
00039 if runnumber != oldRun:
00040 if oldRun>0:
00041 self.__result[oldRun]=ldict
00042 ldict = {}
00043 oldRun = runnumber
00044 lastLumi = 0
00045 NonValidLumi = 0
00046 else:
00047 oldRun = runnumber
00048
00049 try:
00050 delivered, recorded = float( row[5] ), float( row[6] )
00051 except:
00052 print 'Record not parsed, Run = %d, LS = %d' % (runnumber, lsnumber)
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072 elems = [ delivered,recorded ]
00073 ldict[lsnumber]=elems
00074
00075 self.__result[runnumber]=ldict
00076
00077 def runs(self):
00078 return self.__result.keys()
00079 def runsandls(self):
00080 '''return {run:lslist}
00081 '''
00082 return self.__result
00083
00084
00085
00086
00087 def numruns(self):
00088 return len(self.__result.keys())
00089 def numls(self,run):
00090 return len(self.__result[run])
00091
00092 if __name__ == '__main__':
00093 result={}
00094
00095 filename='test.csv'
00096 s=csvLumibyLSParser(filename)
00097 print 'runs : ',s.runs()
00098 print 'full result : ',s.runsandls()
00099
00100 print 'num runs : ',s.numruns()
00101
00102