Skip to content

Commit 403db19

Browse files
Merge pull request #589 from scipp/add-log-stream-mapping
Add log stream name mapping support
2 parents 3ef369b + 158f421 commit 403db19

File tree

8 files changed

+578
-27
lines changed

8 files changed

+578
-27
lines changed

src/ess/livedata/config/instruments/_ess.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,12 @@ def _make_dev_area_detectors(
4040
}
4141

4242

43+
def _make_dev_logs(*, instrument: str, log_names: list[str]) -> StreamLUT:
44+
"""Create log stream mapping for dev mode where source_name equals internal name."""
45+
topic = f'{instrument}_motion'
46+
return {InputStreamKey(topic=topic, source_name=name): name for name in log_names}
47+
48+
4349
def _make_dev_beam_monitors(
4450
instrument: str, monitor_names: list[str] | None = None
4551
) -> StreamLUT:
@@ -80,22 +86,26 @@ def make_dev_stream_mapping(
8086
detector_names: list[str],
8187
area_detector_names: list[str] | None = None,
8288
monitor_names: list[str] | None = None,
89+
log_names: list[str] | None = None,
8390
) -> StreamMapping:
84-
motion_topic = f'{instrument}_motion'
85-
log_topics = {motion_topic}
8691
area_detectors = (
8792
_make_dev_area_detectors(
8893
instrument=instrument, area_detectors=area_detector_names
8994
)
9095
if area_detector_names
9196
else {}
9297
)
98+
logs = (
99+
_make_dev_logs(instrument=instrument, log_names=log_names)
100+
if log_names
101+
else None
102+
)
93103
return StreamMapping(
94104
instrument=instrument,
95105
detectors=_make_dev_detectors(instrument=instrument, detectors=detector_names),
96106
monitors=_make_dev_beam_monitors(instrument, monitor_names=monitor_names),
97107
area_detectors=area_detectors,
98-
log_topics=log_topics,
108+
logs=logs,
99109
**_make_livedata_topics(instrument),
100110
)
101111

@@ -106,6 +116,5 @@ def make_common_stream_mapping_inputs(
106116
return {
107117
'instrument': instrument,
108118
'monitors': _make_cbm_monitors(instrument, monitor_names=monitor_names),
109-
'log_topics': None,
110119
**_make_livedata_topics(instrument),
111120
}

src/ess/livedata/config/instruments/bifrost/specs.py

Lines changed: 130 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -230,11 +230,137 @@ class QMapOutputs(WorkflowOutputsBase):
230230
'bragg_peak_monitor',
231231
]
232232

233-
# Some example motions used for testing, probably not reflecting reality
233+
# Combined f144 log stream configuration.
234+
# Maps internal name -> {source: Kafka source name, units: unit string, topic: topic}
235+
# Generated using: python -m ess.livedata.nexus_helpers <file> --generate --topic <t>
236+
f144_log_streams: dict[str, dict[str, str]] = {
237+
# Motion streams (topic: bifrost_motion)
238+
'attenuator_1': {
239+
'source': 'BIFRO-AttChg:MC-Pne-01:ShtAuxBits07',
240+
'units': 'dimensionless',
241+
'topic': 'bifrost_motion',
242+
},
243+
'attenuator_2': {
244+
'source': 'BIFRO-AttChg:MC-Pne-02:ShtAuxBits07',
245+
'units': 'dimensionless',
246+
'topic': 'bifrost_motion',
247+
},
248+
'attenuator_3': {
249+
'source': 'BIFRO-AttChg:MC-Pne-03:ShtAuxBits07',
250+
'units': 'dimensionless',
251+
'topic': 'bifrost_motion',
252+
},
253+
'detector_rotation': {
254+
'source': 'BIFRO-DtCar:MC-RotZ-01:Mtr.RBV',
255+
'units': 'deg',
256+
'topic': 'bifrost_motion',
257+
},
258+
'get_lost_tube': {
259+
'source': 'BIFRO-InBm:MC-Pne-01:ShtAuxBits07',
260+
'units': 'dimensionless',
261+
'topic': 'bifrost_motion',
262+
},
263+
'goniometer_x': {
264+
'source': 'BIFRO-SpGon:MC-RotX-01:Mtr.RBV',
265+
'units': 'deg',
266+
'topic': 'bifrost_motion',
267+
},
268+
'goniometer_y': {
269+
'source': 'BIFRO-SpGon:MC-RotY-01:Mtr.RBV',
270+
'units': 'deg',
271+
'topic': 'bifrost_motion',
272+
},
273+
'sample_rotation': {
274+
'source': 'BIFRO-SpRot:MC-RotZ-01:Mtr.RBV',
275+
'units': 'deg',
276+
'topic': 'bifrost_motion',
277+
},
278+
'slit_bottom': {
279+
'source': 'BIFRO-SpSl1:MC-SlZm-01:PzMtr.RBV',
280+
'units': 'mm',
281+
'topic': 'bifrost_motion',
282+
},
283+
'slit_left': {
284+
'source': 'BIFRO-SpSl1:MC-SlYp-01:PzMtr.RBV',
285+
'units': 'mm',
286+
'topic': 'bifrost_motion',
287+
},
288+
'slit_right': {
289+
'source': 'BIFRO-SpSl1:MC-SlYm-01:PzMtr.RBV',
290+
'units': 'mm',
291+
'topic': 'bifrost_motion',
292+
},
293+
'slit_top': {
294+
'source': 'BIFRO-SpSl1:MC-SlZp-01:PzMtr.RBV',
295+
'units': 'mm',
296+
'topic': 'bifrost_motion',
297+
},
298+
'slit_position': {
299+
'source': 'BIFRO-SpSl1:MC-LinX-01:PzMtr-PosReadback',
300+
'units': 'mm',
301+
'topic': 'bifrost_motion',
302+
},
303+
# Sample environment streams (topic: bifrost_sample_env)
304+
'heater_1': {
305+
'source': 'YMIR-SEE:SE-LS336-004:HTR1',
306+
'units': 'W',
307+
'topic': 'bifrost_sample_env',
308+
},
309+
'heater_2': {
310+
'source': 'YMIR-SEE:SE-LS336-004:HTR2',
311+
'units': 'W',
312+
'topic': 'bifrost_sample_env',
313+
},
314+
'temperature_0': {
315+
'source': 'YMIR-SEE:SE-LS336-004:KRDG0',
316+
'units': 'K',
317+
'topic': 'bifrost_sample_env',
318+
},
319+
'temperature_1': {
320+
'source': 'YMIR-SEE:SE-LS336-004:KRDG1',
321+
'units': 'K',
322+
'topic': 'bifrost_sample_env',
323+
},
324+
'temperature_2': {
325+
'source': 'YMIR-SEE:SE-LS336-004:KRDG2',
326+
'units': 'K',
327+
'topic': 'bifrost_sample_env',
328+
},
329+
'temperature_3': {
330+
'source': 'YMIR-SEE:SE-LS336-004:KRDG3',
331+
'units': 'K',
332+
'topic': 'bifrost_sample_env',
333+
},
334+
'temperature_setpoint': {
335+
'source': 'YMIR-SEE:SE-LS336-004:SETP_S1',
336+
'units': 'K',
337+
'topic': 'bifrost_sample_env',
338+
},
339+
'sensor_0': {
340+
'source': 'YMIR-SEE:SE-LS336-004:SRDG0',
341+
'units': 'V',
342+
'topic': 'bifrost_sample_env',
343+
},
344+
'sensor_1': {
345+
'source': 'YMIR-SEE:SE-LS336-004:SRDG1',
346+
'units': 'V',
347+
'topic': 'bifrost_sample_env',
348+
},
349+
'sensor_2': {
350+
'source': 'YMIR-SEE:SE-LS336-004:SRDG2',
351+
'units': 'V',
352+
'topic': 'bifrost_sample_env',
353+
},
354+
'sensor_3': {
355+
'source': 'YMIR-SEE:SE-LS336-004:SRDG3',
356+
'units': 'V',
357+
'topic': 'bifrost_sample_env',
358+
},
359+
}
360+
361+
# Derived from f144_log_streams for use by the Instrument
234362
f144_attribute_registry = {
235-
'detector_rotation': {'units': 'deg'},
236-
'sample_rotation': {'units': 'deg'},
237-
'sample_temperature': {'units': 'K'},
363+
name: {'units': info['units']} for name, info in f144_log_streams.items()
238364
}
239365

240366
# Create instrument

src/ess/livedata/config/instruments/bifrost/streams.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
from ess.livedata.kafka import InputStreamKey, StreamLUT, StreamMapping
1313

1414
from .._ess import make_common_stream_mapping_inputs, make_dev_stream_mapping
15-
from .specs import monitors
15+
from .specs import f144_log_streams, monitors
1616

1717

1818
def _bifrost_generator() -> Generator[tuple[str, tuple[int, int]]]:
@@ -61,16 +61,31 @@ def _make_bifrost_detectors() -> StreamLUT:
6161
}
6262

6363

64+
def _make_bifrost_logs() -> StreamLUT:
65+
"""
66+
Bifrost log data mapping.
67+
68+
Derives StreamLUT from f144_log_streams, mapping Kafka source names
69+
(EPICS PV names) to ESSlivedata-internal stream names.
70+
"""
71+
return {
72+
InputStreamKey(topic=info['topic'], source_name=info['source']): internal_name
73+
for internal_name, info in f144_log_streams.items()
74+
}
75+
76+
6477
stream_mapping = {
6578
StreamingEnv.DEV: make_dev_stream_mapping(
6679
'bifrost',
6780
detector_names=list(detector_fakes),
6881
monitor_names=monitors,
82+
log_names=list(f144_log_streams.keys()),
6983
),
7084
StreamingEnv.PROD: StreamMapping(
7185
**make_common_stream_mapping_inputs(
7286
instrument='bifrost', monitor_names=monitors
7387
),
7488
detectors=_make_bifrost_detectors(),
89+
logs=_make_bifrost_logs(),
7590
),
7691
}

src/ess/livedata/config/instruments/dummy/streams.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from ess.livedata.kafka import InputStreamKey, StreamLUT, StreamMapping
77

88
from .._ess import make_common_stream_mapping_inputs, make_dev_stream_mapping
9+
from .specs import instrument
910

1011
detector_fakes = {'panel_0': (1, 128**2)}
1112

@@ -34,6 +35,7 @@ def _make_dummy_area_detectors() -> StreamLUT:
3435
'dummy',
3536
detector_names=list(detector_fakes),
3637
area_detector_names=list(area_detector_fakes),
38+
log_names=list(instrument.f144_attribute_registry.keys()),
3739
),
3840
StreamingEnv.PROD: StreamMapping(
3941
**make_common_stream_mapping_inputs(instrument='dummy'),

src/ess/livedata/kafka/stream_mapping.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ def __init__(
3232
detectors: StreamLUT,
3333
monitors: StreamLUT,
3434
area_detectors: StreamLUT | None = None,
35-
log_topics: set[KafkaTopic] | None = None,
35+
logs: StreamLUT | None = None,
3636
livedata_commands_topic: str,
3737
livedata_data_topic: str,
3838
livedata_responses_topic: str,
@@ -43,9 +43,7 @@ def __init__(
4343
self._detectors = detectors
4444
self._monitors = monitors
4545
self._area_detectors = area_detectors or {}
46-
# Currently we simply reuse the source_name as the stream name
47-
self._logs = None
48-
self._log_topics = log_topics or set()
46+
self._logs = logs
4947
self._livedata_commands_topic = livedata_commands_topic
5048
self._livedata_data_topic = livedata_data_topic
5149
self._livedata_responses_topic = livedata_responses_topic
@@ -94,8 +92,10 @@ def monitor_topics(self) -> set[KafkaTopic]:
9492

9593
@property
9694
def log_topics(self) -> set[KafkaTopic]:
97-
"""Returns the list of log topics."""
98-
return self._log_topics
95+
"""Returns the set of log topics."""
96+
if self._logs is None:
97+
return set()
98+
return {stream.topic for stream in self._logs.keys()}
9999

100100
@property
101101
def detectors(self) -> StreamLUT:

0 commit comments

Comments
 (0)