test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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__
 
def characters
 
def check_results_validity
 
def current_element
 
def endElement
 
def startElement
 

Public Attributes

 current_value
 
 element_position
 
 results
 
 tag_names
 

Static Public Attributes

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

Constructor & Destructor Documentation

def cmsHarvester.DBSXMLHandler.__init__ (   self,
  tag_names 
)

Definition at line 218 of file cmsHarvester.py.

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

Member Function Documentation

def cmsHarvester.DBSXMLHandler.characters (   self,
  content 
)

Definition at line 257 of file cmsHarvester.py.

References cmsHarvester.DBSXMLHandler.current_element(), and cmsHarvester.DBSXMLHandler.tag_names.

258  def characters(self, content):
259  # NOTE: It is possible that the actual contents of the tag
260  # gets split into multiple pieces. This method will be called
261  # for each of the pieces. This means we have to concatenate
262  # everything ourselves.
263  if self.current_element() in self.tag_names:
264  self.current_value.append(content)
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 268 of file cmsHarvester.py.

References cmsHarvester.DBSXMLHandler.results.

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

Definition at line 265 of file cmsHarvester.py.

References cmsHarvester.DBSXMLHandler.element_position.

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

266  def current_element(self):
267  return self.element_position[-1]
def cmsHarvester.DBSXMLHandler.endElement (   self,
  name 
)

Definition at line 244 of file cmsHarvester.py.

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

245  def endElement(self, name):
246  assert self.current_element() == name, \
247  "closing unopenend element `%s'" % name
248 
249  if self.current_element() in self.tag_names:
250  contents = "".join(self.current_value)
251  if self.current_element() in self.results:
252  self.results[self.current_element()].append(contents)
253  else:
254  self.results[self.current_element()] = [contents]
255 
256  self.element_position.pop()
boost::dynamic_bitset append(const boost::dynamic_bitset<> &bs1, const boost::dynamic_bitset<> &bs2)
this method takes two bitsets bs1 and bs2 and returns result of bs2 appended to the end of bs1 ...
static std::string join(char **cmd)
Definition: RemoteFile.cc:18
def cmsHarvester.DBSXMLHandler.startElement (   self,
  name,
  attrs 
)

Definition at line 225 of file cmsHarvester.py.

226  def startElement(self, name, attrs):
227  self.element_position.append(name)
229  self.current_value = []
230 
231  #----------
232 
233  # This is to catch results from DBS 2.0.5 and earlier.
234  if name == "result":
235  for name in self.tag_names:
236  key = DBSXMLHandler.mapping[name]
237  value = str(attrs[key])
238  try:
239  self.results[name].append(value)
240  except KeyError:
241  self.results[name] = [value]
242 
243  #----------
boost::dynamic_bitset append(const boost::dynamic_bitset<> &bs1, const boost::dynamic_bitset<> &bs2)
this method takes two bitsets bs1 and bs2 and returns result of bs2 appended to the end of bs1 ...

Member Data Documentation

cmsHarvester.DBSXMLHandler.current_value

Definition at line 228 of file cmsHarvester.py.

Referenced by cmsHarvester.DBSXMLHandler.endElement().

cmsHarvester.DBSXMLHandler.element_position

Definition at line 221 of file cmsHarvester.py.

Referenced by cmsHarvester.DBSXMLHandler.current_element().

dictionary cmsHarvester.DBSXMLHandler.mapping
static
Initial value:
1 = {
2  "dataset" : "PATH",
3  "dataset.tag" : "PROCESSEDDATASET_GLOBALTAG",
4  "datatype.type" : "PRIMARYDSTYPE_TYPE",
5  "run" : "RUNS_RUNNUMBER",
6  "run.number" : "RUNS_RUNNUMBER",
7  "file.name" : "FILES_LOGICALFILENAME",
8  "file.numevents" : "FILES_NUMBEROFEVENTS",
9  "algo.version" : "APPVERSION_VERSION",
10  "site" : "STORAGEELEMENT_SENAME",
11  }

Definition at line 206 of file cmsHarvester.py.

cmsHarvester.DBSXMLHandler.results

Definition at line 223 of file cmsHarvester.py.

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

cmsHarvester.DBSXMLHandler.tag_names

Definition at line 222 of file cmsHarvester.py.

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