Daq API

class pcdsdaq.daq.Daq(RE=None, hutch_name=None)

The LCLS1 daq as a bluesky-compatible object.

This uses the pydaq module to connect with a running daq instance, controlling it via socket commands.

It can be used as a Reader in a bluesky plan to take data at discrete scan points.

It can be used as a Flyer in a bluesky plan to have the daq start at the beginning of the run and end at the end of the run.

Unlike normal bluesky readable devices or flyers, this has no data to report to the RunEngine on the read or collect calls. No data will pass into the python layer from the daq.

Parameters:
  • RE (RunEngine, optional) – Set RE to the session’s main RunEngine

  • hutch_name (str, optional) – Define a hutch name to use instead of shelling out to get_hutch_name.

begin(events=<object object>, duration=<object object>, record=<object object>, use_l3t=<object object>, controls=<object object>, wait=False, end_run=False)

Start the daq and block until the daq has begun acquiring data.

Optionally block with wait=True until the daq has finished aquiring data. If blocking, a ctrl+c will end the run and clean up.

If omitted, any argument that is shared with configure will fall back to the configured value.

Internally, this calls kickoff and manages its Status object.

Parameters:
  • events (int, optional) – Number events to take in the daq.

  • duration (int, optional) – Time to run the daq in seconds, if events was not provided.

  • record (bool, optional) – If True, we’ll configure the daq to record data before this run.

  • use_l3t (bool, optional) – If True, we’ll run with the level 3 trigger. This means that if we specified a number of events, we will wait for that many “good” events as determined by the daq.

  • controls (dict{name: device} or list[device...], optional) – If provided, values from these will make it into the DAQ data stream as variables. We will check device.position and device.value for quantities to use and we will update these values each time begin is called. To provide a list, all devices must have a name attribute.

  • wait (bool, optional) – If True, wait for the daq to finish aquiring data. A KeyboardInterrupt (ctrl+c) during this wait will end the run and clean up.

  • end_run (bool, optional) – If True, we’ll end the run after the daq has stopped.

begin_infinite(record=<object object>, use_l3t=<object object>, controls=<object object>)

Start the daq to run forever in the background.

collect()

Collect data as part of the bluesky Flyer interface.

As per the bluesky interface, this is a generator that is expected to output partial event documents. However, since we don’t have any events to report to python, this will be a generator that immediately ends.

complete()

If the daq is freely running, this will stop the daq. Otherwise, we’ll simply collect the end_status object.

Returns:

end_statusStatus that will be marked as done when the DAQ has finished acquiring

Return type:

Status

property config

The current configuration, e.g. the last call to configure

config_info(config=None, header='Config:')

Show the config information as a logger.info message.

This will print to the screen if the logger is configured correctly.

Parameters:
  • config (dict, optional) – The configuration to show. If omitted, we’ll use the current config.

  • header (str, optional) – A prefix for the config line.

configure(events=<object object>, duration=<object object>, record=<object object>, use_l3t=<object object>, controls=<object object>, begin_sleep=<object object>)

Changes the daq’s configuration for the next run.

All arguments omitted from the method call will default to the last configured value in the python session.

This is the method that directly interfaces with the daq. If you simply want to get a configuration ready for later, use preconfig.

Parameters:
  • events (int, optional) – If provided, the daq will run for this many events before stopping, unless we override in begin. If not provided, we’ll use the duration argument instead. Defaults to its last configured value, or None on the first configure.

  • duration (int, optional) – If provided, the daq will run for this many seconds before stopping, unless we override in begin. If not provided, and events was also not provided, an empty call like begin() will run indefinitely. You can also achieve this behavior by passing events=None and/or duration=None, Defaults to its last configured value, or None on the first configure.

  • record (bool, optional) – If True, we’ll record the data. If False, we’ll run without recording. If None, we’ll use the option selected in the DAQ GUI. Defaults to the its last configured value, or None on the first configure.

  • use_l3t (bool, optional) – If True, an events argument to begin will be reinterpreted to only count events that pass the level 3 trigger. Defaults to its last configured value, or False on the first configure.

  • controls (dict{name: device} or list[device...], optional) – If provided, values from these will make it into the DAQ data stream as variables. We will check device.position and device.value for quantities to use and we will update these values each time begin is called. To provide a list, all devices must have a name attribute. Defaults to its last configured value, or no controls values on the first configure.

  • begin_sleep (int, optional) – The amount of time to wait after the DAQ returns begin is done. This is a hack because the DAQ often says that a begin transition is done without actually being done, so it needs a short delay. Defaults to its last configured value, or 0 on the first configure.

Returns:

old, new – The old configuration and the new configuration. These dictionaries are verbose, containing all configuration values and the timestamps at which they were configured, as specified by bluesky.

Return type:

tuple of dict

property configured

True if the daq is configured, False otherwise.

connect()

Connect to the live DAQ, giving full control to the Python process.

To undo this, you may call disconnect.

property connected

True if the daq is connected, False otherwise.

describe()

Explain what read returns. There is nothing yet.

describe_collect()

As per the bluesky interface, this is how you interpret the null data from collect. There isn’t anything here, as nothing will be collected.

describe_configuration()

bluesky interface for describing how to interpret the configured values

Returns:

config_desc – Mapping of config key to field metadata.

Return type:

dict

disconnect()

Disconnect from the live DAQ, giving control back to the GUI.

This is the opposite of connect.

end_run()

Call stop, then mark the run as finished.

kickoff(events=<object object>, duration=<object object>, use_l3t=<object object>, controls=<object object>)

Begin acquisition. This method is non-blocking. See begin for a description of the parameters.

This method does not supply arguments for configuration parameters, it supplies arguments directly to pydaq.Control.begin. It will configure before running if there are queued configuration changes.

This is part of the bluesky Flyer interface.

Returns:

ready_statusStatus that will be marked as done when the daq has begun.

Return type:

Status

property next_config

The next queued configuration.

This can be different than config if we have queued up a configuration to be run on the next begin.

pause()

bluesky interface for determining what to do when a plan is interrupted. This will call stop, but it will not call end_run.

preconfig(events=<object object>, duration=<object object>, record=<object object>, use_l3t=<object object>, controls=<object object>, begin_sleep=<object object>, show_queued_cfg=True)

Queue configuration parameters for next call to configure.

These will be overridden by arguments passed directly to configure. These will be cleared after each call to configure.

This can be used to configure the Daq object without connecting.

This will display the next queued configuration using logger.info, assuming the logger has been configured.

read()

Return data. There is no data implemented yet.

This also stops if running so you can use this device in a bluesky scan and wait for “everything else” to be done, then stop the daq afterwards.

read_configuration()

bluesky interface for checking the current configuration

Returns:

config – Mapping of config key to current configured value and timestamp when it was last set.

Return type:

dict

property record

If True, we’ll configure the daq to record data. If False, we will configure the daq to not record data.

Setting this is the equivalent of scheduling a configure call to be executed later, e.g. configure(record=True)

resume()

bluesky interface for determining what to do when an interrupted plan is resumed. This will call begin.

run_number(hutch_name=None)

Determine the run number of the last run, or current run if running.

This requires you to be on an NFS-mounted host. If hutch can be determined from the get_hutch_name script from engineering_tools, then you don’t need to pass in a hutch name.

This is a method and not a property because all properties are run when you try to tab complete, and this isn’t necessarily an instant check. It can also display log messages, which would be annoying on tab complete.

Parameters:

hutch_name (str, optional) – The hutch to check the run number for. If omitted, we’ll guess the hutch based on your session details.

Returns:

run_number – The current run number, or previous run if not recording.

Return type:

int

Raises:
  • RuntimeError: – if we have no access to NFS

  • ValueError: – if an invalid hutch was passed

  • subprocess.TimeoutExpired: – if the get run number script fails

set_filter(*args, event_codes=None, operator='&', or_bykik=False)

Set up the l3t filters.

These connect through pyami to call set_l3t or clear_l3t. The function takes in arbitrary dets whose prefixes are the ami names, along with low and highs.

Event codes are handled as a special case, since you always want high vs low.

Note

If or_bykik is True, this will treat bykik at an l3t pass! This is so you don’t lose your off shots when the l3t trigger is in veto mode.

Parameters:
  • *args ((AmiDet, float, float) n times) – A sequence of (detector, low, high), which create filters that make sure the detector is between low and high. You can omit the first AmiDet as a shorthand for the current monitor, assuming a monitor has been set with Daq.set_monitor or set_monitor_det.

  • event_codes (list, optional) – A list of event codes to include in the filter. l3pass will be when the event code is present.

  • operator (str, optional) – The operator for combining the detector ranges and event codes. This can either be | to or the conditions together, so l3pass will happen if any filter passes, or it can be left at the default & to and the conditions together, so l3pass will only happen if all filters pass.

  • or_bykik (bool, optional) – False by default, appends an or condition that marks l3t pass when we see the bykik event code. This makes sure the off shots make it into the data if we’re in l3t veto mode.

set_monitor(det)

Designate one AmiDet as the monitor.

The monitor det is the default normalization detector and the default filtering detector when no detector is provided.

Parameters:

det (AmiDet or bool) – The detector to set as the monitor. Alternatively, pass in False to disable the monitor det.

stage()

bluesky interface for preparing a device for action.

This sets up the daq to end runs on run stop documents. It also caches the current state, so we know what state to return to after the bluesky scan. If a run is already started, we’ll end it here so that we can start a new run during the scan.

Returns:

staged – list of devices staged

Return type:

list

property state

State as reported by the daq. Can be any of the following: - Disconnected: No active session in python - Connected: Active session in python - Configured: Connected, and the daq has been configured - Open: We are in the middle of a run - Running: We are collecting data in a run

stop()

Stop the current acquisition, ending it early.

trigger()

Begin acquisition. This method blocks until the run begins.

Returns a status object that will be marked done when the daq has stopped acquiring.

This will raise a RuntimeError if the daq was never configured for events or duration.

Returns:

done_statusStatus that will be marked as done when the daq has begun.

Return type:

Status

unstage()

bluesky interface for undoing the stage routine.

Returns:

unstaged – list of devices unstaged

Return type:

list

wait(timeout=None)

Pause the thread until the DAQ is done aquiring.

Parameters:

timeout (float) – Maximum time to wait in seconds.

get_daq

Called by other modules to get the registered DaqBase instance.