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 12 of file inputFilesetParser.py.

Constructor & Destructor Documentation

def inputFilesetParser.inputFilesetParser.__init__ (   self,
  inputfilename 
)

Definition at line 13 of file inputFilesetParser.py.

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
43  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 143 of file inputFilesetParser.py.

References inputFilesetParser.inputFilesetParser.__inputResult, objects.autophobj.float, createfilelist.int, CommonUtil.is_floatstr(), CommonUtil.is_intstr(), and edm.print().

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 RunTimeError('cannot sum types other than int ,float')
172  return result
S & print(S &os, JobReport::InputFile const &f)
Definition: JobReport.cc:65
def is_intstr(s)
Definition: CommonUtil.py:121
def fieldtotal(self, fieldname, fieldtype)
def is_floatstr(s)
Definition: CommonUtil.py:129
def inputFilesetParser.inputFilesetParser.fieldvalues (   self,
  fieldname,
  fieldtype 
)
given the input result field name and typem return the list of values

Definition at line 111 of file inputFilesetParser.py.

References inputFilesetParser.inputFilesetParser.__inputResult, objects.autophobj.float, createfilelist.int, CommonUtil.is_floatstr(), CommonUtil.is_intstr(), and edm.print().

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 RuntimeError('field')
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 RuntimeError('field')
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 RuntimeError('field')
135  else:
136  result.append(float(stringvalue))
137  contine
138  elif fieldtype in ['string','str']:
139  result.append(stringvalue)
140  else:
141  raise RuntimeError('unsupported type '+fieldtype)
142  return result
S & print(S &os, JobReport::InputFile const &f)
Definition: JobReport.cc:65
def is_intstr(s)
Definition: CommonUtil.py:121
def fieldvalues(self, fieldname, fieldtype)
def is_floatstr(s)
Definition: CommonUtil.py:129
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 95 of file inputFilesetParser.py.

References inputFilesetParser.inputFilesetParser.__inputselectionfile.

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  '''
98  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 101 of file inputFilesetParser.py.

References inputFilesetParser.inputFilesetParser.__inputResultHeader.

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

Definition at line 106 of file inputFilesetParser.py.

References inputFilesetParser.inputFilesetParser.__inputResult.

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

Definition at line 177 of file inputFilesetParser.py.

References inputFilesetParser.inputFilesetParser.__inputSelectionFileparsingResult.

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

Definition at line 181 of file inputFilesetParser.py.

References inputFilesetParser.inputFilesetParser.__inputSelectionFileparsingResult.

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

Definition at line 48 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().

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 runnumber not in result:
61  result[runnumber]=None
62  return result.keys()
def is_intstr(s)
Definition: CommonUtil.py:121
#define str(s)
def inputFilesetParser.inputFilesetParser.selectedRunsWithoutresult (   self)
output: [run,run,...]

Definition at line 77 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().

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)
90  return result
def inputFilesetParser.inputFilesetParser.selectedRunsWithresult (   self)
output: [run,run,...]

Definition at line 63 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().

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)
76  return result
def inputFilesetParser.inputFilesetParser.selectionfilename (   self)
return the input selection file name

Definition at line 91 of file inputFilesetParser.py.

References inputFilesetParser.inputFilesetParser.__inputselectionfile.

91  def selectionfilename(self):
92  '''return the input selection file name
93  '''
94  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