How to account for changes in source / key of the mnemonics?
From time to time the name of the key or source attributes of the variables change in Karabo, and these changes must be reflected in the mnemonics.
Typical example is a quick fix to the bunchPatternTable mnemonic: ee69aac8. This fix implies a modification of the code everywhere the mnemonic is used, which is not convenient.
One solution could be the following:
- Add a layer in the definition of the mnemonics to support changes: A mnemonic would have a key 'actual' or 'current' in which the most up-to-date dict with source, key and dim, and other keys like 'pre20210415' for former definitions of the source, key and dim.
Example:
mnemonics = {
'bunchPatternTable': {'actual': {'source': 'SCS_RR_UTC/TSYS/TIMESERVER:outputBunchPattern',
'key': 'data.bunchPatternTable'
'dim': ['pulse_slot']},
'pre20210415': {'source': 'SCS_RR_UTC/TSYS/TIMESERVER',
'key': 'bunchPatternTable.value'
'dim': ['pulse_slot']}
...older versions here
}
}
- Getting the right version of the mnemonic could be facilitated using a function like this, provided an extra_Data DataCollection
run
:
def mnemonic_for_run(run, mnemo):
for version in mnemonics[mnemo]:
if version['source'] in run.all_sources and version['key'] in run.keys_for_source(version['source']):
log(found the correct version for the mnemonic)
return mnemonics[mnemo][version]
log(Error here, no source/key found in the run)
- Loading the corresponding array could be done in a function, with a version argument instead of automatically finding it:
def load_from_mnemo(run, mnemo, version=None):
if version is None:
version = mnemonic_for_run(run, mnemo)
return run.get_array(*mnemonics[mnemo][version].values())
One drawback is that it makes the mnemonics array a bit lengthy, but the main advantage is that it can support many changes and the mnemonic word itself does not change: 'bunchPatternTable' will remain 'bunchPatternTable'.
@lleguy what do you think?