Mantid
Loading...
Searching...
No Matches
NexusDescriptorLazy.h
Go to the documentation of this file.
1// Mantid Repository : https://github.com/mantidproject/mantid
2//
3// Copyright © 2007 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"
11
12#include <concepts>
13#include <map>
14#include <shared_mutex>
15#include <string>
16#include <unordered_set>
17#include <variant>
18#include <vector>
19
20namespace Mantid {
21namespace Nexus {
22
23template <typename T>
24concept entryTypes = std::integral<T> || std::floating_point<T> || std::same_as<T, std::string>;
25
26class MANTID_NEXUS_DLL NexusDescriptorLazy {
27
28public:
30 NXFOUND,
31 NXCACHED,
32 NXNOT_DATASET,
33 NXDATASET_NOT_FOUND,
34 NXWRONG_TYPE,
35 NXERROR,
36 NXUNSET,
37 };
38
39 using CacheValue_t = std::variant<float, double, int8_t, uint8_t, int16_t, uint16_t, int32_t, uint32_t, int64_t,
40 uint64_t, std::string, CacheReturnStatus_t>;
41
46 NexusDescriptorLazy(std::string const &filename);
47
49
50 // there is no reason to copy this object
53 // there is no reason to move this object
56
61
66 inline std::string const &filename() const noexcept { return m_filename; }
67
73 inline std::string const &extension() const noexcept { return m_extension; }
74
76 std::pair<std::string, std::string> const &firstEntryNameType() const noexcept { return m_firstEntryNameType; };
77
79 bool hasRootAttr(std::string const &name) const;
80
90 std::map<std::string, std::string> const &getAllEntries() const noexcept { return m_allEntries; }
91
99 bool isEntry(std::string const &entryName, std::string const &groupClass) const {
100 if (isEntry(entryName)) {
101 return m_allEntries.at(entryName) == groupClass;
102 } else {
103 return false;
104 }
105 }
106
112 bool isEntry(std::string const &entryName) const;
113
120 template <typename T>
121 std::pair<T, NexusDescriptorLazy::CacheReturnStatus_t> getDataValue(const std::string &datasetAddress) const;
122
124 bool classTypeExists(std::string const &classType) const;
125
128 bool classTypeExistsChild(const std::string &parentPath, const std::string &classType) const;
129
133 std::string getStrData(std::string const &address);
134
135private:
140 std::map<std::string, std::string> initAllEntries();
141 void loadGroups(std::map<std::string, std::string> &allEntries, std::string const &address, unsigned int depth,
142 const unsigned int maxDepth);
143
144 const CacheValue_t _getDataValue(const std::string &datasetAddress) const;
145
147 std::string const m_filename;
149 std::string const m_extension;
152
154 mutable std::unordered_set<std::string> m_rootAttrs;
155
156 std::pair<std::string, std::string> m_firstEntryNameType;
157
165 mutable std::map<std::string, std::string> m_allEntries;
166
168 mutable std::shared_mutex m_readNexusMutex;
169
171 mutable std::unordered_set<std::string> m_allMisses;
172
174 mutable std::map<std::string, CacheValue_t> m_readEntries;
175};
176
177} // namespace Nexus
178} // namespace Mantid
std::string name
Definition Run.cpp:60
std::string const m_filename
Nexus HDF5 file name.
NexusDescriptorLazy & operator=(NexusDescriptorLazy const &nd)=delete
std::string const & filename() const noexcept
Returns a constant reference to the current file name.
~NexusDescriptorLazy()=default
Using RAII components, no need to deallocate explicitly.
std::unordered_set< std::string > m_allMisses
the set of non-existent entries that have been checked
std::pair< std::string, std::string > m_firstEntryNameType
std::string const & extension() const noexcept
Access the file extension.
std::map< std::string, std::string > const & getAllEntries() const noexcept
Returns a const reference of the internal map holding all entries in the Nexus HDF5 file.
std::shared_mutex m_readNexusMutex
mutex to protect reading from file after initialization in const methods
std::unordered_set< std::string > m_rootAttrs
Root attributes cache.
bool isEntry(std::string const &entryName, std::string const &groupClass) const
Checks if a full-address entry exists for a particular groupClass in a Nexus dataset.
NexusDescriptorLazy(NexusDescriptorLazy &&nd)=delete
std::variant< float, double, int8_t, uint8_t, int16_t, uint16_t, int32_t, uint32_t, int64_t, uint64_t, std::string, CacheReturnStatus_t > CacheValue_t
std::string const m_extension
Extension.
std::pair< std::string, std::string > const & firstEntryNameType() const noexcept
Returns the name & type of the first entry in the file.
NexusDescriptorLazy(NexusDescriptorLazy const &nd)=delete
std::map< std::string, std::string > m_allEntries
All entries metadata.
UniqueID<&H5Fclose > m_fileID
HDF5 File Handle.
std::map< std::string, CacheValue_t > m_readEntries
the map of all read entry values that have been checked
NexusDescriptorLazy & operator=(NexusDescriptorLazy &&nd)=delete
A wrapper class for managing HDF5 object handles (hid_t).
Definition UniqueID.h:92
Helper class which provides the Collimation Length for SANS instruments.