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 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.

12 
13  def __init__(self,inputfilename):
14  filelist=inputfilename.split('+')
15  self.__inputresultfiles=filelist[0:-1]
16  self.__inputselectionfile=filelist[-1]
18  self.__inputResult=[]
20  if len(self.__inputselectionfile)!=0:
21  basename,extension=os.path.splitext(self.__inputselectionfile)
22  if extension=='.csv':#if file ends with .csv,use csv parser,else parse as json file
24  else:
25  selectf=open(self.__inputselectionfile,'r')
26  inputfilecontent=selectf.read()
28  if len(self.__inputresultfiles)!=0:
29  header=''
30  for f in self.__inputresultfiles:
31  ifile=open(f)
32  hasHeader=filehasHeader(ifile)
33  #hasHeader=csv.Sniffer().has_header(ifile.read(1024)) #sniffer doesn't work well , replace with custom
34  ifile.seek(0)
35  csvReader=csv.reader(ifile,delimiter=',')
36  irow=0
37  for row in csvReader:
38  if hasHeader and irow==0:
39  self.__inputResultHeader=row
40  else:
41  self.__inputResult.append(row)
42  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.

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

143  def fieldtotal(self,fieldname,fieldtype):
144  '''
145  given the input result field name and type, return the total
146  '''
147  fieldidx=None
148  result=0
149  try:
150  fieldidx=self.__inputResultHeader.index(fieldname)
151  except:
152  print 'field ',fieldname,' not found'
153  raise
154  for r in self.__inputResult:
155  stringvalue=r[fieldidx]
156  if fieldtype in ['int','unsigned int']:
157  if not CommonUtil.is_intstr(stringvalue):
158  print 'field ',fieldname,' is not integer type'
159  raise
160  else:
161  result=int(result)+int(stringvalue)
162  continue
163  elif fieldtype in ['float'] :
164  if not CommonUtil.is_floatstr(stringvalue):
165  print 'field ',fieldname,' is not float type'
166  raise
167  else:
168  result=float(result)+float(stringvalue)
169  continue
170  else:
171  raise 'cannot sum types other than int ,float'
return result
def is_floatstr
Definition: CommonUtil.py:128
def is_intstr
Definition: CommonUtil.py:120
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.

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

111  def fieldvalues(self,fieldname,fieldtype):
112  '''
113  given the input result field name and typem return the list of values
114  '''
115  fieldidx=None
116  result=[]
117  try:
118  fieldidx=self.__inputResultHeader.index(fieldname)
119  except:
120  print 'field ',fieldname,' not found'
121  raise
122  for r in self.__inputResult:
123  stringvalue=r[fieldidx]
124  if fieldtype in ['int','unsigned int']:
125  if not CommonUtil.is_intstr(stringvalue):
126  print 'field ',fieldname,' is not integer type'
127  raise
128  else:
129  result.append(int(stringvalue))
130  continue
131  elif fieldtype in ['float']:
132  if not CommonUtil.is_floatstr(stringvalue):
133  print 'field ',fieldname,' is not float type'
134  raise
135  else:
136  result.append(float(stringvalue))
137  contine
138  elif fieldtype in ['string','str']:
139  result.append(stringvalue)
140  else:
141  raise 'unsupported type ',fieldtype
return result
def is_floatstr
Definition: CommonUtil.py:128
def is_intstr
Definition: CommonUtil.py:120
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.

References inputFilesetParser.inputFilesetParser.__inputselectionfile.

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

Definition at line 98 of file inputFilesetParser.py.

References inputFilesetParser.inputFilesetParser.__inputresultfiles.

98 
99  def resultfiles(self):
return self.__inputresultfiles
def inputFilesetParser.inputFilesetParser.resultheader (   self)

Definition at line 43 of file inputFilesetParser.py.

References inputFilesetParser.inputFilesetParser.__inputResultHeader.

43 
44  def resultheader(self):
return self.__inputResultHeader
def inputFilesetParser.inputFilesetParser.resultHeader (   self)
output [headerfields]

Definition at line 100 of file inputFilesetParser.py.

References inputFilesetParser.inputFilesetParser.__inputResultHeader.

101  def resultHeader(self):
102  '''
103  output [headerfields]
104  '''
return self.__inputResultHeader
def inputFilesetParser.inputFilesetParser.resultInput (   self)
output [valuefields]

Definition at line 105 of file inputFilesetParser.py.

References inputFilesetParser.inputFilesetParser.__inputResult.

106  def resultInput(self):
107  '''
108  output [valuefields]
109  '''
return self.__inputResult
def inputFilesetParser.inputFilesetParser.resultlines (   self)

Definition at line 45 of file inputFilesetParser.py.

References inputFilesetParser.inputFilesetParser.__inputResult.

45 
46  def resultlines(self):
return self.__inputResult
def inputFilesetParser.inputFilesetParser.runs (   self)

Definition at line 172 of file inputFilesetParser.py.

References inputFilesetParser.inputFilesetParser.__inputSelectionFileparsingResult.

Referenced by inputFilesetParser.inputFilesetParser.selectedRunsWithoutresult(), and inputFilesetParser.inputFilesetParser.selectedRunsWithresult().

173  def runs(self):
175  return None
return self.__inputSelectionFileparsingResult.runs()
def inputFilesetParser.inputFilesetParser.runsandls (   self)

Definition at line 176 of file inputFilesetParser.py.

References inputFilesetParser.inputFilesetParser.__inputSelectionFileparsingResult.

177  def runsandls(self):
179  return None
return self.__inputSelectionFileparsingResult.runsandls()
def inputFilesetParser.inputFilesetParser.runsandlsStr (   self)

Definition at line 180 of file inputFilesetParser.py.

References inputFilesetParser.inputFilesetParser.__inputSelectionFileparsingResult.

181  def runsandlsStr(self):
183  return None
return self.__inputSelectionFileparsingResult.runsandlsStr()
def inputFilesetParser.inputFilesetParser.runsWithresult (   self)
output: [run,run,...]

Definition at line 47 of file inputFilesetParser.py.

References inputFilesetParser.inputFilesetParser.__inputresultfiles, CommonUtil.is_intstr(), and strip().

Referenced by inputFilesetParser.inputFilesetParser.selectedRunsWithoutresult(), and inputFilesetParser.inputFilesetParser.selectedRunsWithresult().

47 
48  def runsWithresult(self):
49  '''
50  output: [run,run,...]
51  '''
52  result={}
53  for f in self.__inputresultfiles:
54  csvReader=csv.reader(open(f),delimiter=',')
55  for row in csvReader:
56  field0=str(row[0]).strip()
57  if not CommonUtil.is_intstr(field0):
58  continue
59  runnumber=int(field0)
60  if not result.has_key(runnumber):
61  result[runnumber]=None
return result.keys()
void strip(std::string &input, const std::string &blanks=" \n\t")
Definition: stringTools.cc:16
def is_intstr
Definition: CommonUtil.py:120
def inputFilesetParser.inputFilesetParser.selectedRunsWithoutresult (   self)
output: [run,run,...]

Definition at line 76 of file inputFilesetParser.py.

References inputFilesetParser.inputFilesetParser.__inputselectionfile, csvSelectionParser.csvSelectionParser.runs(), fwlite::RunLumiSelector.runs, csvLumibyLSParser.csvLumibyLSParser.runs(), inputFilesetParser.inputFilesetParser.runs(), SiStripConfigDb.runs(), and inputFilesetParser.inputFilesetParser.runsWithresult().

76 
77  def selectedRunsWithoutresult(self):
78  '''
79  output: [run,run,...]
80  '''
81  result=[]
82  if len(self.__inputselectionfile)==0:#actually no selected
83  return result
84  else:
85  runswithresult=self.runsWithresult()
86  selectedruns=self.runs()
87  for r in selectedruns:
88  if r not in runswithresult:
89  result.append(r)
return result
def inputFilesetParser.inputFilesetParser.selectedRunsWithresult (   self)
output: [run,run,...]

Definition at line 62 of file inputFilesetParser.py.

References inputFilesetParser.inputFilesetParser.__inputselectionfile, csvSelectionParser.csvSelectionParser.runs(), fwlite::RunLumiSelector.runs, csvLumibyLSParser.csvLumibyLSParser.runs(), inputFilesetParser.inputFilesetParser.runs(), SiStripConfigDb.runs(), and inputFilesetParser.inputFilesetParser.runsWithresult().

62 
63  def selectedRunsWithresult(self):
64  '''
65  output: [run,run,...]
66  '''
67  result=[]
68  if len(self.__inputselectionfile)==0:#actually no selected
69  return result
70  else:
71  runswithresult=self.runsWithresult()
72  selectedruns=self.runs()
73  for r in selectedruns:
74  if r in runswithresult:
75  result.append(r)
return result
def inputFilesetParser.inputFilesetParser.selectionfilename (   self)
return the input selection file name

Definition at line 90 of file inputFilesetParser.py.

References inputFilesetParser.inputFilesetParser.__inputselectionfile.

90 
91  def selectionfilename(self):
92  '''return the input selection file name
93  '''
return self.__inputselectionfile

Member Data Documentation

inputFilesetParser.inputFilesetParser.__inputResult
private

Definition at line 17 of file inputFilesetParser.py.

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

inputFilesetParser.inputFilesetParser.__inputresultfiles
private

Definition at line 14 of file inputFilesetParser.py.

Referenced by inputFilesetParser.inputFilesetParser.resultfiles(), and inputFilesetParser.inputFilesetParser.runsWithresult().

inputFilesetParser.inputFilesetParser.__inputResultHeader
private

Definition at line 16 of file inputFilesetParser.py.

Referenced by inputFilesetParser.inputFilesetParser.resultheader(), and inputFilesetParser.inputFilesetParser.resultHeader().

inputFilesetParser.inputFilesetParser.__inputselectionfile
private

Definition at line 15 of file inputFilesetParser.py.

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

inputFilesetParser.inputFilesetParser.__inputSelectionFileparsingResult
private

Definition at line 18 of file inputFilesetParser.py.

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