From 5a1a53c2c09e4b07f288cf35a32850492dd1e785 Mon Sep 17 00:00:00 2001 From: Martyn Gigg <martyn.gigg@stfc.ac.uk> Date: Wed, 3 Jul 2013 11:48:40 +0100 Subject: [PATCH] Add access to open NeXus file in HDFDescriptor. Refs #7263 --- .../Framework/Kernel/inc/MantidKernel/HDFDescriptor.h | 7 +++++++ Code/Mantid/Framework/Kernel/src/HDFDescriptor.cpp | 9 +++++---- Code/Mantid/Framework/Kernel/test/HDFDescriptorTest.h | 7 +++++++ 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/Code/Mantid/Framework/Kernel/inc/MantidKernel/HDFDescriptor.h b/Code/Mantid/Framework/Kernel/inc/MantidKernel/HDFDescriptor.h index 26f31b0a497..f186966f990 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 70fd3d55160..a4901a0fc86 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 8406c72ac64..34fef08452e 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(); -- GitLab