diff --git a/Code/Mantid/Framework/Kernel/inc/MantidKernel/HDFDescriptor.h b/Code/Mantid/Framework/Kernel/inc/MantidKernel/HDFDescriptor.h index 6b149b90c8a64bb165d5d2a44dc46b4ec3ba8d06..13b2511e6432e75901f210ccb6c02ab0e447c3ed 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 483dbd6961242b64ace79a4c5902cd34d88cfddf..9c9a185ee521405dbc9c1fc02913a3b5e2092190 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 c599ef1d99c393ea6f09c4562977acecc90d4327..8406c72ac64072dfc37ffa27a257ebcc49cd84e3 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"));