8.6.1.7. pymodaq_data.h5modules.swmr module

Utilities for reading HDF5 files written with SWMR (Single Writer Multiple Reader) mode.

8.6.1.7.1. Typical usage

Open the file once, collect dataset references, then poll in a loop:

from pymodaq_data.h5modules import open_h5_file_for_reading from pymodaq_data.h5modules.swmr import collect_datasets, refresh_cached

f, is_swmr = open_h5_file_for_reading(“scan.h5”) cache = collect_datasets(f[“RawData”]) # dict[str, h5py.Dataset]

while acquiring:

refresh_cached(cache) data = cache[“/RawData/CH000/Data0D/Data00/data”][:]

pymodaq_data.h5modules.swmr.collect_datasets(group)[source]

Walk group recursively and return a mapping of absolute path → dataset.

The returned dict can be passed to refresh_cached() on every poll cycle instead of re-walking the tree each time.

Parameters:

group (Group) – Any h5py.Group (or h5py.File, which is also a group).

Returns:

{"/absolute/path": h5py.Dataset, ...} for every dataset found under group.

Return type:

Dict[str, Dataset]

Examples

>>> f, _ = open_h5_file_for_reading("scan.h5")
>>> cache = collect_datasets(f["RawData"])
>>> cache.keys()
dict_keys(['/RawData/CH000/Data0D/Data00/data', ...])
pymodaq_data.h5modules.swmr.refresh_cached(cache)[source]

Refresh every dataset in a pre-built cache dict.

This is the fast path for polling loops: call collect_datasets() once to build cache, then call this function on each iteration.

Parameters:

cache (Dict[str, Dataset]) – A {path: h5py.Dataset} dict as returned by collect_datasets().

Return type:

None

Examples

>>> cache = collect_datasets(f["RawData"])
>>> while acquiring:
...     refresh_cached(cache)
...     latest_row = cache["/RawData/CH000/Data0D/Data00/data"][-1]
pymodaq_data.h5modules.swmr.refresh_datasets(group)[source]

Refresh every dataset under group so that SWMR readers see the latest data written by the writer process.

This is a convenience wrapper for one-shot use. For polling loops prefer collect_datasets() + refresh_cached() to avoid re-walking the tree on every iteration.

Parameters:

group (Group) – Any h5py.Group (or h5py.File).

Return type:

None

Notes

refresh() is a metadata/chunk-index call; it does not read the actual data. The data is only transferred when you access dataset elements (ds[:], ds[-1], etc.).