TopicWrapper#

class lsst.ts.watcher.TopicWrapper(model, topic)#

Bases: object

Topic wrapper that caches data by a specified key.

To make a topic wrapper, call Model.make_non_filtered_topic_wrapper, instead of constructing a TopicWrapper directly. That allows using a cached instance, if available (and avoids a RuntimeError 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.

Raises:
  • ValueError – If the key does not exist in the data, or if it exists but is an array.

  • RuntimeError – If this NonFilteredTopicWrapper already exists in the model. To avoid this, construct field wrappers by calling Model.make_non_filtered_field_wrapper.

topic#

topic constructor argument.

Type:

lsst.ts.salobj.ReadTopic

descr#

A short description of the wrapper.

Type:

str

data_cache#

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

Type:

str

default_data#

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

call_event#

An event that __call__ sets when it finishes. This is intended for use by unit tests.

Type:

asyncio.Event

Notes

A rule will typically use non-filtered _field_ wrappers (subclasses of BaseFilteredFieldWrapper) rather than NonFilteredTopicWrapper.

Non-filtered field wrappers are high-level objects that store data for a particular key. NonFilteredTopicWrapper is a lower level object that stores data for all keys.

Each BaseFilteredFieldWrapper may contain a NonFilteredTopicWrapper.

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()

Get the most recently seen data, or None if no data seen.

Methods Documentation

__call__(data, topic_callback)#

Update the cached data.

Set data_cache[“key”] to the new data and call update_value for each field wrapper with the matching filter value “self.key”.

Parameters:
  • data (lsst.ts.salobj.BaseMsgType) – Topic data.

  • topic_callback (TopicCallback) – The topic callback that triggered this call.

add_field_wrapper(field_wrapper)#

Add a filtered field wrapper to the internal cache.

Parameters:

field_wrapper (BaseFilteredFieldWrapper) – The filtered field wrapper to add.

get_data()#

Get the most recently seen data, or None if no data seen.