diff --git a/src/toolbox_scs/detectors/bam_detectors.py b/src/toolbox_scs/detectors/bam_detectors.py index 667d20afb4fa39b2626664d9ce7ecc6cada2096f..467cd602cf5eeaede6bfd4aba76d9be7dcf62fdc 100644 --- a/src/toolbox_scs/detectors/bam_detectors.py +++ b/src/toolbox_scs/detectors/bam_detectors.py @@ -14,9 +14,11 @@ import xarray as xr from ..misc.bunch_pattern_external import is_pulse_at from ..mnemonics_machinery import (mnemonics_to_process, mnemonics_for_run) +from ..constants import mnemonics as _mnemonics __all__ = [ 'get_bam', + 'get_bam_params', ] log = logging.getLogger(__name__) @@ -32,7 +34,7 @@ def get_bam(run, mnemonics=None, merge_with=None, bunchPattern='sase3'): Parameters ---------- run: extra_data.DataCollection - DataCollection containing the digitizer data. + DataCollection containing the bam data. mnemonics: str or list of str mnemonics for BAM, e.g. "BAM1932M" or ["BAM414", "BAM1932M"]. If None, defaults to "BAM1932M" in case no merge_with dataset @@ -111,3 +113,40 @@ def get_bam(run, mnemonics=None, merge_with=None, bunchPattern='sase3'): ds = mw_ds.merge(ds, join='inner') return ds + + +def get_bam_params(run, mnemo_or_source='BAM1932S'): + """ + Extract the run values of bamStatus[1-3] and bamError. + + Parameters + ---------- + run: extra_data.DataCollection + DataCollection containing the bam data. + mnemo_or_source: str + mnemonic of the BAM, e.g. 'BAM414', or source name, + e.g. 'SCS_ILH_LAS/DOOCS/BAM_414_B2. + + Returns + ------- + params: dict + dictionnary containing the extracted parameters. + + Note + ---- + The extracted parameters are run values, they do not reflect any + possible change during the run. + """ + + if mnemo_or_source in _mnemonics: + run_mnemonics = mnemonics_for_run(run) + source = run_mnemonics[mnemo_or_source]['source'].split(':')[0] + else: + source = mnemo_or_source + res = {} + res['status1'] = run.get_run_value(source, 'bamStatus1.value') + res['status2'] = run.get_run_value(source, 'bamStatus2.value') + res['status3'] = run.get_run_value(source, 'bamStatus3.value') + res['error'] = run.get_run_value(source, 'bamError.value') + + return res