Belle II Software development
RawRootFile Class Reference

Classes

class  Key
 

Public Member Functions

def __init__ (self, filename)
 
def __del__ (self)
 
def normalize (self, end=None, seekfree=None, nbytesfree=None, nbytesname=None, seekinfo=None)
 
def __iter__ (self)
 
def __next__ (self)
 

Public Attributes

 rootfile
 binary root file
 
 version
 root/file format version
 
 large
 are file location pointers 4 or 8 bits?
 
 wordlen
 size of file location pointers
 
 begin
 pointer to first data record
 
 end
 pointer to first free word at the EOF
 
 seekfree
 pointer to FREE data record
 
 nbytesfree
 number of bytes in FREE data record
 
 nfree
 number of free data records
 
 nbytesname
 number of bytes in TNamed at creation time
 
 units
 number of bytes for file pointers
 
 compress
 compression level and algorithm
 
 seekinfo
 pointer to TStreamerInfo record
 
 nbytesinfo
 number of bytes in TStreamerInfo record
 
 uuid
 universal unique ID
 
 header
 binary header
 
 seekkeys
 pointer to KeysList record
 

Detailed Description

Interface to binary root file content

Definition at line 21 of file b2root.py.

Constructor & Destructor Documentation

◆ __init__()

def __init__ (   self,
  filename 
)
Open a root file and read its header

Definition at line 26 of file b2root.py.

26 def __init__(self, filename):
27 """
28 Open a root file and read its header
29 """
30
31
32 self.rootfile = open(filename, 'rb')
33 root = self.rootfile.read(4)
34 if root != b'root':
35 raise Exception(f"{filename} is not a root file")
36
37 self.version = int.from_bytes(self.rootfile.read(4), byteorder)
38
39 self.large = (self.version >= 1000000)
40
41 self.wordlen = 8 if self.large else 4
42
43 self.begin = int.from_bytes(self.rootfile.read(4), byteorder)
44
45 self.end = int.from_bytes(self.rootfile.read(self.wordlen), byteorder)
46
47 self.seekfree = int.from_bytes(self.rootfile.read(self.wordlen), byteorder)
48
49 self.nbytesfree = int.from_bytes(self.rootfile.read(4), byteorder)
50
51 self.nfree = int.from_bytes(self.rootfile.read(4), byteorder)
52
53 self.nbytesname = int.from_bytes(self.rootfile.read(4), byteorder)
54
55 self.units = int.from_bytes(self.rootfile.read(1), byteorder)
56
57 self.compress = int.from_bytes(self.rootfile.read(4), byteorder)
58
59 self.seekinfo = int.from_bytes(self.rootfile.read(self.wordlen), byteorder)
60
61 self.nbytesinfo = int.from_bytes(self.rootfile.read(self.wordlen), byteorder)
62
63 self.uuid = self.rootfile.read(18)
64 self.rootfile.seek(0)
65
66 self.header = self.rootfile.read(self.begin)
67 self.rootfile.seek(self.begin)
68
69 self.seekkeys = 0
70

◆ __del__()

def __del__ (   self)
Close file

Definition at line 71 of file b2root.py.

71 def __del__(self):
72 """
73 Close file
74 """
75
76 if hasattr(self, 'rootfile'):
77 self.rootfile.close()
78

Member Function Documentation

◆ __iter__()

def __iter__ (   self)
iterator interface

Definition at line 112 of file b2root.py.

112 def __iter__(self):
113 """
114 iterator interface
115 """
116
117 return self
118

◆ __next__()

def __next__ (   self)
Iterate to next key

Definition at line 210 of file b2root.py.

210 def __next__(self):
211 """
212 Iterate to next key
213 """
214
215 pos = self.rootfile.tell()
216 large = pos > 0x80000000
217 nbytes = int.from_bytes(self.rootfile.read(4), byteorder)
218 if (nbytes == 0):
219 raise StopIteration()
220 self.rootfile.seek(-4, 1)
221 result = self.Key(self.rootfile.read(nbytes), large)
222 if pos == self.seekfree:
223 result.showname = b'FreeSegments'
224 elif pos == self.seekinfo:
225 result.showname = b'StreamerInfo'
226 elif pos == self.seekkeys:
227 result.showname = b'KeysList'
228
229 if result.showname == b'TFile':
230 result.filename, pos = result.get_string(result.data, 0)
231 result.filetitle, pos = result.get_string(result.data, pos)
232 result.version = int.from_bytes(result.data[pos:pos+2], byteorder)
233 result.nbyteskeys = int.from_bytes(result.data[pos+10:pos+14], byteorder)
234 result.nbytesname = int.from_bytes(result.data[pos+14:pos+18], byteorder)
235 if result.version > 1000:
236 result.seekdir = int.from_bytes(result.data[pos+18:pos+26], byteorder)
237 result.seekparent = int.from_bytes(result.data[pos+26:pos+34], byteorder)
238 self.seekkeys = int.from_bytes(result.data[pos+34:pos+42], byteorder)
239 else:
240 result.seekdir = int.from_bytes(result.data[pos+18:pos+22], byteorder)
241 result.seekparent = int.from_bytes(result.data[pos+22:pos+26], byteorder)
242 self.seekkeys = int.from_bytes(result.data[pos+26:pos+30], byteorder)
243 return result
244
245

◆ normalize()

def normalize (   self,
  end = None,
  seekfree = None,
  nbytesfree = None,
  nbytesname = None,
  seekinfo = None 
)
Set UUID to zero and adjust pointers that are given as arguments

Definition at line 79 of file b2root.py.

79 def normalize(self, end=None, seekfree=None, nbytesfree=None, nbytesname=None, seekinfo=None):
80 """
81 Set UUID to zero and adjust pointers that are given as arguments
82 """
83
84 if end:
85 self.end = end
86 if seekfree:
87 self.seekfree = seekfree
88 if nbytesfree:
89 self.nbytesfree = nbytesfree
90 if nbytesname:
91 self.nbytesname = nbytesname
92 if seekinfo:
93 self.seekinfo = seekinfo
94 self.uuid = b'\x00' * 18
95
96 self.header = b'root' \
97 + self.version.to_bytes(4, byteorder) \
98 + self.begin.to_bytes(4, byteorder) \
99 + self.end.to_bytes(self.wordlen, byteorder) \
100 + self.seekfree.to_bytes(self.wordlen, byteorder) \
101 + self.nbytesfree.to_bytes(4, byteorder) \
102 + self.nfree.to_bytes(4, byteorder) \
103 + self.nbytesname.to_bytes(4, byteorder) \
104 + self.units.to_bytes(1, byteorder) \
105 + self.compress.to_bytes(4, byteorder) \
106 + self.seekinfo.to_bytes(self.wordlen, byteorder) \
107 + self.nbytesinfo.to_bytes(self.wordlen, byteorder) \
108 + self.uuid
109 nzero = self.begin - len(self.header)
110 self.header += b'\x00' * nzero
111

Member Data Documentation

◆ begin

begin

pointer to first data record

Definition at line 43 of file b2root.py.

◆ compress

compress

compression level and algorithm

Definition at line 57 of file b2root.py.

◆ end

end

pointer to first free word at the EOF

Definition at line 45 of file b2root.py.

◆ header

header

binary header

Definition at line 66 of file b2root.py.

◆ large

large

are file location pointers 4 or 8 bits?

Definition at line 39 of file b2root.py.

◆ nbytesfree

nbytesfree

number of bytes in FREE data record

Definition at line 49 of file b2root.py.

◆ nbytesinfo

nbytesinfo

number of bytes in TStreamerInfo record

Definition at line 61 of file b2root.py.

◆ nbytesname

nbytesname

number of bytes in TNamed at creation time

Definition at line 53 of file b2root.py.

◆ nfree

nfree

number of free data records

Definition at line 51 of file b2root.py.

◆ rootfile

rootfile

binary root file

Definition at line 32 of file b2root.py.

◆ seekfree

seekfree

pointer to FREE data record

Definition at line 47 of file b2root.py.

◆ seekinfo

seekinfo

pointer to TStreamerInfo record

Definition at line 59 of file b2root.py.

◆ seekkeys

seekkeys

pointer to KeysList record

Definition at line 69 of file b2root.py.

◆ units

units

number of bytes for file pointers

Definition at line 55 of file b2root.py.

◆ uuid

uuid

universal unique ID

Definition at line 63 of file b2root.py.

◆ version

version

root/file format version

Definition at line 37 of file b2root.py.

◆ wordlen

wordlen

size of file location pointers

Definition at line 41 of file b2root.py.


The documentation for this class was generated from the following file: