The DetConfig System

DetConfig is the sodetlib module that manages and groups all configuration info.

Loading a Configuration

Below is an example for how to populate the DetConfig object for slot 2:

from sodetlib.det_config import DetConfig

cfg = DetConfig()
cfg.load_config_files(slot=2)

When being run in a script, the DetConfig object will populate an Argparse parser with its own command line arguments with the parse_args function. This can be used as follows:

from sodetlib.det_config import DetConfig

cfg = DetConfig()
cfg.parse_args()

This will pull the slot number and additional info from the command line. Details can be seen in the DetConfig parser and API sections.

Once the configuration has been loaded, the get_smurf_control function can be used to create a pysmurf-instance based on the configuration info. The DetConfig object will automaticlly determine the epics root and set the publisher ID based on the crate and slot number. If dump_configs is set to True, all configuration files will be copied to the pysmurf output directory. For example:

from sodetlib.det_config import DetConfig

cfg = DetConfig()
cfg.load_config_files(slot=2)
S = cfg.get_smurf_control(dump_configs=True)

It is also possible to take all the configuration information and apply it to the pysmurf-instance using the apply_dev_configs argument. This is useful for things like loading pre-set amplifier biases. The argument load_device_tune can be used to automatically load the tune file in the configuration file:

S = cfg.get_smurf_control(dump_configs=True, make_logfile=True,
                      apply_dev_configs=True, load_device_tune=True)

DetConfig parser arguments

usage: python3 sodetlib_script.py [-h] [--sys-file SYS_FILE]
                                  [--dev-file DEV_FILE]
                                  [--pysmurf-file PYSMURF_FILE]
                                  [--uxm-file UXM_FILE] [--slot SLOT]
                                  [--dump-configs]

Named Arguments

--sys-file

Path to sys-config file. Defaults to $SMURF_CONFIG_DIR/sys_config.yml

--dev-file

Path to device-config file. Defaults to the path specified in the sys_config.

--pysmurf-file

Path to Pysmurf config file. Defaults to the path specified in the sys_config.

--uxm-file

Path to the uxm file. Defaults to the path specified in the sys_config

--slot, -N

Smurf slot

--dump-configs, -D

If true, all config info will be written to the pysmurf output directory

Default: False

Using and Updating the Device Config

The device configuration options are stored in the cfg.dev object, split between the exp dictionary for “experiment” level configuraiton, bias_groups which is a list of 12 config dicts containing bias group options, and bands which is a list of 8 dicts containing band configuration.

The methods update_experiment, update_bias_group and update_band can be used to update these configuration objects with new or modified config parmeters. Once updated, a new device config file can be written with the dump function. See the API section for function details.

Here is an example of a function that takes in a config object, modifies dome device configuration options, and writes over the device file with the new parameters:

def optimize_drive_power(S, cfg, band):
   # Logic to find optimial drive power for current cfg params goes here:
   optimal_drive = get_optimal_drive()

   cfg.dev.update_band(band, {'drive': optimal_drive})
   cfg.dev.dump(cfg.dev_file, clobber=True)

API

DetConfig

class sodetlib.det_config.DetConfig(slot=None, sys_file=None, dev_file=None, pysmurf_file=None, uxm_file=None)

General Configuration class for SODETLIB.

sys_file

Path to sys-config file used.

Type:

path

dev_file

Path to device-config file used

Type:

path

pysmurf_file

Path to pysmurf-config file used.

Type:

path

uxm_file

Path to uxm file

Type:

path

sys

System configuration dictionary, generated from the sys_config.yml file or --sys-file command line argument.

Type:

dict

dev

Device configuration dictionary, generated from the device_config file specified in the sys_config or specified by the --dev-file command line argument

Type:

dict

get_smurf_control(offline=False, epics_root=None, smurfpub_id=None, make_logfile=False, setup=False, dump_configs=None, config_dir=None, apply_dev_configs=False, load_device_tune=True, **pysmurf_kwargs)

Creates pysmurf instance based off of configuration parameters. If not specified as keyword arguments epics_root and smurf_pub will be created based on the slot and crate id’s.

Parameters:
  • offline (bool) – Whether to start pysmurf in offline mode. Defaults to False

  • epics_root (str, optional) – Pysmurf epics root. If none, it will be set to smurf_server_s<slot>.

  • smurfpub_id (str, optional) – Pysmurf publisher ID. If None, will default to crate<crate_id>_slot<slot>.

  • make_logfile (bool) – Whether pysmurf should write logs to a file (True) or stdout(False). Defaults to stdout.

  • setup (bool) – Whether pysmurf should run a full setup. Defaults to False.

  • dump_configs (bool) – Whether all configuration settings should be dumped to pysmurf data directory. Defaults to True.

  • **pysmurf_kwargs – Any additional arguments to be passed to pysmurf initialization.

load_config_files(slot=None, sys_file=None, dev_file=None, pysmurf_file=None, uxm_file=None)

Loads configuration files. If arguments are not specified, sensible defaults will be chosen.

Parameters:
  • slot (int, optional) – pysmurf slot number. If None and there is only a single slot in the sys_file, it will use that slot. Otherwise, it will throw and error.

  • sys_file (path, optional) – Path to sys config file. If None, defaults to $SMURF_CONFIG_DIR/sys_config.yml

  • dev_file (path, optional) – Path to the Device file. If None, defaults to the device file specified in the sys-config file (device_configs[slot-2]).

  • pysmurf_file (path, optional) – Path to pysmurf config file. If None, defaults to the file specified in the sys-config (pysmurf_configs[slot-2]).

  • uxm_file (path, optional) – Path to uxm file

parse_args(parser=None, args=None)

Parses command line arguments along with det_config arguments and loads the correct configuration. See load_config for how config files are determined.

Parameters:
  • parser (argparse.ArgumentParser, optional) – custom argparse parser to parse args with. If not specified, will create its own.

  • args (list, optional) – List of command line arguments to parse. Defaults to the command line args.

DeviceConfig

class sodetlib.det_config.DeviceConfig

Configuration object containing all “device” specific information. That is, parameters that will probably change based on which test-bed you are using and what hardware is loaded into that test-bed. Device configuration info is split into three groups: experiment, bias_groups and bands.

The experiment group contains data that is relevant to the whole experiment, e.g. the tunefile that should be loaded or the amplifier currents and voltages that should be set.

The bias_groups group contains data for each individual bias group. For instance this is where the bias_high/low/step values are stored for each bias group.

The bands group contains data for each individual band. For instance, the dc_att and drive values.

exp

Dict with experiment config options

Type:

dict

bias_groups

List of 12 bias group configuration dictionaries.

Type:

list

bands

List of 8 band configuration dictionaries.

Type:

list