ATLAS Offline Software
Loading...
Searching...
No Matches
test-hdf5-merge.cxx File Reference
#include "HDF5Utils/Merger.h"
#include "H5Cpp.h"
#include <algorithm>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
Include dependency graph for test-hdf5-merge.cxx:

Go to the source code of this file.

Functions

int main ()

Function Documentation

◆ main()

int main ( )

Definition at line 57 of file test-hdf5-merge.cxx.

57 {
58 const std::string groupChain = "a/b/c";
59 const std::string dsPath = "/a/b/c/dataset";
60 const hsize_t rows = 5;
61
62 {
63 H5::H5File src("merge_test_src1.h5", H5F_ACC_TRUNC);
64 writeNestedDataset(src, groupChain, "dataset", 0, rows);
65 }
66 {
67 H5::H5File src("merge_test_src2.h5", H5F_ACC_TRUNC);
68 writeNestedDataset(src, groupChain, "dataset", 100, rows);
69 }
70
71 H5::H5File target("merge_test_out.h5", H5F_ACC_TRUNC);
72 H5Utils::Merger merger;
73
74 // Merging into a target with none of "a/b/c" yet: this is the path that
75 // recursively creates new groups, and used to trigger the double merge.
76 {
77 H5::H5File src1("merge_test_src1.h5", H5F_ACC_RDONLY);
78 merger.merge(target, src1);
79 }
80 hsize_t afterFirst = readExtent(target, dsPath);
81 if (afterFirst != rows) {
82 std::cerr << "FAIL: merging into a brand-new nested group produced "
83 << afterFirst << " rows, expected " << rows
84 << " (double-merge bug?)" << std::endl;
85 return 1;
86 }
87
88 // Merging a second source into the now-existing "a/b/c" group: this is
89 // the ordinary "found" path and should still merge exactly once.
90 {
91 H5::H5File src2("merge_test_src2.h5", H5F_ACC_RDONLY);
92 merger.merge(target, src2);
93 }
94 hsize_t afterSecond = readExtent(target, dsPath);
95 if (afterSecond != 2 * rows) {
96 std::cerr << "FAIL: merging into an existing nested group produced "
97 << afterSecond << " rows, expected " << 2 * rows << std::endl;
98 return 1;
99 }
100
101 std::cout << "test-hdf5-merge: OK" << std::endl;
102 return 0;
103}
void merge(H5::Group &target, const H5::Group &source)
Merge a source group into a target group.
Definition Merger.cxx:29