Commit 8b953608 authored by Valentin Valls's avatar Valentin Valls
Browse files

Feed scan_info with fill_meta_at_scan_start

parent 921efa5f
......@@ -1416,16 +1416,16 @@ class Scan:
Method name can be either 'fill_meta_as_scan_start' or 'fill_meta_at_scan_end'
for dev in self.acq_chain.nodes_list:
node = self.nodes.get(dev)
if node is None:
# prepare has not finished ?
for acq_obj in self.acq_chain.nodes_list:
with KillMask(masked_kill_nb=1):
meth = getattr(dev, method_name)
tmp = meth(self.user_scan_meta)
if tmp:
update_node_info(node, tmp)
fill_meta = getattr(acq_obj, method_name)
metadata = fill_meta(self.user_scan_meta)
if metadata is not None:
node = self.nodes.get(acq_obj)
if node is not None:
update_node_info(node, metadata)
if method_name == "fill_meta_at_scan_start":
self._scan_info._set_device_meta(acq_obj, metadata)
def run(self):
"""Run the scan
......@@ -263,6 +263,24 @@ class ScanInfo(dict):
info = self._scan_info.setdefault("sequence-info", {})
info["scan-count"] = int(scan_count)
def _get_key_from_acq_obj(self, acq_obj):
"""Used device key from an acq_obj"""
return f"{str(id(acq_obj))}:{}"
def _set_device_meta(self, acq_obj, metadata: typing.Dict):
"""Protected function called by the scan to feed the device info after
the device preparation.
acq_obj: A device though its acquisition object
metadata: A dictionary of basic python types.
Few reserved keys could be ignored.
devices = self.setdefault("devices", {})
name = self._get_key_from_acq_obj(acq_obj)
device = devices.setdefault(name, {})
def _get_channels_dict(self, acq_object, channels_dict):
scalars = channels_dict.setdefault("scalars", [])
spectra = channels_dict.setdefault("spectra", [])
......@@ -17,6 +17,7 @@ from bliss.scanning.acquisition.counter import SamplingCounterAcquisitionSlave
from bliss.scanning.acquisition.mca import McaAcquisitionSlave
from bliss.scanning.acquisition.motor import LinearStepTriggerMaster
from bliss.scanning.scan import Scan
from bliss.scanning.scan_info import ScanInfo
from import watch_session_scans, ScansObserver, ScansWatcher
from bliss.scanning.chain import AcquisitionChain
from bliss.common import scans
......@@ -460,6 +461,10 @@ def test_scan_observer(session, diode_acq_device_factory, mocker):
master = SoftwareTimerMaster(0.1, npoints=1)
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)
......@@ -470,11 +475,20 @@ def test_scan_observer(session, diode_acq_device_factory, mocker):
# Check that the scan_info looks like what it is expected
sf = ScanInfo()
device_key = sf._get_key_from_acq_obj(acquisition_device_1)
call = observer.on_scan_created.call_args_list[0]
scan_info = call[0][1]
assert "positioners_start" in scan_info["positioners"]
assert "start_timestamp" in scan_info
call = observer.on_scan_started.call_args_list[0]
scan_info = call[0][1]
assert "kind" in scan_info["devices"][device_key]
call = observer.on_scan_finished.call_args_list[0]
scan_info = call[0][1]
assert "end_timestamp" in scan_info
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