Mantid
Loading...
Searching...
No Matches
H5Util.h
Go to the documentation of this file.
1// Mantid Repository : https://github.com/mantidproject/mantid
2//
3// Copyright © 2016 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 +
7#pragma once
8
9#include "MantidNexus/DllConfig.h"
10
11#include <limits>
12#include <map>
13#include <string>
14#include <vector>
15
16// forward declarations
17namespace H5 {
18class DataSpace;
19class DataSet;
20class DSetCreatPropList;
21class DataType;
22class FileAccPropList;
23class Group;
24class H5File;
25class H5Object;
26} // namespace H5
27
28namespace Mantid {
29namespace Nexus {
30namespace H5Util {
35enum class Narrowing : bool { Allow = true, Prevent = false };
36
38MANTID_NEXUS_DLL H5::FileAccPropList defaultFileAcc();
39
41MANTID_NEXUS_DLL bool isHdf5(std::string const &filename);
42
44MANTID_NEXUS_DLL H5::DataSpace getDataSpace(const size_t length);
45
47template <typename NumT> H5::DataType getType();
48
49MANTID_NEXUS_DLL H5::Group createGroupNXS(H5::H5File &file, const std::string &name, const std::string &nxtype);
50
51MANTID_NEXUS_DLL H5::Group createGroupNXS(H5::Group &group, const std::string &name, const std::string &nxtype);
52
53MANTID_NEXUS_DLL H5::Group createGroupCanSAS(H5::Group &group, const std::string &name, const std::string &nxtype,
54 const std::string &cstype);
55
56MANTID_NEXUS_DLL H5::Group createGroupCanSAS(H5::H5File &file, const std::string &name, const std::string &nxtype,
57 const std::string &cstype);
58
65MANTID_NEXUS_DLL H5::DSetCreatPropList setCompressionAttributes(const std::size_t length, const int deflateLevel = 6);
66
67MANTID_NEXUS_DLL void writeStrAttribute(const H5::H5Object &object, const std::string &name, const std::string &value);
68
69template <typename NumT> void writeNumAttribute(const H5::H5Object &object, const std::string &name, const NumT &value);
70
71template <typename NumT>
72void writeNumAttribute(const H5::H5Object &object, const std::string &name, const std::vector<NumT> &value);
73
74MANTID_NEXUS_DLL void write(H5::Group &group, const std::string &name, const std::string &value);
75
76template <typename T>
77void writeScalarDataSetWithStrAttributes(H5::Group &group, const std::string &name, const T &value,
78 const std::map<std::string, std::string> &attributes);
79
80template <typename NumT> void writeArray1D(H5::Group &group, const std::string &name, const std::vector<NumT> &values);
81
82MANTID_NEXUS_DLL std::string readString(H5::H5File &file, const std::string &address);
83
84MANTID_NEXUS_DLL std::string readString(const H5::Group &group, const std::string &name);
85
86MANTID_NEXUS_DLL std::string readString(const H5::DataSet &dataset);
87
88MANTID_NEXUS_DLL std::vector<std::string> readStringVector(H5::Group &, const std::string &);
89
90MANTID_NEXUS_DLL std::vector<std::string> readStringVector(H5::DataSet &);
91
92MANTID_NEXUS_DLL bool hasAttribute(const H5::H5Object &object, const char *attributeName);
93
94MANTID_NEXUS_DLL void readStringAttribute(const H5::H5Object &object, const std::string &attributeName,
95 std::string &output);
96
97template <typename NumT, Narrowing narrow = Narrowing::Allow>
98NumT readNumAttributeCoerce(const H5::H5Object &object, const std::string &attributeName);
99
100template <typename NumT, Narrowing narrow = Narrowing::Allow>
101std::vector<NumT> readNumArrayAttributeCoerce(const H5::H5Object &object, const std::string &attributeName);
102
103template <typename NumT, Narrowing narrow = Narrowing::Allow>
104void readArray1DCoerce(const H5::Group &group, const std::string &name, std::vector<NumT> &output);
105
106template <typename NumT, Narrowing narrow = Narrowing::Allow>
107std::vector<NumT> readArray1DCoerce(const H5::Group &group, const std::string &name);
108
109template <typename NumT, Narrowing narrow = Narrowing::Allow>
110void readArray1DCoerce(const H5::DataSet &dataset, std::vector<NumT> &output,
111 const size_t length = std::numeric_limits<size_t>::max(),
112 const size_t offset = static_cast<size_t>(0));
113
115MANTID_NEXUS_DLL bool groupExists(H5::H5Object const &h5, const std::string &groupAddress);
116
118MANTID_NEXUS_DLL bool keyHasValue(H5::H5Object const &h5, const std::string &key, const std::string &value);
119
121MANTID_NEXUS_DLL void copyGroup(H5::H5Object &dest, const std::string &destGroupAddress, H5::H5Object &src,
122 const std::string &srcGroupAddress);
123
128MANTID_NEXUS_DLL void deleteObjectLink(H5::H5Object &h5, const std::string &target);
129
130} // namespace H5Util
131} // namespace Nexus
132} // namespace Mantid
std::string name
Definition Run.cpp:60
double value
The value of the point.
Definition FitMW.cpp:51
MANTID_NEXUS_DLL void readStringAttribute(const H5::H5Object &object, const std::string &attributeName, std::string &output)
Definition H5Util.cpp:342
Narrowing
H5Util : TODO: DESCRIPTION.
Definition H5Util.h:35
MANTID_NEXUS_DLL bool groupExists(H5::H5Object const &h5, const std::string &groupAddress)
Test if a group already exists within an HDF5 file or parent group.
Definition H5Util.cpp:484
MANTID_NEXUS_DLL std::string readString(H5::H5File &file, const std::string &address)
Definition H5Util.cpp:266
void writeArray1D(H5::Group &group, const std::string &name, const std::vector< NumT > &values)
MANTID_NEXUS_DLL void writeStrAttribute(const H5::H5Object &object, const std::string &name, const std::string &value)
Definition H5Util.cpp:208
MANTID_NEXUS_DLL bool hasAttribute(const H5::H5Object &object, const char *attributeName)
Definition H5Util.cpp:337
MANTID_NEXUS_DLL H5::FileAccPropList defaultFileAcc()
Default file access is H5F_CLOSE_STRONG.
Definition H5Util.cpp:119
void writeNumAttribute(const H5::H5Object &object, const std::string &name, const NumT &value)
Definition H5Util.cpp:216
MANTID_NEXUS_DLL bool isHdf5(std::string const &filename)
Determine if a given file can be opened with HDF5 using the CORRECT file access level (H5F_CLOSE_STRO...
Definition H5Util.cpp:125
MANTID_NEXUS_DLL H5::DataSpace getDataSpace(const size_t length)
Create a 1D data-space to hold data of length.
Definition H5Util.cpp:143
MANTID_NEXUS_DLL void deleteObjectLink(H5::H5Object &h5, const std::string &target)
Delete a target link for a group or dataset from a parent group.
Definition H5Util.cpp:532
std::vector< NumT > readNumArrayAttributeCoerce(const H5::H5Object &object, const std::string &attributeName)
Read a numerical array from an attribute, coerced to type of OutT.
Definition H5Util.cpp:441
MANTID_NEXUS_DLL H5::Group createGroupCanSAS(H5::Group &group, const std::string &name, const std::string &nxtype, const std::string &cstype)
NumT readNumAttributeCoerce(const H5::H5Object &object, const std::string &attributeName)
Read a single quantity from an attribute, coerced to type of OutT.
Definition H5Util.cpp:427
MANTID_NEXUS_DLL bool keyHasValue(H5::H5Object const &h5, const std::string &key, const std::string &value)
Test if an attribute is present and has a specific string value for an HDF5 group or dataset.
Definition H5Util.cpp:496
MANTID_NEXUS_DLL H5::Group createGroupNXS(H5::H5File &file, const std::string &name, const std::string &nxtype)
void readArray1DCoerce(const H5::Group &group, const std::string &name, std::vector< NumT > &output)
MANTID_NEXUS_DLL void copyGroup(H5::H5Object &dest, const std::string &destGroupAddress, H5::H5Object &src, const std::string &srcGroupAddress)
Copy a group and all of its contents, between the same or different HDF5 files or groups.
Definition H5Util.cpp:510
H5::DataType getType()
Convert a primitive type to the appropriate H5::DataType.
Definition H5Util.cpp:36
MANTID_NEXUS_DLL std::vector< std::string > readStringVector(H5::Group &, const std::string &)
MANTID_NEXUS_DLL void write(H5::Group &group, const std::string &name, const std::string &value)
void writeScalarDataSetWithStrAttributes(H5::Group &group, const std::string &name, const T &value, const std::map< std::string, std::string > &attributes)
Definition H5Util.cpp:244
MANTID_NEXUS_DLL H5::DSetCreatPropList setCompressionAttributes(const std::size_t length, const int deflateLevel=6)
Sets up the chunking and compression rate.
Definition H5Util.cpp:200
Helper class which provides the Collimation Length for SANS instruments.