CFEL - ASG Software Suite
2.5.0
CASS
|
A handler for h5 files. More...
#include <hdf5_handle.hpp>
Public Member Functions | |
Handler () | |
default constructor More... | |
Handler (const std::string &filename, const std::string &mode="w") | |
constructor opening the file More... | |
~Handler () | |
destructor More... | |
void | close () |
close the file used by this handler More... | |
void | open (const std::string &filename, const std::string &mode="w", int size=-1) |
open a file More... | |
template<typename type > | |
void | writeScalar (const type value, const std::string &valname) |
write an scalar value with a given name as part of a given group More... | |
template<typename type > | |
type | readScalar (const std::string &valname) |
read an scalar value with a given name as part of a given group More... | |
template<typename type > | |
void | writeArray (const std::vector< type > &array, const size_t arrayLength, const std::string &valname, int compressLevel=2) |
write a 1d array with a given name More... | |
template<typename type > | |
void | readArray (std::vector< type > &array, size_t &arrayLength, const std::string &valname) |
read a array with a given name into a linearized array More... | |
template<typename type > | |
void | writeMatrix (const std::vector< type > &matrix, std::pair< size_t, size_t > shape, const std::string &valname, int compressLevel=2) |
write a linearized matrix with a given name More... | |
template<typename type > | |
void | readMatrix (std::vector< type > &matrix, std::pair< size_t, size_t > &shape, const std::string &valname) |
read a matrix with a given name into a linearized array More... | |
template<typename type > | |
void | appendData (const std::vector< type > &data, shape_t shape, const std::string &valname, int compressLevel=2) |
create/append data to a multidimensional dataset More... | |
template<typename type > | |
void | readMultiDim (std::vector< type > &data, shape_t &shape, const std::string &valname) |
read a multidimensional dataset with a given name into a linearized array More... | |
template<typename type > | |
void | readPartialMultiDim (typename std::vector< type >::iterator data, const partiality_t &part, const std::string &valname) |
partially read a multidimensional dataset with a given name into a linearized array More... | |
void | writeString (const std::string &string, const std::string &dsetName) |
write a string dataset More... | |
std::string | readString (const std::string &dsetName) |
read a string dataset More... | |
template<typename type > | |
void | writeScalarAttribute (const type value, const std::string &valname, const std::string &dsetName) |
write an float scalar attribute with a given name as part of a given dataset More... | |
template<typename type > | |
type | readScalarAttribute (const std::string &valname, const std::string &dsetName) |
read an scalar attribute with a given name as part of a given dataset More... | |
std::string | filename () const |
retrieve the filename of the file associated with the handler More... | |
shape_t | shape (const std::string &valname) const |
get the shape of a dataset with a given name More... | |
size_t | dimension (const std::string &valname) const |
get the dimension of a value with a given name More... | |
dsetList_t | datasets () const |
get the list of datasets in the file More... | |
dsetList_t | rootGroups () const |
get the list of groups of the root group in the file More... | |
size_t | currentFileSize () const |
retrieve the size of the current file More... | |
Private Member Functions | |
Handler (const Handler &) | |
prevent copy construction More... | |
std::string | reopenFile (int &filehandle, size_t maxsize, const std::string ¤tfilename) |
check filesize and open new file if too big More... | |
bool | groupExists (const std::string &groupname) |
check if a groups exists More... | |
void | ensureGroupExists (const std::string &name) |
make sure that the requested group for the datset exists More... | |
Private Attributes | |
hid_t | _fileid |
the file handle More... | |
A handler for h5 files.
Definition at line 167 of file hdf5_handle.hpp.
|
inlineprivate |
prevent copy construction
Definition at line 171 of file hdf5_handle.hpp.
|
inline |
default constructor
Definition at line 177 of file hdf5_handle.hpp.
|
inline |
constructor opening the file
mode | Open the file in read "r" or write "w" mode. Default is "w" |
filename | the name of the file to open |
Definition at line 184 of file hdf5_handle.hpp.
References open().
|
inline |
destructor
flushes and cloeses the file if it is open
Definition at line 194 of file hdf5_handle.hpp.
References close().
|
inline |
create/append data to a multidimensional dataset
The name can contain the group that the value should be written to
type | The type that should be written |
data | the matrix to be written |
shape | the shape of the matrix (first is cols, second is rows) |
valname | the name of the value |
compressLevel | the compression level of the matrix |
turn off error output
ensure that the goup where the data will be appended to exists
get the dataset and check if the dataset exists
the dataset seems to not exist, so create it
create the file dataspace, where the first dim is unlimited
create the property list to be chunked
create the dataset
close the resources
get the filespace of the dataset to extract the current dimensions
get the nbr of dimensions and the dimensions of the dataset
release the old dataspace of the dataset, later we get the new extended filespace of the dataset
check if the dimensions fit the to be appended datas dimensions
create space in memory for the new data of the dataset
extent the dataset so that it can incldue the newly added data
get the filespace of the extended dataset
create hyperslab on the file dataspace where the data will be written to later on
Definition at line 572 of file hdf5_handle.hpp.
References _fileid, ensureGroupExists(), offset, and status.
|
inline |
close the file used by this handler
Definition at line 202 of file hdf5_handle.hpp.
References _fileid.
Referenced by ~Handler().
|
inline |
retrieve the size of the current file
Definition at line 1189 of file hdf5_handle.hpp.
|
inline |
get the list of datasets in the file
Definition at line 1154 of file hdf5_handle.hpp.
References _fileid, hdf5::dataset_iterator_func(), and status.
|
inline |
get the dimension of a value with a given name
retrieve the dataset with the given name, then the dataspace for the dataset. Judge by the type and the number of dimension what the dimensions are.
valname | the name of the value |
Definition at line 1072 of file hdf5_handle.hpp.
References _fileid.
Referenced by cass::HDF5FileInput::runthis().
|
inlineprivate |
make sure that the requested group for the datset exists
strip off the datasetname and check if the group exists. If it doesn't create the group once. Do this with each subgroup until the full path is checked.
name | absolute path containing also the datasetname |
prepend a '/' if its not there to ensure that it is a absolute path
Definition at line 1274 of file hdf5_handle.hpp.
References _fileid, and groupExists().
Referenced by appendData(), writeArray(), writeMatrix(), and writeScalar().
|
inline |
retrieve the filename of the file associated with the handler
determine the size of the filename (which is the return value of the query function
allocate a vector of chars to hold the filanme
and retrieve the filename
use the iterator constructor of string to convert the vector of chars to string
Definition at line 1005 of file hdf5_handle.hpp.
References _fileid, and status.
Referenced by open(), and readPartialMultiDim().
|
inlineprivate |
check if a groups exists
for now just checks if an absolute path exists in the file. Need to turn off error output, since the command will issue an error when the group does not exist.
groupname | the name of the group in absolute path |
Definition at line 1259 of file hdf5_handle.hpp.
References _fileid.
Referenced by ensureGroupExists().
|
inline |
open a file
logic_error | when file could not be opened |
filename | the name of the file to be opened |
mode | Open the file in read "r", write "w" or in read write "rw" mode. Default is "w" |
size | the size of the cache for chuncked data in MB |
Definition at line 221 of file hdf5_handle.hpp.
References _fileid, filename(), and size.
Referenced by Handler().
|
inline |
read a array with a given name into a linearized array
reads a array from the h5 file. The dimensions of the matrix will be returned in the arrayLength and the vector will be resized to fit the data before copying the data into the vector.
type | The type that should be read |
[out] | array | the array that will be read |
[out] | arrayLength | the length of the array |
[in] | valname | the name of the value |
turn off error output
Definition at line 405 of file hdf5_handle.hpp.
References _fileid, and status.
Referenced by cass::HDF5FileInput::runthis().
|
inline |
read a matrix with a given name into a linearized array
reads a matrix from the h5 file. The dimensions of the matrix will be returned in the shape parameter and the vector will be resized to fit the data before copying the data into the vector.
type | The type that should be written |
matrix | the matrix to be read |
shape | the shape of the matrix |
valname | the name of the value |
turn off error output
Definition at line 519 of file hdf5_handle.hpp.
References _fileid, and status.
Referenced by cass::HDF5FileInput::runthis().
|
inline |
read a multidimensional dataset with a given name into a linearized array
reads a multidimensional dataset from the h5 file. The dimensions of the dataset will be returned as it is stored in the hdf5 file in the shape parameter and the vector will be resized to fit the data before copying the data into the vector.
type | The type that should be written |
data | the multidimensional data that will be read |
shape | the shape of the matrix |
valname | the name of the value |
turn off error output
Definition at line 729 of file hdf5_handle.hpp.
|
inline |
partially read a multidimensional dataset with a given name into a linearized array
reads a part of a multidimensional dataset from the h5 file.
type | The type that should be read |
data | pointer to the space where the data will be written to. |
part | the part that should be read |
valname | the name of the value |
turn off error output
do some error checking (check if provided params are suitable
set up the memory and the hypserlab for the partial read
read the partial data directly into the provided dataspace
Definition at line 785 of file hdf5_handle.hpp.
References _fileid, hdf5::partiality_t::block, hdf5::partiality_t::count, hdf5::partiality_t::dims, filename(), hdf5::partiality_t::offset, status, and hdf5::partiality_t::stride.
|
inline |
read an scalar value with a given name as part of a given group
create a dataspace and a dataset for writing the scalar value as part of the given group. Then write the value and close all resources later on.
type | The scalar type that should be written |
valname | the name of the value |
turn off error output
open the scalar dataset
read the attribute and close the resources
Definition at line 307 of file hdf5_handle.hpp.
References _fileid, status, and value.
Referenced by cass::HDF5FileInput::runthis().
|
inline |
read an scalar attribute with a given name as part of a given dataset
invalid_argument | when the requested parameter is not present |
type | The type of the scalar value |
valname | the name of the value |
dsetName | the Name of the Dataset |
turn off error output
open the dataset that the attribute should be added to
attach to the scalar attribute of the dataset and read it
read the attribute and close the resources
Definition at line 969 of file hdf5_handle.hpp.
|
inline |
read a string dataset
dsetName | the name of the dataset that contains the string |
turn off error output
Definition at line 891 of file hdf5_handle.hpp.
|
inlineprivate |
check filesize and open new file if too big
check if the current size of the h5 file is bigger than the user set maximum file size. When this is the case, close the current file and open a new file with the same file name, but with an increasing extension.
filehandle | the filehandle to the hdf5 file |
maxsize | the maximum size of the file before a new file is opened |
currentfilename | the name of the current hdf5 file |
Definition at line 1215 of file hdf5_handle.hpp.
References found.
|
inline |
get the list of groups of the root group in the file
Definition at line 1173 of file hdf5_handle.hpp.
References _fileid, hdf5::group_iterator_func(), and status.
Referenced by cass::HDF5FileInput::runthis().
|
inline |
get the shape of a dataset with a given name
retrieve the dataset with the given name, then the dataspace for the dataset. The order will be that the first will be the slowest dimension, then the second slowest and so on, then the last value will be the fastest dimension.
valname | the name of the dataset |
Definition at line 1038 of file hdf5_handle.hpp.
References _fileid.
|
inline |
write a 1d array with a given name
create a dataspace and a dataset for writing the value as part of the given group. Then write the value and close all resources later on.
The name can contain the group that the value should be written to
type | The type that should be written |
array | the array to be written |
arrayLength | the length of the array to be written |
valname | the name of the value |
compressLevel | the compression level of the array |
create space and dataset for storing the graph (1D hist)
set up the chunck size and the deflate options
Definition at line 350 of file hdf5_handle.hpp.
References _fileid, ensureGroupExists(), and status.
|
inline |
write a linearized matrix with a given name
create a dataspace and a dataset for writing the matrix as part of the given group. Then write the matrix and close all resources later on.
The name can contain the group that the value should be written to
type | The type that should be written |
matrix | the matrix to be written |
shape | the shape of the matrix (first is cols, second is rows) |
valname | the name of the value |
compressLevel | the compression level of the matrix |
create space and dataset for storing the matrix
Definition at line 456 of file hdf5_handle.hpp.
References _fileid, ensureGroupExists(), and status.
|
inline |
write an scalar value with a given name as part of a given group
create a dataspace and a dataset for writing the scalar value as part of the given group. Then write the value and close all resources later on.
type | The scalar type that should be written |
value | the value to be written |
valname | the name of the value |
Definition at line 275 of file hdf5_handle.hpp.
References _fileid, ensureGroupExists(), and status.
|
inline |
write an float scalar attribute with a given name as part of a given dataset
type | The type that should be written |
value | the value to be written |
valname | the name of the value |
dsetName | the Name of the Dataset |
open the dataset that the attribute should be added to
open the attribute space and attribute of the dataset
write the attribute and close the resources
Definition at line 928 of file hdf5_handle.hpp.
|
inline |
write a string dataset
string | the string to write |
dsetName | the name of the string dataset |
Definition at line 855 of file hdf5_handle.hpp.
|
private |
the file handle
Definition at line 1299 of file hdf5_handle.hpp.
Referenced by appendData(), close(), currentFileSize(), datasets(), dimension(), ensureGroupExists(), filename(), groupExists(), open(), readArray(), readMatrix(), readMultiDim(), readPartialMultiDim(), readScalar(), readScalarAttribute(), readString(), rootGroups(), shape(), writeArray(), writeMatrix(), writeScalar(), writeScalarAttribute(), and writeString().