csaxs_bec.devices.epics.mcs_card.mcs_card_csaxs.MCSCardCSAXS#
- class MCSCardCSAXS(name: str, prefix: str = '', scan_info: ScanInfo | None = None, device_manager: DeviceManagerBase | None = None, **kwargs)[source]#
Bases:
PSIDeviceBase,MCSCardImplementation of the MCSCard SIS3820 for CSAXS, prefix ‘X12SA-MCS:’. The basic functionality is inherited from the MCSCard class.
Please note that the number of channels is fixed to 32, so there will be data for all 32 channels. In addition, the logic of the card is linked to the timing system (DDG) and therefore changes have to be coordinated with the logic on the DDG side.
- Parameters:
name (str) – Name of the device.
prefix (str, optional) – Prefix for the EPICS PVs. Defaults to “”.
Initialize the PSI Device Base class.
- Parameters:
name (str) – Name of the device
scan_info (ScanInfo) – The scan info to use.
Methods
Register a callback which will receive each OphydObject instance.
Register a status object to be cancelled when the device is stopped.
Check if the value is valid for this object
Remove a subscription, given the original callback function
Complete the device.
Configure the device for something during a run
Provide schema and meta-data for
read().Provide schema & meta-data for
read_configuration()Destroy the device.
Get the value of all components in the device
Get the compare status for a signal of the device.
The device tuple type associated with an Device class
Yields all of the instantiated signals in a device hierarchy
Get the transition status for a signal of the device.
Kickoff the device.
Recovery procedure for the mcs card.
Method that is called at the end of scan core, but before unstage.
This method is called once the device and all its PVs are connected.
The on destroy hook is called when the device is destroyed, but also reloaded.
Called when the device is initialized.
Called to kickoff a device for a fly scan.
Called right before the scan starts on all devices automatically.
This method is called after on_stage and before the scan starts.
This method is called when the device is staged before a scan.
Hook called when the device is stopped.
Called when the device is triggered.
Called when the device is unstaged.
Attempt to 'pause' the device.
Pre-scan function.
Put a value to all components of the device
Read data from the device.
Dictionary mapping names to value dicts with keys: value, timestamp
Resume a device from a 'paused' state.
Set class-wide defaults for device communications
Stage the device.
Stop the device.
Subscribe to events this event_type generates.
summaryTrigger the device.
Unstage the device.
Remove a subscription
unsubscribe_allUtility method to easily wait for signals or methods to reach an expected state.
Wait for signals to connect
Walk all components in the Device hierarchy
Walk all signals in the Device hierarchy
Walk all sub-Devices classes in the Device hierarchy
Walk all sub-Devices in the hierarchy
Attributes
NUM_MCA_CHANNELSSUB_ACQ_DONESUB_DEVICE_MONITOR_1DSUB_DEVICE_MONITOR_2DSUB_DONE_MOVINGSUB_FILE_EVENTSUB_MOTOR_IS_MOVINGSUB_PROGRESSSUB_READBACKSUB_VALUEUSER_ACCESSWRITE_TIMEOUTacquire_modeA descriptor representing a device component (or signal)
acquiringA descriptor representing a device component (or signal)
attr_namechannel1_sourceA descriptor representing a device component (or signal)
channel_advanceA descriptor representing a device component (or signal)
client_waitA descriptor representing a device component (or signal)
component_namesconfiguration_attrsIf the device is connected.
connection_timeoutcount_on_startA descriptor representing a device component (or signal)
countersAn Device component that dynamically creates an ophyd Device
current_channelA descriptor representing a device component (or signal)
Check if the device has been destroyed.
Return the dotted name
dwellA descriptor representing a device component (or signal)
elapsed_realA descriptor representing a device component (or signal)
enable_client_waitA descriptor representing a device component (or signal)
erase_allA descriptor representing a device component (or signal)
erase_startA descriptor representing a device component (or signal)
Events that can be subscribed to via
obj.subscribefirmwareA descriptor representing a device component (or signal)
hintsinput_modeA descriptor representing a device component (or signal)
input_polarityA descriptor representing a device component (or signal)
kindlazy_wait_for_connectionmax_channelsA descriptor representing a device component (or signal)
mcaA descriptor representing a device component (or signal)
modelA descriptor representing a device component (or signal)
mux_outputA descriptor representing a device component (or signal)
name of the device
num_use_allA descriptor representing a device component (or signal)
output_modeA descriptor representing a device component (or signal)
output_polarityA descriptor representing a device component (or signal)
The parent of the ophyd object.
prescaleA descriptor representing a device component (or signal)
preset_realA descriptor representing a device component (or signal)
progressA descriptor representing a device component (or signal)
read_allA descriptor representing a device component (or signal)
read_attrsread_modeA descriptor representing a device component (or signal)
A report on the object.
Walk parents to find ultimate ancestor (parent's parent...).
signal_namessnl_connectedA descriptor representing a device component (or signal)
software_channel_advanceA descriptor representing a device component (or signal)
Check if the device has been staged.
start_allA descriptor representing a device component (or signal)
stop_allA descriptor representing a device component (or signal)
Check if the device has been stopped.
subscriptionstrigger_signalsuser_ledA descriptor representing a device component (or signal)
- class OphydAttrList(device, kind, remove_kind, recurse_key)#
Bases:
MutableSequencelist proxy to migrate away from Device.read_attrs and Device.config_attrs
- append(value)#
S.append(value) – append value to the end of the sequence
- clear() None -- remove all items from S#
- count(value) integer -- return number of occurrences of value#
- extend(values)#
S.extend(iterable) – extend sequence by appending elements from the iterable
- index(value[, start[, stop]]) integer -- return first index of value.#
Raises ValueError if the value is not present.
Supporting start and stop arguments is optional, but recommended.
- insert(index, object)#
S.insert(index, value) – insert value before index
- pop([index]) item -- remove and return item at index (default last).#
Raise IndexError if list is empty or index is out of range.
- remove(value)#
S.remove(value) – remove first occurrence of value. Raise ValueError if the value is not present.
- reverse()#
S.reverse() – reverse IN PLACE
- classmethod add_instantiation_callback(callback, fail_if_late=False)#
Register a callback which will receive each OphydObject instance.
- Parameters:
callback (callable) – Expected signature:
f(ophydobj_instance)fail_if_late (boolean) – If True, verify that OphydObj has not yet been instantiated and raise
RuntimeErrorif it has, as a way of verify that no instances will be “missed” by this registry. False by default.
- cancel_on_stop(status: StatusBase) None#
Register a status object to be cancelled when the device is stopped.
- Parameters:
status (StatusBase) – The status object to be cancelled.
- check_value(value, **kwargs)#
Check if the value is valid for this object
This function does no normalization, but may raise if the value is invalid.
- Raises:
ValueError –
- clear_sub(cb, event_type=None)#
Remove a subscription, given the original callback function
See also
subscribe(),unsubscribe()- Parameters:
cb (callable) – The callback
event_type (str, optional) – The event to unsubscribe from (if None, removes it from all event types)
- complete() DeviceStatus | StatusBase#
Complete the device.
- configure(d: Dict[str, Any]) Tuple[Dict[str, Any], Dict[str, Any]]#
Configure the device for something during a run
This default implementation allows the user to change any of the configuration_attrs. Subclasses might override this to perform additional input validation, cleanup, etc.
- Parameters:
d (dict) – The configuration dictionary. To specify the order that the changes should be made, use an OrderedDict.
- Returns:
(old, new) tuple of dictionaries
Where old and new are pre- and post-configure configuration states.
- property connected#
If the device is connected.
Subclasses should override this
- describe() OrderedDictType[str, Dict[str, Any]]#
Provide schema and meta-data for
read().This keys in the OrderedDict this method returns must match the keys in the OrderedDict return by
read().This provides schema related information, (ex shape, dtype), the source (ex PV name), and if available, units, limits, precision etc.
- Returns:
data_keys – The keys must be strings and the values must be dict-like with the
event_model.event_descriptor.data_keyschema.- Return type:
OrderedDict
- describe_configuration() OrderedDictType[str, Dict[str, Any]]#
Provide schema & meta-data for
read_configuration()This keys in the OrderedDict this method returns must match the keys in the OrderedDict return by
read().This provides schema related information, (ex shape, dtype), the source (ex PV name), and if available, units, limits, precision etc.
- Returns:
data_keys – The keys must be strings and the values must be dict-like with the
event_model.event_descriptor.data_keyschema.- Return type:
OrderedDict
- destroy()#
Destroy the device.
- property destroyed: bool#
Check if the device has been destroyed.
- property dotted_name: str#
Return the dotted name
- property event_types#
Events that can be subscribed to via
obj.subscribe
- get(**kwargs)#
Get the value of all components in the device
Keyword arguments are passed onto each signal.get(). Components beginning with an underscore will not be included.
- get_compare_status(signal_name: str, expected_value: any, operation_success: str = '==') CompareStatus[source]#
Get the compare status for a signal of the device.
- Parameters:
signal_name – The name of the signal to check the compare status for.
expected_value – The expected value to compare against.
operation_success – The comparison operation to use. Defaults to “==”.
- classmethod get_device_tuple()#
The device tuple type associated with an Device class
This is a tuple representing the full state of all components and dynamic device sub-components.
- get_instantiated_signals(*, attr_prefix=None)#
Yields all of the instantiated signals in a device hierarchy
- Parameters:
attr_prefix (string, optional) – The attribute prefix. If None, defaults to self.name
- Yields:
(fully_qualified_attribute_name, signal_instance)
- get_transition_status(signal_name: str, transition: list) TransitionStatus[source]#
Get the transition status for a signal of the device.
- Parameters:
signal_name – The name of the signal to check the transition status for.
transition (list) – List of transitions to check.
- kickoff() DeviceStatus | StatusBase#
Kickoff the device.
- mcs_recovery(timeout: int = 1) None[source]#
Recovery procedure for the mcs card. This procedure has been empirically found and can be used to ensure that the MCS card is stopped and has no pending data to be emitted. It involves stopping any ongoing acquisition and erasing all data on the card, with a sleep in between to allow the IOC to process the commands.
- Parameters:
timeout (int) – Total timeout for the recovery procedure. Defaults to 1 second.
- property name#
name of the device
- on_complete() CompareStatus[source]#
Method that is called at the end of scan core, but before unstage. This method is used to report whether the device successfully completed its data acquisition for the scan. The check has to be implemented asynchronously and resolve through a status (future) object returned by this method. NOTE: For the MCS card, we need to ensure that all data has been acquired and emitted to BEC as updates after ‘on_complete’ resolved will be rejected by BEC. Therefore, we need to ensure that all data has been emitted to BEC before reporting completion of the device.
This method implements the following procedure: - Starts the IDLE async data monitoring thread that checks if all expected data
has been emitted to BEC through the mca channel callbacks.
- Use a CompareStatus to monitor when the MCS card becomes DONE. Please note that this
only indicates that the card has finished acquisition, but not that all data has been emitted to BEC.
- Return combined status object. A callback is registered to handle failure of the status
if it is stopped externally, e.g. through scan abort. This should ensure that the monitoring thread is stopped properly.
- on_connected()[source]#
This method is called once the device and all its PVs are connected. Any initial setup of PVs should be managed here. Please be aware that settings of the MCS card correlate with its operation mode, input/output modes, and timing. Changing single parameters without understanding the overall logic may lead to unexpected behavior of the device.Therefore, any modification of these parameters should be handled with care and tested.
A brief summary of the procesdure that is implemented here: - Stop any ongoing acquisiton. - Setup the Initial initial settings of the MCS card with respective operation modes - Run ‘mcs_recovery’ procedure to ensure that no pending acquisition data is scheduled
to be pushed through mcs channels
- Subscribe a callback ‘_on_counter_update’ to mcs counter PVs to forward
data through AsyncMultiSignal to BEC
Start the monitoring thread for async data emission after scan is done
- on_destroy()[source]#
The on destroy hook is called when the device is destroyed, but also reloaded. Here, we need to clean up all resources used up by the device, including running threads.
- on_init() None#
Called when the device is initialized.
No signals are connected at this point. If you like to set default values on signals, please use on_connected instead.
- on_kickoff() DeviceStatus | StatusBase | None#
Called to kickoff a device for a fly scan. Has to be called explicitly.
- on_pre_scan() DeviceStatus | StatusBase | None#
Called right before the scan starts on all devices automatically.
- on_prescan() None | StatusBase[source]#
This method is called after on_stage and before the scan starts. For the MCS card, we need to make sure that the card is properly started for fly scans. For step scans, this will be handled by the DDG, so no action is required here.
- on_stage() None[source]#
This method is called when the device is staged before a scan. Any bootstrapping required for the scan should be handled here. We also need to handle MCS card specific logic to ensure that the card is properly prepared for the scan.
The following procedure is implemented here: - Ensure that any ongoing acquisition is stopped (should never happen if not interfered with manually) - Erase all data on the MCS card to ensure a clean start (should never - Set acquisition parameters based on scan parameters (frames_per_trigger, num_points, acquisition_group) - Clear any events and buffers related to async data emission. This includes ‘_omit_mca_callbacks’,
‘_start_monitor_async_data_emission’, ‘_scan_done_callbacks’, and ‘_current_data’.
- on_stop() None[source]#
Hook called when the device is stopped. In addition, any status that is registered through cancel_on_stop will be cancelled here.
- on_trigger() DeviceStatus | StatusBase | None#
Called when the device is triggered.
- on_unstage() None[source]#
Called when the device is unstaged. This method should be omnipotent and resolve fast. It stops any ongoing acquisition, erases all data on the MCS and clears the local buffer ‘_current_data’.
NOTE: It is important that the logic for on_complete is solid and properly waiting for mca data to be emitted to BEC. Otherwise, unstage may interfere with ongoing data emission. Unstage is called after complete during scans. It is crucial that the device itself calls ‘_omit_mca_callbacks’ in its on_stage method to make sure that data is emitted once the card is properly staged.
- property parent#
The parent of the ophyd object.
If at the top of its hierarchy, parent will be None
- pause() None#
Attempt to ‘pause’ the device.
This is called when ever the
RunEngineis interrupted.A device may have internal state that means plans can not safely be re-wound. This method may: put the device in a ‘paused’ state and/or raise
NoReplayAllowedto indicate that the plan can not be rewound.- Raises:
bluesky.run_engine.NoReplayAllowed –
- pre_scan() DeviceStatus | StatusBase | None#
Pre-scan function.
- put(dev_t, **kwargs)#
Put a value to all components of the device
Keyword arguments are passed onto each signal.put()
- Parameters:
dev_t (DeviceTuple or tuple) – The device tuple with the value(s) to put (see get_device_tuple)
- read() OrderedDictType[str, Dict[str, Any]]#
Read data from the device.
This method is expected to be as instantaneous as possible, with any substantial acquisition time taken care of in
trigger().The OrderedDict returned by this method must have identical keys (in the same order) as the OrderedDict returned by
describe().By convention, the first key in the return is the ‘primary’ key and maybe used by heuristics in
bluesky.The values in the ordered dictionary must be dict (-likes) with the keys
{'value', 'timestamp'}. The'value'may have any type, the timestamp must be a float UNIX epoch timestamp in UTC.- Returns:
data – The keys must be strings and the values must be dict-like with the keys
{'value', 'timestamp'}- Return type:
OrderedDict
- read_configuration() OrderedDictType[str, Dict[str, Any]]#
Dictionary mapping names to value dicts with keys: value, timestamp
To control which fields are included, change the Component kinds on the device, or modify the
configuration_attrslist.
- property report#
A report on the object.
- resume() None#
Resume a device from a ‘paused’ state.
This is called by the
bluesky.run_engine.RunEnginewhen it resumes from an interruption and is responsible for ensuring that the device is ready to take data again.
- property root#
Walk parents to find ultimate ancestor (parent’s parent…).
- classmethod set_defaults(*, connection_timeout=10.0)#
Set class-wide defaults for device communications
This may be called only before any instances of Device are made.
This setting applies to the class it is called on and all its subclasses. For example,
>>> Device.set_defaults(...)
will apply to any Device subclass.
- Parameters:
connection_timeout (float, optional) – Time (seconds) allocated for establishing a connection with the IOC.
- Raises:
RuntimeError – If called after
EpicsSignalBasehas been instantiated for the first time.
- stage() list[object] | DeviceStatus | StatusBase#
Stage the device.
- property staged: Staged#
Check if the device has been staged.
- stop(*, success: bool = False) None#
Stop the device.
- Parameters:
success (bool) – True if the action was successful, False otherwise.
- property stopped: bool#
Check if the device has been stopped.
- subscribe(callback, event_type=None, run=True)#
Subscribe to events this event_type generates.
The callback will be called as
cb(*args, **kwargs)with the values passed to _run_subs with the following additional keys:sub_type : the string value of the event_type obj : the host object, added if ‘obj’ not already in kwargs
if the key ‘timestamp’ is in kwargs _and_ is None, then it will be replaced with the current time before running the callback.
The
*args,**kwargspassed to _run_subs will be cached as shallow copies, be aware of passing in mutable data.Warning
If the callback raises any exceptions when run they will be silently ignored.
- Parameters:
callback (callable) –
A callable function (that takes kwargs) to be run when the event is generated. The expected signature is
def cb(*args, obj: OphydObject, sub_type: str, **kwargs) -> None:
The exact args/kwargs passed are whatever are passed to
_run_subsevent_type (str, optional) –
The name of the event to subscribe to (if None, defaults to the default sub for the instance - obj._default_sub)
This maps to the
sub_typekwargs in _run_subsrun (bool, optional) – Run the callback now
See also
clear_sub,_run_subs- Returns:
cid – id of callback, can be passed to unsubscribe to remove the callback
- Return type:
int
- trigger() DeviceStatus | StatusBase#
Trigger the device.
- unstage() list[object] | DeviceStatus | StatusBase#
Unstage the device.
- unsubscribe(cid)#
Remove a subscription
See also
subscribe(),clear_sub()- Parameters:
cid (int) – token return by
subscribe()
- wait_for_condition(condition: Callable[[], bool], timeout: float, check_stopped: bool = False, interval: float = 0.05) bool#
Utility method to easily wait for signals or methods to reach an expected state.
- Parameters:
condition (Callable) – function that returns True if the condition is met, False otherwise
timeout (float) – timeout in seconds
check_stopped (bool) – True if stopped flag should be checked
interval (float) – interval in seconds
- Returns:
True if all signals are in the desired state, False if timeout is reached
- Return type:
bool
Example
>>> self.wait_for_condition(condition=my_condition, timeout=5, interval=0.05, check_stopped=True)
- wait_for_connection(all_signals=False, timeout=<object object>)#
Wait for signals to connect
- Parameters:
all_signals (bool, optional) – Wait for all signals to connect (including lazy ones)
timeout (float or None) – Overall timeout
- classmethod walk_components()#
Walk all components in the Device hierarchy
- Yields:
ComponentWalk – Where ancestors is all ancestors of the signal, including the top-level device walk_components was called on.
- walk_signals(*, include_lazy=False)#
Walk all signals in the Device hierarchy
EXPERIMENTAL: This method is experimental, and there are tentative plans to change its API in a way that may not be backward-compatible.
- Parameters:
include_lazy (bool, optional) – Include not-yet-instantiated lazy signals
- Yields:
ComponentWalk – Where ancestors is all ancestors of the signal, including the top-level device walk_signals was called on.
- classmethod walk_subdevice_classes()#
Walk all sub-Devices classes in the Device hierarchy
- Yields:
(dotted_name, subdevice_class)
- walk_subdevices(*, include_lazy=False)#
Walk all sub-Devices in the hierarchy
EXPERIMENTAL: This method is experimental, and there are tentative plans to change its API in a way that may not be backward-compatible.
- Yields:
(dotted_name, subdevice_instance)