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

Cache first entry name & type in HDFDescriptor. Refs #7263

parent ec3e85aa
No related branches found
No related tags found
No related merge requests found
......@@ -7,6 +7,7 @@
#include <map>
#include <set>
#include <string>
#include <utility>
namespace Mantid
{
......@@ -72,6 +73,8 @@ namespace Mantid
*/
inline const std::string & extension() const { return m_extension; }
/// 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
......@@ -92,6 +95,8 @@ namespace Mantid
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 types to full path strings.
......
......@@ -98,7 +98,8 @@ 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_rootAttrs(), m_typesToPaths(NULL)
: m_filename(), m_extension(), m_firstEntryNameType(),
m_rootAttrs(), m_typesToPaths(NULL)
{
if(filename.empty())
{
......@@ -125,6 +126,11 @@ namespace Mantid
delete m_typesToPaths;
}
/// Returns the name & type of the first entry in the file
const std::pair<std::string,std::string> & HDFDescriptor::firstEntryNameType() const
{
return m_firstEntryNameType;
}
/**
* @param name The name of an attribute
......@@ -193,6 +199,9 @@ namespace Mantid
{
m_rootAttrs.insert(attrInfos[i].name);
}
auto entries = file.getEntries();
auto entryIter = entries.begin();
m_firstEntryNameType = std::make_pair(entryIter->first, entryIter->second);
m_typesToPaths = file.getTypeMap();
}
......
......@@ -105,6 +105,13 @@ public:
TS_ASSERT_THROWS(HDFDescriptor fd(m_testNonHDFPath), std::invalid_argument);
}
void test_firstEntryNameType_Returns_Correct_Details()
{
auto entryType = m_testHDF5->firstEntryNameType();
TS_ASSERT_EQUALS("entry", entryType.first);
TS_ASSERT_EQUALS("NXentry", entryType.second);
}
void test_hasRootAttr_Returns_True_For_Existing_Attr()
{
TS_ASSERT(m_testHDF5->hasRootAttr("file_time"));
......
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