Newer
Older
#ifndef MANTID_KERNEL_NEXUSDESCRIPTOR_H_
#define MANTID_KERNEL_NEXUSDESCRIPTOR_H_
#include "MantidKernel/DllConfig.h"
Gigg, Martyn Anthony
committed
#include <map>
#include <string>
#include <utility>
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
namespace Mantid {
namespace Kernel {
/**
Defines a wrapper around a file whose internal structure can be accessed
using the NeXus API
On construction the simple details about the layout of the file are cached
for faster querying later.
Copyright © 2013 ISIS Rutherford Appleton Laboratory, NScD Oak Ridge
National Laboratory & European Spallation Source
This file is part of Mantid.
Mantid is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
Mantid is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
File change history is stored at: <https://github.com/mantidproject/mantid>
Code Documentation is available at: <http://doxygen.mantidproject.org>
*/
class MANTID_KERNEL_DLL NexusDescriptor {
public:
/// Enumerate HDF possible versions
enum Version { Version4, Version5, AnyVersion };
static const size_t HDFMagicSize;
/// HDF cookie that is stored in the first 4 bytes of the file.
static const unsigned char HDFMagic[4];
/// Size of HDF5 signature
static size_t HDF5SignatureSize;
/// signature identifying a HDF5 file.
static const unsigned char HDF5Signature[8];
/// Returns true if the file is considered to store data in a hierarchy
static bool isHDF(const std::string &filename,
const Version version = AnyVersion);
public:
/// Constructor accepting a filename
NexusDescriptor(const std::string &filename);
/// Destructor
~NexusDescriptor();
/// Disable default constructor
NexusDescriptor() = delete;
/// Disable copy operator
NexusDescriptor(const NexusDescriptor &) = delete;
/// Disable assignment operator
NexusDescriptor &operator=(const NexusDescriptor &) = delete;
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
/**
* Access the filename
* @returns A reference to a const string containing the filename
*/
inline const std::string &filename() const { return m_filename; }
/**
* Access the file extension. Defined as the string after and including the
* last period character
* @returns A reference to a const string containing the file extension
*/
inline const std::string &extension() const { return m_extension; }
/**
* Access the open NeXus File object
* @returns A reference to the open ::NeXus file object
*/
inline ::NeXus::File &data() { return *m_file; }
/// Returns the name & type of the first entry in the file
const std::pair<std::string, std::string> &firstEntryNameType() const;
/// Query if the given attribute exists on the root node
bool hasRootAttr(const std::string &name) const;
/// Query if a path exists
bool pathExists(const std::string &path) const;
/// Query if a path exists of a given type
bool pathOfTypeExists(const std::string &path, const std::string &type) const;
/// return the path of a given type
std::string pathOfType(const std::string &type) const;
/// Query if a given type exists somewhere in the file
bool classTypeExists(const std::string &classType) const;
private:
/// Initialize object with filename
void initialize(const std::string &filename);
/// Walk the tree and cache the structure
void walkFile(::NeXus::File &file, const std::string &rootPath,
const std::string &className,
std::map<std::string, std::string> &pmap, int level);
/// Full filename
std::string m_filename;
/// Extension
std::string m_extension;
/// First entry name/type
std::pair<std::string, std::string> m_firstEntryNameType;
/// Root attributes
std::unordered_set<std::string> m_rootAttrs;
/// Map of full path strings to types. Can check if path exists quickly
std::map<std::string, std::string> m_pathsToTypes;
/// Open NeXus handle
::NeXus::File *m_file;
};
} // namespace Kernel
} // namespace Mantid
#endif /* MANTID_KERNEL_HIERARCHICALFILEDESCRIPTOR_H_ */