CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Public Member Functions | Private Attributes
inputFilesetParser.inputFilesetParser Class Reference
Inheritance diagram for inputFilesetParser.inputFilesetParser:

Public Member Functions

def __init__
 
def fieldtotal
 
def fieldvalues
 
def mergeResultOnly
 
def resultfiles
 
def resultHeader
 
def resultInput
 
def runs
 
def runsandls
 
def runsandlsStr
 
def selectionfilename
 

Private Attributes

 __inputResult
 
 __inputresultfiles
 
 __inputResultHeader
 
 __inputselectionfile
 
 __inputSelectionFileparsingResult
 

Detailed Description

Definition at line 3 of file inputFilesetParser.py.

Constructor & Destructor Documentation

def inputFilesetParser.inputFilesetParser.__init__ (   self,
  inputfilename 
)

Definition at line 4 of file inputFilesetParser.py.

4 
5  def __init__(self,inputfilename):
6  filelist=inputfilename.split('+')
7  self.__inputresultfiles=filelist[0:-1]
8  self.__inputselectionfile=filelist[-1]
10  self.__inputResult=[]
12  if len(self.__inputselectionfile)!=0:
13  basename,extension=os.path.splitext(self.__inputselectionfile)
14  if extension=='.csv':#if file ends with .csv,use csv parser,else parse as json file
16  else:
17  selectf=open(self.__inputselectionfile,'r')
18  inputfilecontent=selectf.read()
20  if len(self.__inputresultfiles)!=0:
21  header=''
22  for f in self.__inputresultfiles:
23  ifile=open(f)
24  hasHeader=csv.Sniffer().has_header(ifile.read(1024))
25  ifile.seek(0)
26  csvReader=csv.reader(ifile,delimiter=',')
27  irow=0
28  for row in csvReader:
29  if hasHeader and irow==0:
30  self.__inputResultHeader=row
31  else:
32  self.__inputResult.append(row)
33  irow=irow+1
ifile.close()

Member Function Documentation

def inputFilesetParser.inputFilesetParser.fieldtotal (   self,
  fieldname,
  fieldtype 
)
given the input result field name and type, return the total

Definition at line 86 of file inputFilesetParser.py.

References inputFilesetParser.inputFilesetParser.__inputResult, CommonUtil.is_floatstr(), and CommonUtil.is_intstr().

86 
87  def fieldtotal(self,fieldname,fieldtype):
88  '''
89  given the input result field name and type, return the total
90  '''
91  fieldidx=None
92  result=0
93  try:
94  fieldidx=self.__inputResultHeader.index(fieldname)
95  except:
96  print 'field ',fieldname,' not found'
97  raise
98  for r in self.__inputResult:
99  stringvalue=r[fieldidx]
100  if fieldtype in ['int','unsigned int']:
101  if not CommonUtil.is_intstr(stringvalue):
102  print 'field ',fieldname,' is not integer type'
103  raise
104  else:
105  result=int(result)+int(stringvalue)
106  continue
107  elif fieldtype in ['float'] :
108  if not CommonUtil.is_floatstr(stringvalue):
109  print 'field ',fieldname,' is not float type'
110  raise
111  else:
112  result=float(result)+float(stringvalue)
113  continue
114  else:
115  raise 'cannot sum types other than int ,float'
return result
def is_floatstr
Definition: CommonUtil.py:34
def is_intstr
Definition: CommonUtil.py:26
def inputFilesetParser.inputFilesetParser.fieldvalues (   self,
  fieldname,
  fieldtype 
)
given the input result field name and typem return the list of values

Definition at line 54 of file inputFilesetParser.py.

References inputFilesetParser.inputFilesetParser.__inputResult, CommonUtil.is_floatstr(), and CommonUtil.is_intstr().

54 
55  def fieldvalues(self,fieldname,fieldtype):
56  '''
57  given the input result field name and typem return the list of values
58  '''
59  fieldidx=None
60  result=[]
61  try:
62  fieldidx=self.__inputResultHeader.index(fieldname)
63  except:
64  print 'field ',fieldname,' not found'
65  raise
66  for r in self.__inputResult:
67  stringvalue=r[fieldidx]
68  if fieldtype in ['int','unsigned int']:
69  if not CommonUtil.is_intstr(stringvalue):
70  print 'field ',fieldname,' is not integer type'
71  raise
72  else:
73  result.append(int(stringvalue))
74  continue
75  elif fieldtype in ['float']:
76  if not CommonUtil.is_floatstr(stringvalue):
77  print 'field ',fieldname,' is not float type'
78  raise
79  else:
80  result.append(float(stringvalue))
81  contine
82  elif fieldtype in ['string','str']:
83  result.append(stringvalue)
84  else:
85  raise 'unsupported type ',fieldtype
return result
def is_floatstr
Definition: CommonUtil.py:34
def is_intstr
Definition: CommonUtil.py:26
def inputFilesetParser.inputFilesetParser.mergeResultOnly (   self)
if empty input selection filename give, I assume you only need to merge pieces of output result files into one 

Definition at line 38 of file inputFilesetParser.py.

References inputFilesetParser.inputFilesetParser.__inputselectionfile.

38 
39  def mergeResultOnly(self):
40  '''if empty input selection filename give, I assume you only need to merge pieces of output result files into one
41  '''
return len(self.__inputselectionfile)==0
def inputFilesetParser.inputFilesetParser.resultfiles (   self)

Definition at line 42 of file inputFilesetParser.py.

References inputFilesetParser.inputFilesetParser.__inputresultfiles.

42 
43  def resultfiles(self):
return self.__inputresultfiles
def inputFilesetParser.inputFilesetParser.resultHeader (   self)
output [headerfields]

Definition at line 44 of file inputFilesetParser.py.

References inputFilesetParser.inputFilesetParser.__inputResultHeader.

44 
45  def resultHeader(self):
46  '''
47  output [headerfields]
48  '''
return self.__inputResultHeader
def inputFilesetParser.inputFilesetParser.resultInput (   self)
output [valuefields]

Definition at line 49 of file inputFilesetParser.py.

References inputFilesetParser.inputFilesetParser.__inputResult.

49 
50  def resultInput(self):
51  '''
52  output [valuefields]
53  '''
return self.__inputResult
def inputFilesetParser.inputFilesetParser.runs (   self)

Definition at line 116 of file inputFilesetParser.py.

References inputFilesetParser.inputFilesetParser.__inputSelectionFileparsingResult.

117  def runs(self):
119  return None
return self.__inputSelectionFileparsingResult.runs()
def inputFilesetParser.inputFilesetParser.runsandls (   self)

Definition at line 120 of file inputFilesetParser.py.

References inputFilesetParser.inputFilesetParser.__inputSelectionFileparsingResult.

121  def runsandls(self):
123  return None
return self.__inputSelectionFileparsingResult.runsandls()
def inputFilesetParser.inputFilesetParser.runsandlsStr (   self)

Definition at line 124 of file inputFilesetParser.py.

References inputFilesetParser.inputFilesetParser.__inputSelectionFileparsingResult.

125  def runsandlsStr(self):
127  return None
return self.__inputSelectionFileparsingResult.runsandlsStr()
def inputFilesetParser.inputFilesetParser.selectionfilename (   self)
return the input selection file name

Definition at line 34 of file inputFilesetParser.py.

References inputFilesetParser.inputFilesetParser.__inputselectionfile.

34 
35  def selectionfilename(self):
36  '''return the input selection file name
37  '''
return self.__inputselectionfile

Member Data Documentation

inputFilesetParser.inputFilesetParser.__inputResult
private

Definition at line 9 of file inputFilesetParser.py.

Referenced by inputFilesetParser.inputFilesetParser.fieldtotal(), inputFilesetParser.inputFilesetParser.fieldvalues(), and inputFilesetParser.inputFilesetParser.resultInput().

inputFilesetParser.inputFilesetParser.__inputresultfiles
private

Definition at line 6 of file inputFilesetParser.py.

Referenced by inputFilesetParser.inputFilesetParser.resultfiles().

inputFilesetParser.inputFilesetParser.__inputResultHeader
private

Definition at line 8 of file inputFilesetParser.py.

Referenced by inputFilesetParser.inputFilesetParser.resultHeader().

inputFilesetParser.inputFilesetParser.__inputselectionfile
private

Definition at line 7 of file inputFilesetParser.py.

Referenced by inputFilesetParser.inputFilesetParser.mergeResultOnly(), and inputFilesetParser.inputFilesetParser.selectionfilename().

inputFilesetParser.inputFilesetParser.__inputSelectionFileparsingResult
private

Definition at line 10 of file inputFilesetParser.py.

Referenced by inputFilesetParser.inputFilesetParser.runs(), inputFilesetParser.inputFilesetParser.runsandls(), and inputFilesetParser.inputFilesetParser.runsandlsStr().