Mantid
Loading...
Searching...
No Matches
H5Util.cpp
Go to the documentation of this file.
1// Mantid Repository : https://github.com/mantidproject/mantid
2//
3// Copyright © 2018 ISIS Rutherford Appleton Laboratory UKRI,
4// NScD Oak Ridge National Laboratory, European Spallation Source,
5// Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
6// SPDX - License - Identifier: GPL - 3.0 +
10
11#include <H5Cpp.h>
12#include <algorithm>
13#include <array>
14#include <boost/numeric/conversion/cast.hpp>
15
16using namespace H5;
17
19
20namespace {
23
24const std::string NX_ATTR_CLASS("NX_class");
25const std::string CAN_SAS_ATTR_CLASS("canSAS_class");
26} // namespace
27
28// -------------------------------------------------------------------
29// convert primitives to HDF5 enum
30// -------------------------------------------------------------------
31
32template <typename NumT> DataType getType() { throw DataTypeIException(); }
33
34template <> MANTID_DATAHANDLING_DLL DataType getType<float>() { return PredType::NATIVE_FLOAT; }
35
36template <> MANTID_DATAHANDLING_DLL DataType getType<double>() { return PredType::NATIVE_DOUBLE; }
37
38template <> MANTID_DATAHANDLING_DLL DataType getType<int32_t>() { return PredType::NATIVE_INT32; }
39
40template <> MANTID_DATAHANDLING_DLL DataType getType<uint32_t>() { return PredType::NATIVE_UINT32; }
41
42template <> MANTID_DATAHANDLING_DLL DataType getType<int64_t>() { return PredType::NATIVE_INT64; }
43
44template <> MANTID_DATAHANDLING_DLL DataType getType<uint64_t>() { return PredType::NATIVE_UINT64; }
45
46DataSpace getDataSpace(const size_t length) {
47 hsize_t dims[] = {length};
48 return DataSpace(1, dims);
49}
50
51template <typename NumT> DataSpace getDataSpace(const std::vector<NumT> &data) {
52 return H5Util::getDataSpace(data.size());
53}
54
55namespace {
56
57template <typename NumT> H5::DataSet writeScalarDataSet(Group &group, const std::string &name, const NumT &value) {
58 static_assert(std::is_integral<NumT>::value || std::is_floating_point<NumT>::value,
59 "The writeNumAttribute function only accepts integral of "
60 "floating point values.");
61 auto dataType = getType<NumT>();
62 DataSpace dataSpace = getDataSpace(1);
63 H5::DataSet data = group.createDataSet(name, dataType, dataSpace);
64 data.write(&value, dataType);
65 return data;
66}
67
68template <>
69H5::DataSet writeScalarDataSet<std::string>(Group &group, const std::string &name, const std::string &value) {
70 StrType dataType(0, value.length() + 1);
71 DataSpace dataSpace = getDataSpace(1);
72 H5::DataSet data = group.createDataSet(name, dataType, dataSpace);
73 data.write(value, dataType);
74 return data;
75}
76
77} // namespace
78
79// -------------------------------------------------------------------
80// write methods
81// -------------------------------------------------------------------
82
83Group createGroupNXS(H5File &file, const std::string &name, const std::string &nxtype) {
84 auto group = file.createGroup(name);
85 writeStrAttribute(group, NX_ATTR_CLASS, nxtype);
86 return group;
87}
88
89Group createGroupNXS(Group &group, const std::string &name, const std::string &nxtype) {
90 auto outGroup = group.createGroup(name);
91 writeStrAttribute(outGroup, NX_ATTR_CLASS, nxtype);
92 return outGroup;
93}
94
95Group createGroupCanSAS(H5File &file, const std::string &name, const std::string &nxtype, const std::string &cstype) {
96 auto outGroup = createGroupNXS(file, name, nxtype);
97 writeStrAttribute(outGroup, CAN_SAS_ATTR_CLASS, cstype);
98 return outGroup;
99}
100
101Group createGroupCanSAS(Group &group, const std::string &name, const std::string &nxtype, const std::string &cstype) {
102 auto outGroup = createGroupNXS(group, name, nxtype);
103 writeStrAttribute(outGroup, CAN_SAS_ATTR_CLASS, cstype);
104 return outGroup;
105}
106
107DSetCreatPropList setCompressionAttributes(const std::size_t length, const int deflateLevel) {
108 DSetCreatPropList propList;
109 hsize_t chunk_dims[1] = {length};
110 propList.setChunk(1, chunk_dims);
111 propList.setDeflate(deflateLevel);
112 return propList;
113}
114
115template <typename LocationType>
116void writeStrAttribute(LocationType &location, const std::string &name, const std::string &value) {
117 StrType attrType(0, H5T_VARIABLE);
118 DataSpace attrSpace(H5S_SCALAR);
119 auto attribute = location.createAttribute(name, attrType, attrSpace);
120 attribute.write(attrType, value);
121}
122
123template <typename NumT, typename LocationType>
124void writeNumAttribute(LocationType &location, const std::string &name, const NumT &value) {
125 static_assert(std::is_integral<NumT>::value || std::is_floating_point<NumT>::value,
126 "The writeNumAttribute function only accepts integral or "
127 "floating point values.");
128 auto attrType = getType<NumT>();
129 DataSpace attrSpace(H5S_SCALAR);
130
131 auto attribute = location.createAttribute(name, attrType, attrSpace);
132 // Wrap the data set in an array
133 std::array<NumT, 1> valueArray = {{value}};
134 attribute.write(attrType, valueArray.data());
135}
136
137template <typename NumT, typename LocationType>
138void writeNumAttribute(LocationType &location, const std::string &name, const std::vector<NumT> &value) {
139 static_assert(std::is_integral<NumT>::value || std::is_floating_point<NumT>::value,
140 "The writeNumAttribute function only accepts integral of "
141 "floating point values.");
142 auto attrType = getType<NumT>();
143 DataSpace attrSpace = getDataSpace(value);
144
145 auto attribute = location.createAttribute(name, attrType, attrSpace);
146 attribute.write(attrType, value.data());
147}
148
149void write(Group &group, const std::string &name, const std::string &value) { writeScalarDataSet(group, name, value); }
150
151template <typename T>
152void writeScalarDataSetWithStrAttributes(H5::Group &group, const std::string &name, const T &value,
153 const std::map<std::string, std::string> &attributes) {
154 auto data = writeScalarDataSet(group, name, value);
155 for (const auto &attribute : attributes) {
156 writeStrAttribute(data, attribute.first, attribute.second);
157 }
158}
159
160template <typename NumT> void writeArray1D(Group &group, const std::string &name, const std::vector<NumT> &values) {
161 DataType dataType(getType<NumT>());
162 DataSpace dataSpace = getDataSpace(values);
163
164 DSetCreatPropList propList = setCompressionAttributes(values.size());
165
166 auto data = group.createDataSet(name, dataType, dataSpace, propList);
167 data.write(values.data(), dataType);
168}
169
170// -------------------------------------------------------------------
171// read methods
172// -------------------------------------------------------------------
173
174std::string readString(H5::H5File &file, const std::string &path) {
175 try {
176 auto data = file.openDataSet(path);
177 return readString(data);
178 } catch (H5::FileIException &e) {
179 UNUSED_ARG(e);
180 return "";
181 } catch (H5::GroupIException &e) {
182 UNUSED_ARG(e);
183 return "";
184 }
185}
186
187std::string readString(H5::Group &group, const std::string &name) {
188 try {
189 auto data = group.openDataSet(name);
190 return readString(data);
191 } catch (H5::GroupIException &e) {
192 UNUSED_ARG(e);
193 return "";
194 }
195}
196
197std::string readString(H5::DataSet &dataset) {
198 std::string value;
199 dataset.read(value, dataset.getDataType(), dataset.getSpace());
200 return value;
201}
202
209std::vector<std::string> readStringVector(Group &group, const std::string &name) {
210 hsize_t dims[1];
211 char **rdata;
212 std::vector<std::string> result;
213
214 DataSet dataset = group.openDataSet(name);
215 DataSpace dataspace = dataset.getSpace();
216 DataType datatype = dataset.getDataType();
217
218 dataspace.getSimpleExtentDims(dims, nullptr);
219
220 rdata = new char *[dims[0]];
221 dataset.read(rdata, datatype);
222
223 for (size_t i = 0; i < dims[0]; ++i)
224 result.emplace_back(std::string(rdata[i]));
225
226 dataset.vlenReclaim(rdata, datatype, dataspace);
227 dataset.close();
228 delete[] rdata;
229
230 return result;
231}
232
233template <typename LocationType>
234std::string readAttributeAsString(LocationType &location, const std::string &attributeName) {
235 auto attribute = location.openAttribute(attributeName);
236 std::string value;
237 attribute.read(attribute.getDataType(), value);
238 return value;
239}
240
241template <typename NumT> std::vector<NumT> readArray1DCoerce(H5::Group &group, const std::string &name) {
242 std::vector<NumT> result;
243
244 try {
245 DataSet dataset = group.openDataSet(name);
246 result = readArray1DCoerce<NumT>(dataset);
247 } catch (H5::GroupIException &e) {
248 UNUSED_ARG(e);
249 g_log.information("Failed to open dataset \"" + name + "\"\n");
250 } catch (H5::DataTypeIException &e) {
251 UNUSED_ARG(e);
252 g_log.information("DataSet \"" + name + "\" should be double" + "\n");
253 }
254
255 return result;
256}
257
258namespace {
259template <typename InputNumT, typename OutputNumT>
260std::vector<OutputNumT> convertingRead(DataSet &dataset, const DataType &dataType) {
261 DataSpace dataSpace = dataset.getSpace();
262
263 std::vector<InputNumT> temp(dataSpace.getSelectNpoints());
264 dataset.read(temp.data(), dataType, dataSpace);
265
266 std::vector<OutputNumT> result;
267 result.resize(temp.size());
268
269 std::transform(temp.begin(), temp.end(), result.begin(),
270 [](const InputNumT a) { // lambda
271 return boost::numeric_cast<OutputNumT>(a);
272 });
273
274 return result;
275}
276
277template <typename InputNumT, typename OutputNumT>
278std::vector<OutputNumT> convertingNumArrayAttributeRead(Attribute &attribute, const DataType &dataType) {
279 DataSpace dataSpace = attribute.getSpace();
280
281 std::vector<InputNumT> temp(dataSpace.getSelectNpoints());
282 attribute.read(dataType, temp.data());
283
284 std::vector<OutputNumT> result;
285 result.resize(temp.size());
286
287 std::transform(temp.begin(), temp.end(), result.begin(),
288 [](const InputNumT a) { return boost::numeric_cast<OutputNumT>(a); });
289
290 return result;
291}
292
293template <typename InputNumT, typename OutputNumT>
294OutputNumT convertingRead(Attribute &attribute, const DataType &dataType) {
295 InputNumT temp;
296 attribute.read(dataType, &temp);
297 auto result = boost::numeric_cast<OutputNumT>(temp);
298 return result;
299}
300
301} // namespace
302
303template <typename NumT, typename LocationType>
304NumT readNumAttributeCoerce(LocationType &location, const std::string &attributeName) {
305 auto attribute = location.openAttribute(attributeName);
306 auto dataType = attribute.getDataType();
307
308 NumT value;
309
310 if (getType<NumT>() == dataType) {
311 attribute.read(dataType, &value);
312 } else if (PredType::NATIVE_INT32 == dataType) {
313 value = convertingRead<int32_t, NumT>(attribute, dataType);
314 } else if (PredType::NATIVE_UINT32 == dataType) {
315 value = convertingRead<uint32_t, NumT>(attribute, dataType);
316 } else if (PredType::NATIVE_INT64 == dataType) {
317 value = convertingRead<int64_t, NumT>(attribute, dataType);
318 } else if (PredType::NATIVE_UINT64 == dataType) {
319 value = convertingRead<uint64_t, NumT>(attribute, dataType);
320 } else if (PredType::NATIVE_FLOAT == dataType) {
321 value = convertingRead<float, NumT>(attribute, dataType);
322 } else if (PredType::NATIVE_DOUBLE == dataType) {
323 value = convertingRead<double, NumT>(attribute, dataType);
324 } else {
325 // not a supported type
326 throw DataTypeIException();
327 }
328 return value;
329}
330
331template <typename NumT, typename LocationType>
332std::vector<NumT> readNumArrayAttributeCoerce(LocationType &location, const std::string &attributeName) {
333 auto attribute = location.openAttribute(attributeName);
334 auto dataType = attribute.getDataType();
335
336 std::vector<NumT> value;
337
338 if (getType<NumT>() == dataType) {
339 DataSpace dataSpace = attribute.getSpace();
340 value.resize(dataSpace.getSelectNpoints());
341 attribute.read(dataType, value.data());
342 } else if (PredType::NATIVE_INT32 == dataType) {
343 value = convertingNumArrayAttributeRead<int32_t, NumT>(attribute, dataType);
344 } else if (PredType::NATIVE_UINT32 == dataType) {
345 value = convertingNumArrayAttributeRead<uint32_t, NumT>(attribute, dataType);
346 } else if (PredType::NATIVE_INT64 == dataType) {
347 value = convertingNumArrayAttributeRead<int64_t, NumT>(attribute, dataType);
348 } else if (PredType::NATIVE_UINT64 == dataType) {
349 value = convertingNumArrayAttributeRead<uint64_t, NumT>(attribute, dataType);
350 } else if (PredType::NATIVE_FLOAT == dataType) {
351 value = convertingNumArrayAttributeRead<float, NumT>(attribute, dataType);
352 } else if (PredType::NATIVE_DOUBLE == dataType) {
353 value = convertingNumArrayAttributeRead<double, NumT>(attribute, dataType);
354 } else {
355 // not a supported type
356 throw DataTypeIException();
357 }
358 return value;
359}
360
361template <typename NumT> std::vector<NumT> readArray1DCoerce(DataSet &dataset) {
362 DataType dataType = dataset.getDataType();
363
364 if (getType<NumT>() == dataType) { // no conversion necessary
365 std::vector<NumT> result;
366 DataSpace dataSpace = dataset.getSpace();
367 result.resize(dataSpace.getSelectNpoints());
368 dataset.read(result.data(), dataType, dataSpace);
369 return result;
370 }
371
372 if (PredType::NATIVE_INT32 == dataType) {
373 return convertingRead<int32_t, NumT>(dataset, dataType);
374 } else if (PredType::NATIVE_UINT32 == dataType) {
375 return convertingRead<uint32_t, NumT>(dataset, dataType);
376 } else if (PredType::NATIVE_INT64 == dataType) {
377 return convertingRead<int64_t, NumT>(dataset, dataType);
378 } else if (PredType::NATIVE_UINT64 == dataType) {
379 return convertingRead<uint64_t, NumT>(dataset, dataType);
380 } else if (PredType::NATIVE_FLOAT == dataType) {
381 return convertingRead<float, NumT>(dataset, dataType);
382 } else if (PredType::NATIVE_DOUBLE == dataType) {
383 return convertingRead<double, NumT>(dataset, dataType);
384 }
385
386 // not a supported type
387 throw DataTypeIException();
388}
389
390// -------------------------------------------------------------------
391// instantiations for writeStrAttribute
392// -------------------------------------------------------------------
393template MANTID_DATAHANDLING_DLL void writeStrAttribute(H5::Group &location, const std::string &name,
394 const std::string &value);
395
396template MANTID_DATAHANDLING_DLL void writeStrAttribute(H5::DataSet &location, const std::string &name,
397 const std::string &value);
398
399// -------------------------------------------------------------------
400// instantiations for writeNumAttribute
401// -------------------------------------------------------------------
402
403template MANTID_DATAHANDLING_DLL void writeNumAttribute(H5::Group &location, const std::string &name,
404 const float &value);
405template MANTID_DATAHANDLING_DLL void writeNumAttribute(H5::DataSet &location, const std::string &name,
406 const float &value);
407template MANTID_DATAHANDLING_DLL void writeNumAttribute(H5::Group &location, const std::string &name,
408 const double &value);
409template MANTID_DATAHANDLING_DLL void writeNumAttribute(H5::DataSet &location, const std::string &name,
410 const double &value);
411template MANTID_DATAHANDLING_DLL void writeNumAttribute(H5::Group &location, const std::string &name,
412 const int32_t &value);
413template MANTID_DATAHANDLING_DLL void writeNumAttribute(H5::DataSet &location, const std::string &name,
414 const int32_t &value);
415template MANTID_DATAHANDLING_DLL void writeNumAttribute(H5::Group &location, const std::string &name,
416 const uint32_t &value);
417template MANTID_DATAHANDLING_DLL void writeNumAttribute(H5::DataSet &location, const std::string &name,
418 const uint32_t &value);
419template MANTID_DATAHANDLING_DLL void writeNumAttribute(H5::Group &location, const std::string &name,
420 const int64_t &value);
421template MANTID_DATAHANDLING_DLL void writeNumAttribute(H5::DataSet &location, const std::string &name,
422 const int64_t &value);
423template MANTID_DATAHANDLING_DLL void writeNumAttribute(H5::Group &location, const std::string &name,
424 const uint64_t &value);
425template MANTID_DATAHANDLING_DLL void writeNumAttribute(H5::DataSet &location, const std::string &name,
426 const uint64_t &value);
427
428template MANTID_DATAHANDLING_DLL void writeNumAttribute(H5::Group &location, const std::string &name,
429 const std::vector<float> &value);
430template MANTID_DATAHANDLING_DLL void writeNumAttribute(H5::DataSet &location, const std::string &name,
431 const std::vector<float> &value);
432template MANTID_DATAHANDLING_DLL void writeNumAttribute(H5::Group &location, const std::string &name,
433 const std::vector<double> &value);
434template MANTID_DATAHANDLING_DLL void writeNumAttribute(H5::DataSet &location, const std::string &name,
435 const std::vector<double> &value);
436template MANTID_DATAHANDLING_DLL void writeNumAttribute(H5::Group &location, const std::string &name,
437 const std::vector<int32_t> &value);
438template MANTID_DATAHANDLING_DLL void writeNumAttribute(H5::DataSet &location, const std::string &name,
439 const std::vector<int32_t> &value);
440template MANTID_DATAHANDLING_DLL void writeNumAttribute(H5::Group &location, const std::string &name,
441 const std::vector<uint32_t> &value);
442template MANTID_DATAHANDLING_DLL void writeNumAttribute(H5::DataSet &location, const std::string &name,
443 const std::vector<uint32_t> &value);
444template MANTID_DATAHANDLING_DLL void writeNumAttribute(H5::Group &location, const std::string &name,
445 const std::vector<int64_t> &value);
446template MANTID_DATAHANDLING_DLL void writeNumAttribute(H5::DataSet &location, const std::string &name,
447 const std::vector<int64_t> &value);
448template MANTID_DATAHANDLING_DLL void writeNumAttribute(H5::Group &location, const std::string &name,
449 const std::vector<uint64_t> &value);
450template MANTID_DATAHANDLING_DLL void writeNumAttribute(H5::DataSet &location, const std::string &name,
451 const std::vector<uint64_t> &value);
452
453// -------------------------------------------------------------------
454// instantiations for readAttributeAsString
455// -------------------------------------------------------------------
456template MANTID_DATAHANDLING_DLL std::string readAttributeAsString(H5::Group &location,
457 const std::string &attributeName);
458
459template MANTID_DATAHANDLING_DLL std::string readAttributeAsString(H5::DataSet &location,
460 const std::string &attributeName);
461
462// -------------------------------------------------------------------
463// instantiations for readNumAttributeCoerce
464// -------------------------------------------------------------------
465template MANTID_DATAHANDLING_DLL float readNumAttributeCoerce(H5::Group &location, const std::string &attributeName);
466template MANTID_DATAHANDLING_DLL float readNumAttributeCoerce(H5::DataSet &location, const std::string &attributeName);
467template MANTID_DATAHANDLING_DLL double readNumAttributeCoerce(H5::Group &location, const std::string &attributeName);
468template MANTID_DATAHANDLING_DLL double readNumAttributeCoerce(H5::DataSet &location, const std::string &attributeName);
469template MANTID_DATAHANDLING_DLL int32_t readNumAttributeCoerce(H5::Group &location, const std::string &attributeName);
470template MANTID_DATAHANDLING_DLL int32_t readNumAttributeCoerce(H5::DataSet &location,
471 const std::string &attributeName);
472template MANTID_DATAHANDLING_DLL uint32_t readNumAttributeCoerce(H5::Group &location, const std::string &attributeName);
473template MANTID_DATAHANDLING_DLL uint32_t readNumAttributeCoerce(H5::DataSet &location,
474 const std::string &attributeName);
475template MANTID_DATAHANDLING_DLL int64_t readNumAttributeCoerce(H5::Group &location, const std::string &attributeName);
476template MANTID_DATAHANDLING_DLL int64_t readNumAttributeCoerce(H5::DataSet &location,
477 const std::string &attributeName);
478template MANTID_DATAHANDLING_DLL uint64_t readNumAttributeCoerce(H5::Group &location, const std::string &attributeName);
479template MANTID_DATAHANDLING_DLL uint64_t readNumAttributeCoerce(H5::DataSet &location,
480 const std::string &attributeName);
481
482// -------------------------------------------------------------------
483// instantiations for readNumArrayAttributeCoerce
484// -------------------------------------------------------------------
485template MANTID_DATAHANDLING_DLL std::vector<float> readNumArrayAttributeCoerce(H5::Group &location,
486 const std::string &attributeName);
487template MANTID_DATAHANDLING_DLL std::vector<float> readNumArrayAttributeCoerce(H5::DataSet &location,
488 const std::string &attributeName);
489template MANTID_DATAHANDLING_DLL std::vector<double> readNumArrayAttributeCoerce(H5::Group &location,
490 const std::string &attributeName);
491template MANTID_DATAHANDLING_DLL std::vector<double> readNumArrayAttributeCoerce(H5::DataSet &location,
492 const std::string &attributeName);
493template MANTID_DATAHANDLING_DLL std::vector<int32_t> readNumArrayAttributeCoerce(H5::Group &location,
494 const std::string &attributeName);
495template MANTID_DATAHANDLING_DLL std::vector<int32_t> readNumArrayAttributeCoerce(H5::DataSet &location,
496 const std::string &attributeName);
497template MANTID_DATAHANDLING_DLL std::vector<uint32_t> readNumArrayAttributeCoerce(H5::Group &location,
498 const std::string &attributeName);
499template MANTID_DATAHANDLING_DLL std::vector<uint32_t> readNumArrayAttributeCoerce(H5::DataSet &location,
500 const std::string &attributeName);
501template MANTID_DATAHANDLING_DLL std::vector<int64_t> readNumArrayAttributeCoerce(H5::Group &location,
502 const std::string &attributeName);
503template MANTID_DATAHANDLING_DLL std::vector<int64_t> readNumArrayAttributeCoerce(H5::DataSet &location,
504 const std::string &attributeName);
505template MANTID_DATAHANDLING_DLL std::vector<uint64_t> readNumArrayAttributeCoerce(H5::Group &location,
506 const std::string &attributeName);
507template MANTID_DATAHANDLING_DLL std::vector<uint64_t> readNumArrayAttributeCoerce(H5::DataSet &location,
508 const std::string &attributeName);
509
510// -------------------------------------------------------------------
511// instantiations for writeArray1D
512// -------------------------------------------------------------------
513template MANTID_DATAHANDLING_DLL void writeArray1D(H5::Group &group, const std::string &name,
514 const std::vector<float> &values);
515template MANTID_DATAHANDLING_DLL void writeArray1D(H5::Group &group, const std::string &name,
516 const std::vector<double> &values);
517template MANTID_DATAHANDLING_DLL void writeArray1D(H5::Group &group, const std::string &name,
518 const std::vector<int32_t> &values);
519template MANTID_DATAHANDLING_DLL void writeArray1D(H5::Group &group, const std::string &name,
520 const std::vector<uint32_t> &values);
521template MANTID_DATAHANDLING_DLL void writeArray1D(H5::Group &group, const std::string &name,
522 const std::vector<int64_t> &values);
523template MANTID_DATAHANDLING_DLL void writeArray1D(H5::Group &group, const std::string &name,
524 const std::vector<uint64_t> &values);
525
526// -------------------------------------------------------------------
527// Instantiations for writeScalarWithStrAttributes
528// -------------------------------------------------------------------
529template MANTID_DATAHANDLING_DLL void
530writeScalarDataSetWithStrAttributes(H5::Group &group, const std::string &name, const std::string &value,
531 const std::map<std::string, std::string> &attributes);
532template MANTID_DATAHANDLING_DLL void
533writeScalarDataSetWithStrAttributes(H5::Group &group, const std::string &name, const float &value,
534 const std::map<std::string, std::string> &attributes);
535template MANTID_DATAHANDLING_DLL void
536writeScalarDataSetWithStrAttributes(H5::Group &group, const std::string &name, const double &value,
537 const std::map<std::string, std::string> &attributes);
538template MANTID_DATAHANDLING_DLL void
539writeScalarDataSetWithStrAttributes(H5::Group &group, const std::string &name, const int32_t &value,
540 const std::map<std::string, std::string> &attributes);
541template MANTID_DATAHANDLING_DLL void
542writeScalarDataSetWithStrAttributes(H5::Group &group, const std::string &name, const uint32_t &value,
543 const std::map<std::string, std::string> &attributes);
544template MANTID_DATAHANDLING_DLL void
545writeScalarDataSetWithStrAttributes(H5::Group &group, const std::string &name, const int64_t &value,
546 const std::map<std::string, std::string> &attributes);
547template MANTID_DATAHANDLING_DLL void
548writeScalarDataSetWithStrAttributes(H5::Group &group, const std::string &name, const uint64_t &value,
549 const std::map<std::string, std::string> &attributes);
550
551// -------------------------------------------------------------------
552// instantiations for getDataSpace
553// -------------------------------------------------------------------
554template MANTID_DATAHANDLING_DLL DataSpace getDataSpace(const std::vector<float> &data);
555template MANTID_DATAHANDLING_DLL DataSpace getDataSpace(const std::vector<double> &data);
556template MANTID_DATAHANDLING_DLL DataSpace getDataSpace(const std::vector<int32_t> &data);
557template MANTID_DATAHANDLING_DLL DataSpace getDataSpace(const std::vector<uint32_t> &data);
558template MANTID_DATAHANDLING_DLL DataSpace getDataSpace(const std::vector<int64_t> &data);
559template MANTID_DATAHANDLING_DLL DataSpace getDataSpace(const std::vector<uint64_t> &data);
560
561// -------------------------------------------------------------------
562// instantiations for readArray1DCoerce
563// -------------------------------------------------------------------
564template MANTID_DATAHANDLING_DLL std::vector<float> readArray1DCoerce(H5::Group &group, const std::string &name);
565template MANTID_DATAHANDLING_DLL std::vector<double> readArray1DCoerce(H5::Group &group, const std::string &name);
566template MANTID_DATAHANDLING_DLL std::vector<int32_t> readArray1DCoerce(H5::Group &group, const std::string &name);
567template MANTID_DATAHANDLING_DLL std::vector<uint32_t> readArray1DCoerce(H5::Group &group, const std::string &name);
568template MANTID_DATAHANDLING_DLL std::vector<int64_t> readArray1DCoerce(H5::Group &group, const std::string &name);
569template MANTID_DATAHANDLING_DLL std::vector<uint64_t> readArray1DCoerce(H5::Group &group, const std::string &name);
570
571template MANTID_DATAHANDLING_DLL std::vector<float> readArray1DCoerce<float>(DataSet &dataset);
572template MANTID_DATAHANDLING_DLL std::vector<double> readArray1DCoerce<double>(DataSet &dataset);
573template MANTID_DATAHANDLING_DLL std::vector<int32_t> readArray1DCoerce<int32_t>(DataSet &dataset);
574template MANTID_DATAHANDLING_DLL std::vector<uint32_t> readArray1DCoerce<uint32_t>(DataSet &dataset);
575template MANTID_DATAHANDLING_DLL std::vector<int64_t> readArray1DCoerce<int64_t>(DataSet &dataset);
576template MANTID_DATAHANDLING_DLL std::vector<uint64_t> readArray1DCoerce<uint64_t>(DataSet &dataset);
577} // namespace Mantid::DataHandling::H5Util
double value
The value of the point.
Definition: FitMW.cpp:51
#define UNUSED_ARG(x)
Function arguments are sometimes unused in certain implmentations but are required for documentation ...
Definition: System.h:64
Attribute is a non-fitting parameter.
Definition: IFunction.h:282
The class Group represents a set of symmetry operations (or symmetry group).
Definition: Group.h:135
The Logger class is in charge of the publishing messages from the framework through various channels.
Definition: Logger.h:52
void information(const std::string &msg)
Logs at information level.
Definition: Logger.cpp:105
Definition: H5Util.h:16
Kernel::Logger g_log("ExperimentInfo")
static logger object
MANTID_DATAHANDLING_DLL H5::DSetCreatPropList setCompressionAttributes(const std::size_t length, const int deflateLevel=6)
Sets up the chunking and compression rate.
Definition: H5Util.cpp:107
MANTID_DATAHANDLING_DLL DataType getType< int32_t >()
Definition: H5Util.cpp:38
template MANTID_DATAHANDLING_DLL std::vector< double > readArray1DCoerce< double >(DataSet &dataset)
MANTID_DATAHANDLING_DLL DataType getType< uint64_t >()
Definition: H5Util.cpp:44
MANTID_DATAHANDLING_DLL std::string readString(H5::H5File &file, const std::string &path)
Definition: H5Util.cpp:174
MANTID_DATAHANDLING_DLL std::vector< std::string > readStringVector(H5::Group &, const std::string &)
MANTID_DATAHANDLING_DLL H5::Group createGroupCanSAS(H5::Group &group, const std::string &name, const std::string &nxtype, const std::string &cstype)
template MANTID_DATAHANDLING_DLL std::vector< int64_t > readArray1DCoerce< int64_t >(DataSet &dataset)
void writeNumAttribute(LocationType &location, const std::string &name, const NumT &value)
Definition: H5Util.cpp:124
MANTID_DATAHANDLING_DLL DataType getType< int64_t >()
Definition: H5Util.cpp:42
template MANTID_DATAHANDLING_DLL std::vector< float > readArray1DCoerce< float >(DataSet &dataset)
void writeArray1D(H5::Group &group, const std::string &name, const std::vector< NumT > &values)
MANTID_DATAHANDLING_DLL H5::DataSpace getDataSpace(const size_t length)
H5Util : TODO: DESCRIPTION.
Definition: H5Util.cpp:46
MANTID_DATAHANDLING_DLL H5::Group createGroupNXS(H5::H5File &file, const std::string &name, const std::string &nxtype)
std::string readAttributeAsString(LocationType &dataset, const std::string &attributeName)
Definition: H5Util.cpp:234
NumT readNumAttributeCoerce(LocationType &location, const std::string &attributeName)
Definition: H5Util.cpp:304
MANTID_DATAHANDLING_DLL void write(H5::Group &group, const std::string &name, const std::string &value)
MANTID_DATAHANDLING_DLL DataType getType< uint32_t >()
Definition: H5Util.cpp:40
std::vector< NumT > readNumArrayAttributeCoerce(LocationType &location, const std::string &attributeName)
Definition: H5Util.cpp:332
template MANTID_DATAHANDLING_DLL std::vector< int32_t > readArray1DCoerce< int32_t >(DataSet &dataset)
void writeStrAttribute(LocationType &location, const std::string &name, const std::string &value)
Definition: H5Util.cpp:116
template MANTID_DATAHANDLING_DLL std::vector< uint64_t > readArray1DCoerce< uint64_t >(DataSet &dataset)
std::vector< NumT > readArray1DCoerce(H5::Group &group, const std::string &name)
Definition: H5Util.cpp:241
void writeScalarDataSetWithStrAttributes(H5::Group &group, const std::string &name, const T &value, const std::map< std::string, std::string > &attributes)
Definition: H5Util.cpp:152
MANTID_DATAHANDLING_DLL DataType getType< double >()
Definition: H5Util.cpp:36
H5::DataType getType()
Convert a primitive type to the appropriate H5::DataType.
Definition: H5Util.cpp:32
MANTID_DATAHANDLING_DLL DataType getType< float >()
Definition: H5Util.cpp:34
template MANTID_DATAHANDLING_DLL std::vector< uint32_t > readArray1DCoerce< uint32_t >(DataSet &dataset)