hdf5_file_singleton module¶
HDF5 file singleton used by the HDF5 cache.
- class gemseo.caches.hdf5_file_singleton.HDF5FileSingleton(*args, **kwargs)[source]
Bases:
object
Singleton to access an HDF file.
Used for multithreading/multiprocessing access with a lock.
- Parameters:
hdf_file_path – The path to the HDF file.
args (Any) –
kwargs (Any) –
- Return type:
Any
- clear(hdf_node_path)[source]
Clear a node.
- Parameters:
hdf_node_path (str) – The name of the HDF group to clear, possibly passed as a path
root_name/.../group_name/.../node_name
.- Return type:
None
- has_group(index, group, hdf_node_path)[source]
Check if an entry has data corresponding to a given group.
- keep_open()[source]
Keep the file open for all file operations done in this context manager.
- Return type:
Iterator[None]
- read_data(index, group, hdf_node_path)[source]
Read the data for given index and group.
- Parameters:
index (int) – The index of the entry.
group (AbstractCache.Group) – The group.
hdf_node_path (str) – The name of the HDF group where the entries are stored, possibly passed as a path
root_name/.../group_name/.../node_name
.
- Returns:
The group data and the input data hash.
- Raises:
ValueError – If the group cannot be found.
- Return type:
- read_hashes(hashes_to_indices, hdf_node_path)[source]
Read the hashes in the HDF file.
- classmethod update_file_format(hdf_file_path)[source]
Update the format of a HDF5 file.
GEMSEO 3.2.0 added a
HDF5FileSingleton.FILE_FORMAT_VERSION
to the HDF5 files, to allow handling its maintenance and evolutions. In particular, GEMSEO 3.2.0 fixed the hashing of the data dictionaries.- Parameters:
hdf_file_path (str | Path) – A HDF5 file path.
- Return type:
None
- write_data(data, group, index, hdf_node_path)[source]
Cache input data to avoid re-evaluation.
- Parameters:
data (DataMapping) – The data containing the values of the names to cache.
group (AbstractCache.Group) – The group.
index (int) – The index of the entry in the cache.
hdf_node_path (str) – The name of the HDF group to store the entries, possibly passed as a path
root_name/.../group_name/.../node_name
.
- Return type:
None
- FILE_FORMAT_VERSION: ClassVar[int] = 2
The version of the file format.
- HASH_TAG: ClassVar[str] = 'hash'
The label for the hash.
- hdf_file_path: str
The path to the HDF file.
- lock: RLockType
The lock used for multithreading.