Skip to content

Commit

Permalink
Add access to open NeXus file in HDFDescriptor. Refs #7263
Browse files Browse the repository at this point in the history
  • Loading branch information
martyngigg committed Jul 3, 2013
1 parent 7b1bfbe commit 19119d5
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
7 changes: 7 additions & 0 deletions Code/Mantid/Framework/Kernel/inc/MantidKernel/HDFDescriptor.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
};


Expand Down
9 changes: 5 additions & 4 deletions Code/Mantid/Framework/Kernel/src/HDFDescriptor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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())
{
Expand All @@ -123,6 +123,7 @@ namespace Mantid
*/
HDFDescriptor::~HDFDescriptor()
{
delete m_file;
}

/// Returns the name & type of the first entry in the file
Expand Down Expand Up @@ -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);
}

/**
Expand Down
7 changes: 7 additions & 0 deletions Code/Mantid/Framework/Kernel/test/HDFDescriptorTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -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>

Expand Down Expand Up @@ -105,6 +106,12 @@ class HDFDescriptorTest : public CxxTest::TestSuite
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();
Expand Down

0 comments on commit 19119d5

Please sign in to comment.