Newer
Older
#ifndef MANTID_KERNEL_HIERARCHICALFILEDESCRIPTOR_H_
#define MANTID_KERNEL_HIERARCHICALFILEDESCRIPTOR_H_
#include "MantidKernel/ClassMacros.h"
#include "MantidKernel/DllConfig.h"
Gigg, Martyn Anthony
committed
#include <map>
#include <set>
#include <string>
#include <utility>
namespace NeXus
{
class File;
}
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
namespace Mantid
{
namespace Kernel
{
/**
Defines a wrapper around a file whose internal structure is stored in a hierarchy, e.g NeXus.
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
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 HDFDescriptor
{
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
HDFDescriptor(const std::string & filename);
Gigg, Martyn Anthony
committed
/// Destructor
~HDFDescriptor();
/**
* 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
Gigg, Martyn Anthony
committed
* @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
Gigg, Martyn Anthony
committed
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);
Gigg, Martyn Anthony
committed
/// Query if a given type exists somewhere in the file
bool classTypeExists(const std::string & classType) const;
private:
DISABLE_DEFAULT_CONSTRUCT(HDFDescriptor);
DISABLE_COPY_AND_ASSIGN(HDFDescriptor);
/// 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::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_ */