From 5d723229c6be4088067f51a6c250eeadad0721da Mon Sep 17 00:00:00 2001 From: Martyn Gigg <martyn.gigg@stfc.ac.uk> Date: Sat, 29 Jun 2013 14:52:35 +0100 Subject: [PATCH] Cache first entry name & type in HDFDescriptor. Refs #7263 --- .../Framework/Kernel/inc/MantidKernel/HDFDescriptor.h | 5 +++++ Code/Mantid/Framework/Kernel/src/HDFDescriptor.cpp | 11 ++++++++++- Code/Mantid/Framework/Kernel/test/HDFDescriptorTest.h | 7 +++++++ 3 files changed, 22 insertions(+), 1 deletion(-) diff --git a/Code/Mantid/Framework/Kernel/inc/MantidKernel/HDFDescriptor.h b/Code/Mantid/Framework/Kernel/inc/MantidKernel/HDFDescriptor.h index 6b149b90c8a..13b2511e643 100644 --- a/Code/Mantid/Framework/Kernel/inc/MantidKernel/HDFDescriptor.h +++ b/Code/Mantid/Framework/Kernel/inc/MantidKernel/HDFDescriptor.h @@ -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. diff --git a/Code/Mantid/Framework/Kernel/src/HDFDescriptor.cpp b/Code/Mantid/Framework/Kernel/src/HDFDescriptor.cpp index 483dbd69612..9c9a185ee52 100644 --- a/Code/Mantid/Framework/Kernel/src/HDFDescriptor.cpp +++ b/Code/Mantid/Framework/Kernel/src/HDFDescriptor.cpp @@ -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(); } diff --git a/Code/Mantid/Framework/Kernel/test/HDFDescriptorTest.h b/Code/Mantid/Framework/Kernel/test/HDFDescriptorTest.h index c599ef1d99c..8406c72ac64 100644 --- a/Code/Mantid/Framework/Kernel/test/HDFDescriptorTest.h +++ b/Code/Mantid/Framework/Kernel/test/HDFDescriptorTest.h @@ -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")); -- GitLab