Commit a99dd065 authored by Matias Guijarro's avatar Matias Guijarro Committed by Vincent Michel
Browse files

bliss/scanning/acquisition changes: according to new AcquisitionChannelList...

bliss/scanning/acquisition changes: according to new AcquisitionChannelList object (see previous commit)
parent 017a0923
...@@ -29,13 +29,11 @@ class BaseCounterAcquisitionDevice(AcquisitionDevice): ...@@ -29,13 +29,11 @@ class BaseCounterAcquisitionDevice(AcquisitionDevice):
self.__count_time = count_time self.__count_time = count_time
self.__grouped_read_counters_list = list() self.__grouped_read_counters_list = list()
self.__counter_names = list()
self._nb_acq_points = 0 self._nb_acq_points = 0
if not isinstance(counter, GroupedReadMixin): if not isinstance(counter, GroupedReadMixin):
self.channels.append(AcquisitionChannel( self.channels.append(AcquisitionChannel(
counter.name, numpy.double, (1,))) counter.name, numpy.double, (1,)))
self.__counter_names.append(counter.name)
@property @property
def count_time(self): def count_time(self):
...@@ -45,24 +43,17 @@ class BaseCounterAcquisitionDevice(AcquisitionDevice): ...@@ -45,24 +43,17 @@ class BaseCounterAcquisitionDevice(AcquisitionDevice):
def grouped_read_counters(self): def grouped_read_counters(self):
return self.__grouped_read_counters_list return self.__grouped_read_counters_list
@property
def counter_names(self):
return self.__counter_names
def add_counter(self, counter): def add_counter(self, counter):
if not isinstance(self.device, GroupedReadMixin): if not isinstance(self.device, GroupedReadMixin):
raise RuntimeError( raise RuntimeError(
"Cannot add counter to single-read counter acquisition device") "Cannot add counter to single-read counter acquisition device")
self.__grouped_read_counters_list.append(counter) self.__grouped_read_counters_list.append(counter)
self.__counter_names.append(counter.name)
self.channels.append(AcquisitionChannel( self.channels.append(AcquisitionChannel(
counter.name, numpy.double, (1,))) counter.name, numpy.double, (1,)))
def _emit_new_data(self, data): def _emit_new_data(self, data):
channel_data = dict([(name, data[i]) self.channels.update_from_iterable(data)
for i, name in enumerate(self.counter_names)])
dispatcher.send("new_data", self, {"channel_data": channel_data})
class SamplingCounterAcquisitionDevice(BaseCounterAcquisitionDevice): class SamplingCounterAcquisitionDevice(BaseCounterAcquisitionDevice):
...@@ -144,8 +135,7 @@ class SamplingCounterAcquisitionDevice(BaseCounterAcquisitionDevice): ...@@ -144,8 +135,7 @@ class SamplingCounterAcquisitionDevice(BaseCounterAcquisitionDevice):
nb_read = 0 nb_read = 0
acc_read_time = 0 acc_read_time = 0
acc_value = numpy.zeros( acc_value = numpy.zeros((len(self.channels),), dtype=numpy.double)
(len(self.counter_names),), dtype=numpy.double)
stop_time = trig_time + self.count_time or 0 stop_time = trig_time + self.count_time or 0
# Counter integration loop # Counter integration loop
while not self._stop_flag: while not self._stop_flag:
......
...@@ -110,8 +110,8 @@ class SoftwarePositionTriggerMaster(MotorMaster): ...@@ -110,8 +110,8 @@ class SoftwarePositionTriggerMaster(MotorMaster):
self.movable.stop(wait=False) self.movable.stop(wait=False)
self.exception = sys.exc_info() self.exception = sys.exc_info()
else: else:
dispatcher.send("new_data", self, self.channels[0].value = position
{"channel_data": {self.movable.name: numpy.double(position)}}) self.channels.update()
def move_done(self, done): def move_done(self, done):
if done: if done:
...@@ -247,9 +247,7 @@ class _StepTriggerMaster(AcquisitionMaster): ...@@ -247,9 +247,7 @@ class _StepTriggerMaster(AcquisitionMaster):
def trigger(self): def trigger(self):
self.trigger_slaves() self.trigger_slaves()
dispatcher.send("new_data", self, self.channels.update_from_iterable([axis.position() for axis in self._axes])
{"channel_data": dict((axis.name, numpy.double(axis.position()))
for axis in self._axes)})
self.wait_slaves() self.wait_slaves()
......
...@@ -95,9 +95,7 @@ class MusstAcquisitionDevice(AcquisitionDevice): ...@@ -95,9 +95,7 @@ class MusstAcquisitionDevice(AcquisitionDevice):
def _send_data(self, last_read_event): def _send_data(self, last_read_event):
data = self.musst.get_data(len(self.channels), last_read_event) data = self.musst.get_data(len(self.channels), last_read_event)
if data.size > 0: if data.size > 0:
channel_data = dict(zip((c.name for c in self.channels), [ self.channels.update_from_array(data)
data[:, i] for i in range(len(self.channels))]))
dispatcher.send("new_data", self, {"channel_data": channel_data})
nb_event_read = data.shape[0] nb_event_read = data.shape[0]
last_read_event += nb_event_read last_read_event += nb_event_read
return last_read_event return last_read_event
...@@ -49,8 +49,8 @@ class SoftwareTimerMaster(AcquisitionMaster): ...@@ -49,8 +49,8 @@ class SoftwareTimerMaster(AcquisitionMaster):
gevent.sleep(self.sleep_time) gevent.sleep(self.sleep_time)
start_trigger = time.time() start_trigger = time.time()
dispatcher.send("new_data", self, self.channels[0].value = start_trigger
{"channel_data": {'timestamp': numpy.double(time.time())}}) self.channels.update()
self.trigger_slaves() self.trigger_slaves()
elapsed_trigger = time.time() - start_trigger elapsed_trigger = time.time() - start_trigger
......
...@@ -19,6 +19,10 @@ class AcquisitionChannelList(list): ...@@ -19,6 +19,10 @@ class AcquisitionChannelList(list):
self.__parent = parent self.__parent = parent
def __emit_new_data(self):
dispatcher.send("new_data", self.__parent, {
"channel_data": dict(((c.name, c.value) for c in self))})
def update(self, values_dict=None): def update(self, values_dict=None):
"""Update all channels and emit the new_data event """Update all channels and emit the new_data event
...@@ -30,8 +34,19 @@ class AcquisitionChannelList(list): ...@@ -30,8 +34,19 @@ class AcquisitionChannelList(list):
for channel in self: for channel in self:
channel.value = values_dict[channel.name] channel.value = values_dict[channel.name]
dispatcher.send("new_data", self.__parent, { self.__emit_new_data()
"channel_data": dict([(c.name, c.value) for c in self])})
def update_from_iterable(self, iterable):
for i, channel in enumerate(self):
channel.value = iterable[i]
self.__emit_new_data()
def update_from_array(self, array):
for i, channel in enumerate(self):
channel.value = array[:, i]
self.__emit_new_data()
class AcquisitionChannel(object): class AcquisitionChannel(object):
......
...@@ -82,10 +82,12 @@ def test_default_chain_with_three_sampling_counters(beacon): ...@@ -82,10 +82,12 @@ def test_default_chain_with_three_sampling_counters(beacon):
assert nodes[2] != nodes[1] assert nodes[2] != nodes[1]
assert nodes[1].counter_names == ['diode'] counter_names = [c.name for c in nodes[1].channels]
assert counter_names == ['diode']
# counters order is not important # counters order is not important
# as we use **set** to eliminate duplicated counters # as we use **set** to eliminate duplicated counters
assert set(nodes[2].counter_names) == set(['diode2', 'diode3']) counter_names = set([c.name for c in nodes[2].channels])
assert counter_names == set(['diode2', 'diode3'])
def test_default_chain_with_bpm(beacon): def test_default_chain_with_bpm(beacon):
...@@ -122,7 +124,7 @@ def test_default_chain_with_bpm(beacon): ...@@ -122,7 +124,7 @@ def test_default_chain_with_bpm(beacon):
assert isinstance(nodes[1], LimaAcquisitionMaster) assert isinstance(nodes[1], LimaAcquisitionMaster)
assert isinstance(nodes[2], IntegratingCounterAcquisitionDevice) assert isinstance(nodes[2], IntegratingCounterAcquisitionDevice)
assert len(nodes[2].counter_names) == 3 assert len(nodes[2].channels) == 3
assert nodes[2].count_time == timer.count_time assert nodes[2].count_time == timer.count_time
assert nodes[1].save_flag == False assert nodes[1].save_flag == False
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment