CMS 3D CMS Logo

Public Member Functions | Private Attributes

inputFilesetParser::inputFilesetParser Class Reference

List of all members.

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.

00005                                     :
00006         filelist=inputfilename.split('+')
00007         self.__inputresultfiles=filelist[0:-1]
00008         self.__inputselectionfile=filelist[-1]
00009         self.__inputResultHeader=[]
00010         self.__inputResult=[]
00011         self.__inputSelectionFileparsingResult=None
00012         if len(self.__inputselectionfile)!=0:
00013             basename,extension=os.path.splitext(self.__inputselectionfile)
00014             if extension=='.csv':#if file ends with .csv,use csv parser,else parse as json file
00015                 self.__inputSelectionFileparsingResult=csvSelectionParser.csvSelectionParser(self.__inputselectionfile)
00016             else:
00017                 selectf=open(self.__inputselectionfile,'r')
00018                 inputfilecontent=selectf.read()
00019                 self.__inputSelectionFileparsingResult=selectionParser.selectionParser(inputfilecontent)
00020         if len(self.__inputresultfiles)!=0:
00021             header=''
00022             for f in self.__inputresultfiles:
00023                 ifile=open(f)
00024                 hasHeader=csv.Sniffer().has_header(ifile.read(1024))
00025                 ifile.seek(0)
00026                 csvReader=csv.reader(ifile,delimiter=',')
00027                 irow=0
00028                 for row in csvReader:
00029                     if hasHeader and irow==0:
00030                         self.__inputResultHeader=row
00031                     else:
00032                         self.__inputResult.append(row)
00033                     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.

00087                                             :
00088         '''
00089         given the input result field name and type, return the total
00090         '''
00091         fieldidx=None
00092         result=0
00093         try:
00094             fieldidx=self.__inputResultHeader.index(fieldname)
00095         except:
00096             print 'field ',fieldname,' not found'
00097             raise
00098         for r in self.__inputResult:
00099             stringvalue=r[fieldidx]
00100             if fieldtype in ['int','unsigned int']:
00101                 if not CommonUtil.is_intstr(stringvalue):
00102                     print 'field ',fieldname,' is not integer type'
00103                     raise
00104                 else:
00105                     result=int(result)+int(stringvalue)
00106                     continue
00107             elif fieldtype in ['float'] :
00108                 if not CommonUtil.is_floatstr(stringvalue):
00109                     print 'field ',fieldname,' is not float type'
00110                     raise
00111                 else:
00112                     result=float(result)+float(stringvalue)
00113                     continue
00114             else:
00115                 raise 'cannot sum types other than int ,float'
        return result
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.

00055                                              :
00056         '''
00057         given the input result field name and typem return the list of values
00058         '''
00059         fieldidx=None
00060         result=[]
00061         try:
00062             fieldidx=self.__inputResultHeader.index(fieldname)
00063         except:
00064             print 'field ',fieldname,' not found'
00065             raise
00066         for r in self.__inputResult:
00067             stringvalue=r[fieldidx]
00068             if fieldtype in ['int','unsigned int']:
00069                 if not CommonUtil.is_intstr(stringvalue):
00070                     print 'field ',fieldname,' is not integer type'
00071                     raise
00072                 else:
00073                     result.append(int(stringvalue))
00074                     continue
00075             elif fieldtype in ['float']:
00076                 if not CommonUtil.is_floatstr(stringvalue):
00077                     print 'field ',fieldname,' is not float type'
00078                     raise
00079                 else:
00080                     result.append(float(stringvalue))
00081                     contine
00082             elif  fieldtype in ['string','str']:
00083                 result.append(stringvalue)
00084             else:
00085                 raise 'unsupported type ',fieldtype
        return result
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.

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

Definition at line 42 of file inputFilesetParser.py.

00043                          :
        return self.__inputresultfiles
def inputFilesetParser::inputFilesetParser::resultHeader (   self)
output [headerfields]

Definition at line 44 of file inputFilesetParser.py.

00045                           :
00046         '''
00047         output [headerfields]
00048         '''
        return self.__inputResultHeader
def inputFilesetParser::inputFilesetParser::resultInput (   self)
output [valuefields]

Definition at line 49 of file inputFilesetParser.py.

00050                          :
00051         '''
00052         output [valuefields]
00053         '''
        return self.__inputResult
def inputFilesetParser::inputFilesetParser::runs (   self)

Definition at line 116 of file inputFilesetParser.py.

00117                   :
00118         if not self.__inputSelectionFileparsingResult:
00119             return None
        return self.__inputSelectionFileparsingResult.runs()
def inputFilesetParser::inputFilesetParser::runsandls (   self)

Definition at line 120 of file inputFilesetParser.py.

00121                        :
00122         if not self.__inputSelectionFileparsingResult:
00123             return None
        return self.__inputSelectionFileparsingResult.runsandls()
def inputFilesetParser::inputFilesetParser::runsandlsStr (   self)

Definition at line 124 of file inputFilesetParser.py.

00125                           :
00126         if not self.__inputSelectionFileparsingResult:
00127             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.

00035                                :
00036         '''return the input selection file name
00037         '''
        return self.__inputselectionfile

Member Data Documentation

Definition at line 4 of file inputFilesetParser.py.

Definition at line 4 of file inputFilesetParser.py.

Definition at line 4 of file inputFilesetParser.py.

Definition at line 4 of file inputFilesetParser.py.

Definition at line 4 of file inputFilesetParser.py.