Skip to content

Commit

Permalink
Use handshake length for alignment.
Browse files Browse the repository at this point in the history
  • Loading branch information
matham committed Dec 23, 2019
1 parent 9fdaca0 commit 0ecf802
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 14 deletions.
18 changes: 14 additions & 4 deletions ceed/analysis/merge_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -31,6 +32,8 @@ class AlignmentException(Exception):

class DigitalDataStore(object):

counter_bit_width = 32

short_count_indices = None

short_count_data = None
Expand All @@ -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):
Expand Down Expand Up @@ -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):
Expand All @@ -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):
Expand All @@ -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
Expand Down
30 changes: 20 additions & 10 deletions ceed/storage/controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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

0 comments on commit 0ecf802

Please sign in to comment.