BNMR: Mode changer

From DaqWiki
Revision as of 16:58, 27 April 2022 by Bsmith (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Introduction

The mode changer program mode_changer.py is responsible for:

  • re-configuring the ODB when the user wants to change experimental mode
  • letting the user change between real and test runs (including changing the run number accordingly)
  • saving ODB settings (both manually and automatically when the user changes mode)
  • loading ODB settings (both manually, automatically when the user changes mode, and from previous MUD files)

The program is built using Midas' python tools, and provides a JRPC interface that webpages can use to interact with it (e.g. getting the list of supported modes; requesting that the mode be changed).

Changing mode

Modes are defined as a combination of features. For example:

  • Mode 1c has Enables CAMP scan=True and PPG timing=1n
  • Mode 2b has Enables RF=True, RF scanned in PPG loop=True and PPG timing=2b

When changing modes, the program:

  • saves the current ODB settings for the old mode
  • loads the most recent settings that were used with the new mode (if available)
  • changes the flags in /CurrentMode to those of the new mode (this lets other programs know what features should be enabled, without having to refer directly to mode names)

Changing between real and test runs

Note that the user may change between real/test while a run is in progress!

When changing between real and test runs, the program:

  • changes the key /RealOrTest/Name to real or test
  • computes the new run number to use
  • enables the alarm system and helicity checks if changing to a real run
  • tells the data logger about the new configuration via JRPC (this lets it rename data files that have already been written for this run and name new files appropriately). JRPC is used rather than an ODB hotlink so that errors can be reported to the user more effectively.

Saving and loading ODB settings

Saving and loading of ODB parameters build on the odb_save_load package, which provides the raw tools for saving parts of the ODB as JSON files on disk, with metadata like a comment and save date.

The mode changer program extends this functionality by automatically saving/loading settings when changing modes, and integrating the "manual" saving/loading with the custom settings page.

What gets saved

The definition of which bits of the ODB get saved is stored in /Saveload/Sections. It currently includes:

  • /Equipment/PPGCompiler/Settings
  • /Equipment/PPGCompiler/Programming
  • /Equipment/RFCalculator/PPG questions
  • /Scanning/PSM/Settings
  • /Scanning/BNXRCustomCycleLogic/Settings
  • /Scanning/Histograms/Settings
  • /Scanning/SampleReference/Settings
  • /Scanning/Epics/Settings
  • /Scanning/Camp/Settings
  • /Scanning/Global/Settings
  • /Scanning/Helicity/Settings

Handling changes to the ODB structure

Experiments often edit their DAQ code to add/remove keys. This can cause a problem if you later try to load some settings that were saved with the "old" ODB structure. To avoid these issues, the odb_save_load/save_load.py python script allows you to adjust the saved settings in a fairly user-friendly way.

All of the commands accept an --odb-path argument. The script will automatically determine which section that ODB path belongs to, find the right bit of the ODB structure in the saved file, and modify it accordingly.

The possible commands are:

  • add_from_live - read the current value of an ODB key from the live experiment, and store it in any files that don't currently have that key. Files that already have that key present are not touched.
  • add - like add_from_live, but manually specify the value to store as the --json-value parameter. You should encode the new value as the value member of a JSON string, e.g. --json-value='{"value": true}' to store a boolean true. Files that already have the key present are not touched.
  • delete - remove the specified ODB key from all saved settings that contain it.
  • edit_from_live - like add_from_live, but also change the value in files that already have the key present.
  • edit - like add, but also change the value in files that already have the key present.

A full example command would be:

python3.6 save_load.py add_from_live --odb-path="/Equipment/PPGCompiler/Settings/Enable formulae" odb_save_load/save_load.py

Loading settings from a MUD file

The mode changer also allows loading any ODB settings that were saved in the MUD file. It uses the bdata package to load the file and get the list of variables that were saved. The RF calculator uses the mud_ind_var_links.py file to decide which ODB variables should be saved for each mode (mapping "real" ODB locations to names in the MUD file), and the mode changer uses the same file to go in the opposite direction (mapping names in the MUD file to ODB locations).

Unfortunately, some variables are stored differently in the MUD file vs the ODB (e.g. booleans in the ODB vs a string in the MUD file). These "manipulations" are defined in two places:

  • ODB to MUD in compute_ppg_xxx() in ppg_prog_helper.py
  • MUD to ODB in load_from_old_run() in mode_changer.py

Note that not all ODB settings are stored in the MUD file; in particular, PSM RF modulation parameters are generally not stored.