CMS 3D CMS Logo

List of all members | Public Member Functions | Private Attributes
inputFilesetParser.inputFilesetParser Class Reference
Inheritance diagram for inputFilesetParser.inputFilesetParser:

Public Member Functions

def __init__ (self, inputfilename)
 
def fieldtotal (self, fieldname, fieldtype)
 
def fieldvalues (self, fieldname, fieldtype)
 
def mergeResultOnly (self)
 
def resultfiles (self)
 
def resultheader (self)
 
def resultHeader (self)
 
def resultInput (self)
 
def resultlines (self)
 
def runs (self)
 
def runsandls (self)
 
def runsandlsStr (self)
 
def runsWithresult (self)
 
def selectedRunsWithoutresult (self)
 
def selectedRunsWithresult (self)
 
def selectionfilename (self)
 

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

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

110  def fieldvalues(self,fieldname,fieldtype):
111  '''
112  given the input result field name and typem return the list of values
113  '''
114  fieldidx=None
115  result=[]
116  try:
117  fieldidx=self.__inputResultHeader.index(fieldname)
118  except:
119  print 'field ',fieldname,' not found'
120  raise
121  for r in self.__inputResult:
122  stringvalue=r[fieldidx]
123  if fieldtype in ['int','unsigned int']:
124  if not CommonUtil.is_intstr(stringvalue):
125  print 'field ',fieldname,' is not integer type'
126  raise
127  else:
128  result.append(int(stringvalue))
129  continue
130  elif fieldtype in ['float']:
131  if not CommonUtil.is_floatstr(stringvalue):
132  print 'field ',fieldname,' is not float type'
133  raise
134  else:
135  result.append(float(stringvalue))
136  contine
137  elif fieldtype in ['string','str']:
138  result.append(stringvalue)
139  else:
140  raise 'unsupported type ',fieldtype
141  return result
def is_intstr(s)
Definition: CommonUtil.py:120
def fieldvalues(self, fieldname, fieldtype)
def is_floatstr(s)
Definition: CommonUtil.py:128
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  def mergeResultOnly(self):
95  '''if empty input selection filename give, I assume you only need to merge pieces of output result files into one
96  '''
97  return len(self.__inputselectionfile)==0
def inputFilesetParser.inputFilesetParser.resultfiles (   self)
def inputFilesetParser.inputFilesetParser.resultheader (   self)
def inputFilesetParser.inputFilesetParser.resultHeader (   self)
output [headerfields]

Definition at line 100 of file inputFilesetParser.py.

References inputFilesetParser.inputFilesetParser.__inputResultHeader.

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

Definition at line 105 of file inputFilesetParser.py.

References inputFilesetParser.inputFilesetParser.__inputResult.

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

Definition at line 176 of file inputFilesetParser.py.

References inputFilesetParser.inputFilesetParser.__inputSelectionFileparsingResult.

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

Definition at line 180 of file inputFilesetParser.py.

References inputFilesetParser.inputFilesetParser.__inputSelectionFileparsingResult.

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

Definition at line 47 of file inputFilesetParser.py.

References inputFilesetParser.inputFilesetParser.__inputresultfiles, createfilelist.int, CommonUtil.is_intstr(), str, and digitizers_cfi.strip.

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

47  def runsWithresult(self):
48  '''
49  output: [run,run,...]
50  '''
51  result={}
52  for f in self.__inputresultfiles:
53  csvReader=csv.reader(open(f),delimiter=',')
54  for row in csvReader:
55  field0=str(row[0]).strip()
56  if not CommonUtil.is_intstr(field0):
57  continue
58  runnumber=int(field0)
59  if runnumber not in result:
60  result[runnumber]=None
61  return result.keys()
def is_intstr(s)
Definition: CommonUtil.py:120
#define str(s)
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().

77  '''
78  output: [run,run,...]
79  '''
80  result=[]
81  if len(self.__inputselectionfile)==0:#actually no selected
82  return result
83  else:
84  runswithresult=self.runsWithresult()
85  selectedruns=self.runs()
86  for r in selectedruns:
87  if r not in runswithresult:
88  result.append(r)
89  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().

63  '''
64  output: [run,run,...]
65  '''
66  result=[]
67  if len(self.__inputselectionfile)==0:#actually no selected
68  return result
69  else:
70  runswithresult=self.runsWithresult()
71  selectedruns=self.runs()
72  for r in selectedruns:
73  if r in runswithresult:
74  result.append(r)
75  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  def selectionfilename(self):
91  '''return the input selection file name
92  '''
93  return self.__inputselectionfile

Member Data Documentation

inputFilesetParser.inputFilesetParser.__inputResult
private
inputFilesetParser.inputFilesetParser.__inputresultfiles
private
inputFilesetParser.inputFilesetParser.__inputResultHeader
private
inputFilesetParser.inputFilesetParser.__inputselectionfile
private
inputFilesetParser.inputFilesetParser.__inputSelectionFileparsingResult
private