Skip to content

Commit

Permalink
Cache first entry name & type in HDFDescriptor. Refs #7263
Browse files Browse the repository at this point in the history
  • Loading branch information
martyngigg committed Jul 3, 2013
1 parent 4743494 commit 3b88b84
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
5 changes: 5 additions & 0 deletions Code/Mantid/Framework/Kernel/inc/MantidKernel/HDFDescriptor.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <map>
#include <set>
#include <string>
#include <utility>

namespace Mantid
{
Expand Down Expand Up @@ -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
Expand All @@ -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.
Expand Down
11 changes: 10 additions & 1 deletion Code/Mantid/Framework/Kernel/src/HDFDescriptor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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())
{
Expand All @@ -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
Expand Down Expand Up @@ -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();
}

Expand Down
7 changes: 7 additions & 0 deletions Code/Mantid/Framework/Kernel/test/HDFDescriptorTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,13 @@ class HDFDescriptorTest : public CxxTest::TestSuite
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"));
Expand Down

0 comments on commit 3b88b84

Please sign in to comment.