|
GammaLib 2.2.0.dev
|
COSI instrument response function class. More...
#include <GHdf5.hpp>
Public Member Functions | |
| GHdf5 (void) | |
| Void constructor. | |
| GHdf5 (const GFilename &filename) | |
| Load constructor. | |
| GHdf5 (const GHdf5 &file) | |
| Copy constructor. | |
| virtual | ~GHdf5 (void) |
| Destructor. | |
| GHdf5 & | operator= (const GHdf5 &file) |
| Assignment operator. | |
| void | clear (void) |
| Clear instance. | |
| GHdf5 * | clone (void) const |
| Clone instance. | |
| std::string | classname (void) const |
| Return class name. | |
| bool | is_empty (void) const |
| Signals if HDF5 instance is empty. | |
| void | load (const GFilename &filename) |
| Load data from HDF5 file into instance. | |
| void | read (FILE *fptr) |
| Read data from HDF5 file into instance. | |
| const GXml & | xml (void) const |
| Return HDF5 metadata as XML object. | |
| const GXmlElement * | xml_hdf5_entry (const std::string &name) const |
| Return XML element to entry tag. | |
| std::string | print (const GChatter &chatter=NORMAL) const |
| Print HDF5 file. | |
Public Member Functions inherited from GBase | |
| virtual | ~GBase (void) |
| Destructor. | |
Private Member Functions | |
| void | init_members (void) |
| Initialise class members. | |
| void | copy_members (const GHdf5 &file) |
| Copy class members. | |
| void | free_members (void) |
| Delete class members. | |
| void | read_superblock (FILE *fptr) |
| Read HDF5 file superblock. | |
| void | read_symbol_table_node (FILE *fptr, const uint64_t &address, const uint64_t &offset, const std::string &heap, GXmlElement *table, const int &indent) |
| Read HDF5 symbol table node. | |
| void | read_symbol_table_entry (FILE *fptr, const uint64_t &address, const uint64_t &offset, const std::string &heap, GXmlElement *entry, const int &indent) |
| Read and handle HDF5 symbol table entry. | |
| void | read_group (FILE *fptr, const uint64_t &address_btree, const uint64_t &address_heap, GXmlElement *group, const int &indent) |
| Read and handle HDF5 group. | |
| void | read_btree_chunked (FILE *fptr, const uint64_t &address, const int &dimensions, GXmlElement *btree) |
| Read HDF5 B-tree for chunked data. | |
| void | read_object_header (FILE *fptr, const uint64_t &address, GXmlElement *header, const int &indent) |
| Read object header. | |
| void | read_object_header_v1 (FILE *fptr, GXmlElement *header, const int &indent) |
| Read object header version 1. | |
| void | read_object_header_v2 (FILE *fptr, GXmlElement *header, const int &indent) |
| Read object header version 2. | |
| void | read_object_header_message (FILE *fptr, const int &type, GXmlElement *message, const int &indent) |
| Read one object header message. | |
| void | read_message_dataspace (FILE *fptr, GXmlElement *message, std::string &msg) |
| Read dataspace message. | |
| void | read_message_datatype (FILE *fptr, GXmlElement *message, std::string &msg) |
| Read datatype message. | |
| void | read_message_layout (FILE *fptr, GXmlElement *message, std::string &msg) |
| Read Data Storage - Layout message. | |
| void | read_message_filter (FILE *fptr, GXmlElement *message, std::string &msg) |
| Read Data Storage - Filter pipeline message. | |
| void | read_message_attribute (FILE *fptr, GXmlElement *message, std::string &msg) |
| Read Attribute message. | |
| std::string | global_heap_string (FILE *fptr, const uint64_t &address, const int &id, const uint32_t &length) |
| Get string from global heap. | |
| void | debug_msg (const std::string &msg, const int &indent) |
| Show debug message. | |
| std::string | hexaddress (const uint64_t &address) |
| Format address for debugging. | |
| std::string | extract (const std::string &string, const int &pos) |
| Extract string from position until next null termination. | |
| int | pad2eight (const int &nbytes) |
| Pad number of Bytes to 8 Bytes. | |
Private Attributes | |
| GFilename | m_filename |
| int | m_offset |
| int | m_length |
| GXml | m_xml |
COSI instrument response function class.
The COSI instrument response function class defines the function that translates from physical quantities to measured quantities.
| GHdf5::GHdf5 | ( | void | ) |
Void constructor.
Creates an empty instance of the HDF5 class.
Definition at line 156 of file GHdf5.cpp.
References init_members().
Referenced by clone().
| GHdf5::GHdf5 | ( | const GFilename & | filename | ) |
Load constructor.
| [in] | filename | File name of HDF5 file. |
Create HDF5 instance by loading data from a HDF5 file.
Definition at line 173 of file GHdf5.cpp.
References init_members(), and load().
| GHdf5::GHdf5 | ( | const GHdf5 & | file | ) |
Copy constructor.
| [in] | file | HDF5 file instance. |
Definition at line 191 of file GHdf5.cpp.
References copy_members(), and init_members().
|
virtual |
|
inlinevirtual |
|
virtual |
Clear instance.
Clears HDF5 file instance by resetting all class members to an initial state. Any information that was present before will be lost.
Implements GBase.
Definition at line 267 of file GHdf5.cpp.
References free_members(), and init_members().
|
virtual |
|
private |
Copy class members.
| [in] | file | HDF5 file instance. |
Definition at line 464 of file GHdf5.cpp.
References m_filename, m_length, m_offset, and m_xml.
Referenced by GHdf5(), and operator=().
|
private |
Show debug message.
| [in] | msg | Debug message. |
| [in] | indent | Number of spaces to indent |
Definition at line 2874 of file GHdf5.cpp.
Referenced by read_group(), read_object_header_message(), read_object_header_v1(), read_superblock(), read_symbol_table_entry(), and read_symbol_table_node().
|
private |
Extract string from position until next null termination.
| [in] | string | String. |
| [in] | pos | Start position in string. |
Returns extracted string.
Definition at line 2916 of file GHdf5.cpp.
Referenced by read_symbol_table_entry().
|
private |
Delete class members.
Definition at line 480 of file GHdf5.cpp.
Referenced by clear(), operator=(), and ~GHdf5().
|
private |
Get string from global heap.
| [in] | fptr | File pointer. |
| [in] | address | Collection address (address of global heap). |
| [in] | id | Heap object index. |
| [in] | length | Length of string. |
| GException::invalid_value | Invalid group heap signature Invalid group heap version Object index not found in global heap collection Length of string does not correspond to length of object |
Get string from the global heap using it's collection address address and the heap object index id.
If the requested global heap does not yet exist in the XML object it is read from the file and stored into a "gobal_heap" element. Multiple global heap elements may exist and are identified by their file address.
Definition at line 2684 of file GHdf5.cpp.
References GXmlNode::append(), GXmlElement::attribute(), GXml::element(), GXmlNode::element(), GXmlNode::elements(), gammalib::hdf5::fread_data(), gammalib::hdf5::fread_int(), gammalib::hdf5::fread_string(), gammalib::hdf5::fread_uint32(), gammalib::hdf5::fread_uint64(), gammalib::hdf5::fread_zero(), G_GLOBAL_HEAP_STRING, hexaddress(), m_length, m_xml, pad2eight(), read(), gammalib::str(), and gammalib::toint().
Referenced by read_message_attribute().
|
private |
Format address for debugging.
| [in] | address | Address. |
Returns a string with the address in hexadecimal format.
Definition at line 2897 of file GHdf5.cpp.
References gammalib::str().
Referenced by global_heap_string(), read_btree_chunked(), read_group(), read_message_attribute(), read_message_layout(), read_object_header_message(), read_object_header_v1(), read_symbol_table_entry(), and read_symbol_table_node().
|
private |
Initialise class members.
Definition at line 446 of file GHdf5.cpp.
References GFilename::clear(), GXml::clear(), m_filename, m_length, m_offset, and m_xml.
Referenced by clear(), GHdf5(), GHdf5(), GHdf5(), and operator=().
|
inline |
Signals if HDF5 instance is empty.
Definition at line 225 of file GHdf5.hpp.
References GXml::is_empty(), and m_xml.
| void GHdf5::load | ( | const GFilename & | filename | ) |
Load data from HDF5 file into instance.
| [in] | filename | File name of HDF5 file. |
| GException::file_error | Unable to open specified file. |
Load data from HDF5 file into a HDF5 file.
Definition at line 301 of file GHdf5.cpp.
References clear(), gammalib::expand_env(), G_LOAD, m_filename, read(), and GFilename::url().
Referenced by GHdf5().
Assignment operator.
| [in] | file | HDF5 file instance. |
Assign HDF5 file instance to this object. The assignment performs a deep copy of all information, hence the original object from which the assignment was made can be destroyed after this operation without any loss of information.
Definition at line 234 of file GHdf5.cpp.
References copy_members(), free_members(), and init_members().
|
private |
Pad number of Bytes to 8 Bytes.
| [in] | nbytes | Number of Bytes. |
Returns a padded number of Bytes so that nbytes becomes a multiple of 8 Bytes.
Definition at line 2948 of file GHdf5.cpp.
Referenced by global_heap_string(), and read_message_attribute().
Print HDF5 file.
| [in] | chatter | Chattiness. |
Implements GBase.
Definition at line 407 of file GHdf5.cpp.
References GFilename::length(), m_filename, m_length, m_offset, gammalib::parformat(), SILENT, and gammalib::str().
| void GHdf5::read | ( | FILE * | fptr | ) |
Read data from HDF5 file into instance.
| [in] | fptr | File pointer to HDF5 file. |
Read data from HDF5 file into a HDF5 file.
Definition at line 338 of file GHdf5.cpp.
References clear(), and read_superblock().
Referenced by global_heap_string(), and load().
|
private |
Read HDF5 B-tree for chunked data.
| [in] | fptr | File pointer. |
| [in] | address | Address of B-tree. |
| [in] | dimensions | Dataset dimensions + 1. |
| [in] | btree | Pointer to XML element for btree. |
| GException::invalid_value | TREE signature not found B-tree node type is not 1 |
This method only supports version 1 B-trees. Version 2 B-trees have the signature "BTHD" and need to be implemented if required.
Definition at line 1073 of file GHdf5.cpp.
References GXmlNode::append(), GXmlElement::attribute(), gammalib::hdf5::fread_int(), gammalib::hdf5::fread_string(), gammalib::hdf5::fread_uint64(), G_READ_BTREE_CHUNKED, hexaddress(), m_offset, read_btree_chunked(), and gammalib::str().
Referenced by read_btree_chunked(), and read_message_layout().
|
private |
Read and handle HDF5 group.
| [in] | fptr | File pointer. |
| [in] | btree_address | Address of B-tree. |
| [in] | heap_address | Address of heap. |
| [in] | group | Pointer to XML element for group. |
| [in] | indent | Indent for debugging messages. |
| GException::invalid_value | TREE or HEAP signatures not found Heap version is not zero B-tree node type is not 0 or 1 |
This method only supports version 1 B-trees. Version 2 B-trees have the signature "BTHD" and need to be implemented if required.
Definition at line 923 of file GHdf5.cpp.
References GXmlNode::append(), debug_msg(), gammalib::hdf5::fread_data(), gammalib::hdf5::fread_int(), gammalib::hdf5::fread_string(), gammalib::hdf5::fread_uint64(), gammalib::hdf5::fread_zero(), G_READ_GROUP, hexaddress(), m_length, m_offset, read_symbol_table_node(), and gammalib::str().
Referenced by read_symbol_table_entry().
|
private |
Read Attribute message.
| [in] | fptr | File pointer. |
| [in] | type | Message type. |
| [in] | msg | String for debugging messages. |
| GException::invalid_value | Invalid attribute version |
The Attribute message is used to store objects in the HDF5 file which are used as attributes, or "metadata" about the current object. An attribute is a small dataset; it has a name, a datatype, a dataspace, and raw data.
Since attributes are stored in the object header, they should be relatively small (in other words, less than 64KB). They can be associated with any type of object which has an object header (groups, datasets, or committed (named) datatypes).
Note: Attributes on an object must have unique names: the HDF5 Library currently enforces this by causing the creation of an attribute with a duplicate name to fail. Attributes on different objects may have the same name, however.
Definition at line 2491 of file GHdf5.cpp.
References GXmlNode::append(), GXmlElement::attribute(), gammalib::hdf5::fread_data_as_string(), gammalib::hdf5::fread_int(), gammalib::hdf5::fread_string(), gammalib::hdf5::fread_uint32(), gammalib::hdf5::fread_uint64(), gammalib::hdf5::fread_zero(), G_READ_MESSAGE_ATTRIBUTE, global_heap_string(), GXmlElement::has_attribute(), hexaddress(), m_offset, pad2eight(), read_message_dataspace(), read_message_datatype(), sign(), gammalib::str(), and gammalib::toint().
Referenced by read_object_header_message().
|
private |
Read dataspace message.
| [in] | fptr | File pointer. |
| [in] | type | Message type. |
| [in] | msg | String for debugging messages (not used if empty length). |
The dataspace message describes the number of dimensions (in other words, "rank") and size of each dimension that the data object has. This message is only used for datasets which have a simple, rectilinear, array-like layout; datasets requiring a more complex layout are not yet supported.
This method supports versions 1 and 2 of the dataspace message. If other version numbers are encountered the validity flag is set to 0 and the decoding is stopped.
Definition at line 1760 of file GHdf5.cpp.
References GXmlElement::attribute(), gammalib::hdf5::fread_int(), gammalib::hdf5::fread_uint64(), gammalib::hdf5::fread_zero(), m_length, and gammalib::str().
Referenced by read_message_attribute(), and read_object_header_message().
|
private |
Read datatype message.
| [in] | fptr | File pointer. |
| [in] | message | Pointer to XML element. |
| [in] | msg | String for debugging messages (not used if empty length). |
| GException::invalid_value | Invalid datatype version or class |
The datatype message defines the datatype for each element of a dataset or a common datatype for sharing between multiple datasets. A datatype can describe an atomic type like a fixed- or floating-point type or more complex types like a C struct (compound datatype), array (array datatype) or C++ vector (variable-length datatype).
Datatype messages that are part of a dataset object do not describe how elements are related to one another; the dataspace message is used for that purpose. Datatype messages that are part of a committed datatype (formerly named datatype) message describe a common datatype that can be shared by multiple datasets in the file.
Definition at line 1938 of file GHdf5.cpp.
References GXmlNode::append(), GXmlElement::attribute(), gammalib::hdf5::classname(), gammalib::hdf5::fread_data(), gammalib::hdf5::fread_data_as_string(), gammalib::hdf5::fread_int(), G_READ_MESSAGE_DATATYPE, read_message_datatype(), sign(), and gammalib::str().
Referenced by read_message_attribute(), read_message_datatype(), and read_object_header_message().
|
private |
Read Data Storage - Filter pipeline message.
| [in] | fptr | File pointer. |
| [in] | type | Message type. |
| [in] | msg | String for debugging messages. |
| GException::invalid_value | Invalid data filter pipeline message version |
Definition at line 2378 of file GHdf5.cpp.
References GXmlNode::append(), GXmlElement::attribute(), gammalib::hdf5::fread_int(), gammalib::hdf5::fread_string(), gammalib::hdf5::fread_zero(), G_READ_MESSAGE_FILTER, and gammalib::str().
Referenced by read_object_header_message().
|
private |
Read Data Storage - Layout message.
| [in] | fptr | File pointer. |
| [in] | message | Pointer to XML element. |
| [in] | msg | String for debugging messages. |
| GException::invalid_value | Invalid data storage layout version or class |
Definition at line 2203 of file GHdf5.cpp.
References GXmlNode::append(), GXmlElement::attribute(), gammalib::hdf5::fread_int(), gammalib::hdf5::fread_uint64(), G_READ_MESSAGE_LAYOUT, hexaddress(), m_length, m_offset, read_btree_chunked(), and gammalib::str().
Referenced by read_object_header_message().
|
private |
Read object header.
| [in] | fptr | File pointer. |
| [in] | address | Address of header. |
| [in] | header | Pointer to XML element for header. |
| [in] | indent | Indent for debugging messages. |
| GException::invalid_value | Invalid object header version |
The header information of an object is designed to encompass all the information about an object, except for the data itself. This information includes the dataspace, datatype, information about how the data is stored on disk (in external files, compressed, broken up in blocks, and so on), as well as other information used by the library to speed up access to the data objects or maintain a file’s integrity. Information stored by user applications as attributes is also stored in the object’s header. The header of each object is not necessarily located immediately prior to the object’s data in the file and in fact may be located in any position in the file. The order of the messages in an object header is not significant.
Object headers are composed of a prefix and a set of messages. The prefix contains the information needed to interpret the messages and a small amount of metadata about the object, and the messages contain the majority of the metadata about the object.
Definition at line 1207 of file GHdf5.cpp.
References gammalib::hdf5::fread_int(), G_READ_OBJECT_HEADER, read_object_header_v1(), read_object_header_v2(), and gammalib::str().
Referenced by read_symbol_table_entry().
|
private |
Read one object header message.
| [in] | fptr | File pointer. |
| [in] | type | Message type. |
| [in] | message | Pointer to XML element for message. |
| [in] | indent | Indent for debugging messages. |
| GException::invalid_value | Invalid message |
Definition at line 1380 of file GHdf5.cpp.
References GXmlElement::attribute(), debug_msg(), gammalib::hdf5::fread_int(), gammalib::hdf5::fread_uint64(), hexaddress(), m_offset, read_message_attribute(), read_message_dataspace(), read_message_datatype(), read_message_filter(), read_message_layout(), and gammalib::str().
Referenced by read_object_header_v1().
|
private |
Read object header version 1.
| [in] | fptr | File pointer. |
| [in] | header | Pointer to XML element for header. |
| [in] | indent | Indent for debugging messages. |
| GException::invalid_value | Invalid message type |
Definition at line 1249 of file GHdf5.cpp.
References GXmlNode::append(), debug_msg(), gammalib::hdf5::fread_int(), gammalib::hdf5::fread_uint64(), gammalib::hdf5::fread_zero(), G_READ_OBJECT_HEADER_V1, hexaddress(), m_length, m_offset, read_object_header_message(), and gammalib::str().
Referenced by read_object_header().
|
private |
Read object header version 2.
| [in] | fptr | File pointer. |
| [in] | header | Pointer to XML element for header. |
| [in] | indent | Indent for debugging messages. |
| GException::feature_not_implemented | Method not yet implemented. |
Method not yet implemented.
Definition at line 1356 of file GHdf5.cpp.
References G_READ_OBJECT_HEADER_V2.
Referenced by read_object_header().
|
private |
Read HDF5 file superblock.
| [in] | fptr | File pointer. |
| GException::invalid_value | File is not a HDF5 file Superblock version out of valid range Invalid offset and length values |
Reads the superblock of the HDF5 file and walks done the hierarchical HDF5 file structure to extract all metadata. The information is stored in the XML file member m_xml that will echo the hierarchical information of the HDF5 file.
The superblock may begin at certain predefined offsets within the HDF5 file, allowing a block of unspecified content for users to place additional information at the beginning (and end) of the HDF5 file without limiting the HDF5 library's ability to manage the objects within the file itself.
This method assumes that the fptr file pointer points to the superblock. If an offset is needed, the client needs to position the file pointer accordingly.
This method fully supports superblock versions 0 and 1. For superblock versions 2 and 3, entering of the group graph still needs to be implemented.
Definition at line 516 of file GHdf5.cpp.
References GXml::append(), GXmlElement::attribute(), debug_msg(), gammalib::hdf5::fread_int(), gammalib::hdf5::fread_string(), gammalib::hdf5::fread_uint32(), gammalib::hdf5::fread_uint64(), gammalib::hdf5::fread_zero(), G_READ_SUPERBLOCK, m_length, m_offset, m_xml, read_symbol_table_entry(), and gammalib::str().
Referenced by read().
|
private |
Read and handle HDF5 symbol table entry.
| [in] | fptr | File pointer. |
| [in] | address | Address of symbol table entry. |
| [in] | offset | Byte offset in heap. |
| [in] | heap | Heap. |
| [in] | entry | Pointer to XML element for entry. |
| [in] | indent | Indent for debugging messages. |
| GException::invalid_value | Invalid cache type encountered |
Read and handle a symbol table entry. If the entry has a cache type of 1 the method will read the corresponding group.
Each symbol table entry in a symbol table node is designed to allow for very fast browsing of stored objects. Toward that design goal, the symbol table entries include space for caching certain constant metadata from the object header.
Definition at line 809 of file GHdf5.cpp.
References GXmlNode::append(), GXmlElement::attribute(), debug_msg(), extract(), gammalib::hdf5::fread_uint32(), gammalib::hdf5::fread_uint64(), gammalib::hdf5::fread_zero(), G_READ_SYMBOL_TABLE_ENTRY, hexaddress(), m_offset, read_group(), read_object_header(), and gammalib::str().
Referenced by read_superblock(), and read_symbol_table_node().
|
private |
Read HDF5 symbol table node.
| [in] | fptr | File pointer. |
| [in] | address | Address of symbol table node. |
| [in] | offset | Byte offset in heap. |
| [in] | heap | Heap. |
| [in] | table | Pointer to XML element for table. |
| [in] | indent | Indent for debugging messages. |
| GException::invalid_value | Symbol table node signature not found Invalid symbol table node version |
This method reads a symbol table node from the file. The symbol table node is a leaf of a B-tree.
Each symbol table node starts with the signature "SNOD" and contains an arbitrary number of symbols (group entries). All symbol table nodes have the same length of 2*m_offset+24.
Definition at line 720 of file GHdf5.cpp.
References GXmlNode::append(), debug_msg(), gammalib::hdf5::fread_int(), gammalib::hdf5::fread_string(), gammalib::hdf5::fread_uint32(), gammalib::hdf5::fread_zero(), G_READ_SYMBOL_TABLE_NODE, hexaddress(), m_offset, read_symbol_table_entry(), and gammalib::str().
Referenced by read_group().
|
inline |
| const GXmlElement * GHdf5::xml_hdf5_entry | ( | const std::string & | name | ) | const |
Return XML element to entry tag.
| [in] | name | Entry name. |
| GException::invalid_value | No HDF5 metadata were loaded. No entry element with specified name found. |
Returns a XML pointer to an entry element with a given name.
The method works recursevely down the entire XML structure of the HDF5 file and stops once the first entry element with a "name" attribute equal to name was found. If no such element could be found, the method throws an exception.
Definition at line 371 of file GHdf5.cpp.
References GXml::element(), G_XML_HDF5_ENTRY, GXml::is_empty(), m_xml, and gammalib::xml_get_element_by_attribute().
|
private |
Definition at line 200 of file GHdf5.hpp.
Referenced by copy_members(), init_members(), load(), and print().
|
private |
Definition at line 202 of file GHdf5.hpp.
Referenced by copy_members(), global_heap_string(), init_members(), print(), read_group(), read_message_dataspace(), read_message_layout(), read_object_header_v1(), and read_superblock().
|
private |
Definition at line 201 of file GHdf5.hpp.
Referenced by copy_members(), init_members(), print(), read_btree_chunked(), read_group(), read_message_attribute(), read_message_layout(), read_object_header_message(), read_object_header_v1(), read_superblock(), read_symbol_table_entry(), and read_symbol_table_node().
|
private |
Definition at line 203 of file GHdf5.hpp.
Referenced by copy_members(), global_heap_string(), init_members(), is_empty(), read_superblock(), xml(), and xml_hdf5_entry().