Daq API¶
- class pcdsdaq.daq.Daq(RE=None, hutch_name=None)¶
The LCLS1 daq as a
bluesky-compatible object.This uses the
pydaqmodule to connect with a running daq instance, controlling it via socket commands.It can be used as a
Readerin ablueskyplan to take data at discrete scan points.It can be used as a
Flyerin ablueskyplan to have the daq start at the beginning of the run and end at the end of the run.Unlike normal
blueskyreadable devices or flyers, this has no data to report to theRunEngineon thereadorcollectcalls. No data will pass into the python layer from the daq.- Parameters:
RE (
RunEngine, optional) – SetREto the session’s mainRunEnginehutch_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=Trueuntil the daq has finished aquiring data. If blocking, actrl+cwill end the run and clean up.If omitted, any argument that is shared with
configurewill fall back to the configured value.Internally, this calls
kickoffand manages itsStatusobject.- Parameters:
events (
int, optional) – Number events to take in the daq.duration (
int, optional) – Time to run the daq in seconds, ifeventswas not provided.record (
bool, optional) – IfTrue, we’ll configure the daq to record data before this run.use_l3t (
bool, optional) – IfTrue, 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}orlist[device...], optional) – If provided, values from these will make it into the DAQ data stream as variables. We will checkdevice.positionanddevice.valuefor quantities to use and we will update these values each time begin is called. To provide a list, all devices must have anameattribute.wait (
bool, optional) – IfTrue, wait for the daq to finish aquiring data. AKeyboardInterrupt(ctrl+c) during this wait will end the run and clean up.end_run (
bool, optional) – IfTrue, 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
blueskyFlyerinterface.As per the
blueskyinterface, 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
stopthe daq. Otherwise, we’ll simply collect the end_status object.- Returns:
end_status –
Statusthat will be marked as done when the DAQ has finished acquiring- Return type:
Status
- 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 inbegin. If not provided, we’ll use thedurationargument instead. Defaults to its last configured value, orNoneon the first configure.duration (
int, optional) – If provided, the daq will run for this many seconds before stopping, unless we override inbegin. If not provided, andeventswas also not provided, an empty call likebegin()will run indefinitely. You can also achieve this behavior by passing events=None and/or duration=None, Defaults to its last configured value, orNoneon the first configure.record (
bool, optional) – IfTrue, we’ll record the data. IfFalse, we’ll run without recording. IfNone, we’ll use the option selected in the DAQ GUI. Defaults to the its last configured value, orNoneon the first configure.use_l3t (
bool, optional) – IfTrue, aneventsargument to begin will be reinterpreted to only count events that pass the level 3 trigger. Defaults to its last configured value, orFalseon the first configure.controls (
dict{name: device}orlist[device...], optional) – If provided, values from these will make it into the DAQ data stream as variables. We will checkdevice.positionanddevice.valuefor quantities to use and we will update these values each time begin is called. To provide a list, all devices must have anameattribute. 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:
tupleofdict
- property configured¶
Trueif the daq is configured,Falseotherwise.
- connect()¶
Connect to the live DAQ, giving full control to the Python process.
To undo this, you may call
disconnect.
- property connected¶
Trueif the daq is connected,Falseotherwise.
- describe()¶
Explain what read returns. There is nothing yet.
- describe_collect()¶
As per the
blueskyinterface, this is how you interpret the null data fromcollect. There isn’t anything here, as nothing will be collected.
- describe_configuration()¶
blueskyinterface 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.
- kickoff(events=<object object>, duration=<object object>, use_l3t=<object object>, controls=<object object>)¶
Begin acquisition. This method is non-blocking. See
beginfor 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
blueskyFlyerinterface.- Returns:
ready_status –
Statusthat 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
configif we have queued up a configuration to be run on the next begin.
- pause()¶
blueskyinterface for determining what to do when a plan is interrupted. This will callstop, but it will not callend_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 toconfigure.This can be used to
configuretheDaqobject 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()¶
blueskyinterface 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. IfFalse, we will configure the daq to not record data.Setting this is the equivalent of scheduling a
configurecall to be executed later, e.g.configure(record=True)
- resume()¶
blueskyinterface for determining what to do when an interrupted plan is resumed. This will callbegin.
- 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 firstAmiDetas a shorthand for the current monitor, assuming a monitor has been set withDaq.set_monitororset_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|toorthe conditions together, so l3pass will happen if any filter passes, or it can be left at the default&toandthe conditions together, so l3pass will only happen if all filters pass.or_bykik (
bool, optional) – False by default, appends anorcondition 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
AmiDetas the monitor.The monitor det is the default normalization detector and the default filtering detector when no detector is provided.
- Parameters:
det (
AmiDetorbool) – The detector to set as the monitor. Alternatively, pass inFalseto disable the monitor det.
- stage()¶
blueskyinterface 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
blueskyscan. 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_status –
Statusthat will be marked as done when the daq has begun.- Return type:
Status
- unstage()¶
blueskyinterface for undoing thestageroutine.- 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.
Called by other modules to get the registered |