CMS 3D CMS Logo

List of all members | Public Member Functions | Public Attributes | Static Public Attributes
cmsHarvester.DBSXMLHandler Class Reference

Helper class: DBSXMLHandler. More...

Inheritance diagram for cmsHarvester.DBSXMLHandler:

Public Member Functions

def __init__ (self, tag_names)
 
def characters (self, content)
 
def check_results_validity (self)
 
def current_element (self)
 
def endElement (self, name)
 
def startElement (self, name, attrs)
 

Public Attributes

 current_value
 
 element_position
 
 results
 
 tag_names
 

Static Public Attributes

 mapping
 

Detailed Description

Helper class: DBSXMLHandler.

XML handler class to parse DBS results.

The tricky thing here is that older DBS versions (2.0.5 and
earlier) return results in a different XML format than newer
versions. Previously the result values were returned as attributes
to the `result' element. The new approach returns result values as
contents of named elements.

The old approach is handled directly in startElement(), the new
approach in characters().

NOTE: All results are returned in the form of string values of
      course!

Definition at line 188 of file cmsHarvester.py.

Constructor & Destructor Documentation

◆ __init__()

def cmsHarvester.DBSXMLHandler.__init__ (   self,
  tag_names 
)

Definition at line 221 of file cmsHarvester.py.

221  def __init__(self, tag_names):
222  # This is a list used as stack to keep track of where we are
223  # in the element tree.
224  self.element_position = []
225  self.tag_names = tag_names
226  self.results = {}
227 

Member Function Documentation

◆ characters()

def cmsHarvester.DBSXMLHandler.characters (   self,
  content 
)

Definition at line 260 of file cmsHarvester.py.

260  def characters(self, content):
261  # NOTE: It is possible that the actual contents of the tag
262  # gets split into multiple pieces. This method will be called
263  # for each of the pieces. This means we have to concatenate
264  # everything ourselves.
265  if self.current_element() in self.tag_names:
266  self.current_value.append(content)
267 

References mps_setup.append, cmsHarvester.DBSXMLHandler.current_element(), cmsHarvester.DBSXMLHandler.current_value, and cmsHarvester.DBSXMLHandler.tag_names.

◆ check_results_validity()

def cmsHarvester.DBSXMLHandler.check_results_validity (   self)
Make sure that all results arrays have equal length.

We should have received complete rows from DBS. I.e. all
results arrays in the handler should be of equal length.

Definition at line 271 of file cmsHarvester.py.

271  def check_results_validity(self):
272  """Make sure that all results arrays have equal length.
273 
274  We should have received complete rows from DBS. I.e. all
275  results arrays in the handler should be of equal length.
276 
277  """
278 
279  results_valid = True
280 
281  res_names = self.results.keys()
282  if len(res_names) > 1:
283  for res_name in res_names[1:]:
284  res_tmp = self.results[res_name]
285  if len(res_tmp) != len(self.results[res_names[0]]):
286  results_valid = False
287 
288  return results_valid
289 

References relativeConstraints.keys, and cmsHarvester.DBSXMLHandler.results.

◆ current_element()

def cmsHarvester.DBSXMLHandler.current_element (   self)

Definition at line 268 of file cmsHarvester.py.

268  def current_element(self):
269  return self.element_position[-1]
270 

References cmsHarvester.DBSXMLHandler.element_position.

Referenced by cmsHarvester.DBSXMLHandler.characters(), and cmsHarvester.DBSXMLHandler.endElement().

◆ endElement()

def cmsHarvester.DBSXMLHandler.endElement (   self,
  name 
)

Definition at line 247 of file cmsHarvester.py.

247  def endElement(self, name):
248  assert self.current_element() == name, \
249  "closing unopenend element `%s'" % name
250 
251  if self.current_element() in self.tag_names:
252  contents = "".join(self.current_value)
253  if self.current_element() in self.results:
254  self.results[self.current_element()].append(contents)
255  else:
256  self.results[self.current_element()] = [contents]
257 
258  self.element_position.pop()
259 

References mps_setup.append, cmsHarvester.DBSXMLHandler.current_element(), cmsHarvester.DBSXMLHandler.current_value, cmsHarvester.DBSXMLHandler.element_position, join(), cmsHarvester.DBSXMLHandler.results, and cmsHarvester.DBSXMLHandler.tag_names.

◆ startElement()

def cmsHarvester.DBSXMLHandler.startElement (   self,
  name,
  attrs 
)

Definition at line 228 of file cmsHarvester.py.

228  def startElement(self, name, attrs):
229  self.element_position.append(name)
230 
231  self.current_value = []
232 
233  #----------
234 
235  # This is to catch results from DBS 2.0.5 and earlier.
236  if name == "result":
237  for name in self.tag_names:
238  key = DBSXMLHandler.mapping[name]
239  value = str(attrs[key])
240  try:
241  self.results[name].append(value)
242  except KeyError:
243  self.results[name] = [value]
244 
245  #----------
246 

References mps_setup.append, and cmsHarvester.DBSXMLHandler.element_position.

Member Data Documentation

◆ current_value

cmsHarvester.DBSXMLHandler.current_value

◆ element_position

cmsHarvester.DBSXMLHandler.element_position

◆ mapping

cmsHarvester.DBSXMLHandler.mapping
static

Definition at line 209 of file cmsHarvester.py.

Referenced by progressbar.FormatLabel.update().

◆ results

cmsHarvester.DBSXMLHandler.results

◆ tag_names

cmsHarvester.DBSXMLHandler.tag_names
join
static std::string join(char **cmd)
Definition: RemoteFile.cc:17
relativeConstraints.keys
keys
Definition: relativeConstraints.py:89
str
#define str(s)
Definition: TestProcessor.cc:52
mps_setup.append
append
Definition: mps_setup.py:85