BNMR: Mode changer
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
hasEnables CAMP scan=True
andPPG timing=1n
- Mode
2b
hasEnables RF=True
,RF scanned in PPG loop=True
andPPG 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)
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:
python 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()
inppg_prog_helper.py
- MUD to ODB in
load_from_old_run()
inmode_changer.py
Note that not all ODB settings are stored in the MUD file; in particular, PSM RF modulation parameters are generally not stored.
Changing mode without loading saved settings
Sometimes the saved settings for a mode can fail to load correctly. If this is the case, you can use the Expert webpage to change the mode and load the default settings for that mode.
Changing mode from the command-line
You may change the mode via a command-line interface as well as via webpages. This may be useful for scripting a series of runs.
python mode_changer.py --oneshot --mode=1f
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
ortest
- 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.
Resetting the run numbers
BNMR and BNQR reuse run numbers each year (i.e. you need to specify both the year and run number to identify a dataset).
At the start of each year, you need to reset the first run number to be used (and where the data is being written to).
cd /isdaq/data1/<expt>/dlog mkdir <year> rm current ln -s <year> current python ~/packages/<expt>/bnxr_common/mode_changer.py --reset_run_numbers