#### ------ Generator Functions to read the HLD into the (sub)event classes ------ ####
def read(hld_stream):
+ for (header_bytes, data_bytes) in event_chunker(hld_stream):
+ yield Event(header_bytes, data_bytes)
+
+def event_chunker(hld_stream):
while True:
header_bytes = hld_stream.read(Event.HEADERSIZE)
if len(header_bytes) < Event.HEADERSIZE: break
# The size of the event in bytes is given in the first data word of the event.
- # The size also includes the 4 bytes of its own data word:
+ # The size also includes the 4 bytes of its own data word.
size = struct.unpack('<I', header_bytes[:WORDSIZE])[0]
- # We read already the full header, so we need to subtract
- actual_num_bytes = size - Event.HEADERSIZE
- # The HLD file always writes blocks of length BLOCKSIZE and pads with 0x00 bytes at the end of blocks
- remaining_num_bytes = int(math.ceil(actual_num_bytes/BLOCKSIZE)*BLOCKSIZE)
- data_bytes = hld_stream.read(remaining_num_bytes)
- data_bytes = data_bytes[:actual_num_bytes]
- #pdb.set_trace()
- yield Event(header_bytes, data_bytes)
+ # We read already the full header, so we need to subtract
+ payload_num_bytes = size - Event.HEADERSIZE
+ # The HLD file always writes blocks of length BLOCKSIZE and pads with 0x00 bytes at the end of blocks
+ padded_num_bytes = int(math.ceil(payload_num_bytes/BLOCKSIZE)*BLOCKSIZE)
+ payload_bytes = hld_stream.read(padded_num_bytes)[:payload_num_bytes]
+ yield (header_bytes, payload_bytes)
def read_subevents(subevents_stream):
while True: