BaseRule#

class lsst.ts.watcher.BaseRule(config, name, remote_info_list, log=None)#

Bases: ABC

Base class for watcher rules.

Parameters:
  • config (types.SimpleNamespace) – Rule configuration, as validated by the schema.

  • name (str) – Name of alarm. This must be unique among all alarms and should be of the form system.[subsystem….]_name so that groups of related alarms can be acknowledged.

  • remote_info_list (list [RemoteInfo]) – Information about the remotes used by this rule.

  • log (logging.Logger, optional) – Parent logger.

alarm#

The alarm associated with this rule.

Type:

Alarm

remote_keys#

Set of remote keys. Each element is a tuple of:

  • SAL component name (e.g. “ATPtg”)

  • SAL index

Type:

frozenset [tuple [str, int]]

Notes

Model.add_rule adds an attribute {lowerremotename}_{index} = `` `RemoteWrapper` to the rule for each remote in `remote_info_list`, where ``lowerremotename is the name of the SAL component cast to lowercase, and index is the SAL index (0 if not an indexed component). For example: atdome_0 for ATDome (which is not indexed). This gives each rule ready access to its remote wrappers.

Attributes Summary

name

Get the rule name.

Methods Summary

compute_alarm_severity(**kwargs)

Compute and set alarm severity and reason.

get_schema()

Return a jsonschema as a dict, to validate configuration.

is_usable(disabled_sal_components)

Return True if rule can be used, despite disabled SAL components.

make_config(**kwargs)

Make a config from keyword arguments, after applying defaults.

setup(model)

Perform post-constructor setup.

start()

Start any background tasks, such as a polling loop.

stop()

Stop all background tasks.

update_alarm_severity(**kwargs)

Compute and set alarm severity and reason.

Attributes Documentation

name#

Get the rule name.

Methods Documentation

abstract compute_alarm_severity(**kwargs)#

Compute and set alarm severity and reason.

Parameters:

**kwargs (dict [str, typing.Any]) –

Keyword arguments. If triggered by TopicCallback calling update_alarm_severity, the arguments will be as follows:

  • data : salobj.BaseMsgType Message from the topic described by topic_callback.

  • topic_callback : TopicCallback Topic callback wrapper.

Return type:

tuple[AlarmSeverity, str] | None

Returns:

  • None, if no change or unknown, or a tuple of two values

  • severity (lsst.ts.xml.enums.Watcher.AlarmSeverity) – The new alarm severity.

  • reason (str) – Detailed reason for the severity, e.g. a string describing what value is out of range, and what the range is. If severity is NONE then this value is ignored (but still required) and the old reason is retained until the alarm is reset to nominal state.

Notes

You may return NoneNoReason if the alarm state is NONE.

abstract classmethod get_schema()#

Return a jsonschema as a dict, to validate configuration.

Return type:

dict[str, Any]

Notes

Please provide default values for all fields for which defaults make sense. This makes watcher configuration files easier to write.

If your rule has no configuration then return None.

We recommend that you write the schema as yaml, for compactness, then use yaml.safe_load to convert it to a dict. For example:

schema_yaml = """
    $schema: http://json-schema.org/draft-07/schema#
    description: Configuration for MyRule
    type: object
    properties:
    ...
    required: [...]
    additionalProperties: false
"""
return yaml.safe_load(schema_yaml)
is_usable(disabled_sal_components)#

Return True if rule can be used, despite disabled SAL components.

The default implementation returns true if all remotes used by this rule are enabled. Override if you need something more complicated. The attributes config, name and remote_info_list are all available when this method is called.

Parameters:

disabled_sal_components (set [tuple [str, int]]) –

Set of disabled SAL components. Each element is a tuple of:

  • SAL component name (e.g. “ATPtg”)

  • SAL index

Return type:

bool

classmethod make_config(**kwargs)#

Make a config from keyword arguments, after applying defaults.

Parameters:

kwargs (str) – The configuration, as a dict of property: name. The allowed properties and values are specified by the rule’s config schema.

Returns:

config – The rule configuration, with defaults applied as needed.

Return type:

types.SimpleNamespace

Raises:

jsonschema.ValidationError – If the provided kwargs are incorrect (missing keys, misspelled keys, incorrect data types…).

setup(model)#

Perform post-constructor setup.

Called after the remotes are constructed and populated with topics, but before the remotes have started.

Parameters:

model (Model) – The watcher model.

Return type:

None

Notes

Possible uses:

  • Rules in which topics and/or fields are specified in configuration should check that the topics and/or fields exist. They may also set variables pointing to the appropriate topics.

  • Rules that start a background process may start the process here rather than in the constructor; this is especially helpful if the process needs access to topics or fields.

Few rules require setup, so the default implemention is a no-op.

start()#

Start any background tasks, such as a polling loop.

This is called when the watcher goes into the enabled state.

Return type:

None

Notes

Do not assume that start is called before stop; the order depends on the initial state of the Watcher.

Immediate subclasses need not call super().start()

stop()#

Stop all background tasks.

This is called when the watcher goes out of the enabled state, and must stop any tasks that might trigger an alarm state change.

Return type:

None

Notes

Do not assume that start is called before stop; the order depends on the initial state of the Watcher.

This base implementation does nothing, so immediate subclasses need not call super().stop().

async update_alarm_severity(**kwargs)#

Compute and set alarm severity and reason.

This must run quickly. If computing alarm severity is expensive, override this method to start a thread that computes the data and create a background task to manage the thread, then return.

Parameters:

**kwargs (dict [str, typing.Any]) –

Keyword arguments. If called by TopicCallback, the arguments will be as follows:

  • data : salobj.BaseMsgType Message from the topic described by topic_callback.

  • topic_callback : TopicCallback Topic callback wrapper.

Return type:

None