FilteredTopicWrapper¶
- class lsst.ts.watcher.FilteredTopicWrapper(model, topic, filter_field)¶
Bases:
object
Topic wrapper that caches data by the value of a filter field.
To make a topic wrapper call
Model.make_filtered_topic_wrapper
, instead of constructing aTopicWrapper
directly. That allows using a cached instance, if available (and avoids aRuntimeError
in the constructor, if an instance exists).- Parameters:
- model
Model
Watcher model. Used to add a TopicCallback to the topic, if one does not already exist.
- topic
lsst.ts.salobj.ReadTopic
Topic to read.
- filter_field
str
Field to filter on. The field must be a scalar. It should also have a smallish number of expected values, in order to avoid caching too much data.
- model
- Raises:
- ValueError
If filter_field does not exist in the data, or if it exists but is an array.
- RuntimeError
If this
FilteredTopicWrapper
already exists in the model. To avoid this, construct field wrappers by callingModel.make_filtered_field_wrapper
.
Notes
A rule will typically use filtered _field_ wrappers (subclasses of
BaseFilteredFieldWrapper
) rather thanFilteredTopicWrapper
.Filtered field wrappers are high-level objects that store data for a particular value of filter_field (e.g. a particular subsystem).
FilteredTopicWrapper
is lower level object that stores data for all values offilter_field
(e.g. all subsystems).Each
BaseFilteredFieldWrapper
contains aFilteredTopicWrapper
.- Attributes:
- topic
lsst.ts.salobj.ReadTopic
topic
constructor argument.- filter_field
str
filter_field
constructor argument.- descr
str
A short description of the wrapper.
- data_cache
str
Dict of value of filter_field: most recent data seen for that value.
- default_data
Default-constructed data. Use for validation of field wrappers.
- call_event
asyncio.Event
An event that
__call__
sets when it finishes. This is intended for use by unit tests.
- topic
Methods Summary
__call__
(data, topic_callback)Update the cached data.
add_field_wrapper
(field_wrapper)Add a filtered field wrapper to the internal cache.
get_data
(filter_value)Get the most recently seen data for the given filter_value, or None if no data seen.
Methods Documentation
- __call__(data, topic_callback)¶
Update the cached data.
Set data_cache[filter_value] to the new data, and call update_value for each filtered field wrapper with the matching filter value.
- Parameters:
- data
lsst.ts.salobj.BaseMsgType
Topic data.
- topic_callback
TopicCallback
The topic callback that triggered this call.
- data
- add_field_wrapper(field_wrapper)¶
Add a filtered field wrapper to the internal cache.
- Parameters:
- field_wrapper
BaseFilteredFieldWrapper
The filtered field wrapper to add.
- field_wrapper
- get_data(filter_value)¶
Get the most recently seen data for the given filter_value, or None if no data seen.
- Parameters:
- filter_valuescalar
Value of
filter_field
for which to return data.