]> jspc29.x-matter.uni-frankfurt.de Git - mvdsensorcontrol.git/commitdiff
python_hld_unpacker: introduce event_chunker() into read()
authorPhilipp Klaus <klaus@physik.uni-frankfurt.de>
Fri, 21 Nov 2014 15:36:47 +0000 (16:36 +0100)
committerPhilipp Klaus <klaus@physik.uni-frankfurt.de>
Fri, 21 Nov 2014 15:36:47 +0000 (16:36 +0100)
tools/python_hld_unpacker/hld_unpacker/unpacker.py

index b28e205dd0043ccef8a8dd416f150fc5fac97831..151a3ce068ad28b0f58f2ee3d216fd4b3fac6716 100644 (file)
@@ -115,20 +115,22 @@ class SubSubEvent(object):
 #### ------ 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: