Pycaldaq

Pycaldaq is a suite of Python code that allows users to easily interact with Pyrame, and more specifically the Run Control. It also allows to launch those scripts throught the graphical interface, once installed in /opt/pyrame/rc_scripts/.

For example, it allows to execute any transition of the Calicoes state machine.

We will analyze a simple run script to understand the way to use it:

#!/usr/bin/env python2

def timed_run_init():
    declare_param("run_name","name of run","test")
    declare_param("acq_time","duration of acquisition (min)","1")

def timed_run_run(run_name,acq_time):
    run=new_run(run_name)
    timed_acq("%s_minutes"%(acq_time),run,float(acq_time)*60)
    wait_run_finished(run)

def timed_run_get_progress():
    return progress_acq

execfile("/opt/calicoes/pycaldaq_rcs.py")

The name of the script is timed_run. The filename must therefore be named timed_run.py. At least one function named NAME_run must exist. In this case that is timed_run_run. Two more functions can optionally be used:

  • NAME_run: This is the main function that runs the script.
  • NAME_init: This is the initialization function. It is run when loading the script and is typically used to declare parameters. The declaration of parameters allows to define a description and a default value. This is how GUIs can expose meaningful dialogs for scripts.
  • NAME_get_progress: This function must return the progress status of the script at any moment. In the example, timed_acq sets a global variable named progress_acq that we can use externally.

At the end of the script, the mandatory execfile(“/opt/calicoes/pycaldaq_rcs.py”) command is required. pycaldaq_rcs.py will in turn load the required Pyrame’s /opt/pyrame/rc_script.py.

These scripts can be simply executed as ./timed_run.py or through the GUI.

See more information about Run Control Scripts on Pyrame’s documentation.

Functions available to scripts

pycaldaq_rcs.initialize()[source]

Perform the initialize transition. If not in UNDEFINED state, the necessary transitions to get to that state will also be performed beforehand

pycaldaq_rcs.deinitialize()[source]

Perform the deinitialize transition. If not in READY state, the necessary transitions to get to that state will also be performed beforehand

pycaldaq_rcs.fconfigure()[source]

Perform the configure transition. If not in READY state, the necessary transitions to get to that state will also be performed beforehand

pycaldaq_rcs.configure()[source]

Perform the configure transition. If not in READY state, the necessary transitions to get to that state will also be performed beforehand

pycaldaq_rcs.validate()[source]

Perform the validate transition. If not in RECONFIGURED state, the necessary transitions to get to that state will also be performed beforehand

pycaldaq_rcs.invalidate()[source]

Perform the invalidate transition. If not in CONFIGURED state, the necessary transitions to get to that state will also be performed beforehand

pycaldaq_rcs.start_acq(acq)[source]

Perform the start_acq transition. If not in CONFIGURED state, the necessary transitions to get to that state will also be performed beforehand

pycaldaq_rcs.stop_acq()[source]

Perform the stop_acq transition. If not in ACQUIRING state, the necessary transitions to get to that state will also be performed beforehand

pycaldaq_rcs.list_dev(dev_type, root)[source]

Get the list of devices from the current configuration of type dev_type descendants of device root.

pycaldaq_rcs.get_state()[source]

Get current state of ecal state machine

pycaldaq_rcs.get_dev_id(dev_name)[source]

Get id of device dev_name

pycaldaq_rcs.get_var(var_name)[source]

Get value of var_name in module varmod

pycaldaq_rcs.get_param(dev_name, param_name)[source]

Get value of parameter param_name of device dev_name in the current configuration

pycaldaq_rcs.reconfigure(dev_name, func, *params)[source]

Perform a reconfiguration by running function func on device dev_name with params arguments

pycaldaq_rcs.timed_acq(acq_name, run, acq_time)[source]

Performed a timed acquisition named acq_name in run run (object returned by new_run) during acq_time seconds

pycaldaq_rcs.nb_hits_acq(acq_name, run, nb_hits)[source]

Perform an acquisition with nb_hits hits, named acq_name in run run (object returned by new_run)

pycaldaq_rcs.nb_spills_acq(acq_name, run, nb_spills)[source]

Performed an acquisition named acq_name in run run (object returned by new_run) during nb_spills spills

pycaldaq_rcs.timed_scurves(acq_name, run, trig_max, trig_min, step, acq_time, roctype)[source]

Perform an timed S-curve run named run_name. Start on trigger threshold trig_max and descend with step down to trig_min. Each step takes acq_time seconds. roctype defined the type of ROC (skiroc,spiroc2d,...)

pycaldaq_rcs.nb_hits_scurves(acq_name, run, trig_max, trig_min, step, nb_hits, roctype)[source]

Perform an S-curve run named run_name with a defined number of hits nb_hits per step. Start on trigger threshold trig_max and descend with step down to trig_min. roctype defined the type of ROC (skiroc,spiroc2d,...)

pycaldaq_rcs.run_cmdfile(filename)[source]

Run as python code every line of filename separately until a line with the keyword quit is found

pycaldaq_rcs.check_stop()

Check if the stop flag has been set by the Run Control. If yes, raise a rc_stop_exception

pycaldaq_rcs.declare_param(name, desc, value)

Declare script parameter named name and described by desc. Initialized to value.

pycaldaq_rcs.get_param_acq_rcs(storage_id, acq, name)

Get the value of parameter name for acquisition acq (object returned by new_acq). Use the storage module with storage_id

pycaldaq_rcs.get_param_run_rcs(storage_id, run, name)

Get the value of parameter name for run (object returned by new_run). Use the storage module with storage_id

pycaldaq_rcs.int_sleep(timeout)

Perform an interruptible sleep of timeout seconds

pycaldaq_rcs.load_config_file(filename)

Load an XML configuration file filename

pycaldaq_rcs.new_acq_rcs(storage_id, acq_name, run, mode='append', convert_script='undef')

Create a new acquisition named acq_name in run. mode can be remove or append. ‘remove’ overwrites any existing acq with the same name. Use the storage module with storage_id

pycaldaq_rcs.new_run_rcs(storage_id, run_name, mode='append')

Create a new run named run_name. mode can be remove or append. ‘remove’ overwrites existing runs with the same name. Use the storage module with storage_id

pycaldaq_rcs.rc_call(function, *args)

Performs a call to a pyrame function through RC. This function checks for stop signal before returning

pycaldaq_rcs.rc_exec(command, *params)

Executes a command in a shell and checks for stop signal and turns bash returns 1 into exceptions and returns output (stdout and stderr) of command

pycaldaq_rcs.rc_pycall(function, *args)

Performs a call to a pyrame function through RC. This function checks for stop signal before returning

pycaldaq_rcs.save_config_file(filename)

Save the current configuration file to filename

pycaldaq_rcs.set_param_acq_rcs(storage_id, acq, name, value)

Set the value of parameter name for acquisition acq (object returned by new_acq). Use the storage module with storage_id

pycaldaq_rcs.set_param_run_rcs(storage_id, run, name, value)

Set the value of parameter name for run (object returned by new_run). Use the storage module with storage_id

pycaldaq_rcs.transition(dev_name, transition_name, transition_fallback, params='')

Perform an arbitrary transition with name transition_name and in case of error, perform the transition transition_fallback. Pass params to transitions

pycaldaq_rcs.wait_acq_finished_rcs(storage_id, acq)

Wait until the acquisition acq (object returned by new_acq) has finished. Use the storage module with storage_id

pycaldaq_rcs.wait_run_finished_rcs(storage_id, run)

Wait until the run run (object returned by new_run) has finished. Use the storage module with storage_id

As you can see, it is very easy to create calibration sequences with this tool. You are also free to launch an analysis tool at every iteration with the rc_exec command. This tool can generate reconfigure patterns (in a file for example) that can be applied by the run_cmdfile pycaldaq script.