pytac.data_source#

Module containing pytac data source classes.

Members

DataSource

Abstract base class for element or lattice data sources.

DataSourceManager

Class that manages all the data sources and UnitConv objects associated with a lattice or element.

DeviceDataSource

Data source containing control system devices.

class pytac.data_source.DataSource[source]#

Abstract base class for element or lattice data sources.

Typically an instance would represent hardware via a control system, or a simulation.

Attributes:

units#

pytac.PHYS or pytac.ENG.

Type:

str

Methods:

get_fields()[source]#

Get all the fields represented by this data source.

Returns:

all fields.

Return type:

iterable

get_value(field, handle, throw)[source]#

Get a value for a field.

Parameters:
  • field (str) – field of the requested value.

  • handle (str) – pytac.RB or pytac.SP

  • throw (bool) – On failure: if True, raise ControlSystemException; if False, return None and log a warning.

Returns:

value for specified field and handle.

Return type:

float

set_value(field, value, throw)[source]#

Set a value for a field.

This is always set to pytac.SP, never pytac.RB.

Parameters:
  • field (str) – field to set.

  • value (float) – value to set.

  • throw (bool) – On failure: if True, raise ControlSystemException: if False, log a warning.

class pytac.data_source.DataSourceManager[source]#

Class that manages all the data sources and UnitConv objects associated with a lattice or element.

It receives requests from a lattice or element object and directs them to the correct data source. The unit conversion objects for all fields are also held here.

default_units#

Holds the current default unit type, pytac.PHYS or pytac.ENG, for an element or lattice.

Type:

str

default_data_source#

Holds the current default data source, pytac.LIVE or pytac.SIM, for an element or lattice.

Type:

str

Methods:

set_data_source(data_source, data_source_type)[source]#

Add a data source to the manager.

Parameters:
  • data_source (DataSource) – the data source to be set.

  • data_source_type (str) – the type of the data source being set pytac.LIVE or pytac.SIM.

get_data_source(data_source_type)[source]#

Get a data source.

Parameters:

data_source_type (str) – the type of the data source being set pytac.LIVE or pytac.SIM.

Raises:

DataSourceException – if there is no data source on the given field.

get_fields()[source]#

Get all the fields defined on the manager.

Includes all fields defined by all data sources.

Returns:

A dictionary of all the fields defined on the manager,

separated by data source(key).

Return type:

dict

add_device(field, device, uc)[source]#

Add device and unit conversion objects to a given field.

A DeviceDataSource must be set before calling this method, this defaults to pytac.LIVE as that is the only data source that currently uses devices.

Parameters:
  • field (str) – The key to store the unit conversion and device objects.

  • device (Device) – The device object used for this field.

  • uc (UnitConv) – The unit conversion object used for this field.

Raises:

DataSourceException – if no DeviceDataSource is set.

get_device(field)[source]#

Get the device for the given field.

A DeviceDataSource must be set before calling this method, this defaults to pytac.LIVE as that is the only data source that currently uses devices.

Parameters:

field (str) – The lookup key to find the device on the manager.

Returns:

The device on the given field.

Return type:

Device

Raises:

DataSourceException – if no DeviceDataSource is set.

get_unitconv(field)[source]#

Get the unit conversion option for the specified field.

Parameters:

field (str) – The field associated with this conversion.

Returns:

The object associated with the specified field.

Return type:

UnitConv

Raises:

FieldException – if no unit conversion object is present.

set_unitconv(field, uc)[source]#

set the unit conversion option for the specified field.

Parameters:
  • field (str) – The field associated with this conversion.

  • uc (UnitConv) – The unit conversion object to be set.

get_value(field: str, handle: str = 'readback', units: str = 'default', data_source_type: str = 'default', throw: bool = True) float[source]#

Get the value for a field.

Returns the value of a field on the manager. This value is uniquely identified by a field and a handle. The returned value is either in engineering or physics units. The data_source flag returns either real or simulated values. If handle, units or data_source are not given then the lattice default values are used.

Parameters:
  • field – The requested field.

  • handle – pytac.SP or pytac.RB.

  • units – pytac.ENG or pytac.PHYS returned.

  • data_source – pytac.LIVE or pytac.SIM.

  • throw – On failure: if True, raise ControlSystemException; if False, return None and log a warning.

Returns:

The value of the requested field

Raises:
set_value(field: str, value: float, units: str = 'default', data_source_type: str = 'default', throw: bool = True) None[source]#

Set the value for a field.

This sets a value on the machine or the simulation. If handle,units or data_source are not given then the lattice default values are used.

Parameters:
  • field – The requested field.

  • value – The value to set.

  • units – pytac.ENG or pytac.PHYS.

  • data_source_type – pytac.LIVE or pytac.SIM.

  • throw – On failure: if True, raise ControlSystemException: if False, log a warning.

Raises:
class pytac.data_source.DeviceDataSource[source]#

Data source containing control system devices.

Attributes:

units#

pytac.ENG or pytac.PHYS, pytac.ENG by default.

Type:

str

Methods:

add_device(field, device)[source]#

Add device to this data_source.

Parameters:
  • field (str) – field this device represents.

  • device (Device) – device object.

get_device(field)[source]#

Get device from the data_source.

Parameters:

field (str) – field of the requested device.

Returns:

The device of the specified field.

Return type:

Device

Raises:

FieldException – if the specified field doesn’t exist on this data source.

get_fields()[source]#

Get all the fields from the data_source.

Returns:

list of strings of all the fields of the data_source.

Return type:

list

get_value(field, handle, throw=True)[source]#

Get the value of a readback or setpoint PV for a field from the data_source.

Parameters:
  • field (str) – field of the requested value.

  • handle (str) – pytac.RB or pytac.SP.

  • throw (bool) – On failure: if True, raise ControlSystemException; if False, return None and log a warning.

Returns:

The value of the PV.

Return type:

float

Raises:

FieldException – if the device does not have the specified field.

set_value(field, value, throw=True)[source]#

Set the value of a readback or setpoint PV for a field from the data_source.

Parameters:
  • field (str) – field for the requested value.

  • value (float) – The value to set on the PV.

  • throw (bool) – On failure: if True, raise ControlSystemException: if False, log a warning.

Raises:

FieldException – if the device does not have the specified field.