Mantid
Loading...
Searching...
No Matches
NexusDescriptor.h
Go to the documentation of this file.
1// Mantid Repository : https://github.com/mantidproject/mantid
2//
3// Copyright © 2013 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 "MantidKernel/DllConfig.h"
10
11#include <map>
12#include <memory>
13#include <string>
14#include <unordered_set>
15#include <utility>
16
17namespace NeXus {
18class File;
19}
20
21namespace Mantid {
22namespace Kernel {
23
31class MANTID_KERNEL_DLL NexusDescriptor {
32public:
34 enum Version { Version4, Version5, AnyVersion };
35
36 static const size_t HDFMagicSize;
38 static const unsigned char HDFMagic[4];
40 static size_t HDF5SignatureSize;
42 static const unsigned char HDF5Signature[8];
43
45 static bool isReadable(const std::string &filename, const Version version = AnyVersion);
46
47public:
54 NexusDescriptor(const std::string &filename, const bool init = true);
57
59 NexusDescriptor() = delete;
60
63
66
71 inline const std::string &filename() const { return m_filename; }
77 inline const std::string &extension() const { return m_extension; }
82 inline ::NeXus::File &data() { return *m_file; }
83
85 const std::pair<std::string, std::string> &firstEntryNameType() const;
87 bool hasRootAttr(const std::string &name) const;
89 bool pathExists(const std::string &path) const;
91 bool pathOfTypeExists(const std::string &path, const std::string &type) const;
93 std::string pathOfType(const std::string &type) const;
95 bool classTypeExists(const std::string &classType) const;
96
97private:
99 void initialize(const std::string &filename);
101 void walkFile(::NeXus::File &file, const std::string &rootPath, const std::string &className,
102 std::map<std::string, std::string> &pmap, int level);
103
105 std::string m_filename;
107 std::string m_extension;
109 std::pair<std::string, std::string> m_firstEntryNameType;
111 std::unordered_set<std::string> m_rootAttrs;
113 std::map<std::string, std::string> m_pathsToTypes;
114
116 std::unique_ptr<::NeXus::File> m_file;
117};
118
119} // namespace Kernel
120} // namespace Mantid
Defines a wrapper around a file whose internal structure can be accessed using the NeXus API.
std::map< std::string, std::string > m_pathsToTypes
Map of full path strings to types. Can check if path exists quickly.
std::unordered_set< std::string > m_rootAttrs
Root attributes.
const std::string & extension() const
Access the file extension.
std::string m_filename
Full filename.
std::pair< std::string, std::string > m_firstEntryNameType
First entry name/type.
Version
Enumerate HDF possible versions.
NexusDescriptor()=delete
Disable default constructor.
NexusDescriptor(const NexusDescriptor &)=delete
Disable copy operator.
static const size_t HDFMagicSize
Size of HDF magic number.
inline ::NeXus::File & data()
Access the open NeXus File object.
static size_t HDF5SignatureSize
Size of HDF5 signature.
std::unique_ptr<::NeXus::File > m_file
Open NeXus handle.
std::string m_extension
Extension.
const std::string & filename() const
Access the filename.
NexusDescriptor & operator=(const NexusDescriptor &)=delete
Disable assignment operator.
Helper class which provides the Collimation Length for SANS instruments.
Generate a tableworkspace to store the calibration results.