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 resultHeader
def resultInput
def resultlines
def runs
def runsandls
def runsandlsStr
def runsWithresult
def selectedRunsWithoutresult
def selectedRunsWithresult
def selectionfilename

Private Attributes

 __inputResult
 __inputresultfiles
 __inputResultHeader
 __inputselectionfile
 __inputSelectionFileparsingResult

Detailed Description

Definition at line 11 of file inputFilesetParser.py.


Constructor & Destructor Documentation

def inputFilesetParser::inputFilesetParser::__init__ (   self,
  inputfilename 
)

Definition at line 12 of file inputFilesetParser.py.

00013                                     :
00014         filelist=inputfilename.split('+')
00015         self.__inputresultfiles=filelist[0:-1]
00016         self.__inputselectionfile=filelist[-1]
00017         self.__inputResultHeader=[]
00018         self.__inputResult=[]
00019         self.__inputSelectionFileparsingResult=None
00020         if len(self.__inputselectionfile)!=0:
00021             basename,extension=os.path.splitext(self.__inputselectionfile)
00022             if extension=='.csv':#if file ends with .csv,use csv parser,else parse as json file
00023                 self.__inputSelectionFileparsingResult=csvSelectionParser.csvSelectionParser(self.__inputselectionfile)
00024             else:
00025                 selectf=open(self.__inputselectionfile,'r')
00026                 inputfilecontent=selectf.read()
00027                 self.__inputSelectionFileparsingResult=selectionParser.selectionParser(inputfilecontent)
00028         if len(self.__inputresultfiles)!=0:
00029             header=''
00030             for f in self.__inputresultfiles:
00031                 ifile=open(f)
00032                 hasHeader=filehasHeader(ifile)
00033                 #hasHeader=csv.Sniffer().has_header(ifile.read(1024)) #sniffer doesn't work well , replace with custom
00034                 ifile.seek(0)
00035                 csvReader=csv.reader(ifile,delimiter=',')
00036                 irow=0
00037                 for row in csvReader:
00038                     if hasHeader and irow==0:
00039                         self.__inputResultHeader=row
00040                     else:
00041                         self.__inputResult.append(row)
00042                     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 142 of file inputFilesetParser.py.

00143                                             :
00144         '''
00145         given the input result field name and type, return the total
00146         '''
00147         fieldidx=None
00148         result=0
00149         try:
00150             fieldidx=self.__inputResultHeader.index(fieldname)
00151         except:
00152             print 'field ',fieldname,' not found'
00153             raise
00154         for r in self.__inputResult:
00155             stringvalue=r[fieldidx]
00156             if fieldtype in ['int','unsigned int']:
00157                 if not CommonUtil.is_intstr(stringvalue):
00158                     print 'field ',fieldname,' is not integer type'
00159                     raise
00160                 else:
00161                     result=int(result)+int(stringvalue)
00162                     continue
00163             elif fieldtype in ['float'] :
00164                 if not CommonUtil.is_floatstr(stringvalue):
00165                     print 'field ',fieldname,' is not float type'
00166                     raise
00167                 else:
00168                     result=float(result)+float(stringvalue)
00169                     continue
00170             else:
00171                 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 110 of file inputFilesetParser.py.

00111                                              :
00112         '''
00113         given the input result field name and typem return the list of values
00114         '''
00115         fieldidx=None
00116         result=[]
00117         try:
00118             fieldidx=self.__inputResultHeader.index(fieldname)
00119         except:
00120             print 'field ',fieldname,' not found'
00121             raise
00122         for r in self.__inputResult:
00123             stringvalue=r[fieldidx]
00124             if fieldtype in ['int','unsigned int']:
00125                 if not CommonUtil.is_intstr(stringvalue):
00126                     print 'field ',fieldname,' is not integer type'
00127                     raise
00128                 else:
00129                     result.append(int(stringvalue))
00130                     continue
00131             elif fieldtype in ['float']:
00132                 if not CommonUtil.is_floatstr(stringvalue):
00133                     print 'field ',fieldname,' is not float type'
00134                     raise
00135                 else:
00136                     result.append(float(stringvalue))
00137                     contine
00138             elif  fieldtype in ['string','str']:
00139                 result.append(stringvalue)
00140             else:
00141                 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 94 of file inputFilesetParser.py.

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

Definition at line 98 of file inputFilesetParser.py.

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

Definition at line 100 of file inputFilesetParser.py.

00101                           :
00102         '''
00103         output [headerfields]
00104         '''
        return self.__inputResultHeader
def inputFilesetParser::inputFilesetParser::resultheader (   self)

Definition at line 43 of file inputFilesetParser.py.

00044                           :
        return self.__inputResultHeader
def inputFilesetParser::inputFilesetParser::resultInput (   self)
output [valuefields]

Definition at line 105 of file inputFilesetParser.py.

00106                          :
00107         '''
00108         output [valuefields]
00109         '''
        return self.__inputResult
def inputFilesetParser::inputFilesetParser::resultlines (   self)

Definition at line 45 of file inputFilesetParser.py.

00046                          :
        return self.__inputResult
def inputFilesetParser::inputFilesetParser::runs (   self)

Definition at line 172 of file inputFilesetParser.py.

00173                   :
00174         if not self.__inputSelectionFileparsingResult:
00175             return None
        return self.__inputSelectionFileparsingResult.runs()
def inputFilesetParser::inputFilesetParser::runsandls (   self)

Definition at line 176 of file inputFilesetParser.py.

00177                        :
00178         if not self.__inputSelectionFileparsingResult:
00179             return None
        return self.__inputSelectionFileparsingResult.runsandls()
def inputFilesetParser::inputFilesetParser::runsandlsStr (   self)

Definition at line 180 of file inputFilesetParser.py.

00181                           :
00182         if not self.__inputSelectionFileparsingResult:
00183             return None
        return self.__inputSelectionFileparsingResult.runsandlsStr()
def inputFilesetParser::inputFilesetParser::runsWithresult (   self)
output: [run,run,...]

Definition at line 47 of file inputFilesetParser.py.

00048                             :
00049         '''
00050         output: [run,run,...]
00051         '''
00052         result={}
00053         for f in self.__inputresultfiles:
00054             csvReader=csv.reader(open(f),delimiter=',')
00055             for row in csvReader:
00056                 field0=str(row[0]).strip()
00057                 if not CommonUtil.is_intstr(field0):
00058                     continue
00059                 runnumber=int(field0)
00060                 if not result.has_key(runnumber):
00061                     result[runnumber]=None
        return result.keys()
def inputFilesetParser::inputFilesetParser::selectedRunsWithoutresult (   self)
output: [run,run,...]

Definition at line 76 of file inputFilesetParser.py.

00077                                        :
00078         '''
00079         output: [run,run,...]
00080         '''
00081         result=[]
00082         if len(self.__inputselectionfile)==0:#actually no selected
00083             return result
00084         else:
00085             runswithresult=self.runsWithresult()
00086             selectedruns=self.runs()
00087             for r in selectedruns:
00088                 if r not in runswithresult:
00089                     result.append(r)
        return result
def inputFilesetParser::inputFilesetParser::selectedRunsWithresult (   self)
output: [run,run,...]

Definition at line 62 of file inputFilesetParser.py.

00063                                     :
00064         '''
00065         output: [run,run,...]
00066         '''
00067         result=[]
00068         if len(self.__inputselectionfile)==0:#actually no selected
00069             return result
00070         else:
00071             runswithresult=self.runsWithresult()
00072             selectedruns=self.runs()
00073             for r in selectedruns:
00074                 if r in runswithresult:
00075                     result.append(r)
        return result
def inputFilesetParser::inputFilesetParser::selectionfilename (   self)
return the input selection file name

Definition at line 90 of file inputFilesetParser.py.

00091                                :
00092         '''return the input selection file name
00093         '''
        return self.__inputselectionfile

Member Data Documentation

Definition at line 12 of file inputFilesetParser.py.

Definition at line 12 of file inputFilesetParser.py.

Definition at line 12 of file inputFilesetParser.py.

Definition at line 12 of file inputFilesetParser.py.

Definition at line 12 of file inputFilesetParser.py.