CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
csvSelectionParser.py
Go to the documentation of this file.
1 import csv
2 def is_intstr(s):
3  try:
4  int(s)
5  return True
6  except ValueError:
7  return False
9  def __init__(self,filename):
10  self.__result={}
11  self.__strresult={}
12  self.__filename=filename
13  csvReader=csv.reader(open(filename),delimiter=',')
14  for row in csvReader:
15  field0=str(row[0]).strip()
16  try:
17  field1=str(row[1]).strip()
18  except Exception,e:
19  field1='1' # for list with run number only, fake lsnum
20  if not is_intstr(field0) or not is_intstr(field1):
21  continue
22  runnumber=int(field0)
23  lsnumber=int(field1)
24  if self.__result.has_key(runnumber):
25  self.__result[runnumber].append(lsnumber)
26  else:
27  self.__result[runnumber]=[lsnumber]
28  for k,lsvalues in self.__result.items():
29  lsvalues.sort()
30  self.__strresult[k]=[str(x) for x in lsvalues]
31  def runs(self):
32  return self.__result.keys()
33  def runsandls(self):
34  '''return {run:lslist}
35  '''
36  return self.__result
37  def runsandlsStr(self):
38  '''return {'run':lslist}
39  '''
40  return self.__strresult
41  def numruns(self):
42  return len(self.__result.keys())
43  def numls(self,run):
44  return len(self.__result[run])
45 
46 if __name__ == '__main__':
47  result={}
48  #filename='../test/lumi_by_LS_all.csv'
49  filename='../test/newruns.csv'
50  s=csvSelectionParser(filename)
51  print 'runs : ',s.runs()
52  print 'full result : ',s.runsandls()
53  print 'str result : ',s.runsandlsStr()
54  print 'num runs : ',s.numruns()
55  #print 'numls in run : ',s.numls(135175)
56 
void strip(std::string &input, const std::string &blanks=" \n\t")
Definition: stringTools.cc:16
list object
Definition: dbtoconf.py:77