10#include <nexus/NeXusFile.hpp>
11#include <nexus/NeXusException.hpp>
51 throw std::invalid_argument(
"HierarchicalFileDescriptor::isHierarchical - Invalid file handle");
57 unsigned char buffer[8] = {
'0',
'0',
'0',
'0',
'0',
'0',
'0',
'0'};
60 throw std::runtime_error(
"Error while reading file");
74 std::rewind(fileHandle);
91 FILE *fd = fopen(
filename.c_str(),
"rb");
93 throw std::invalid_argument(
"HierarchicalFileDescriptor::isHierarchical - Unable to open file '" +
filename +
"'");
95 const bool result = isHDFHandle(fd, version);
112 : m_filename(), m_extension(), m_firstEntryNameType(), m_rootAttrs(), m_pathsToTypes(), m_file(nullptr) {
114 throw std::invalid_argument(
"NexusDescriptor() - Empty filename '" +
filename +
"'");
117 throw std::invalid_argument(
"NexusDescriptor() - File '" +
filename +
"' does not exist");
124 }
catch (::NeXus::Exception &e) {
125 throw std::invalid_argument(
"NexusDescriptor::initialize - File '" +
filename +
126 "' does not look like a HDF file.\n Error was: " + e.what());
160 return (it->second == type);
173 if (type == it->second)
186 if (classType == it->second)
220 std::map<std::string, std::string> &
pmap,
int level) {
221 if (!rootPath.empty()) {
222 pmap.emplace(rootPath, className);
225 auto attrInfos = file.getAttrInfos();
226 for (
auto &attrInfo : attrInfos) {
231 auto dirents = file.getEntries();
232 auto itend = dirents.end();
233 for (
auto it = dirents.begin(); it != itend; ++it) {
234 const std::string &entryName = it->first;
235 const std::string &entryClass = it->second;
236 const std::string entryPath = std::string(rootPath).append(
"/").append(entryName);
237 if (entryClass ==
"SDS" || entryClass ==
"ILL_data_scan_vars" || entryClass ==
"NXill_data_scan_vars") {
238 pmap.emplace(entryPath, entryClass);
239 }
else if (entryClass ==
"CDF0.0") {
244 file.openGroup(entryName, entryClass);
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.
bool hasRootAttr(const std::string &name) const
Query if the given attribute exists on the root node.
std::string m_filename
Full filename.
void walkFile(::NeXus::File &file, const std::string &rootPath, const std::string &className, std::map< std::string, std::string > &pmap, int level)
Walk the tree and cache the structure.
bool classTypeExists(const std::string &classType) const
Query if a given type exists somewhere in the file.
static const unsigned char HDF5Signature[8]
signature identifying a HDF5 file.
~NexusDescriptor()
Destructor.
std::pair< std::string, std::string > m_firstEntryNameType
First entry name/type.
static bool isReadable(const std::string &filename, const Version version=AnyVersion)
Returns true if the file is considered to store data in a hierarchy.
Version
Enumerate HDF possible versions.
NexusDescriptor()=delete
Disable default constructor.
bool pathOfTypeExists(const std::string &path, const std::string &type) const
Query if a path exists of a given type.
void initialize(const std::string &filename)
Initialize object with filename.
static const unsigned char HDFMagic[4]
HDF cookie that is stored in the first 4 bytes of the file.
static const size_t HDFMagicSize
Size of HDF magic number.
const std::pair< std::string, std::string > & firstEntryNameType() const
Returns the name & type of the first entry in the file.
static size_t HDF5SignatureSize
Size of HDF5 signature.
std::unique_ptr<::NeXus::File > m_file
Open NeXus handle.
std::string m_extension
Extension.
bool pathExists(const std::string &path) const
Query if a path exists.
const std::string & filename() const
Access the filename.
std::string pathOfType(const std::string &type) const
return the path of a given type
bool exists(::NeXus::File &file, const std::string &name)
Based on the current group in the file, does the named sub-entry exist?
Generate a tableworkspace to store the calibration results.