WriteTopic¶
- class lsst.ts.salobj.topics.WriteTopic(*, salinfo: SalInfo, attr_name: str, min_seq_num: int | None = 1, max_seq_num: int = 2147483647, initial_seq_num: int | None = None)¶
Bases:
BaseTopicBase class for topics that are written.
This includes controller events, controller telemetry, remote commands and
ackcmdwriters.- Parameters:
- salinfo
SalInfo SAL component information
- attr_name
str Topic name with attribute prefix. The prefix must be one of:
cmd_,evt_,tel_, or (only for the ackcmd topic)ack_.- min_seq_num
intorNone, optional Minimum value for the
private_seqNumfield. The default is 1. IfNonethenprivate_seqNumis not set; this is needed for the ackcmd writer, which sets the field itself.- max_seq_num
int, optional Maximum value for
private_seqNum, inclusive. The default is the maximum allowed positive value (private_seqNumis a 4-byte signed int). Ignored ifmin_seq_numisNone.- initial_seq_num
int, optional Initial sequence number; if
Noneuse min_seq_num.
- salinfo
- Attributes:
Attributes Summary
The type (class) for a message of this topic.
Get the salobj topic attribute name, e.g.
Internally cached message.
Has
dataever been set?Get the SAL topic name, e.g.
Methods Summary
A synchronous and possibly less thorough version of
close.close()Shut down and release resources.
set(**kwargs)Set one or more fields of message data
self.data.set_write(*[, force_output])Set zero or more fields of
self.dataand write if any field changed or if output forced.write()Write the current data and return a copy of the data written.
Attributes Documentation
- DataType¶
The type (class) for a message of this topic.
When you read or write a message for this topic you are reading or writing an instance of
DataType.Notes
The preferred way to set data and write a message for a topic is:
RemoteCommand.set_startto start a command.CommandEvent.set_writeto write an event.CommandTelemetry.set_writeto write a telemetry message.
- attr_name¶
Get the salobj topic attribute name, e.g. evt_summaryState.
- data¶
Internally cached message.
- Raises:
- TypeError
If
datais not an instance ofDataType
Notes
Do not assume the data will be constant. You can make a copy using
copy.copy(data).
- has_data¶
Has
dataever been set?Note: a value of true means at least one field has been set, not that all fields have been set.
- sal_name¶
Get the SAL topic name, e.g. logevent_summaryState.
Methods Documentation
- basic_close() None¶
A synchronous and possibly less thorough version of
close.Intended for exit handlers and constructor error handlers.
- async close() None¶
Shut down and release resources.
Intended to be called by SalInfo.close(), since that tracks all topics.
- set(**kwargs: Any) bool¶
Set one or more fields of message data
self.data.This is useful when accumulating data for a topic in different bits of code. Have each bit of code call
setto set the fields it knows about. Have the last bit of code callwriteto set the remaining fields and write the completed message.If you have all the information for a topic in one place, it is simpler to call
set_writeto set all of the fields and write the message.- Parameters:
- Returns:
- Raises:
- AttributeError
If the topic does not have the specified field.
- ValueError
If the field cannot be set to the specified value.
Notes
If one or more fields cannot be set, the message data may be partially updated.
- async set_write(*, force_output: bool | None = None, **kwargs: Any) SetWriteResult¶
Set zero or more fields of
self.dataand write if any field changed or if output forced.- Parameters:
- force_output
bool, optional If True then write the event, even if no fields have changed. If None (the default), use the class default, which is True for all except ControllerEvent. (The default value is given by class constant
default_force_output).- **kwargs
dict[str,any] The remaining keyword arguments are field name = new value for that field. See
setfor more information about values.
- force_output
- Returns:
- result
SetWriteResult The resulting data and some flags.
- result
Notes
The reason there are separate
set_writeandwritemethods is thatwritereliably writes the data, whereas the event version ofset_writeonly writes the data ifkwargschanges it, or ifforce_outputis true.
- async write() BaseMsgType¶
Write the current data and return a copy of the data written.
- Returns:
- dataself.DataType
The data that was written. This can be useful to avoid race conditions (as found in RemoteCommand).
- Raises:
- RuntimeError
If not running.