Belle II Software development
RawRootFile.Key Class Reference

Public Member Functions

def __init__ (self, keydata, large=False)
 
def normalize (self, pos=None, offset=None)
 
def recreate_header (self)
 
def get_int (self, data, pos, wordlen=4)
 
def get_string (self, data, pos)
 

Public Attributes

 large
 are file location pointers 4 or 8 bits?
 
 wordlen
 size of file location pointers
 
 header
 length of compressed object (in bytes)
 
 data
 data bytes associated to the object
 
 showname
 name to show in the list of keys
 
 datime
 date and time when object was written to file
 
 seekkey
 pointer to record itself (consistency check)
 

Detailed Description

Root file key

Definition at line 119 of file b2root.py.

Constructor & Destructor Documentation

◆ __init__()

def __init__ (   self,
  keydata,
  large = False 
)
Obtain key header and data payload from given data and extract header information

Definition at line 124 of file b2root.py.

124 def __init__(self, keydata, large=False):
125 """
126 Obtain key header and data payload from given data and extract header information
127 """
128
129
130 self.large = large
131
132 self.wordlen = 8 if self.large else 4
133 pos = 0
134
135 self.nbytes, pos = self.get_int(keydata, pos)
136
137 self.version, pos = self.get_int(keydata, pos, 2)
138
139 self.objlen, pos = self.get_int(keydata, pos)
140
141 self.datime, pos = keydata[pos:pos+4], pos+4
142
143 self.keylen, pos = self.get_int(keydata, pos, 2)
144
145 self.cycle, pos = self.get_int(keydata, pos, 2)
146
147 self.seekkey, pos = self.get_int(keydata, pos, self.wordlen)
148
149 self.seekpdir, pos = self.get_int(keydata, pos, self.wordlen)
150
151 self.classname, pos = self.get_string(keydata, pos)
152
153 self.name, pos = self.get_string(keydata, pos)
154
155 self.title, pos = self.get_string(keydata, pos)
156
157 self.header = keydata[:pos]
158
159 self.data = keydata[pos:]
160
161 self.showname = self.classname
162

Member Function Documentation

◆ get_int()

def get_int (   self,
  data,
  pos,
  wordlen = 4 
)
Helper function to read an int from binary data

Definition at line 195 of file b2root.py.

195 def get_int(self, data, pos, wordlen=4):
196 """
197 Helper function to read an int from binary data
198 """
199
200 return (int.from_bytes(data[pos:pos+wordlen], byteorder), pos+wordlen)
201

◆ get_string()

def get_string (   self,
  data,
  pos 
)
Helper function to read a string from binary data

Definition at line 202 of file b2root.py.

202 def get_string(self, data, pos):
203 """
204 Helper function to read a string from binary data
205 """
206
207 strlen = data[pos]
208 return (data[pos+1:pos+1+strlen], pos+1+strlen)
209
210 def __next__(self):

◆ normalize()

def normalize (   self,
  pos = None,
  offset = None 
)
Set the key datime to zero adjust the pointer to itself if given as argument

Definition at line 163 of file b2root.py.

163 def normalize(self, pos=None, offset=None):
164 """
165 Set the key datime to zero adjust the pointer to itself if given as argument
166 """
167
168
169 self.datime = b'\x00' * 4
170 if self.seekkey > 0:
171 if pos:
172
173 self.seekkey = pos
174 elif offset:
175 self.seekkey += offset
176 self.recreate_header()
177

◆ recreate_header()

def recreate_header (   self)
Build the binary header information from the data members

Definition at line 178 of file b2root.py.

178 def recreate_header(self):
179 """
180 Build the binary header information from the data members
181 """
182
183 self.header = self.nbytes.to_bytes(4, byteorder) \
184 + self.version.to_bytes(2, byteorder) \
185 + self.objlen.to_bytes(4, byteorder) \
186 + self.datime \
187 + self.keylen.to_bytes(2, byteorder) \
188 + self.cycle.to_bytes(2, byteorder) \
189 + self.seekkey.to_bytes(self.wordlen, byteorder) \
190 + self.seekpdir.to_bytes(self.wordlen, byteorder) \
191 + len(self.classname).to_bytes(1, byteorder) + self.classname \
192 + len(self.name).to_bytes(1, byteorder) + self.name \
193 + len(self.title).to_bytes(1, byteorder) + self.title
194

Member Data Documentation

◆ data

data

data bytes associated to the object

Definition at line 159 of file b2root.py.

◆ datime

datime

date and time when object was written to file

Definition at line 169 of file b2root.py.

◆ header

header

length of compressed object (in bytes)

TKey version identifier

length of uncompressed object

date and time when object was written to file

length of the key structure (in bytes)

cycle of key

pointer to record itself (consistency check)

pointer to directory header

object Class Name

name of the object

title of the object

binary header

Definition at line 157 of file b2root.py.

◆ large

large

are file location pointers 4 or 8 bits?

Definition at line 130 of file b2root.py.

◆ seekkey

seekkey

pointer to record itself (consistency check)

Definition at line 173 of file b2root.py.

◆ showname

showname

name to show in the list of keys

Definition at line 161 of file b2root.py.

◆ wordlen

wordlen

size of file location pointers

Definition at line 132 of file b2root.py.


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