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