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
make_filtered_topic_wrapper
, instead of constructing aTopicWrapper
directly.- 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.
Notes
Use FilteredTopicWrapper to monitor a topic for a SAL component that writes the same topic for more than one subsystem.
For example an ESS CSC may write the same topic for several different sensors, each identified by a different value of the sensorName field. To read an ESS topic: create a FilteredFieldWrapper with filter_field=”sensorName”.
To use FilteredTopicWrapper in a watcher rule:
In the rule’s constructor: figure out which topics need such wrappers. Use this to create the
RemoteInfo
s. Be sure to list each wrapped topic using thewrapper_names
orcallback_names
constructor argument ofRemoteInfo
.You cannot create the topic wrappers yet, because the
Model
has not created the topics, so save the information about the topic wrappers for thesetup
method.In the rule’s
BaseRule.setup
method construct the filtered topic wrappers by callingmake_filtered_topic_wrapper
. Also construct filtered field wrappers, if desired.In the rule’s
BaseRule.__call__
method use the topic wrapper’s data to determine the alarm severity. You can use the data in two ways:To get the most recent data: call
get_data
. Theprivate_sndStamp
field is usually the best way to get the timestamp for the data, though some topics have a more accurate timestamp, often namedtimestamp
.To extract specific values from a field wrapper, access the
value
attribute of each wrapper.
- 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.
- topic
Methods Summary
__call__
(topic_callback)Update the cached data.
add_field_wrapper
(field_wrapper)Add a 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__(topic_callback)¶
Update the cached data.
- add_field_wrapper(field_wrapper)¶
Add a field wrapper to the internal cache.
Call field_wrapper.update_value when update_data is called with the appropriate filter_value.
- get_data(filter_value)¶
Get the most recently seen data for the given filter_value, or None if no data seen.