2 """Parses a classes_def.xml file looking for class declarations that contain 3 ClassVersion attributes. Once found looks for sub-elements named 'version' 4 which contain the ClassVersion to checksum mappings. 11 versionsToChecksumIndex = 2
13 def __init__(self, filename, includeNonVersionedClasses=False, normalizeClassNames=True):
22 import xml.parsers.expat
23 p = xml.parsers.expat.ParserCreate()
28 rxml, nxml = f.read(),
'' 31 if (q1
or q2)
and c ==
'<' : nxml +=
'<' 32 elif (q1
or q2)
and c ==
'>' : nxml +=
'>' 35 if c ==
'"' : q1 =
not q1
36 if c ==
"'" : q2 =
not q2
38 except xml.parsers.expat.ExpatError
as e :
39 print (
'--->> edmCheckClassVersion: ERROR: parsing selection file ',self.
_file)
40 print (
'--->> edmCheckClassVersion: ERROR: Error is:', e)
44 if name
in (
'class',
'struct'):
47 normalizedName = self.
genNName(attrs[
'name'])
48 if 'ClassVersion' in attrs:
49 self.
classes[normalizedName]=[attrs[
'name'],
int(attrs[
'ClassVersion']),[]]
53 if not (
'persistent' in attrs
and attrs[
'persistent'] ==
"false"):
54 self.
classes[normalizedName]=[attrs[
'name'],-1,[]]
56 raise RuntimeError(f
"There is an element '{name}' without 'name' attribute.")
59 raise RuntimeError(f
"Class element for type '{self._presentClass}' contains a 'version' element, but 'ClassVersion' attribute is missing from the 'class' element")
61 classVersion =
int(attrs[
'ClassVersion'])
63 raise RuntimeError(f
"Version element for type '{self._presentClass}' is missing 'ClassVersion' attribute")
65 checksum =
int(attrs[
'checksum'])
67 raise RuntimeError(f
"Version element for type '{self._presentClass}' is missing 'checksum' attribute")
71 if name
in (
'class',
'struct'):
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'],
86 [
'std::string',
'std::basic_string<char>']] :
87 n_name = n_name.replace(e[0],e[1])
88 n_name = n_name.replace(
' ',
'')
94 ROOT.PyConfig.DisableRootLogon =
True 97 ROOT.gROOT.SetBatch(
True)
98 ROOT.gROOT.ProcessLine(
".autodict")
99 if library
is not None:
100 if ROOT.gSystem.Load(library) < 0 :
101 raise RuntimeError(
"failed to load library '"+library+
"'")
104 """Must be called before checkClass()""" 106 ROOT.gROOT.ProcessLine(
"class checkclass {public: int f(char const* name) {TClass* cl = TClass::GetClass(name); bool b = false; cl->GetCheckSum(b); return (int)b;} };")
107 ROOT.gROOT.ProcessLine(
"checkclass checkTheClass;")
112 errorRootDoesNotMatchClassDef =1
113 errorMustUpdateClassVersion=2
114 errorMustAddChecksum=3
118 c = ROOT.TClass.GetClass(name)
120 raise RuntimeError(
"failed to load dictionary for class '"+name+
"'")
121 temp =
"checkTheClass.f(" +
'"' + name +
'"' +
");" 122 retval = ROOT.gROOT.ProcessLine(temp)
124 raise RuntimeError(
"TClass::GetCheckSum: Failed to load dictionary for base class. See previous Error message")
125 classChecksum = c.GetCheckSum()
126 classVersion = c.GetClassVersion()
129 if version != classVersion:
130 return (errorRootDoesNotMatchClassDef,classVersion,classChecksum)
135 for v,cs
in versionsToChecksums:
138 if classChecksum != cs:
139 return (errorMustUpdateClassVersion,classVersion,classChecksum)
141 if not found
and classVersion != 0:
142 return (errorMustAddChecksum,classVersion,classChecksum)
143 return (noError,classVersion,classChecksum)
def checkClass(name, version, versionsToChecksums)
def readClassesDefXML(self)
def start_element(self, name, attrs)
def end_element(self, name)
static std::string join(char **cmd)
def __init__(self, filename, includeNonVersionedClasses=False, normalizeClassNames=True)
_includeNonVersionedClasses