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 187 of file cmsHarvester.py.

Constructor & Destructor Documentation

◆ __init__()

def cmsHarvester.DBSXMLHandler.__init__ (   self,
  tag_names 
)

Definition at line 220 of file cmsHarvester.py.

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

Member Function Documentation

◆ characters()

def cmsHarvester.DBSXMLHandler.characters (   self,
  content 
)

Definition at line 259 of file cmsHarvester.py.

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

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 270 of file cmsHarvester.py.

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

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

◆ current_element()

def cmsHarvester.DBSXMLHandler.current_element (   self)

Definition at line 267 of file cmsHarvester.py.

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

References cmsHarvester.DBSXMLHandler.element_position.

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

◆ endElement()

def cmsHarvester.DBSXMLHandler.endElement (   self,
  name 
)

Definition at line 246 of file cmsHarvester.py.

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

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 227 of file cmsHarvester.py.

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

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 208 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:53
mps_setup.append
append
Definition: mps_setup.py:85