QMCPACK
test_hdf_archive.cpp File Reference
+ Include dependency graph for test_hdf_archive.cpp:

Go to the source code of this file.

Functions

 TEST_CASE ("hdf_archive_empty_file", "[hdf]")
 
 TEST_CASE ("hdf_archive_failed_to_open", "[hdf]")
 
 TEST_CASE ("hdf_archive_simple_data", "[hdf]")
 
 TEST_CASE ("hdf_archive_vector", "[hdf]")
 
 TEST_CASE ("hdf_archive_group", "[hdf]")
 
 TEST_CASE ("hdf_archive_scalar_convert", "[hdf]")
 
 TEST_CASE ("hdf_archive_tiny_vector", "[hdf]")
 
 TEST_CASE ("hdf_archive_tensor", "[hdf]")
 
 TEST_CASE ("hdf_archive_string", "[hdf]")
 
 TEST_CASE ("hdf_archive_string_vector", "[hdf]")
 
 TEST_CASE ("hdf_archive_dataset_existence_checking", "[hdf]")
 
 TEST_CASE ("hdf_archive_dataset_type_checking", "[hdf]")
 
 TEST_CASE ("hdf_std_vec_bool", "[hdf]")
 

Function Documentation

◆ TEST_CASE() [1/13]

TEST_CASE ( "hdf_archive_empty_file"  ,
""  [hdf] 
)

Definition at line 27 of file test_hdf_archive.cpp.

References hdf_archive::close(), hdf_archive::create(), qmcplusplus::okay, hdf_archive::open(), and qmcplusplus::REQUIRE().

28 {
29  hdf_archive hd;
30  bool okay = hd.create("test1.hdf");
31  REQUIRE(okay);
32  hd.close();
33 
34  hdf_archive hd2;
35  okay = hd2.open("test1.hdf");
36  REQUIRE(okay);
37  hd2.close();
38 }
bool open(const std::filesystem::path &fname, unsigned flags=H5F_ACC_RDWR)
open a file
void close()
close all the open groups and file
Definition: hdf_archive.cpp:38
class to handle hdf file
Definition: hdf_archive.h:51
REQUIRE(std::filesystem::exists(filename))
bool create(const std::filesystem::path &fname, unsigned flags=H5F_ACC_TRUNC)
create a file

◆ TEST_CASE() [2/13]

TEST_CASE ( "hdf_archive_failed_to_open"  ,
""  [hdf] 
)

Definition at line 41 of file test_hdf_archive.cpp.

References hdf_archive::close(), qmcplusplus::okay, hdf_archive::open(), and qmcplusplus::REQUIRE().

42 {
43  hdf_archive hd;
44  bool okay = hd.open("should_not_exist.hdf");
45  REQUIRE(okay == false);
46  hd.close();
47 }
bool open(const std::filesystem::path &fname, unsigned flags=H5F_ACC_RDWR)
open a file
void close()
close all the open groups and file
Definition: hdf_archive.cpp:38
class to handle hdf file
Definition: hdf_archive.h:51
REQUIRE(std::filesystem::exists(filename))

◆ TEST_CASE() [3/13]

TEST_CASE ( "hdf_archive_simple_data"  ,
""  [hdf] 
)

Definition at line 50 of file test_hdf_archive.cpp.

References hdf_archive::close(), hdf_archive::create(), hdf_archive::getShape(), qmcplusplus::okay, hdf_archive::open(), hdf_archive::read(), hdf_archive::readEntry(), qmcplusplus::REQUIRE(), hdf_archive::write(), and hdf_archive::writeEntry().

51 {
52  hdf_archive hd;
53  hd.create("test_simple_data.hdf");
54  bool b = true;
55  bool okay = hd.writeEntry(b, "bool");
56  REQUIRE(okay);
57 
58  int i = 23;
59  okay = hd.writeEntry(i, "int");
60  REQUIRE(okay);
61 
62  float f = -2.3;
63  okay = hd.writeEntry(f, "float");
64  REQUIRE(okay);
65 
66  const double d = 4.5;
67  okay = hd.writeEntry(d, "double");
68  REQUIRE(okay);
69 
70  std::complex<float> cf(2.3, 3.4);
71  okay = hd.writeEntry(cf, "complex float");
72  REQUIRE(okay);
73 
74  hd.close();
75 
76  // Use the internally checked writes
77 
78  hdf_archive hd3;
79  hd3.create("test_simple_data.hdf");
80  hd3.write(b, "bool");
81  hd3.write(i, "int");
82  hd3.write(f, "float");
83  hd3.write(d, "double");
84  hd3.writeEntry(cf, "complex float");
85  hd3.close();
86 
87  // now read the file and ensure the values are the same
88 
89  hdf_archive hd2;
90  hd2.open("test_simple_data.hdf");
91  bool b2 = false;
92  okay = hd2.readEntry(b2, "bool");
93  REQUIRE(okay);
94  REQUIRE(b == b2);
95 
96  int i2;
97  okay = hd2.readEntry(i2, "int");
98  REQUIRE(okay);
99  REQUIRE(i == i2);
100 
101  // deliberately out of order
102  double d2;
103  okay = hd2.readEntry(d2, "double");
104  REQUIRE(okay);
105  REQUIRE(d == d2);
106 
107  double f2;
108  okay = hd2.readEntry(f2, "float");
109  REQUIRE(okay);
110  REQUIRE(f == f2);
111 
112  std::complex<float> cf2;
113  okay = hd2.readEntry(cf2, "complex float");
114  REQUIRE(okay);
115  REQUIRE(cf == cf2);
116 
117  // check an error occurs for non-existent entry
118  int i666;
119  okay = hd2.readEntry(i666, "not an entry");
120  REQUIRE(!okay);
121 
122  hd2.close();
123 
124  // now read the file and ensure the values are the same
125 
126  hdf_archive hd4;
127  hd4.open("test_simple_data.hdf");
128  bool b4 = false;
129  hd4.read(b4, "bool");
130  REQUIRE(b == b4);
131 
132  int i4;
133  hd4.read(i4, "int");
134  REQUIRE(i == i4);
135 
136  // deliberately out of order
137  double d4;
138  hd4.read(d4, "double");
139  REQUIRE(d == d4);
140 
141  float f4;
142  hd4.read(f4, "float");
143  REQUIRE(f == f4);
144 
145  std::complex<float> cf4;
146  hd4.read(cf4, "complex float");
147  REQUIRE(cf == cf4);
148 
149  //read scalar
150  std::vector<int> datashape;
151  okay = hd4.getShape<double>("double", datashape);
152  REQUIRE(okay);
153  REQUIRE(datashape.size() == 0);
154 
155  okay = hd4.getShape<std::complex<float>>("complex float", datashape);
156  REQUIRE(okay);
157  REQUIRE(datashape.size() == 0);
158 
159  okay = hd4.getShape<float>("complex float", datashape);
160  REQUIRE(okay);
161  REQUIRE(datashape.size() == 1);
162  REQUIRE(datashape[0] == 2);
163 
164  hd4.close();
165 }
void write(T &data, const std::string &aname)
write the data to the group aname and check status runtime error is issued on I/O error ...
Definition: hdf_archive.h:259
bool open(const std::filesystem::path &fname, unsigned flags=H5F_ACC_RDWR)
open a file
void close()
close all the open groups and file
Definition: hdf_archive.cpp:38
class to handle hdf file
Definition: hdf_archive.h:51
bool getShape(const std::string &aname, std::vector< int > &sizes_out)
read the shape of multidimensional filespace from the group aname this function can be used to query ...
Definition: hdf_archive.h:231
REQUIRE(std::filesystem::exists(filename))
bool create(const std::filesystem::path &fname, unsigned flags=H5F_ACC_TRUNC)
create a file
void read(T &data, const std::string &aname)
read the data from the group aname and check status runtime error is issued on I/O error ...
Definition: hdf_archive.h:306
bool readEntry(T &data, const std::string &aname)
read the data from the group aname and return status use read() for inbuilt error checking ...
Definition: hdf_archive.h:293
bool writeEntry(T &data, const std::string &aname)
write the data to the group aname and return status use write() for inbuilt error checking ...
Definition: hdf_archive.h:244

◆ TEST_CASE() [4/13]

TEST_CASE ( "hdf_archive_vector"  ,
""  [hdf] 
)

Definition at line 167 of file test_hdf_archive.cpp.

References qmcplusplus::CHECK(), hdf_archive::close(), hdf_archive::create(), qmcplusplus::okay, hdf_archive::open(), hdf_archive::readEntry(), qmcplusplus::REQUIRE(), and hdf_archive::writeEntry().

168 {
169  hdf_archive hd;
170  hd.create("test_stl.hdf");
171 
172  vector<double> v(3);
173  v[0] = 2.3;
174  v[1] = -100.3;
175  v[2] = 135.22;
176 
177  bool okay = hd.writeEntry(v, "vector_double");
178  REQUIRE(okay);
179 
180  const vector<double> v_const(v);
181  okay = hd.writeEntry(v_const, "vector_double_const");
182  REQUIRE(okay);
183 
184  hd.close();
185 
186  hdf_archive hd2;
187  okay = hd2.open("test_stl.hdf");
188  REQUIRE(okay);
189 
190  vector<double> v2;
191  okay = hd2.readEntry(v2, "vector_double");
192  REQUIRE(v2.size() == 3);
193  for (int i = 0; i < v.size(); i++)
194  CHECK(v[i] == v2[i]);
195 
196  vector<double> v2_for_const;
197  okay = hd2.readEntry(v2_for_const, "vector_double_const");
198  REQUIRE(v2_for_const.size() == 3);
199  for (int i = 0; i < v_const.size(); i++)
200  CHECK(v_const[i] == v2_for_const[i]);
201 }
bool open(const std::filesystem::path &fname, unsigned flags=H5F_ACC_RDWR)
open a file
void close()
close all the open groups and file
Definition: hdf_archive.cpp:38
class to handle hdf file
Definition: hdf_archive.h:51
REQUIRE(std::filesystem::exists(filename))
bool create(const std::filesystem::path &fname, unsigned flags=H5F_ACC_TRUNC)
create a file
CHECK(log_values[0]==ComplexApprox(std::complex< double >{ 5.603777579195571, -6.1586603331188225 }))
bool readEntry(T &data, const std::string &aname)
read the data from the group aname and return status use read() for inbuilt error checking ...
Definition: hdf_archive.h:293
bool writeEntry(T &data, const std::string &aname)
write the data to the group aname and return status use write() for inbuilt error checking ...
Definition: hdf_archive.h:244

◆ TEST_CASE() [5/13]

TEST_CASE ( "hdf_archive_group"  ,
""  [hdf] 
)

Definition at line 203 of file test_hdf_archive.cpp.

References qmcplusplus::CHECK(), hdf_archive::close(), hdf_archive::create(), hdf_archive::group_path_as_string(), qmcplusplus::okay, hdf_archive::open(), hdf_archive::push(), qmcplusplus::REQUIRE(), and hdf_archive::writeEntry().

204 {
205  hdf_archive hd;
206  hd.create("test_group.hdf");
207 
208  int i = 3;
209  bool okay = hd.writeEntry(i, "int");
210  REQUIRE(okay);
211 
212  CHECK(hd.group_path_as_string() == "");
213 
214  hd.push("name1");
215 
216  CHECK(hd.group_path_as_string() == "name1");
217 
218  int j = 3;
219  okay = hd.writeEntry(j, "int2");
220  REQUIRE(okay);
221 
222  hd.push("name2");
223  CHECK(hd.group_path_as_string() == "name1/name2");
224 
225  hd.close();
226 
227  // Check that opening a group on a closed file throws an exception
228  REQUIRE_THROWS(hd.push("group"));
229 
230  hdf_archive hd2;
231  hd2.open("test_group.hdf");
232  bool int_is_group = hd2.is_group("int");
233  REQUIRE(int_is_group == false);
234 
235  bool name1_is_group = hd2.is_group("name1");
236  REQUIRE(name1_is_group);
237 
238  int j2 = 0;
239  okay = hd2.readEntry(j2, "name1/int2");
240  REQUIRE(okay);
241  REQUIRE(j2 == j);
242 
243  int j3 = 0;
244  hd2.push("name1", false);
245  okay = hd2.readEntry(j3, "int2");
246  REQUIRE(okay);
247  REQUIRE(j3 == j);
248 
249  REQUIRE_THROWS(hd2.push("nonexistent_group", false));
250 
251  hd2.close();
252 }
bool open(const std::filesystem::path &fname, unsigned flags=H5F_ACC_RDWR)
open a file
void close()
close all the open groups and file
Definition: hdf_archive.cpp:38
class to handle hdf file
Definition: hdf_archive.h:51
REQUIRE(std::filesystem::exists(filename))
void push(const std::string &gname, bool createit=true)
push a group to the group stack
bool create(const std::filesystem::path &fname, unsigned flags=H5F_ACC_TRUNC)
create a file
std::string group_path_as_string() const
Return a string representation of the current group stack.
CHECK(log_values[0]==ComplexApprox(std::complex< double >{ 5.603777579195571, -6.1586603331188225 }))
bool writeEntry(T &data, const std::string &aname)
write the data to the group aname and return status use write() for inbuilt error checking ...
Definition: hdf_archive.h:244

◆ TEST_CASE() [6/13]

TEST_CASE ( "hdf_archive_scalar_convert"  ,
""  [hdf] 
)

Definition at line 254 of file test_hdf_archive.cpp.

References hdf_archive::close(), hdf_archive::create(), qmcplusplus::okay, hdf_archive::open(), hdf_archive::readEntry(), qmcplusplus::REQUIRE(), and hdf_archive::writeEntry().

255 {
256  hdf_archive hd;
257  hd.create("test_scalar_convert.hdf");
258 
259  TinyVector<double, 1> v0(1);
260  bool okay = hd.writeEntry(v0, "tiny_vector_one");
261  REQUIRE(okay);
262 
263  double v1(1);
264  okay = hd.writeEntry(v1, "tiny_scalar_one");
265  REQUIRE(okay);
266 
267  hd.close();
268 
269  hdf_archive hd2;
270  hd2.open("test_scalar_convert.hdf");
271 
272  TinyVector<double, 1> v2(0);
273  okay = hd2.readEntry(v2, "tiny_scalar_one");
274  REQUIRE(okay);
275 
276  double v3(0);
277  okay = hd2.readEntry(v3, "tiny_vector_one");
278  REQUIRE(okay);
279 
280  REQUIRE(v0[0] == v3);
281  REQUIRE(v1 == v2[0]);
282 }
Fixed-size array.
Definition: OhmmsTinyMeta.h:30
bool open(const std::filesystem::path &fname, unsigned flags=H5F_ACC_RDWR)
open a file
void close()
close all the open groups and file
Definition: hdf_archive.cpp:38
class to handle hdf file
Definition: hdf_archive.h:51
REQUIRE(std::filesystem::exists(filename))
bool create(const std::filesystem::path &fname, unsigned flags=H5F_ACC_TRUNC)
create a file
bool readEntry(T &data, const std::string &aname)
read the data from the group aname and return status use read() for inbuilt error checking ...
Definition: hdf_archive.h:293
bool writeEntry(T &data, const std::string &aname)
write the data to the group aname and return status use write() for inbuilt error checking ...
Definition: hdf_archive.h:244

◆ TEST_CASE() [7/13]

TEST_CASE ( "hdf_archive_tiny_vector"  ,
""  [hdf] 
)

Definition at line 284 of file test_hdf_archive.cpp.

References hdf_archive::close(), hdf_archive::create(), qmcplusplus::okay, hdf_archive::open(), hdf_archive::readEntry(), qmcplusplus::REQUIRE(), TinyVector< T, D >::size(), and hdf_archive::writeEntry().

285 {
286  hdf_archive hd;
287  hd.create("test_tiny_vector.hdf");
288 
290  TinyVector<std::complex<double>, 2> v_cplx(2);
291 
292  v_cplx[0] = v[0] = 1.2;
293  v_cplx[1] = v[1] = 1.3;
294 
295  bool okay = hd.writeEntry(v, "tiny_vector_double");
296  REQUIRE(okay);
297  okay = hd.writeEntry(v_cplx, "tiny_vector_complex_double");
298  REQUIRE(okay);
299 
300  hd.close();
301 
302  hdf_archive hd2;
303  hd2.open("test_tiny_vector.hdf");
304 
306  TinyVector<std::complex<double>, 2> v2_cplx(2);
307  okay = hd2.readEntry(v2, "tiny_vector_double");
308  REQUIRE(okay);
309  okay = hd2.readEntry(v2_cplx, "tiny_vector_complex_double");
310  REQUIRE(okay);
311  for (int i = 0; i < v.size(); i++)
312  {
313  REQUIRE(v[i] == v2[i]);
314  REQUIRE(v_cplx[i] == v2_cplx[i]);
315  }
316 }
bool open(const std::filesystem::path &fname, unsigned flags=H5F_ACC_RDWR)
open a file
void close()
close all the open groups and file
Definition: hdf_archive.cpp:38
class to handle hdf file
Definition: hdf_archive.h:51
REQUIRE(std::filesystem::exists(filename))
bool create(const std::filesystem::path &fname, unsigned flags=H5F_ACC_TRUNC)
create a file
bool readEntry(T &data, const std::string &aname)
read the data from the group aname and return status use read() for inbuilt error checking ...
Definition: hdf_archive.h:293
bool writeEntry(T &data, const std::string &aname)
write the data to the group aname and return status use write() for inbuilt error checking ...
Definition: hdf_archive.h:244

◆ TEST_CASE() [8/13]

TEST_CASE ( "hdf_archive_tensor"  ,
""  [hdf] 
)

Definition at line 318 of file test_hdf_archive.cpp.

References hdf_archive::close(), hdf_archive::create(), qmcplusplus::okay, hdf_archive::open(), hdf_archive::readEntry(), qmcplusplus::REQUIRE(), and hdf_archive::writeEntry().

319 {
320  hdf_archive hd;
321  hd.create("test_tensor.hdf");
322 
323  Tensor<float, 2> v(2);
324 
325  v(0, 1) = 1.2f;
326  v(1, 0) = 1.3f;
327  v(0, 1) = -2.3f;
328  v(1, 1) = 10.0f;
329 
330  bool okay = hd.writeEntry(v, "tiny_tensor_float");
331  REQUIRE(okay);
332 
333  hd.close();
334 
335  hdf_archive hd2;
336  hd2.open("test_tensor.hdf");
337 
338  Tensor<float, 2> v2;
339  okay = hd2.readEntry(v2, "tiny_tensor_float");
340  REQUIRE(okay);
341  for (int i = 0; i < 2; i++)
342  {
343  for (int j = 0; j < 2; j++)
344  {
345  REQUIRE(v(i, j) == v2(i, j));
346  }
347  }
348 }
bool open(const std::filesystem::path &fname, unsigned flags=H5F_ACC_RDWR)
open a file
void close()
close all the open groups and file
Definition: hdf_archive.cpp:38
class to handle hdf file
Definition: hdf_archive.h:51
Tensor<T,D> class for D by D tensor.
Definition: OhmmsTinyMeta.h:32
REQUIRE(std::filesystem::exists(filename))
bool create(const std::filesystem::path &fname, unsigned flags=H5F_ACC_TRUNC)
create a file
bool readEntry(T &data, const std::string &aname)
read the data from the group aname and return status use read() for inbuilt error checking ...
Definition: hdf_archive.h:293
bool writeEntry(T &data, const std::string &aname)
write the data to the group aname and return status use write() for inbuilt error checking ...
Definition: hdf_archive.h:244

◆ TEST_CASE() [9/13]

TEST_CASE ( "hdf_archive_string"  ,
""  [hdf] 
)

Definition at line 350 of file test_hdf_archive.cpp.

References hdf_archive::close(), hdf_archive::create(), qmcplusplus::okay, hdf_archive::open(), hdf_archive::readEntry(), qmcplusplus::REQUIRE(), qmcplusplus::Units::time::s, and hdf_archive::writeEntry().

351 {
352  hdf_archive hd;
353  hd.create("test_string.hdf");
354 
355  string s("this is a test");
356  bool okay = hd.writeEntry(s, "string");
357  REQUIRE(okay);
358 
359 
360  std::ostringstream o;
361  o << "Another test" << std::endl;
362  okay = hd.writeEntry(o, "ostringstream");
363  REQUIRE(okay);
364 
365  hd.close();
366 
367  hdf_archive hd2;
368  okay = hd2.open("test_string.hdf");
369  REQUIRE(okay);
370  string s2;
371  okay = hd2.readEntry(s2, "string");
372  REQUIRE(okay);
373  REQUIRE(s == s2);
374 
375  string o2;
376  okay = hd2.readEntry(o2, "ostringstream");
377  REQUIRE(okay);
378  REQUIRE(o.str() == o2);
379 }
bool open(const std::filesystem::path &fname, unsigned flags=H5F_ACC_RDWR)
open a file
void close()
close all the open groups and file
Definition: hdf_archive.cpp:38
class to handle hdf file
Definition: hdf_archive.h:51
REQUIRE(std::filesystem::exists(filename))
bool create(const std::filesystem::path &fname, unsigned flags=H5F_ACC_TRUNC)
create a file
bool readEntry(T &data, const std::string &aname)
read the data from the group aname and return status use read() for inbuilt error checking ...
Definition: hdf_archive.h:293
bool writeEntry(T &data, const std::string &aname)
write the data to the group aname and return status use write() for inbuilt error checking ...
Definition: hdf_archive.h:244

◆ TEST_CASE() [10/13]

TEST_CASE ( "hdf_archive_string_vector"  ,
""  [hdf] 
)

Definition at line 381 of file test_hdf_archive.cpp.

References hdf_archive::close(), hdf_archive::create(), qmcplusplus::okay, hdf_archive::open(), hdf_archive::readEntry(), qmcplusplus::REQUIRE(), and hdf_archive::writeEntry().

382 {
383  hdf_archive hd;
384  hd.create("test_string_vector.hdf");
385 
386  std::vector<std::string> strings;
387  strings.push_back("first");
388  // One entry should be longer than 15 characters to avoid the short
389  // string optimization and allocate space for the string on the heap
390  strings.push_back("really long string");
391 
392  bool okay = hd.writeEntry(strings, "string_vector");
393  REQUIRE(okay);
394 
395  hd.close();
396 
397  hdf_archive hd2;
398  okay = hd2.open("test_string_vector.hdf");
399  REQUIRE(okay);
400 
401  std::vector<std::string> strings2;
402  okay = hd2.readEntry(strings2, "string_vector");
403  REQUIRE(okay);
404 
405  REQUIRE(strings2.size() == 2);
406  REQUIRE(strings2[0] == "first");
407  REQUIRE(strings2[1] == "really long string");
408 }
bool open(const std::filesystem::path &fname, unsigned flags=H5F_ACC_RDWR)
open a file
void close()
close all the open groups and file
Definition: hdf_archive.cpp:38
class to handle hdf file
Definition: hdf_archive.h:51
REQUIRE(std::filesystem::exists(filename))
bool create(const std::filesystem::path &fname, unsigned flags=H5F_ACC_TRUNC)
create a file
bool readEntry(T &data, const std::string &aname)
read the data from the group aname and return status use read() for inbuilt error checking ...
Definition: hdf_archive.h:293
bool writeEntry(T &data, const std::string &aname)
write the data to the group aname and return status use write() for inbuilt error checking ...
Definition: hdf_archive.h:244

◆ TEST_CASE() [11/13]

TEST_CASE ( "hdf_archive_dataset_existence_checking"  ,
""  [hdf] 
)

Definition at line 410 of file test_hdf_archive.cpp.

References hdf_archive::close(), hdf_archive::create(), hdf_archive::is_dataset(), qmcplusplus::okay, hdf_archive::open(), qmcplusplus::REQUIRE(), and hdf_archive::writeEntry().

411 {
412  hdf_archive hd;
413  hd.create("test_dataset_existence_checking.hdf");
414 
415  std::vector<uint64_t> numbers;
416  numbers.push_back(123456);
417  std::string ds_tag = "numbers_vector";
418 
419  bool okay = hd.writeEntry(numbers, ds_tag);
420  REQUIRE(okay);
421 
422  hd.close();
423 
424  hdf_archive hd2;
425  okay = hd2.open("test_dataset_existence_checking.hdf");
426  REQUIRE(okay);
427 
428  REQUIRE(hd2.is_dataset(ds_tag));
429  REQUIRE(!hd2.is_dataset("tag_doesnt_exist"));
430 }
bool open(const std::filesystem::path &fname, unsigned flags=H5F_ACC_RDWR)
open a file
void close()
close all the open groups and file
Definition: hdf_archive.cpp:38
class to handle hdf file
Definition: hdf_archive.h:51
REQUIRE(std::filesystem::exists(filename))
bool is_dataset(const std::string &aname)
check if aname is a dataset
Definition: hdf_archive.h:165
bool create(const std::filesystem::path &fname, unsigned flags=H5F_ACC_TRUNC)
create a file
bool writeEntry(T &data, const std::string &aname)
write the data to the group aname and return status use write() for inbuilt error checking ...
Definition: hdf_archive.h:244

◆ TEST_CASE() [12/13]

TEST_CASE ( "hdf_archive_dataset_type_checking"  ,
""  [hdf] 
)

Definition at line 432 of file test_hdf_archive.cpp.

References hdf_archive::close(), hdf_archive::create(), hdf_archive::is_dataset_of_type(), qmcplusplus::okay, hdf_archive::open(), qmcplusplus::REQUIRE(), and hdf_archive::writeEntry().

433 {
434  hdf_archive hd;
435  hd.create("test_dataset_type_checking.hdf");
436 
437  std::vector<uint64_t> numbers;
438  numbers.push_back(123456);
439  std::string ds_tag = "numbers_vector";
440 
441  bool okay = hd.writeEntry(numbers, ds_tag);
442  REQUIRE(okay);
443 
444  hd.close();
445 
446  hdf_archive hd2;
447  okay = hd2.open("test_dataset_type_checking.hdf");
448  REQUIRE(okay);
449 
450  bool is_correct_type = hd2.is_dataset_of_type<uint64_t>(ds_tag);
451  REQUIRE(is_correct_type);
452  is_correct_type = hd2.is_dataset_of_type<int64_t>(ds_tag);
453  REQUIRE(is_correct_type == false);
454  REQUIRE_THROWS_AS(hd2.is_dataset_of_type<uint64_t>("tag_doesnt_exist"), std::runtime_error);
455 }
bool open(const std::filesystem::path &fname, unsigned flags=H5F_ACC_RDWR)
open a file
void close()
close all the open groups and file
Definition: hdf_archive.cpp:38
class to handle hdf file
Definition: hdf_archive.h:51
bool is_dataset_of_type(const std::string &aname)
check if aname is a dataset of type T
Definition: hdf_archive.h:180
REQUIRE(std::filesystem::exists(filename))
bool create(const std::filesystem::path &fname, unsigned flags=H5F_ACC_TRUNC)
create a file
bool writeEntry(T &data, const std::string &aname)
write the data to the group aname and return status use write() for inbuilt error checking ...
Definition: hdf_archive.h:244

◆ TEST_CASE() [13/13]

TEST_CASE ( "hdf_std_vec_bool"  ,
""  [hdf] 
)

Definition at line 457 of file test_hdf_archive.cpp.

References qmcplusplus::CHECK(), hdf_archive::close(), hdf_archive::create(), qmcplusplus::okay, hdf_archive::open(), hdf_archive::readEntry(), qmcplusplus::REQUIRE(), and hdf_archive::writeEntry().

458 {
459  hdf_archive hd;
460  hd.create("test_vec_bool.hdf");
461 
462  std::vector<bool> v(3, false);
463  v[0] = true;
464 
465  bool okay = hd.writeEntry(v, "vector_bool");
466  REQUIRE(okay);
467 
468  const std::vector<bool> v_const(v);
469  okay = hd.writeEntry(v_const, "vector_bool_const");
470  REQUIRE(okay);
471 
472  hd.close();
473 
474  hdf_archive hd2;
475  okay = hd2.open("test_vec_bool.hdf");
476  REQUIRE(okay);
477 
478  std::vector<bool> v2;
479  okay = hd2.readEntry(v2, "vector_bool");
480  REQUIRE(v2.size() == 3);
481  for (int i = 0; i < v.size(); i++)
482  CHECK(v[i] == v2[i]);
483 
484  std::vector<bool> v2_for_const;
485  okay = hd2.readEntry(v2_for_const, "vector_bool_const");
486  REQUIRE(v2_for_const.size() == 3);
487  for (int i = 0; i < v_const.size(); i++)
488  CHECK(v_const[i] == v2_for_const[i]);
489 
490 }
bool open(const std::filesystem::path &fname, unsigned flags=H5F_ACC_RDWR)
open a file
void close()
close all the open groups and file
Definition: hdf_archive.cpp:38
class to handle hdf file
Definition: hdf_archive.h:51
REQUIRE(std::filesystem::exists(filename))
bool create(const std::filesystem::path &fname, unsigned flags=H5F_ACC_TRUNC)
create a file
CHECK(log_values[0]==ComplexApprox(std::complex< double >{ 5.603777579195571, -6.1586603331188225 }))
bool readEntry(T &data, const std::string &aname)
read the data from the group aname and return status use read() for inbuilt error checking ...
Definition: hdf_archive.h:293
bool writeEntry(T &data, const std::string &aname)
write the data to the group aname and return status use write() for inbuilt error checking ...
Definition: hdf_archive.h:244