Skip to content

Commit

Permalink
MNT #14 integrate
Browse files Browse the repository at this point in the history
  • Loading branch information
prjemian committed Nov 28, 2024
1 parent f9d48b8 commit a97940b
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 8 deletions.
9 changes: 6 additions & 3 deletions src/instrument/configs/iconfig.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,12 @@ RUN_ENGINE:
### Default: `RE.md["scan_id"]` (not using an EPICS PV)
# SCAN_ID_PV: f"{IOC}bluesky_scan_id"

### Directory to "autosave" the RE.md dictionary (uses PersistentDict).
### Default: HOME/.config/Bluesky_RunEngine_md'
# MD_PATH: /home/beams/USERNAME/.config/Bluesky_RunEngine_md
### Where to "autosave" the RE.md dictionary.
### Defaults:
# MD_STORAGE_HANDLER: PersistentDict
# MD_PATH: HOME/.config/Bluesky_RunEngine_md'
MD_STORAGE_HANDLER: StoredDict
MD_PATH: .re_md_dict.yml

### The progress bar is nice to see,
### except when it clutters the output in Jupyter notebooks.
Expand Down
16 changes: 12 additions & 4 deletions src/instrument/core/run_engine_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
from ..utils.controls_setup import set_timeouts
from ..utils.metadata import MD_PATH
from ..utils.metadata import re_metadata
from ..utils.stored_dict import StoredDict
from .best_effort_init import bec
from .catalog_init import cat

Expand All @@ -31,13 +32,20 @@

# Save/restore RE.md dictionary, in this precise order.
if MD_PATH is not None:
handler_name = re_config.get("MD_STORAGE_HANDLER", "PersistentDict")
try:
RE.md = bluesky.utils.PersistentDict(MD_PATH)
except Exception as e:
handler = {
"PersistentDict": bluesky.utils.PersistentDict,
"StoredDict": StoredDict,
}[handler_name]
RE.md = handler(MD_PATH)
except Exception as error:
print(
f"\n Could not create PersistentDict for RE metadata. Continuing without "
f"saving metadata to disk. The error is: {e} \n"
"\n"
f"Could not create {handler_name} for RE metadata. Continuing"
f" without saving metadata to disk. {error=}\n"
)
logger.warning("%s('%s') error:%s", handler_name, MD_PATH, error)

RE.md.update(re_metadata(cat)) # programmatic metadata
RE.md.update(re_config.get("DEFAULT_METADATA", {}))
Expand Down
4 changes: 3 additions & 1 deletion src/instrument/utils/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,13 @@
pysumreg=pysumreg.__version__,
spec2nexus=spec2nexus.__version__,
)
RE_CONFIG = iconfig.get("RUN_ENGINE", {})


def get_md_path():
"""Get PersistentDict directory for RE metadata."""
path = pathlib.Path(iconfig.get("MD_PATH", DEFAULT_MD_PATH))
md_path_name = RE_CONFIG.get("MD_PATH", DEFAULT_MD_PATH)
path = pathlib.Path(md_path_name)
logger.info("RunEngine metadata saved in directory: %s", str(path))
return str(path)

Expand Down

0 comments on commit a97940b

Please sign in to comment.