Skip to content
Snippets Groups Projects
Commit ec3e85aa authored by Gigg, Martyn Anthony's avatar Gigg, Martyn Anthony
Browse files

Add root attribute query methods to HDFDescriptor. Refs #7263

parent 9a591118
No related branches found
No related tags found
No related merge requests found
......@@ -5,6 +5,7 @@
#include "MantidKernel/DllConfig.h"
#include <map>
#include <set>
#include <string>
namespace Mantid
......@@ -71,6 +72,8 @@ namespace Mantid
*/
inline const std::string & extension() const { return m_extension; }
/// 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
......@@ -89,6 +92,8 @@ namespace Mantid
std::string m_filename;
/// Extension
std::string m_extension;
/// Root attributes
std::set<std::string> m_rootAttrs;
/// Map of types to full path strings.
std::multimap<std::string, std::string> *m_typesToPaths;
};
......
......@@ -98,7 +98,7 @@ namespace Mantid
* involves simply checking for the signature if a HDF file at the start of the file
*/
HDFDescriptor::HDFDescriptor(const std::string & filename)
: m_filename(), m_extension(), m_typesToPaths(NULL)
: m_filename(), m_extension(), m_rootAttrs(), m_typesToPaths(NULL)
{
if(filename.empty())
{
......@@ -126,6 +126,15 @@ namespace Mantid
}
/**
* @param name The name of an attribute
* @return True if the attribute exists, false otherwise
*/
bool HDFDescriptor::hasRootAttr(const std::string &name) const
{
return (m_rootAttrs.count(name) == 1);
}
/**
* @param path A string giving a path using UNIX-style path separators (/), e.g. /raw_data_1, /entry/bank1
* @return True if the path exists in the file, false otherwise
......@@ -179,11 +188,13 @@ namespace Mantid
m_extension = "." + Poco::Path(filename).getExtension();
::NeXus::File file(this->filename());
auto attrInfos = file.getAttrInfos();
for(size_t i = 0; i < attrInfos.size(); ++i)
{
m_rootAttrs.insert(attrInfos[i].name);
}
m_typesToPaths = file.getTypeMap();
}
} // namespace Kernel
} // namespace Mantid
......@@ -105,6 +105,16 @@ public:
TS_ASSERT_THROWS(HDFDescriptor fd(m_testNonHDFPath), std::invalid_argument);
}
void test_hasRootAttr_Returns_True_For_Existing_Attr()
{
TS_ASSERT(m_testHDF5->hasRootAttr("file_time"));
}
void test_hasRootAttr_Returns_False_For_Non_Existing_Attr()
{
TS_ASSERT(!m_testHDF5->hasRootAttr("not_attr"));
}
void test_PathExists_Returns_False_For_Path_Not_In_File()
{
TS_ASSERT(!m_testHDF5->pathExists("/raw_data_1/bank1"));
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment