HPC quality persistence with few lines
01: #include <h5cpp/core>
02: #include "generated.h"
03: #include <h5cpp/io>
04: int main(int argc, char *argv[] ){
05: h5::fd_t fd = h5::create("lightning-talk-example.h5",H5F_ACC_TRUNC);
06: try {
07: h5::pt_t pt = h5::create<sn::example::complicated_struct_t>(fd, "dataset name",
08: h5::max_dims{H5S_UNLIMITED}, h5::chunk{1024} );
09: sn::example::complicated_struct_t event;
10: for(size_t i=0; i<size; i++ )
12: h5::append(pt, event);
13: } catch ( const h5::error::any& e ){ ... }
14: }
01: namespace sn::example {
02: struct complicated_struct_t {
03: unsigned long idx;
... };
12: }
- take an arbitrary complex POD type
- persist it within a tight event loop
- with a CRUD like operator
- into a dataset -- with some properties
- where the dataset is part of the HDF5 container
- generated.h doesn't exist yet
The header file with HDF5 Compound Type descriptors:
#ifndef H5CPP_GUARD_kCTha
#define H5CPP_GUARD_kCTha
namespace h5 {
template<> hid_t inline register_struct<sn::example::complicated_struct_t>(){
hsize_t at_00_[] ={7}; hid_t at_00 = H5Tarray_create(H5T_NATIVE_FLOAT,1,at_00_);
hsize_t at_01_[] ={3}; hid_t at_01 = H5Tarray_create(H5T_NATIVE_DOUBLE,1,at_01_);
hid_t ct_00 = H5Tcreate(H5T_COMPOUND, sizeof (sn::other::struct_t));
H5Tinsert(ct_00, "idx", HOFFSET(sn::other::struct_t,idx),H5T_NATIVE_ULONG);
H5Tinsert(ct_00, "field_02", HOFFSET(sn::other::struct_t,field_02),at_01);
hsize_t at_02_[] ={5}; hid_t at_02 = H5Tarray_create(ct_00,1,at_02_);
hsize_t at_03_[] ={8}; hid_t at_03 = H5Tarray_create(ct_00,1,at_03_);
hsize_t at_04_[] ={3}; hid_t at_04 = H5Tarray_create(at_03,1,at_04_);
hid_t ct_01 = H5Tcreate(H5T_COMPOUND, sizeof (sn::example::complicated_struct_t));
H5Tinsert(ct_01, "idx", HOFFSET(sn::example::complicated_struct_t,idx),H5T_NATIVE_ULONG);
H5Tinsert(ct_01, "field_02", HOFFSET(sn::example::complicated_struct_t,field_02),at_00);
H5Tinsert(ct_01, "field_03", HOFFSET(sn::example::complicated_struct_t,field_03),at_02);
H5Tinsert(ct_01, "field_04", HOFFSET(sn::example::complicated_struct_t,field_04),at_04);
H5Tclose(at_00); H5Tclose(at_01); H5Tclose(ct_00); H5Tclose(at_02); H5Tclose(at_03);
H5Tclose(at_04);
return ct_01;
};
}
H5CPP_REGISTER_STRUCT(sn::example::complicated_struct_t);
#endif
- random include guards
- within namespace
- template specialization for h5::operators
- compound types are recursively created
- resources are closed to prevent leak