Commit 9bf73fff authored by Thomas Vincent's avatar Thomas Vincent

make open/close public

parent 65c5bfdc
......@@ -118,23 +118,35 @@ class XsocsH5Base(object):
if prev_mode is not None:
self.mode = prev_mode
def _open(self):
def open(self):
"""Open the file if it is not opened.
This increase the *open counter* by 1.
You MUST call :meth:`close` for each call to this method
"""
if self.__file is None:
self.__file = _h5py.File(self.__h5_f, self.mode)
self.__file_count += 1
def _close(self):
def close(self):
"""Decreases the *open counter* by 1.
If the *open counter* reaches 0, the HDF5 file is closed.
"""
if self.__file_count <= 0:
raise RuntimeError("Cannot close, open counter already 0")
self.__file_count -= 1
if self.__file_count == 0 and self.__file:
self.__file.close()
self.__file = None
def __enter__(self):
self._open()
self.open()
return self
def __exit__(self, *args):
self._close()
self.close()
def _get_scalar_data(self, path):
with self._get_file() as h5_file:
......
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