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

Counter: use the HasMetadataForScan protocol to make it uniform with other...

Counter: use the HasMetadataForScan protocol to make it uniform with other metadata generating classes
parent 8598bcc3
......@@ -15,6 +15,7 @@ import inspect
import numpy
from bliss.common.utils import autocomplete_property
from bliss.common.protocols import HasMetadataForScan
def add_conversion_function(obj, method_name, function):
......@@ -58,7 +59,7 @@ def _identity(val):
return val
class Counter:
class Counter(HasMetadataForScan):
""" Counter class """
def __init__(self, name, controller, conversion_function=None, unit=None):
......@@ -122,8 +123,8 @@ class Counter:
assert callable(func)
self._conversion_function = func
def get_metadata(self):
return {}
def scan_metadata(self):
return None
def __info__(self, counter_type=None):
info_str = f"'{self.name}` counter info:\n"
......
......@@ -37,6 +37,8 @@ from bliss.common.image_tools import (
test_image,
)
from bliss.common.protocols import HasMetadataForScan
# CHAIN OBJECT NOTES:
#
......@@ -397,9 +399,14 @@ class FakeAcquisitionSlave(AcquisitionSlave):
# self.channels.update({self.chname: self.positions})
def fill_meta_at_scan_start(self, scan_meta):
tmp_dict = {}
tmp_dict = super().fill_meta_at_scan_start(scan_meta)
for cnt in self._counters:
deep_update(tmp_dict, cnt.get_metadata())
if isinstance(cnt, HasMetadataForScan):
mdata = cnt.scan_metadata()
if mdata is not None:
if tmp_dict is None:
tmp_dict = dict()
deep_update(tmp_dict, mdata)
return tmp_dict
def prepare(self):
......
......@@ -421,7 +421,7 @@ class RoiStatCounter(IntegratingCounter):
name = f"{self.roi_name}_{stat.name.lower()}"
super().__init__(name, kwargs.pop("controller"), **kwargs)
def get_metadata(self):
def scan_metadata(self):
return {self.roi_name: self._counter_controller.get(self.roi_name).to_dict()}
def __int__(self):
......@@ -480,7 +480,7 @@ class RoiProfileCounter(IntegratingCounter):
self.roi_name = roi_name
super().__init__(roi_name, controller, conversion_function, unit)
def get_metadata(self):
def scan_metadata(self):
return {self.roi_name: self._counter_controller.get(self.roi_name).to_dict()}
@property
......@@ -508,7 +508,7 @@ class RoiCollectionCounter(IntegratingCounter):
def __init__(self, name, controller):
super().__init__(name, controller)
def get_metadata(self):
def scan_metadata(self):
params = [roi.get_params() for roi in self._counter_controller.get_rois()]
xs, ys, ws, hs = zip(*params)
meta = {"kind": "collection", "x": xs, "y": ys, "width": ws, "height": hs}
......
......@@ -18,10 +18,10 @@ from bliss.common.logtools import user_print
from bliss.common import timedisplay
from bliss.controllers.counter import counter_namespace
from bliss.scanning.scan_meta import NonScannableHasMetadataForScan
from bliss.scanning.chain import ChainPreset, ChainIterationPreset
from bliss.common import tango
from bliss.common.protocols import HasMetadataForDataset
from bliss.scanning.scan_meta import NonScannableHasMetadataForScan
from bliss.controllers.tango_attr_as_counter import (
TangoCounterController,
TangoAttrCounter,
......
......@@ -17,6 +17,7 @@ from bliss.common.utils import all_equal, deep_update
from bliss.scanning.chain import AcquisitionSlave, AcquisitionObject
from bliss.scanning.channel import AcquisitionChannel
from bliss.common.counter import SamplingMode
from bliss.common.protocols import HasMetadataForScan
class BaseCounterAcquisitionSlave(AcquisitionSlave):
......@@ -68,15 +69,14 @@ class BaseCounterAcquisitionSlave(AcquisitionSlave):
self.channels.update_from_iterable(data)
def fill_meta_at_scan_start(self, scan_meta):
tmp_dict = super(BaseCounterAcquisitionSlave, self).fill_meta_at_scan_start(
scan_meta
)
if tmp_dict is None:
tmp_dict = {}
tmp_dict = super().fill_meta_at_scan_start(scan_meta)
for cnt in self._counters:
deep_update(tmp_dict, cnt.get_metadata())
if isinstance(cnt, HasMetadataForScan):
mdata = cnt.scan_metadata()
if mdata is not None:
if tmp_dict is None:
tmp_dict = dict()
deep_update(tmp_dict, mdata)
return tmp_dict
def prepare_device(self):
......
......@@ -460,7 +460,12 @@ class LimaAcquisitionMaster(AcquisitionMaster):
return self._reading_task.get()
def fill_meta_at_scan_end(self, scan_meta):
return {"acq_parameters": self.acq_params, "ctrl_parameters": self.ctrl_params}
tmp_dict = super().fill_meta_at_scan_end(scan_meta)
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
class RoiCountersAcquisitionSlave(IntegratingCounterAcquisitionSlave):
......
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