Skip to content

Commit 84a8ddd

Browse files
author
steven varga
committed
Merge branch '36-regenerate-h5-goldens' into staging
2 parents fb3611f + 8aa3a4b commit 84a8ddd

11 files changed

Lines changed: 484 additions & 500 deletions

tests/golden/h5_chunk.expected

Lines changed: 59 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -1,75 +1,74 @@
11
#pragma once
22

3-
#include <hdf5.h>
43
#include <h5cpp/all>
5-
64
namespace h5::generated::sn__sensor__chunked_t_ {
7-
8-
struct row_t {
9-
unsigned long long timestamp_ns;
10-
hvl_t samples;
11-
};
12-
13-
inline hid_t compound_type() {
14-
static const hid_t ct = []{
15-
hid_t v_samples = H5Tvlen_create(H5T_NATIVE_DOUBLE);
16-
hid_t ct = H5Tcreate(H5T_COMPOUND, sizeof(row_t));
17-
H5Tinsert(ct, "timestamp_ns", HOFFSET(row_t, timestamp_ns), H5T_NATIVE_ULLONG);
18-
H5Tinsert(ct, "samples", HOFFSET(row_t, samples), v_samples);
5+
struct row_t {
6+
unsigned long long timestamp_ns;
7+
hvl_t samples;
8+
};
9+
inline hid_t compound_type() {
10+
static const hid_t ct = []{
11+
hid_t v_samples = H5Tvlen_create(H5T_NATIVE_DOUBLE);
12+
hid_t ct = H5Tcreate(H5T_COMPOUND, sizeof(row_t));
13+
H5Tinsert(ct, "timestamp_ns", HOFFSET(row_t, timestamp_ns), H5T_NATIVE_ULLONG);
14+
H5Tinsert(ct, "samples", HOFFSET(row_t, samples), v_samples);
15+
return ct;
16+
}();
1917
return ct;
20-
}();
21-
return ct;
22-
}
23-
18+
}
2419
} // namespace h5::generated::sn__sensor__chunked_t_
2520

2621
namespace h5 {
27-
template<> inline h5::ds_t scatter<sn::sensor::chunked_t>(
28-
hid_t fd, const std::string& path, const sn::sensor::chunked_t& obj) {
29-
using namespace ::h5::generated::sn__sensor__chunked_t_;
30-
h5::ds_t ds;
31-
h5::mute();
32-
bool exists = H5Lexists(fd, path.c_str(), H5P_DEFAULT) > 0;
33-
h5::unmute();
34-
if (exists) {
35-
ds = h5::open(fd, path, h5::default_dapl);
36-
} else {
37-
h5::dcpl_t dcpl{H5Pcreate(H5P_DATASET_CREATE)};
38-
hsize_t chunk = 256;
39-
H5Pset_chunk(dcpl, 1, &chunk);
40-
hsize_t cur = 0;
41-
hsize_t max = H5S_UNLIMITED;
42-
hid_t space = H5Screate_simple(1, &cur, &max);
43-
ds = h5::createds(fd, path, compound_type(), h5::sp_t{space},
44-
h5::default_lcpl, dcpl, h5::default_dapl);
22+
template<> inline h5::ds_t scatter<sn::sensor::chunked_t>(
23+
hid_t fd, const std::string& path, const sn::sensor::chunked_t& obj) {
24+
using namespace ::h5::generated::sn__sensor__chunked_t_;
25+
h5::ds_t ds;
26+
h5::mute();
27+
bool exists = H5Lexists(fd, path.c_str(), H5P_DEFAULT) > 0;
28+
h5::unmute();
29+
if (!exists) {
30+
h5::dcpl_t dcpl{H5Pcreate(H5P_DATASET_CREATE)};
31+
hsize_t chunk = 256;
32+
H5Pset_chunk(dcpl, 1, &chunk);
33+
hsize_t cur = 0;
34+
hsize_t max = H5S_UNLIMITED;
35+
hid_t space = H5Screate_simple(1, &cur, &max);
36+
ds = h5::createds(fd, path, compound_type(), h5::sp_t{space},
37+
h5::default_lcpl, dcpl, h5::default_dapl);
38+
} else ds = h5::open(fd, path, h5::default_dapl);
39+
hsize_t row = h5::detail::next_row(ds);
40+
hsize_t samples_len = obj.samples.size();
41+
auto* samples_ptr = obj.samples.data();
42+
row_t r{
43+
obj.timestamp_ns,
44+
hvl_t{samples_len, (void*)samples_ptr}
45+
};
46+
herr_t err = h5::detail::write_one_row(ds, compound_type(), row, &r);
47+
(void)err;
48+
return ds;
4549
}
46-
hsize_t row = h5::detail::next_row(ds);
47-
hsize_t samples_len = obj.samples.size();
48-
auto* samples_ptr = obj.samples.data();
49-
row_t r{
50-
obj.timestamp_ns,
51-
hvl_t{samples_len, (void*)samples_ptr}
52-
};
53-
herr_t err = h5::detail::write_one_row(ds, compound_type(), row, &r);
54-
(void)err;
55-
return ds;
56-
}
5750
} // namespace h5
5851

5952
namespace h5 {
60-
template<> inline void gather<sn::sensor::chunked_t>(
61-
hid_t fd, const std::string& path, sn::sensor::chunked_t& obj) {
62-
using namespace ::h5::generated::sn__sensor__chunked_t_;
63-
h5::ds_t ds = h5::open(fd, path, h5::default_dapl);
64-
hsize_t nrows = h5::detail::next_row(ds);
65-
if (nrows == 0) return;
66-
row_t r{};
67-
herr_t err = h5::detail::read_one_row(ds, compound_type(), nrows - 1, &r);
68-
(void)err;
69-
obj.timestamp_ns = r.timestamp_ns;
70-
obj.samples.assign(static_cast<double*>(r.samples.p), static_cast<double*>(r.samples.p) + r.samples.len);
71-
H5Treclaim(compound_type(), H5S_ALL, H5P_DEFAULT, &r);
72-
}
53+
template<> inline void gather<sn::sensor::chunked_t>(
54+
hid_t fd, const std::string& path, sn::sensor::chunked_t& obj) {
55+
using namespace ::h5::generated::sn__sensor__chunked_t_;
56+
h5::ds_t ds = h5::open(fd, path, h5::default_dapl);
57+
hsize_t nrows = h5::detail::next_row(ds);
58+
if (nrows == 0) return;
59+
row_t r{};
60+
herr_t err = h5::detail::read_one_row(ds, compound_type(), nrows - 1, &r);
61+
(void)err;
62+
obj.timestamp_ns = r.timestamp_ns;
63+
obj.samples.assign(static_cast<double*>(r.samples.p), static_cast<double*>(r.samples.p) + r.samples.len);
64+
hid_t reclaim_space = H5Screate(H5S_SCALAR);
65+
#if H5_VERSION_GE(1,12,0)
66+
H5Treclaim(compound_type(), reclaim_space, H5P_DEFAULT, &r);
67+
#else
68+
H5Dvlen_reclaim(compound_type(), reclaim_space, H5P_DEFAULT, &r);
69+
#endif
70+
H5Sclose(reclaim_space);
71+
}
7372
} // namespace h5
7473

7574
H5CPP_REGISTER_SCATTER(sn::sensor::chunked_t);

tests/golden/h5_chunk_compress.expected

Lines changed: 60 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1,76 +1,75 @@
11
#pragma once
22

3-
#include <hdf5.h>
43
#include <h5cpp/all>
5-
64
namespace h5::generated::sn__sensor__chunked_compressed_t_ {
7-
8-
struct row_t {
9-
unsigned long long timestamp_ns;
10-
hvl_t samples;
11-
};
12-
13-
inline hid_t compound_type() {
14-
static const hid_t ct = []{
15-
hid_t v_samples = H5Tvlen_create(H5T_NATIVE_DOUBLE);
16-
hid_t ct = H5Tcreate(H5T_COMPOUND, sizeof(row_t));
17-
H5Tinsert(ct, "timestamp_ns", HOFFSET(row_t, timestamp_ns), H5T_NATIVE_ULLONG);
18-
H5Tinsert(ct, "samples", HOFFSET(row_t, samples), v_samples);
5+
struct row_t {
6+
unsigned long long timestamp_ns;
7+
hvl_t samples;
8+
};
9+
inline hid_t compound_type() {
10+
static const hid_t ct = []{
11+
hid_t v_samples = H5Tvlen_create(H5T_NATIVE_DOUBLE);
12+
hid_t ct = H5Tcreate(H5T_COMPOUND, sizeof(row_t));
13+
H5Tinsert(ct, "timestamp_ns", HOFFSET(row_t, timestamp_ns), H5T_NATIVE_ULLONG);
14+
H5Tinsert(ct, "samples", HOFFSET(row_t, samples), v_samples);
15+
return ct;
16+
}();
1917
return ct;
20-
}();
21-
return ct;
22-
}
23-
18+
}
2419
} // namespace h5::generated::sn__sensor__chunked_compressed_t_
2520

2621
namespace h5 {
27-
template<> inline h5::ds_t scatter<sn::sensor::chunked_compressed_t>(
28-
hid_t fd, const std::string& path, const sn::sensor::chunked_compressed_t& obj) {
29-
using namespace ::h5::generated::sn__sensor__chunked_compressed_t_;
30-
h5::ds_t ds;
31-
h5::mute();
32-
bool exists = H5Lexists(fd, path.c_str(), H5P_DEFAULT) > 0;
33-
h5::unmute();
34-
if (exists) {
35-
ds = h5::open(fd, path, h5::default_dapl);
36-
} else {
37-
h5::dcpl_t dcpl{H5Pcreate(H5P_DATASET_CREATE)};
38-
hsize_t chunk = 128;
39-
H5Pset_chunk(dcpl, 1, &chunk);
40-
H5Pset_deflate(dcpl, 9);
41-
hsize_t cur = 0;
42-
hsize_t max = H5S_UNLIMITED;
43-
hid_t space = H5Screate_simple(1, &cur, &max);
44-
ds = h5::createds(fd, path, compound_type(), h5::sp_t{space},
45-
h5::default_lcpl, dcpl, h5::default_dapl);
22+
template<> inline h5::ds_t scatter<sn::sensor::chunked_compressed_t>(
23+
hid_t fd, const std::string& path, const sn::sensor::chunked_compressed_t& obj) {
24+
using namespace ::h5::generated::sn__sensor__chunked_compressed_t_;
25+
h5::ds_t ds;
26+
h5::mute();
27+
bool exists = H5Lexists(fd, path.c_str(), H5P_DEFAULT) > 0;
28+
h5::unmute();
29+
if (!exists) {
30+
h5::dcpl_t dcpl{H5Pcreate(H5P_DATASET_CREATE)};
31+
hsize_t chunk = 128;
32+
H5Pset_chunk(dcpl, 1, &chunk);
33+
H5Pset_deflate(dcpl, 9);
34+
hsize_t cur = 0;
35+
hsize_t max = H5S_UNLIMITED;
36+
hid_t space = H5Screate_simple(1, &cur, &max);
37+
ds = h5::createds(fd, path, compound_type(), h5::sp_t{space},
38+
h5::default_lcpl, dcpl, h5::default_dapl);
39+
} else ds = h5::open(fd, path, h5::default_dapl);
40+
hsize_t row = h5::detail::next_row(ds);
41+
hsize_t samples_len = obj.samples.size();
42+
auto* samples_ptr = obj.samples.data();
43+
row_t r{
44+
obj.timestamp_ns,
45+
hvl_t{samples_len, (void*)samples_ptr}
46+
};
47+
herr_t err = h5::detail::write_one_row(ds, compound_type(), row, &r);
48+
(void)err;
49+
return ds;
4650
}
47-
hsize_t row = h5::detail::next_row(ds);
48-
hsize_t samples_len = obj.samples.size();
49-
auto* samples_ptr = obj.samples.data();
50-
row_t r{
51-
obj.timestamp_ns,
52-
hvl_t{samples_len, (void*)samples_ptr}
53-
};
54-
herr_t err = h5::detail::write_one_row(ds, compound_type(), row, &r);
55-
(void)err;
56-
return ds;
57-
}
5851
} // namespace h5
5952

6053
namespace h5 {
61-
template<> inline void gather<sn::sensor::chunked_compressed_t>(
62-
hid_t fd, const std::string& path, sn::sensor::chunked_compressed_t& obj) {
63-
using namespace ::h5::generated::sn__sensor__chunked_compressed_t_;
64-
h5::ds_t ds = h5::open(fd, path, h5::default_dapl);
65-
hsize_t nrows = h5::detail::next_row(ds);
66-
if (nrows == 0) return;
67-
row_t r{};
68-
herr_t err = h5::detail::read_one_row(ds, compound_type(), nrows - 1, &r);
69-
(void)err;
70-
obj.timestamp_ns = r.timestamp_ns;
71-
obj.samples.assign(static_cast<double*>(r.samples.p), static_cast<double*>(r.samples.p) + r.samples.len);
72-
H5Treclaim(compound_type(), H5S_ALL, H5P_DEFAULT, &r);
73-
}
54+
template<> inline void gather<sn::sensor::chunked_compressed_t>(
55+
hid_t fd, const std::string& path, sn::sensor::chunked_compressed_t& obj) {
56+
using namespace ::h5::generated::sn__sensor__chunked_compressed_t_;
57+
h5::ds_t ds = h5::open(fd, path, h5::default_dapl);
58+
hsize_t nrows = h5::detail::next_row(ds);
59+
if (nrows == 0) return;
60+
row_t r{};
61+
herr_t err = h5::detail::read_one_row(ds, compound_type(), nrows - 1, &r);
62+
(void)err;
63+
obj.timestamp_ns = r.timestamp_ns;
64+
obj.samples.assign(static_cast<double*>(r.samples.p), static_cast<double*>(r.samples.p) + r.samples.len);
65+
hid_t reclaim_space = H5Screate(H5S_SCALAR);
66+
#if H5_VERSION_GE(1,12,0)
67+
H5Treclaim(compound_type(), reclaim_space, H5P_DEFAULT, &r);
68+
#else
69+
H5Dvlen_reclaim(compound_type(), reclaim_space, H5P_DEFAULT, &r);
70+
#endif
71+
H5Sclose(reclaim_space);
72+
}
7473
} // namespace h5
7574

7675
H5CPP_REGISTER_SCATTER(sn::sensor::chunked_compressed_t);

0 commit comments

Comments
 (0)