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):
self.__count_time = count_time
self.__grouped_read_counters_list = list()
self.__counter_names = list()
self._nb_acq_points = 0
if not isinstance(counter, GroupedReadMixin):
self.channels.append(AcquisitionChannel(
counter.name, numpy.double, (1,)))
self.__counter_names.append(counter.name)
@property
def count_time(self):
......@@ -45,24 +43,17 @@ class BaseCounterAcquisitionDevice(AcquisitionDevice):
def grouped_read_counters(self):
return self.__grouped_read_counters_list
@property
def counter_names(self):
return self.__counter_names
def add_counter(self, counter):
if not isinstance(self.device, GroupedReadMixin):
raise RuntimeError(
"Cannot add counter to single-read counter acquisition device")
self.__grouped_read_counters_list.append(counter)
self.__counter_names.append(counter.name)
self.channels.append(AcquisitionChannel(
counter.name, numpy.double, (1,)))
def _emit_new_data(self, data):
channel_data = dict([(name, data[i])
for i, name in enumerate(self.counter_names)])
dispatcher.send("new_data", self, {"channel_data": channel_data})
self.channels.update_from_iterable(data)
class SamplingCounterAcquisitionDevice(BaseCounterAcquisitionDevice):
......@@ -144,8 +135,7 @@ class SamplingCounterAcquisitionDevice(BaseCounterAcquisitionDevice):
nb_read = 0
acc_read_time = 0
acc_value = numpy.zeros(
(len(self.counter_names),), dtype=numpy.double)
acc_value = numpy.zeros((len(self.channels),), dtype=numpy.double)
stop_time = trig_time + self.count_time or 0
# Counter integration loop
while not self._stop_flag:
......
......@@ -110,8 +110,8 @@ class SoftwarePositionTriggerMaster(MotorMaster):
self.movable.stop(wait=False)
self.exception = sys.exc_info()
else:
dispatcher.send("new_data", self,
{"channel_data": {self.movable.name: numpy.double(position)}})
self.channels[0].value = position
self.channels.update()
def move_done(self, done):
if done:
......@@ -247,9 +247,7 @@ class _StepTriggerMaster(AcquisitionMaster):
def trigger(self):
self.trigger_slaves()
dispatcher.send("new_data", self,
{"channel_data": dict((axis.name, numpy.double(axis.position()))
for axis in self._axes)})
self.channels.update_from_iterable([axis.position() for axis in self._axes])
self.wait_slaves()
......
......@@ -95,9 +95,7 @@ class MusstAcquisitionDevice(AcquisitionDevice):
def _send_data(self, last_read_event):
data = self.musst.get_data(len(self.channels), last_read_event)
if data.size > 0:
channel_data = dict(zip((c.name for c in self.channels), [
data[:, i] for i in range(len(self.channels))]))
dispatcher.send("new_data", self, {"channel_data": channel_data})
self.channels.update_from_array(data)
nb_event_read = data.shape[0]
last_read_event += nb_event_read
return last_read_event
......@@ -49,8 +49,8 @@ class SoftwareTimerMaster(AcquisitionMaster):
gevent.sleep(self.sleep_time)
start_trigger = time.time()
dispatcher.send("new_data", self,
{"channel_data": {'timestamp': numpy.double(time.time())}})
self.channels[0].value = start_trigger
self.channels.update()
self.trigger_slaves()
elapsed_trigger = time.time() - start_trigger
......
......@@ -19,6 +19,10 @@ class AcquisitionChannelList(list):
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):
"""Update all channels and emit the new_data event
......@@ -30,8 +34,19 @@ class AcquisitionChannelList(list):
for channel in self:
channel.value = values_dict[channel.name]
dispatcher.send("new_data", self.__parent, {
"channel_data": dict([(c.name, c.value) for c in self])})
self.__emit_new_data()
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):
......
......@@ -82,10 +82,12 @@ def test_default_chain_with_three_sampling_counters(beacon):
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
# 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):
......@@ -122,7 +124,7 @@ def test_default_chain_with_bpm(beacon):
assert isinstance(nodes[1], LimaAcquisitionMaster)
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[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