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 a TopicWrapper directly.

Parameters
modelModel

Watcher model. Used to add a TopicCallback to the topic, if one does not already exist.

topiclsst.ts.salobj.ReadTopic

Topic to read.

filter_fieldstr

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.

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 RemoteInfos. Be sure to list each wrapped topic using the wrapper_names or callback_names constructor argument of RemoteInfo.

    You cannot create the topic wrappers yet, because the Model has not created the topics, so save the information about the topic wrappers for the setup method.

  • In the rule’s BaseRule.setup method construct the filtered topic wrappers by calling make_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. The private_sndStamp field is usually the best way to get the timestamp for the data, though some topics have a more accurate timestamp, often named timestamp.

    • To extract specific values from a field wrapper, access the value attribute of each wrapper.

Attributes
topiclsst.ts.salobj.ReadTopic

topic constructor argument.

filter_fieldstr

filter_field constructor argument.

descrstr

A short description of the wrapper.

data_cachestr

Dict of value of filter_field: most recent data seen for that value.

default_data

Default-constructed data. Use for validation of field wrappers.

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.