CMS 3D CMS Logo

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

Public Member Functions

def __init__ (self, filename, includeNonVersionedClasses=False, normalizeClassNames=True)
 
def end_element (self, name)
 
def genNName (self, name)
 
def readClassesDefXML (self)
 
def start_element (self, name, attrs)
 

Public Attributes

 classes
 

Static Public Attributes

 classVersionIndex
 
 originalNameIndex
 
 versionsToChecksumIndex
 

Private Attributes

 _file
 
 _includeNonVersionedClasses
 
 _normalizeClassNames
 
 _presentClass
 
 _presentClassForVersion
 

Detailed Description

Parses a classes_def.xml file looking for class declarations that contain
ClassVersion attributes. Once found looks for sub-elements named 'version'
which contain the ClassVersion to checksum mappings.

Definition at line 1 of file ClassesDefXmlUtils.py.

Constructor & Destructor Documentation

◆ __init__()

def ClassesDefXmlUtils.XmlParser.__init__ (   self,
  filename,
  includeNonVersionedClasses = False,
  normalizeClassNames = True 
)

Definition at line 13 of file ClassesDefXmlUtils.py.

13  def __init__(self, filename, includeNonVersionedClasses=False, normalizeClassNames=True):
14  self._file = filename
15  self.classes = dict()
16  self._presentClass = None
17  self._presentClassForVersion = None
18  self._includeNonVersionedClasses = includeNonVersionedClasses
19  self._normalizeClassNames = normalizeClassNames
20  self.readClassesDefXML()
def __init__(self, dataset, job_number, job_id, job_name, isDA, isMC, applyBOWS, applyEXTRACOND, extraconditions, runboundary, lumilist, intlumi, maxevents, gt, allFromGT, alignmentDB, alignmentTAG, apeDB, apeTAG, bowDB, bowTAG, vertextype, tracktype, refittertype, ttrhtype, applyruncontrol, ptcut, CMSSW_dir, the_dir)

Member Function Documentation

◆ end_element()

def ClassesDefXmlUtils.XmlParser.end_element (   self,
  name 
)

Definition at line 70 of file ClassesDefXmlUtils.py.

References ClassesDefXmlUtils.XmlParser._presentClass, and ClassesDefXmlUtils.XmlParser._presentClassForVersion.

Referenced by ClassesDefXmlUtils.XmlParser.readClassesDefXML().

70  def end_element(self,name):
71  if name in ('class','struct'):
72  self._presentClass = None
73  self._presentClassForVersion = None

◆ genNName()

def ClassesDefXmlUtils.XmlParser.genNName (   self,
  name 
)

Definition at line 74 of file ClassesDefXmlUtils.py.

References ClassesDefXmlUtils.XmlParser._normalizeClassNames, and join().

Referenced by ClassesDefXmlUtils.XmlParser.start_element().

74  def genNName(self, name ):
75  if not self._normalizeClassNames:
76  return name
77  n_name = " ".join(name.split())
78  for e in [ ['long long unsigned int', 'unsigned long long'],
79  ['long long int', 'long long'],
80  ['unsigned short int', 'unsigned short'],
81  ['short unsigned int', 'unsigned short'],
82  ['short int', 'short'],
83  ['long unsigned int', 'unsigned long'],
84  ['unsigned long int', 'unsigned long'],
85  ['long int', 'long'],
86  ['std::string', 'std::basic_string<char>']] :
87  n_name = n_name.replace(e[0],e[1])
88  n_name = n_name.replace(' ','')
89  return n_name
90 
static std::string join(char **cmd)
Definition: RemoteFile.cc:21

◆ readClassesDefXML()

def ClassesDefXmlUtils.XmlParser.readClassesDefXML (   self)

Definition at line 21 of file ClassesDefXmlUtils.py.

References ClassesDefXmlUtils.XmlParser._file, CommonAnalyzer._file, condhdf5tohdf5.H5Tag._file, condhdf5tohdf5.H5GlobalTag._file, dqm-mbProfile.Profile._file, ClassesDefXmlUtils.XmlParser.end_element(), and ClassesDefXmlUtils.XmlParser.start_element().

21  def readClassesDefXML(self):
22  import xml.parsers.expat
23  p = xml.parsers.expat.ParserCreate()
24  p.StartElementHandler = self.start_element
25  p.EndElementHandler = self.end_element
26  f = open(self._file)
27  # Replace any occurence of <>& in the attribute values by the xml parameter
28  rxml, nxml = f.read(), ''
29  q1,q2 = 0,0
30  for c in rxml :
31  if (q1 or q2) and c == '<' : nxml += '&lt;'
32  elif (q1 or q2) and c == '>' : nxml += '&gt;'
33  # elif (q1 or q2) and c == '&' : nxml += '&amp;'
34  else : nxml += c
35  if c == '"' : q1 = not q1
36  if c == "'" : q2 = not q2
37  try : p.Parse(nxml)
38  except xml.parsers.expat.ExpatError as e :
39  print ('--->> edmCheckClassVersion: ERROR: parsing selection file ',self._file)
40  print ('--->> edmCheckClassVersion: ERROR: Error is:', e)
41  raise
42  f.close()

◆ start_element()

def ClassesDefXmlUtils.XmlParser.start_element (   self,
  name,
  attrs 
)

Definition at line 43 of file ClassesDefXmlUtils.py.

References ClassesDefXmlUtils.XmlParser._includeNonVersionedClasses, ClassesDefXmlUtils.XmlParser._presentClass, ClassesDefXmlUtils.XmlParser._presentClassForVersion, mps_setup.append, ClassesDefXmlUtils.XmlParser.classes, MainPageGenerator.MainPageGenerator.classes, condformats_serialization_generate.SerializationCodeGenerator.classes, ClassesDefXmlUtils.XmlParser.genNName(), and createfilelist.int.

Referenced by ClassesDefXmlUtils.XmlParser.readClassesDefXML().

43  def start_element(self,name,attrs):
44  if name in ('class','struct'):
45  if 'name' in attrs:
46  self._presentClass=attrs['name']
47  normalizedName = self.genNName(attrs['name'])
48  if 'ClassVersion' in attrs:
49  self.classes[normalizedName]=[attrs['name'],int(attrs['ClassVersion']),[]]
50  self._presentClassForVersion=normalizedName
51  elif self._includeNonVersionedClasses:
52  # skip transient data products
53  if not ('persistent' in attrs and attrs['persistent'] == "false"):
54  self.classes[normalizedName]=[attrs['name'],-1,[]]
55  else:
56  raise RuntimeError(f"There is an element '{name}' without 'name' attribute.")
57  if name == 'version':
58  if self._presentClassForVersion is None:
59  raise RuntimeError(f"Class element for type '{self._presentClass}' contains a 'version' element, but 'ClassVersion' attribute is missing from the 'class' element")
60  try:
61  classVersion = int(attrs['ClassVersion'])
62  except KeyError:
63  raise RuntimeError(f"Version element for type '{self._presentClass}' is missing 'ClassVersion' attribute")
64  try:
65  checksum = int(attrs['checksum'])
66  except KeyError:
67  raise RuntimeError(f"Version element for type '{self._presentClass}' is missing 'checksum' attribute")
68  self.classes[self._presentClassForVersion][XmlParser.versionsToChecksumIndex].append([classVersion, checksum])
69  pass

Member Data Documentation

◆ _file

ClassesDefXmlUtils.XmlParser._file
private

◆ _includeNonVersionedClasses

ClassesDefXmlUtils.XmlParser._includeNonVersionedClasses
private

Definition at line 18 of file ClassesDefXmlUtils.py.

Referenced by ClassesDefXmlUtils.XmlParser.start_element().

◆ _normalizeClassNames

ClassesDefXmlUtils.XmlParser._normalizeClassNames
private

Definition at line 19 of file ClassesDefXmlUtils.py.

Referenced by ClassesDefXmlUtils.XmlParser.genNName().

◆ _presentClass

ClassesDefXmlUtils.XmlParser._presentClass
private

◆ _presentClassForVersion

ClassesDefXmlUtils.XmlParser._presentClassForVersion
private

◆ classes

ClassesDefXmlUtils.XmlParser.classes

Definition at line 15 of file ClassesDefXmlUtils.py.

Referenced by ClassesDefXmlUtils.XmlParser.start_element().

◆ classVersionIndex

ClassesDefXmlUtils.XmlParser.classVersionIndex
static

Definition at line 10 of file ClassesDefXmlUtils.py.

◆ originalNameIndex

ClassesDefXmlUtils.XmlParser.originalNameIndex
static

Definition at line 9 of file ClassesDefXmlUtils.py.

◆ versionsToChecksumIndex

ClassesDefXmlUtils.XmlParser.versionsToChecksumIndex
static

Definition at line 11 of file ClassesDefXmlUtils.py.