From 0ecf802ac4cd01f9fad04da19179bb1334d5a6f2 Mon Sep 17 00:00:00 2001 From: Matthew Einhorn Date: Mon, 23 Dec 2019 15:18:05 -0500 Subject: [PATCH] Use handshake length for alignment. --- ceed/analysis/merge_data.py | 18 ++++++++++++++---- ceed/storage/controller.py | 30 ++++++++++++++++++++---------- 2 files changed, 34 insertions(+), 14 deletions(-) diff --git a/ceed/analysis/merge_data.py b/ceed/analysis/merge_data.py index 6b8faf7..f649d31 100644 --- a/ceed/analysis/merge_data.py +++ b/ceed/analysis/merge_data.py @@ -18,6 +18,7 @@ import numpy as np import nixio as nix from base_kivy_app.utils import yaml_dumps, yaml_loads +from ceed.storage.controller import num_ticks_handshake __all__ = ('CeedMCSDataMerger', 'DigitalDataStore', 'MCSDigitalData', 'CeedDigitalData', 'AlignmentException') @@ -31,6 +32,8 @@ class AlignmentException(Exception): class DigitalDataStore(object): + counter_bit_width = 32 + short_count_indices = None short_count_data = None @@ -54,12 +57,14 @@ class DigitalDataStore(object): came from. ''' - def __init__(self, short_count_indices, count_indices, clock_index): + def __init__(self, short_count_indices, count_indices, clock_index, + counter_bit_width): '''indices are first mapped with projector_to_aquisition_map. ''' super(DigitalDataStore, self).__init__() self.short_count_indices = short_count_indices self.count_indices = count_indices self.clock_index = clock_index + self.counter_bit_width = counter_bit_width self.populate_indices() def populate_indices(self): @@ -332,12 +337,14 @@ def create_or_reuse_ceed_data_container(self): short_count_indices = config['short_count_indices'] count_indices = config['count_indices'] clock_index = config['clock_idx'] + counter_bit_width = config['counter_bit_width'] if self.ceed_data_container is None or not self.ceed_data_container.\ compare_indices( short_count_indices, count_indices, clock_index): self.ceed_data_container = CeedDigitalData( - short_count_indices, count_indices, clock_index) + short_count_indices, count_indices, clock_index, + counter_bit_width) return self.ceed_data_container def create_or_reuse_mcs_data_container(self): @@ -348,12 +355,14 @@ def create_or_reuse_mcs_data_container(self): short_count_indices = map_f(config['short_count_indices']) count_indices = map_f(config['count_indices']) clock_index = map_f(config['clock_idx']) + counter_bit_width = config['counter_bit_width'] if self.mcs_data_container is None or not self.mcs_data_container.\ compare_indices( short_count_indices, count_indices, clock_index): self.mcs_data_container = MCSDigitalData( - short_count_indices, count_indices, clock_index) + short_count_indices, count_indices, clock_index, + counter_bit_width) return self.mcs_data_container def parse_ceed_digital_data(self): @@ -372,9 +381,10 @@ def get_alignment(self, find_by=None, force=False): mcs = self.mcs_data_container s = 0 - # counter_bit_width = 32 + counter_bit_width = ceed_.counter_bit_width if find_by is None: # find by uuid # n is number of frames we need to send uuid + n = num_ticks_handshake(counter_bit_width, ceed_.count_indices, 16) n = int(ceil(32 / float(len(ceed_.count_indices)))) * 5 # following searches for the uuid in the mcs data diff --git a/ceed/storage/controller.py b/ceed/storage/controller.py index 6c99913..9b084db 100644 --- a/ceed/storage/controller.py +++ b/ceed/storage/controller.py @@ -34,7 +34,7 @@ from base_kivy_app.app import app_error from base_kivy_app.utils import yaml_dumps, yaml_loads -__all__ = ('CeedDataWriterBase', 'DataSerializerBase') +__all__ = ('CeedDataWriterBase', 'DataSerializerBase', 'num_ticks_handshake') class CeedDataWriterBase(EventDispatcher): @@ -939,12 +939,22 @@ def num_ticks_handshake(self, config_len): :param config_len: The number of config **bytes** being sent. """ - num_bytes = self.counter_bit_width // 8 - # the message + padding in bytes - config_len += num_bytes - (config_len % num_bytes) - config_len //= num_bytes # in - config_len += 1 # the message length byte - - ticks_per_int = int( - ceil(self.counter_bit_width / len(self.count_indices))) - return config_len * ticks_per_int * 2 + 2 + return num_ticks_handshake( + self.counter_bit_width, self.count_indices, config_len) + + +def num_ticks_handshake(counter_bit_width, count_indices, config_len): + """Gets the number of ticks required to transmit the handshake + signature of the experiment as provided to :meth:`get_bits` with + ``config_bytes``. + + :param config_len: The number of config **bytes** being sent. + """ + num_bytes = counter_bit_width // 8 + # the message + padding in bytes + config_len += num_bytes - (config_len % num_bytes) + config_len //= num_bytes # in + config_len += 1 # the message length byte + + ticks_per_int = int(ceil(counter_bit_width / len(count_indices))) + return config_len * ticks_per_int * 2 + 2