Skip to content
Snippets Groups Projects
Commit 5a1a53c2 authored by Gigg, Martyn Anthony's avatar Gigg, Martyn Anthony
Browse files

Add access to open NeXus file in HDFDescriptor. Refs #7263

parent 0e0bd351
No related merge requests found
...@@ -77,6 +77,10 @@ namespace Mantid ...@@ -77,6 +77,10 @@ namespace Mantid
* @returns A reference to a const string containing the file extension * @returns A reference to a const string containing the file extension
*/ */
inline const std::string & extension() const { return m_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 /// Returns the name & type of the first entry in the file
const std::pair<std::string,std::string> & firstEntryNameType() const; const std::pair<std::string,std::string> & firstEntryNameType() const;
...@@ -109,6 +113,9 @@ namespace Mantid ...@@ -109,6 +113,9 @@ namespace Mantid
std::set<std::string> m_rootAttrs; std::set<std::string> m_rootAttrs;
/// Map of full path strings to types. Can check if path exists quickly /// Map of full path strings to types. Can check if path exists quickly
std::map<std::string, std::string> m_pathsToTypes; std::map<std::string, std::string> m_pathsToTypes;
/// Open NeXus handle
::NeXus::File *m_file;
}; };
......
...@@ -99,7 +99,7 @@ namespace Mantid ...@@ -99,7 +99,7 @@ namespace Mantid
*/ */
HDFDescriptor::HDFDescriptor(const std::string & filename) HDFDescriptor::HDFDescriptor(const std::string & filename)
: m_filename(), m_extension(), m_firstEntryNameType(), : m_filename(), m_extension(), m_firstEntryNameType(),
m_rootAttrs(), m_pathsToTypes() m_rootAttrs(), m_pathsToTypes(), m_file(NULL)
{ {
if(filename.empty()) if(filename.empty())
{ {
...@@ -123,6 +123,7 @@ namespace Mantid ...@@ -123,6 +123,7 @@ namespace Mantid
*/ */
HDFDescriptor::~HDFDescriptor() HDFDescriptor::~HDFDescriptor()
{ {
delete m_file;
} }
/// Returns the name & type of the first entry in the file /// Returns the name & type of the first entry in the file
...@@ -190,12 +191,12 @@ namespace Mantid ...@@ -190,12 +191,12 @@ namespace Mantid
m_filename = filename; m_filename = filename;
m_extension = "." + Poco::Path(filename).getExtension(); 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_rootAttrs.clear();
m_pathsToTypes.clear(); m_pathsToTypes.clear();
walkFile(file, "", "", m_pathsToTypes,0); walkFile(*m_file, "", "", m_pathsToTypes,0);
} }
/** /**
......
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#include <boost/make_shared.hpp> #include <boost/make_shared.hpp>
#include <boost/shared_ptr.hpp> #include <boost/shared_ptr.hpp>
#include <nexus/NeXusFile.hpp>
#include <Poco/Path.h> #include <Poco/Path.h>
#include <Poco/File.h> #include <Poco/File.h>
...@@ -105,6 +106,12 @@ public: ...@@ -105,6 +106,12 @@ public:
TS_ASSERT_THROWS(HDFDescriptor fd(m_testNonHDFPath), std::invalid_argument); 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() void test_firstEntryNameType_Returns_Correct_Details()
{ {
auto entryType = m_testHDF5->firstEntryNameType(); auto entryType = m_testHDF5->firstEntryNameType();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment