CMS 3D CMS Logo

csvSelectionParser.py
Go to the documentation of this file.
1 from __future__ import print_function
2 import csv
3 def is_intstr(s):
4  try:
5  int(s)
6  return True
7  except ValueError:
8  return False
10  def __init__(self,filename):
11  self.__result={}
12  self.__strresult={}
13  self.__filename=filename
14  csvReader=csv.reader(open(filename),delimiter=',')
15  for row in csvReader:
16  field0=str(row[0]).strip()
17  try:
18  field1=str(row[1]).strip()
19  except Exception as e:
20  field1='1' # for list with run number only, fake lsnum
21  if not is_intstr(field0) or not is_intstr(field1):
22  continue
23  runnumber=int(field0)
24  lsnumber=int(field1)
25  if runnumber in self.__result:
26  self.__result[runnumber].append(lsnumber)
27  else:
28  self.__result[runnumber]=[lsnumber]
29  for k,lsvalues in self.__result.items():
30  lsvalues.sort()
31  self.__strresult[k]=[str(x) for x in lsvalues]
32  def runs(self):
33  return self.__result.keys()
34  def runsandls(self):
35  '''return {run:lslist}
36  '''
37  return self.__result
38  def runsandlsStr(self):
39  '''return {'run':lslist}
40  '''
41  return self.__strresult
42  def numruns(self):
43  return len(self.__result)
44  def numls(self,run):
45  return len(self.__result[run])
46 
47 if __name__ == '__main__':
48  result={}
49  #filename='../test/lumi_by_LS_all.csv'
50  filename='../test/newruns.csv'
51  s=csvSelectionParser(filename)
52  print('runs : ',s.runs())
53  print('full result : ',s.runsandls())
54  print('str result : ',s.runsandlsStr())
55  print('num runs : ',s.numruns())
56  #print 'numls in run : ',s.numls(135175)
57 
S & print(S &os, JobReport::InputFile const &f)
Definition: JobReport.cc:66
#define str(s)