HFD5 Groups
Groups realize the hierarchy in HDF5. They allow the creation of trees and more general storage structures - in general groups allow an easier organization of your file and to keep the overview of your data. Users not familiar with the concept of HDF5 groups can read all details on the HDF5 website.
Understanding the concept of groups is key to an efficient organization of your objects in HDF5. This chapter will explain all options for creating and managing groups and how to use them for the managements of other objects.
Creating Groups
H5Group represents groups in HDF5 files in ILNumerics. The creation is straightforward. Simply provide a name to the constructor. The group is persisted, once it was added to an existing group in a HDF5 file.
The name of the group given in the constructor may contain a path with several segments /subgroups. It describes the path from the group used to add the new group all the way down to the final object which we are going to create. That way we can add several groups at once.
Here, a new group object with the name "g1/g2/g3" was added to the group node created earlier. ILNumerics walks down the path given, creating the subgroups if necessary, eventually creating the new group at its final position in the hierarchy.
Absolut and Relative Paths
The path given above is a relative path: it is valid relative to the node it has been applied to ('group' in our example). If path starts with a slash '/' it is considered to be an absolute path which will always start at the root of the H5File - regardless which node Add() was called on.
The same result we could have been achieved by:
Accessing Groups and Children
Two options exist for accessing objects in a HD5 file. C# indexers are utilized on a group object in order to retrieve a child addressed by its path.
Any object can be fetched that way. Therefore, the indexer returns H5Object instances. You can cast them to their actual type in order to work with them afterwards.The second option involves the specification of the target type. It might be a little less common but in general the recommended method:
This will fetch the object as its derived type. So no casting is necessary. The filter name, again, can be absolute (i.e. relative to the files root node) or relative to the node the Get() method is used on.
Further, more sophisticated options for accessing and enumerating objects in a HDF5 file are found here: Accessing Objects
Removing Objects
Assign null to an indexer on a group node in order to remove the object addressed by the indexer parameter from the H5File. In a correct sense, the 'link' to the object addressed will be removed rather than the object itself. There might be other links in the file still pointing to the same object. However, removing the last link to any object will render the object inaccessible. So be careful!
Note further: removing a group object will also remove all of its children.
Use the H5Group.Remove(path) function if you cannot or do not want to use C# indexers.