diff --git a/Code/Mantid/Framework/Kernel/inc/MantidKernel/HDFDescriptor.h b/Code/Mantid/Framework/Kernel/inc/MantidKernel/HDFDescriptor.h index 26f31b0a49758e0611e6b1a353adc1a6d89af3f6..f186966f9906c6b79c5bbdb56d735108056b91a1 100644 --- a/Code/Mantid/Framework/Kernel/inc/MantidKernel/HDFDescriptor.h +++ b/Code/Mantid/Framework/Kernel/inc/MantidKernel/HDFDescriptor.h @@ -77,6 +77,10 @@ namespace Mantid * @returns A reference to a const string containing the file extension */ inline const std::string & extension() const { return m_extension; } + /** + * Access the open NeXus File object + */ + inline ::NeXus::File & data() { return *m_file; } /// Returns the name & type of the first entry in the file const std::pair<std::string,std::string> & firstEntryNameType() const; @@ -109,6 +113,9 @@ namespace Mantid std::set<std::string> m_rootAttrs; /// Map of full path strings to types. Can check if path exists quickly std::map<std::string, std::string> m_pathsToTypes; + + /// Open NeXus handle + ::NeXus::File *m_file; }; diff --git a/Code/Mantid/Framework/Kernel/src/HDFDescriptor.cpp b/Code/Mantid/Framework/Kernel/src/HDFDescriptor.cpp index 70fd3d55160939d301b2b20af2c17f98a9d95773..a4901a0fc8675d18e6cb833eaecb899fbe63b8fe 100644 --- a/Code/Mantid/Framework/Kernel/src/HDFDescriptor.cpp +++ b/Code/Mantid/Framework/Kernel/src/HDFDescriptor.cpp @@ -99,7 +99,7 @@ namespace Mantid */ HDFDescriptor::HDFDescriptor(const std::string & filename) : m_filename(), m_extension(), m_firstEntryNameType(), - m_rootAttrs(), m_pathsToTypes() + m_rootAttrs(), m_pathsToTypes(), m_file(NULL) { if(filename.empty()) { @@ -123,6 +123,7 @@ namespace Mantid */ HDFDescriptor::~HDFDescriptor() { + delete m_file; } /// Returns the name & type of the first entry in the file @@ -190,12 +191,12 @@ namespace Mantid m_filename = filename; m_extension = "." + Poco::Path(filename).getExtension(); - ::NeXus::File file(this->filename()); + m_file = new ::NeXus::File(this->filename()); - file.openPath("/"); + m_file->openPath("/"); m_rootAttrs.clear(); m_pathsToTypes.clear(); - walkFile(file, "", "", m_pathsToTypes,0); + walkFile(*m_file, "", "", m_pathsToTypes,0); } /** diff --git a/Code/Mantid/Framework/Kernel/test/HDFDescriptorTest.h b/Code/Mantid/Framework/Kernel/test/HDFDescriptorTest.h index 8406c72ac64072dfc37ffa27a257ebcc49cd84e3..34fef08452e01086982a3402e65d8af3f0b8f254 100644 --- a/Code/Mantid/Framework/Kernel/test/HDFDescriptorTest.h +++ b/Code/Mantid/Framework/Kernel/test/HDFDescriptorTest.h @@ -8,6 +8,7 @@ #include <boost/make_shared.hpp> #include <boost/shared_ptr.hpp> +#include <nexus/NeXusFile.hpp> #include <Poco/Path.h> #include <Poco/File.h> @@ -105,6 +106,12 @@ public: TS_ASSERT_THROWS(HDFDescriptor fd(m_testNonHDFPath), std::invalid_argument); } + void test_File_Handle_Returned_By_Data_Is_Valid() + { + auto & file = m_testHDF5->data(); + TS_ASSERT_EQUALS("", file.getPath()) + } + void test_firstEntryNameType_Returns_Correct_Details() { auto entryType = m_testHDF5->firstEntryNameType();