Commit 90894a21 authored by payno's avatar payno
Browse files

Merge branch 'check_virtual_dataset' into 'master'

Check HDF5 virtual sources

See merge request !35
parents bf3ea398 5daae085
Pipeline #43901 passed with stages
in 13 minutes and 15 seconds
......@@ -27,15 +27,16 @@ __authors__ = ["W. de Nolf"]
__license__ = "MIT"
__date__ = "25/08/2020"
import h5py
from tomoscan.utils import SharedLockPool
import os
from contextlib import contextmanager
import logging
import os
import traceback
import errno
import h5py
from tomoscan.utils import SharedLockPool
HASSWMR = h5py.version.hdf5_version_tuple >= h5py.get_config().swmr_min_hdf5_version
_logger = logging.getLogger(__name__)
class HDF5File(h5py.File):
......@@ -127,3 +128,32 @@ def isErrno(e, errno):
# Because e.__cause__ is None for chained exceptions
return "errno = {}".format(errno) in "".join(traceback.format_exc())
def check_virtual_sources_exist(fname, data_path):
Check that a virtual dataset points to actual data.
:param str fname: HDF5 file path
:param str data_path: Path within the HDF5 file
:return bool res: Whether the virtual dataset points to actual data.
with HDF5File(fname, "r") as f:
if data_path not in f:
_logger.error("No dataset %s in file %s" % (data_path, fname))
return False
dptr = f[data_path]
if not dptr.is_virtual:
return True
for vsource in dptr.virtual_sources():
vsource_fname = os.path.join(
os.path.dirname(dptr.file.filename), vsource.file_name
if not os.path.isfile(vsource_fname):
_logger.error("No such file: %s" % vsource_fname)
return False
elif not check_virtual_sources_exist(vsource_fname, vsource.dset_name):
_logger.error("Error with virtual source %s" % vsource_fname)
return False
return True
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment