GammaLib 2.2.0.dev
Loading...
Searching...
No Matches
gammalib::hdf5 Namespace Reference

Functions

std::string fread_data (FILE *fptr, const int &nbytes)
 Read data from HDF5 file.
 
std::string fread_data (FILE *fptr, const GXmlElement *dataspace, const GXmlElement *datatype, const GXmlElement *datalayout, const GXmlElement *datafilter=NULL)
 Read data.
 
std::string fread_data_chunk (FILE *fptr, const GXmlElement *chunk, const GXmlElement *dataspace, const GXmlElement *datatype, const GXmlElement *datalayout, const GXmlElement *datafilter=NULL)
 Read data chunk.
 
int fread_int (FILE *fptr, const int &nbytes)
 Read data as integer from HDF5 file.
 
uint32_t fread_uint32 (FILE *fptr, const int &nbytes)
 Read data as unsiged 32 Bit integer from HDF5 file.
 
uint64_t fread_uint64 (FILE *fptr, const int &nbytes)
 Read data as unsiged 64 Bit integer from HDF5 file.
 
std::string fread_string (FILE *fptr, const int &nbytes)
 Read string data from HDF5 file.
 
std::string fread_data_as_string (FILE *fptr, const GXmlElement *datatype)
 Read data with any data type as a string.
 
void fread_zero (FILE *fptr, const int &nbytes)
 Read zero data from HDF5 file.
 
int data_to_int (const char *data, const GXmlElement *datatype)
 Convert data into integer value.
 
double data_to_double (const char *data, const GXmlElement *datatype)
 Convert data into double precision floating point value.
 
std::string data_to_string (const char *data, const GXmlElement *datatype)
 Convert data into string.
 
std::string data_filter (const std::string &data, const GXmlElement *datafilter)
 Filter data.
 
std::string data_filter_bitshuffle (const std::string &data, const GXmlElement *filter)
 Filter data according to Bitshuffle algorithm.
 
const GXmlElementxml_msg_type (const GXmlElement *header, const std::string &type, const int &number=0)
 Return specific occurence of header message of given type.
 
bool xml_has_msg_type (const GXmlElement *header, const std::string &type, const int &number=0)
 Checks if specific occurence of header message of given type exists.
 
int xml_msg_attributes (const GXmlElement *header, const std::string &name="")
 Return number of "Attribute" messages in header.
 
const GXmlElementxml_msg_attribute (const GXmlElement *header, const std::string &name, const int &number=0)
 Return "Attribute" message XML element with specified name.
 
bool xml_has_msg_attribute (const GXmlElement *header, const std::string &name, const int &number=0)
 Checks if "Attribute" message XML element with specified name exists.
 
std::string xml_msg_attribute (const GXmlElement *header, const std::string &name, const std::string &key)
 Return "Attribute" message key value from attribute with specified name.
 
const GXmlElementxml_msg_dataspace (const GXmlElement *header)
 Return "Dataspace" message XML element.
 
const GXmlElementxml_msg_datatype (const GXmlElement *header)
 Return "Datatype" message XML element.
 
const GXmlElementxml_msg_datalayout (const GXmlElement *header)
 Return "DataStorageLayout" message XML element.
 
const GXmlElementxml_msg_datafilter (const GXmlElement *header)
 Return "DataStorageFilterPipeline" message XML element.
 
std::string classname (const int &cls)
 Convert datatype class into classname.
 

Function Documentation

◆ classname()

std::string gammalib::hdf5::classname ( const int & cls)

Convert datatype class into classname.

Parameters
[in]clsDatatype class.
Returns
Classname.

Return class name from datatype class.

Definition at line 4365 of file GHdf5.cpp.

References classname().

Referenced by classname(), data_to_double(), data_to_int(), data_to_string(), and GHdf5::read_message_datatype().

◆ data_filter()

std::string gammalib::hdf5::data_filter ( const std::string & data,
const GXmlElement * datafilter )

Filter data.

Parameters
[in]dataData string.
[in]datafilterPointer to datafilter XML element.
Returns
Filtered data string.
Exceptions
GException::invalid_argumentNo "filters" attribute in datafilter
GException::invalid_valueUnxpected number of "filter" elements
GException::feature_not_implementedRequested filter is not yet implemented

Filter data according to specified datafilter.

Definition at line 3822 of file GHdf5.cpp.

References GXmlElement::attribute(), data_filter_bitshuffle(), GXmlNode::element(), GXmlNode::elements(), G_DATA_FILTER, GXmlElement::has_attribute(), gammalib::str(), and gammalib::toint().

Referenced by fread_data(), and fread_data_chunk().

◆ data_filter_bitshuffle()

std::string gammalib::hdf5::data_filter_bitshuffle ( const std::string & data,
const GXmlElement * filter )

Filter data according to Bitshuffle algorithm.

Parameters
[in]dataData string.
[in]filterPointer to bitshuffle filter XML element.
Returns
Filtered data string.
Exceptions
GException::invalid_argumentInvalid number of client data values found in filter
GException::feature_not_implementedUnsupported Bitshuffle algorithm specified in filter

Filter data according to Bitshuffle algorithm with parameters specified by filter.

The method was inspired by https://github.com/kiyo-masui/bitshuffle and specifically the bshuf_h5_filter() function in the file bshuf_h5filter.c.

Definition at line 3903 of file GHdf5.cpp.

References bitshuffle_decompress(), bitshuffle_read_uint32(), bitshuffle_read_uint64(), GXmlNode::element(), GXmlNode::elements(), G_DATA_FILTER_BITSHUFFLE, GXmlElement::integer(), and gammalib::str().

Referenced by data_filter().

◆ data_to_double()

double gammalib::hdf5::data_to_double ( const char * data,
const GXmlElement * datatype )

Convert data into double precision floating point value.

Parameters
[in]dataPointer to data.
[in]datatypePointer to datatype XML element.
Returns
Data converted into double precision floating point value.
Exceptions
GException::feature_not_implementedConversion of specified datatype not yet supported GException::invalid_value Conversion of datatype not supported

Converts one data element of given datatype into a double precision floating point value.

Definition at line 3639 of file GHdf5.cpp.

References GXmlElement::attribute(), classname(), G_DATA_TO_DOUBLE, gammalib::order(), gammalib::str(), and gammalib::toint().

◆ data_to_int()

int gammalib::hdf5::data_to_int ( const char * data,
const GXmlElement * datatype )

Convert data into integer value.

Parameters
[in]dataPointer to data.
[in]datatypePointer to datatype XML element.
Returns
Data converted into integer value.
Exceptions
GException::feature_not_implementedConversion of specified datatype not yet supported GException::invalid_value Conversion of datatype not supported

Converts one data element of given datatype into an integer value. The method does not check for overflow. Fixed-point data are assumed to be stored in little endian order.

Definition at line 3558 of file GHdf5.cpp.

References GXmlElement::attribute(), classname(), G_DATA_TO_INT, gammalib::order(), gammalib::str(), and gammalib::toint().

◆ data_to_string()

std::string gammalib::hdf5::data_to_string ( const char * data,
const GXmlElement * datatype )

Convert data into string.

Parameters
[in]dataPointer to data.
[in]datatypePointer to datatype XML element.
Returns
Data converted into string.
Exceptions
GException::feature_not_implementedConversion of specified datatype not yet supported

Converts one data element of given datatype into a character string.

Definition at line 3717 of file GHdf5.cpp.

References GXmlElement::attribute(), classname(), data_to_string(), GXmlNode::element(), G_DATA_TO_STRING, gammalib::number(), sign(), gammalib::str(), and gammalib::toint().

Referenced by data_to_string(), and fread_data_as_string().

◆ fread_data() [1/2]

std::string gammalib::hdf5::fread_data ( FILE * fptr,
const GXmlElement * dataspace,
const GXmlElement * datatype,
const GXmlElement * datalayout,
const GXmlElement * datafilter = NULL )

Read data.

Parameters
[in]fptrFile pointer.
[in]dataspacePointer to "Dataspace" message XML element.
[in]datatypePointer to "Datatype" message XML element.
[in]datalayoutPointer to "DataStorageLayout" message XML element.
[in]datafilterPointer to "DataStorageFilterPipeline" message XML element.
Returns
String holding the data.
Exceptions
GException::invalid_argumentNo "elements" attribute in dataspace No "size" attribute in datatype No "address" attribute in datalayout No "class" attribute in datalayout @excaption GException::runtime_error Attempt to read beyond end of file

Reads entire data structure and stores the Bytes into a string.

The address from where to read the data is extracted from datalayout. The current position of the file pointer fptr is not modified by the function. The number of Bytes to read is extracted from dataspace and datatype.

If datafilter is not NULL, a data filter is applied to the data before returning them to the client.

Definition at line 3044 of file GHdf5.cpp.

References GXmlElement::attribute(), data_filter(), G_FREAD_DATA2, GXmlElement::has_attribute(), gammalib::str(), gammalib::toint(), and gammalib::toulonglong().

◆ fread_data() [2/2]

std::string gammalib::hdf5::fread_data ( FILE * fptr,
const int & nbytes )

Read data from HDF5 file.

Parameters
[in]fptrFile pointer.
[in]nbytesNumber of Bytes to read (>0).
Returns
String holding the data that was read.
Exceptions
GException::invalid_argumentNumber of Bytes not positive
GException::runtime_errorAttempt to read beyond end of file

Reads nbytes from the current position of the file pointer fptr into a string.

Definition at line 2984 of file GHdf5.cpp.

References G_FREAD_DATA1, and gammalib::str().

Referenced by GHdf5::global_heap_string(), GHdf5::read_group(), and GHdf5::read_message_datatype().

◆ fread_data_as_string()

std::string gammalib::hdf5::fread_data_as_string ( FILE * fptr,
const GXmlElement * datatype )

Read data with any data type as a string.

Parameters
[in]fptrFile pointer.
[in]datatypeDatatype.
Returns
Data converted into a string.
Exceptions
GException::runtime_errorAttempt reading beyond end of file

Reads one element of any datatype and return it as a string.

Definition at line 3456 of file GHdf5.cpp.

References GXmlElement::attribute(), data_to_string(), G_FREAD_DATA_AS_STRING, gammalib::str(), and gammalib::toint().

Referenced by GHdf5::read_message_attribute(), and GHdf5::read_message_datatype().

◆ fread_data_chunk()

std::string gammalib::hdf5::fread_data_chunk ( FILE * fptr,
const GXmlElement * chunk,
const GXmlElement * dataspace,
const GXmlElement * datatype,
const GXmlElement * datalayout,
const GXmlElement * datafilter = NULL )

Read data chunk.

Parameters
[in]fptrFile pointer.
[in]chunkPointer to "key" XML element.
[in]dataspacePointer to "Dataspace" message XML element.
[in]datatypePointer to "Datatype" message XML element.
[in]datalayoutPointer to "DataStorageLayout" message XML element.
[in]datafilterPointer to "DataStorageFilterPipeline" message XML element.
Returns
String holding the data chunk.
Exceptions
GException::invalid_argumentNo "address" attribute in chunk key No "size" attribute in chunk key No "class" attribute in datalayout "DataStorageLayout" is not chunked
GException::runtime_errorAttempt to read beyond end of file

Reads a data chunk and stores the Bytes into a string.

The address from where to read the data and the number of Bytes to read is extracted from chunk.

The current position of the file pointer fptr is not modified by the function.

If datafilter is not NULL, a data filter is applied to the data before returning them to the client.

Definition at line 3172 of file GHdf5.cpp.

References GXmlElement::attribute(), data_filter(), G_FREAD_DATA_CHUNK, GXmlElement::has_attribute(), gammalib::str(), gammalib::toint(), and gammalib::toulonglong().

◆ fread_int()

int gammalib::hdf5::fread_int ( FILE * fptr,
const int & nbytes )

Read data as integer from HDF5 file.

Parameters
[in]fptrFile pointer.
[in]nbytesNumber of Bytes to read (1...4).
Returns
Integer.
Exceptions
GException::out_of_rangeNumber of Bytes not in valid range GException::runtime_error Attempt to read beyond end of file

Definition at line 3256 of file GHdf5.cpp.

References G_FREAD_INT, and gammalib::str().

Referenced by GHdf5::global_heap_string(), GHdf5::read_btree_chunked(), GHdf5::read_group(), GHdf5::read_message_attribute(), GHdf5::read_message_dataspace(), GHdf5::read_message_datatype(), GHdf5::read_message_filter(), GHdf5::read_message_layout(), GHdf5::read_object_header(), GHdf5::read_object_header_message(), GHdf5::read_object_header_v1(), GHdf5::read_superblock(), and GHdf5::read_symbol_table_node().

◆ fread_string()

std::string gammalib::hdf5::fread_string ( FILE * fptr,
const int & nbytes )

Read string data from HDF5 file.

Parameters
[in]fptrFile pointer.
[in]nbytesNumber of Bytes to read (>0).
Returns
String.
Exceptions
GException::invalid_argumentNumber of Bytes not positive
GException::runtime_errorAttempt to read beyond end of file

Reads a string from the current position of the file pointer fptr into a string. The method always reads nbytes from the file and advances the file pointer by that amount. If a NULL termination character is encountered the string is truncated to the segement before that character.

Definition at line 3399 of file GHdf5.cpp.

References G_FREAD_STRING, and gammalib::str().

Referenced by GHdf5::global_heap_string(), GHdf5::read_btree_chunked(), GHdf5::read_group(), GHdf5::read_message_attribute(), GHdf5::read_message_filter(), GHdf5::read_superblock(), and GHdf5::read_symbol_table_node().

◆ fread_uint32()

uint32_t gammalib::hdf5::fread_uint32 ( FILE * fptr,
const int & nbytes )

Read data as unsiged 32 Bit integer from HDF5 file.

Parameters
[in]fptrFile pointer.
[in]nbytesNumber of Bytes to read (1...4).
Returns
Unsiged 32 Bit integer.
Exceptions
GException::out_of_rangeNumber of Bytes not in valid range GException::runtime_error Attempt to read beyond end of file

Definition at line 3302 of file GHdf5.cpp.

References G_FREAD_UINT32, and gammalib::str().

Referenced by GHdf5::global_heap_string(), GHdf5::read_message_attribute(), GHdf5::read_superblock(), GHdf5::read_symbol_table_entry(), and GHdf5::read_symbol_table_node().

◆ fread_uint64()

uint64_t gammalib::hdf5::fread_uint64 ( FILE * fptr,
const int & nbytes )

Read data as unsiged 64 Bit integer from HDF5 file.

Parameters
[in]fptrFile pointer.
[in]nbytesNumber of Bytes to read (1...8).
Returns
Unsiged 64 Bit integer.
Exceptions
GException::out_of_rangeNumber of Bytes not in valid range GException::runtime_error Attempt to read beyond end of file

Definition at line 3348 of file GHdf5.cpp.

References G_FREAD_UINT64, and gammalib::str().

Referenced by GHdf5::global_heap_string(), GHdf5::read_btree_chunked(), GHdf5::read_group(), GHdf5::read_message_attribute(), GHdf5::read_message_dataspace(), GHdf5::read_message_layout(), GHdf5::read_object_header_message(), GHdf5::read_object_header_v1(), GHdf5::read_superblock(), and GHdf5::read_symbol_table_entry().

◆ fread_zero()

void gammalib::hdf5::fread_zero ( FILE * fptr,
const int & nbytes )

Read zero data from HDF5 file.

Parameters
[in]fptrFile pointer.
[in]nbytesNumber of Bytes to read (>0).
Exceptions
GException::out_of_rangeNumber of Bytes not positive GException::runtime_error Attempt to read beyond end of file

Definition at line 3498 of file GHdf5.cpp.

References G_FREAD_ZERO, and gammalib::str().

Referenced by GHdf5::global_heap_string(), GHdf5::read_group(), GHdf5::read_message_attribute(), GHdf5::read_message_dataspace(), GHdf5::read_message_filter(), GHdf5::read_object_header_v1(), GHdf5::read_superblock(), GHdf5::read_symbol_table_entry(), and GHdf5::read_symbol_table_node().

◆ xml_has_msg_attribute()

bool gammalib::hdf5::xml_has_msg_attribute ( const GXmlElement * header,
const std::string & name,
const int & number = 0 )

Checks if "Attribute" message XML element with specified name exists.

Parameters
[in]headerPointer to XML header element.
[in]nameName of "Attribute" message.
[in]numberNumber of occurences to return (0=return first occurence).
Returns
True if message exists, false otherwise.

Returns true if an "Attribute" message with name exists.

Definition at line 4261 of file GHdf5.cpp.

References GXmlElement::attribute(), GXmlNode::element(), GXmlNode::elements(), GXmlElement::has_attribute(), and gammalib::number().

◆ xml_has_msg_type()

bool gammalib::hdf5::xml_has_msg_type ( const GXmlElement * header,
const std::string & type,
const int & number = 0 )

Checks if specific occurence of header message of given type exists.

Parameters
[in]headerPointer to XML header element.
[in]typeMessage type.
[in]numberOccurence of message.
Returns
True if ith occurence of message exists, false otherwise.

Returns true if the occurence number of header message of type exists.

Definition at line 4089 of file GHdf5.cpp.

References GXmlElement::attribute(), GXmlNode::element(), GXmlNode::elements(), GXmlElement::has_attribute(), and gammalib::number().

Referenced by xml_msg_datafilter(), xml_msg_datalayout(), xml_msg_dataspace(), and xml_msg_datatype().

◆ xml_msg_attribute() [1/2]

const GXmlElement * gammalib::hdf5::xml_msg_attribute ( const GXmlElement * header,
const std::string & name,
const int & number = 0 )

Return "Attribute" message XML element with specified name.

Parameters
[in]headerPointer to XML header element.
[in]nameName of "Attribute" message.
[in]numberNumber of occurences to return (0=return first occurence).
Returns
Pointer to "Attribute" message XML element with specified name.

Returns a XML pointer to a message element of type "Attribute" and with the specified name.

If several "Attribute" messages have the same name, the first of these messages is returned.

Definition at line 4193 of file GHdf5.cpp.

References GXmlElement::attribute(), GXmlNode::element(), GXmlNode::elements(), G_XML_MSG_ATTRIBUTE, GXmlElement::has_attribute(), gammalib::number(), and gammalib::order().

◆ xml_msg_attribute() [2/2]

std::string gammalib::hdf5::xml_msg_attribute ( const GXmlElement * header,
const std::string & name,
const std::string & key )

Return "Attribute" message key value from attribute with specified name.

Parameters
[in]headerPointer to XML header element.
[in]nameName of "Attribute" message.
[in]keyKey of "Attribute" message.
Returns
String with value of key in "Attribute" message with name.

Returns the value of an attribute key in an "Attribute" message with the specified name as a string. If the attribute or the key was not found then return an empty string.

If several "Attribute" messages have the same name and p@ key, the first corresponding value is returned.

Definition at line 4319 of file GHdf5.cpp.

References GXmlElement::attribute(), GXmlNode::element(), GXmlNode::elements(), and GXmlElement::has_attribute().

◆ xml_msg_attributes()

int gammalib::hdf5::xml_msg_attributes ( const GXmlElement * header,
const std::string & name = "" )

Return number of "Attribute" messages in header.

Parameters
[in]headerPointer to XML header element.
[in]nameName of "Attribute" message.
Returns
Number of attributes in message header.

Returns the number of message elements of type "Attribute" in the specified header element. If name is not empty, the method will only count the attributes of which the "name" attribute equals to name.

Definition at line 4138 of file GHdf5.cpp.

References GXmlElement::attribute(), GXmlNode::element(), GXmlNode::elements(), GXmlElement::has_attribute(), and gammalib::number().

◆ xml_msg_datafilter()

const GXmlElement * gammalib::hdf5::xml_msg_datafilter ( const GXmlElement * header)
inline

Return "DataStorageFilterPipeline" message XML element.

Parameters
[in]headerPointer to XML header element.
Returns
Pointer to "DataStorageFilterPipeline" message XML element.

Returns a XML pointer to the first header message of type "DataStorageFilterPipeline". If no "DataStorageFilterPipeline" header message exists a NULL pointer is returned.

Definition at line 319 of file GHdf5.hpp.

References xml_has_msg_type(), and xml_msg_type().

◆ xml_msg_datalayout()

const GXmlElement * gammalib::hdf5::xml_msg_datalayout ( const GXmlElement * header)
inline

Return "DataStorageLayout" message XML element.

Parameters
[in]headerPointer to XML header element.
Returns
Pointer to "DataStorageLayout" message XML element.

Returns a XML pointer to the first header message of type "DataStorageLayout". If no "DataStorageLayout" header message exists a NULL pointer is returned.

Definition at line 298 of file GHdf5.hpp.

References xml_has_msg_type(), and xml_msg_type().

◆ xml_msg_dataspace()

const GXmlElement * gammalib::hdf5::xml_msg_dataspace ( const GXmlElement * header)
inline

Return "Dataspace" message XML element.

Parameters
[in]headerPointer to XML header element.
Returns
Pointer to "Dataspace" message XML element.

Returns a XML pointer to the first header message of type "Dataspace". If no "Dataspace" header message exists a NULL pointer is returned.

Definition at line 257 of file GHdf5.hpp.

References xml_has_msg_type(), and xml_msg_type().

◆ xml_msg_datatype()

const GXmlElement * gammalib::hdf5::xml_msg_datatype ( const GXmlElement * header)
inline

Return "Datatype" message XML element.

Parameters
[in]headerPointer to XML header element.
Returns
Pointer to "Datatype" message XML element.

Returns a XML pointer to the first header message of type "Datatype". If no "Datatype" header message exists a NULL pointer is returned.

Definition at line 277 of file GHdf5.hpp.

References xml_has_msg_type(), and xml_msg_type().

◆ xml_msg_type()

const GXmlElement * gammalib::hdf5::xml_msg_type ( const GXmlElement * header,
const std::string & type,
const int & number = 0 )

Return specific occurence of header message of given type.

Parameters
[in]headerPointer to XML header element.
[in]typeMessage type.
[in]numberOccurence of message.
Returns
Pointer to XML element of specific occurence of message type.

GException::invalid_value No type message found in header.

Returns a XML pointer to the ocurrence number of a message of specified type.

Definition at line 4026 of file GHdf5.cpp.

References GXmlElement::attribute(), GXmlNode::element(), GXmlNode::elements(), G_XML_MSG_TYPE, GXmlElement::has_attribute(), gammalib::number(), and gammalib::order().

Referenced by xml_msg_datafilter(), xml_msg_datalayout(), xml_msg_dataspace(), and xml_msg_datatype().