Commit faf6f2f7 authored by Wout De Nolf's avatar Wout De Nolf
Browse files

Replace all AcquisitioObject.fill_meta_at_scan* methods with single...

Replace all AcquisitioObject.fill_meta_at_scan* methods with single AcquisitioObject.get_acquisition_metadata(timing=None)
parent 41c21e07
Pipeline #47482 passed with stages
in 97 minutes and 12 seconds
......@@ -122,14 +122,8 @@ class _Base:
def wait_ready(self):
return self.device.wait_ready()
def fill_meta_at_scan_start(self):
return self.device.fill_meta_at_scan_start()
def fill_meta_at_scan_prepared(self):
return self.device.fill_meta_at_scan_prepared()
def fill_meta_at_scan_end(self):
return self.device.fill_meta_at_scan_end()
def get_acquisition_metadata(self, *args, **kw):
return self.device.get_acquisition_metadata(*args, **kw)
def _all_point_rx(self):
"""
......
......@@ -398,8 +398,10 @@ class FakeAcquisitionSlave(AcquisitionSlave):
# self.channels.update_from_array(data)
# self.channels.update({self.chname: self.positions})
def fill_meta_at_scan_prepared(self):
tmp_dict = super().fill_meta_at_scan_prepared()
def get_acquisition_metadata(self, timing=None):
tmp_dict = super().get_acquisition_metadata(timing=timing)
if timing != self.META_TIMING.PREPARED:
return tmp_dict
for cnt in self._counters:
if isinstance(cnt, HasMetadataForScan):
mdata = cnt.scan_metadata()
......
......@@ -68,8 +68,10 @@ class BaseCounterAcquisitionSlave(AcquisitionSlave):
def _emit_new_data(self, data):
self.channels.update_from_iterable(data)
def fill_meta_at_scan_prepared(self):
tmp_dict = super().fill_meta_at_scan_prepared()
def get_acquisition_metadata(self, timing=None):
tmp_dict = super().get_acquisition_metadata(timing=timing)
if timing != self.META_TIMING.PREPARED:
return tmp_dict
for cnt in self._counters:
if isinstance(cnt, HasMetadataForScan):
mdata = cnt.scan_metadata()
......
......@@ -459,12 +459,13 @@ class LimaAcquisitionMaster(AcquisitionMaster):
return True
return self._reading_task.get()
def fill_meta_at_scan_end(self):
tmp_dict = super().fill_meta_at_scan_end()
if tmp_dict is None:
tmp_dict = dict()
tmp_dict["acq_parameters"] = self.acq_params
tmp_dict["ctrl_parameters"] = self.ctrl_params
def get_acquisition_metadata(self, timing=None):
tmp_dict = super().get_acquisition_metadata(timing=timing)
if timing == self.META_TIMING.END:
if tmp_dict is None:
tmp_dict = dict()
tmp_dict["acq_parameters"] = self.acq_params
tmp_dict["ctrl_parameters"] = self.ctrl_params
return tmp_dict
......
......@@ -23,6 +23,7 @@ from bliss.common.greenlet_utils import KillMask
from bliss.scanning.channel import AcquisitionChannelList, AcquisitionChannel
from bliss.scanning.channel import duplicate_channel, attach_channels
from bliss.common.validator import BlissValidator
from bliss.scanning.scan_meta import META_TIMING
TRIGGER_MODE_ENUM = enum.IntEnum("TriggerMode", "HARDWARE SOFTWARE")
......@@ -459,37 +460,17 @@ class AcquisitionObject:
if isinstance(self.device, CounterController):
self.device.apply_parameters(self._ctrl_params)
def fill_meta_at_scan_start(self):
"""
In this method, acquisition device should collect any meta data
related to this device. It is called after scan start.
The return value of this function is used to fill the meta data of the
node attached to this AcqObj
"""
return None
def fill_meta_at_scan_prepared(self):
"""
In this method, acquisition device should collect any meta data
related to this device. It is called after all devices are prepared.
META_TIMING = META_TIMING
The return value of this function is used to fill the meta data of the
node attached to this AcqObj
def get_acquisition_metadata(self, timing=None):
"""
device = self.device
if isinstance(device, HasMetadataForScan):
return device.scan_metadata()
return None
def fill_meta_at_scan_end(self):
"""
In this method, acquisition device should collect and meta data
related to this device. It is called at the end of the scan.
The return value of this function is used to fill the meta data of the
node attached to this AcqObj
In this method, acquisition device should collect time-dependent
any meta data related to this device.
"""
if timing == META_TIMING.PREPARED:
device = self.device
if isinstance(device, HasMetadataForScan):
return device.scan_metadata()
return None
# --------------------------- OVERLOAD METHODS ---------------------------------------------
......
......@@ -1435,15 +1435,15 @@ class Scan:
if len(display_extra) > 0:
self._scan_info["_display_extra"] = display_extra
def _metadata_of_user(self, meta_timing):
def _metadata_of_user(self, timing):
"""Update scan_info with user scan metadata. The metadata will be
stored in the user metadata categories.
"""
if not self._enable_scanmeta:
return
self._evaluate_scan_meta(self._user_scan_meta, meta_timing)
self._evaluate_scan_meta(self._user_scan_meta, timing)
def _metadata_of_nonacq_controllers(self, meta_timing):
def _metadata_of_nonacq_controllers(self, timing):
"""Update scan_info with controller scan metadata. The metadata
will be stored in the "instrument" metadata category under the
"scan_metadata_name" which is the controller name by default
......@@ -1451,9 +1451,9 @@ class Scan:
"""
if not self._enable_scanmeta:
return
self._evaluate_scan_meta(self._controllers_scan_meta, meta_timing)
self._evaluate_scan_meta(self._controllers_scan_meta, timing)
def _metadata_of_acq_controllers(self, meta_timing):
def _metadata_of_acq_controllers(self, timing):
"""Update the controller Redis nodes with metadata. Update
the "devices" section of scan_info. Note that the "instrument"
metadata category or any other metadata category is not modified.
......@@ -1462,14 +1462,6 @@ class Scan:
# metadata of the acquistion controllers.
# not self._enable_scanmeta:
# return
if meta_timing == META_TIMING.START:
method_name = "fill_meta_at_scan_start"
elif meta_timing == META_TIMING.PREPARED:
method_name = "fill_meta_at_scan_prepared"
elif meta_timing == META_TIMING.END:
method_name = "fill_meta_at_scan_end"
else:
return
if self._controllers_scan_meta:
instrument = self._controllers_scan_meta.instrument
......@@ -1488,8 +1480,7 @@ class Scan:
# An empty dict shows up as a group in the Nexus file
# while None does not.
with KillMask(masked_kill_nb=1):
fill_meta = getattr(acq_obj, method_name)
metadata = fill_meta()
metadata = acq_obj.get_acquisition_metadata(timing=timing)
if metadata is None:
continue
......@@ -1500,16 +1491,16 @@ class Scan:
# Add to the local scan_info, but in a different
# place than where _controllers_scan_meta would put it
if meta_timing in (META_TIMING.START, META_TIMING.PREPARED):
if timing in (META_TIMING.START, META_TIMING.PREPARED):
self._scan_info._set_device_meta(acq_obj, metadata)
def _evaluate_scan_meta(self, scan_meta, meta_timing):
def _evaluate_scan_meta(self, scan_meta, timing):
"""Evaluate the metadata generators of a ScanMeta instance
and update scan_info.
"""
assert isinstance(scan_meta, ScanMeta)
with KillMask(masked_kill_nb=1):
metadata = scan_meta.to_dict(self, timing=meta_timing)
metadata = scan_meta.to_dict(self, timing=timing)
if not metadata:
return
deep_update(self._scan_info, metadata)
......
......@@ -318,8 +318,13 @@ def test_scan_observer(
chain.add(master, acquisition_device_1)
scan = Scan(chain, "test", save=False)
meta = {"kind": "foo"}
acquisition_device_1.fill_meta_at_scan_start = mocker.Mock(return_value=meta)
def side_effect(timing):
if timing == acquisition_device_1.META_TIMING.PREPARED:
return {"kind": "foo"}
else:
return None
acquisition_device_1.get_acquisition_metadata = mocker.Mock(side_effect=side_effect)
with watching(session, test_observer):
scan.run()
......
......@@ -489,7 +489,11 @@ def test_sequence(test_session_with_flint, lima_simulator):
def create_1d_controller(device_name, fixed_xarray=False, fixed_xchannel=False):
class OneDimAcquisitionSlave(SamplingCounterAcquisitionSlave):
def fill_meta_at_scan_prepared(self):
def get_acquisition_metadata(self, timing=None):
tmp_dict = super().get_acquisition_metadata(timing=timing)
if timing != self.META_TIMING.PREPARED:
return tmp_dict
def get_channel_by_counter_name(name):
for counter, channels in self._counters.items():
if counter.name == name:
......
......@@ -544,7 +544,9 @@ def test_children_timing(beacon, session):
g.kill()
def test_scan_end_timing(session, scan_meta, dummy_acq_master, dummy_acq_device):
def test_scan_end_timing(
session, scan_meta, dummy_acq_master, dummy_acq_device, mocker
):
scan_meta.clear()
# Get controllers
......@@ -552,13 +554,17 @@ def test_scan_end_timing(session, scan_meta, dummy_acq_master, dummy_acq_device)
master = dummy_acq_master.get(None, name="master", npoints=1)
device = dummy_acq_device.get(None, name="device", npoints=1)
def fill_meta_at_scan_end():
# this sleep is the point of the test...
# delay the filling of scan_info
gevent.sleep(.2)
return {"state": "slow"}
def side_effect(timing):
if timing == device.META_TIMING.END:
# this sleep is the point of the test...
# delay the filling of scan_info
gevent.sleep(.2)
return {"state": "slow"}
else:
return None
device.get_acquisition_metadata = mocker.Mock(side_effect=side_effect)
device.fill_meta_at_scan_end = fill_meta_at_scan_end
chain.add(master, device)
scan = Scan(chain, "test", save=False, scan_info={"instrument": {"some": "text"}})
......
......@@ -87,8 +87,9 @@ def test_scan_meta_master_and_device(session, scan_meta):
def __init__(self):
super().__init__(name="my_master")
def fill_meta_at_scan_prepared(self):
return master_dict
def get_acquisition_metadata(self, timing=None):
if timing == self.META_TIMING.PREPARED:
return master_dict
def prepare(self):
pass
......@@ -115,8 +116,9 @@ def test_scan_meta_master_and_device(session, scan_meta):
def __init__(self):
super().__init__(name=device_name)
def fill_meta_at_scan_prepared(self):
return device_dict
def get_acquisition_metadata(self, timing=None):
if timing == self.META_TIMING.PREPARED:
return device_dict
def prepare(self):
pass
......
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