diff --git a/Code/Mantid/Framework/API/inc/MantidAPI/FileBackedExperimentInfo.h b/Code/Mantid/Framework/API/inc/MantidAPI/FileBackedExperimentInfo.h index b110a9515b8a5b3f6c3b328d059ab7f481e42720..2322fb3e882d9f0e1722add864a48cac5bdf10b7 100644 --- a/Code/Mantid/Framework/API/inc/MantidAPI/FileBackedExperimentInfo.h +++ b/Code/Mantid/Framework/API/inc/MantidAPI/FileBackedExperimentInfo.h @@ -37,7 +37,7 @@ namespace API { class MANTID_API_DLL FileBackedExperimentInfo : public ExperimentInfo { public: /// Constructor - FileBackedExperimentInfo(::NeXus::File *file, const std::string &path); + FileBackedExperimentInfo(const std::string & filename, const std::string &path); ExperimentInfo *cloneExperimentInfo() const; @@ -99,8 +99,8 @@ private: void populateFromFile() const; mutable bool m_loaded; - ::NeXus::File *m_file; - std::string m_path; + std::string m_filename; + std::string m_nxpath; }; } // namespace API diff --git a/Code/Mantid/Framework/API/src/FileBackedExperimentInfo.cpp b/Code/Mantid/Framework/API/src/FileBackedExperimentInfo.cpp index 2a32eb2579f06b58aede778e4b897b96f44dedd7..79bff7b89c7793898584705474f84e73fab73152 100644 --- a/Code/Mantid/Framework/API/src/FileBackedExperimentInfo.cpp +++ b/Code/Mantid/Framework/API/src/FileBackedExperimentInfo.cpp @@ -2,10 +2,13 @@ // Includes //---------------------------------------------------------------------------------------------- #include "MantidAPI/FileBackedExperimentInfo.h" -#include <nexus/NeXusException.hpp> #include <sstream> +#include <nexus/NeXusException.hpp> +#include <nexus/NeXusFile.hpp> + + namespace Mantid { namespace API { @@ -17,12 +20,12 @@ Kernel::Logger g_log("FileBackedExperimentInfo"); /** * Create an object based on a NeXus file and path - * @param file A pointer to an open NeXus file object - * @param path Path to the location of the data + * @param filename The full path to the file + * @param nxpath Path to the location of the experiment information */ -FileBackedExperimentInfo::FileBackedExperimentInfo(::NeXus::File *file, - const std::string &path) - : ExperimentInfo(), m_loaded(false), m_file(file), m_path(path) {} +FileBackedExperimentInfo::FileBackedExperimentInfo(const std::string &filename, + const std::string &nxpath) + : ExperimentInfo(), m_loaded(false), m_filename(filename), m_nxpath(nxpath) {} /** * @return A clone of the object @@ -288,7 +291,8 @@ void FileBackedExperimentInfo::populateIfNotLoaded() const { */ void FileBackedExperimentInfo::populateFromFile() const { try { - m_file->openPath(m_path); + ::NeXus::File nxFile(m_filename); + nxFile.openPath(m_nxpath); // The loadExperimentInfo calls things such as mutableSample() // and if m_loaded is not true then this function is // will be called recursively. @@ -296,7 +300,7 @@ void FileBackedExperimentInfo::populateFromFile() const { std::string parameterStr; const_cast<FileBackedExperimentInfo *>(this) - ->loadExperimentInfoNexus(m_file, parameterStr); + ->loadExperimentInfoNexus(&nxFile, parameterStr); const_cast<FileBackedExperimentInfo *>(this) ->readParameterMap(parameterStr); } catch (::NeXus::Exception &exc) { diff --git a/Code/Mantid/Framework/API/test/FileBackedExperimentInfoTest.h b/Code/Mantid/Framework/API/test/FileBackedExperimentInfoTest.h index 5512a32943aff109d026e8b8bf41fa24b7c9f010..b7ec12deea2623c62f7a1f549a5331f76a69ad92 100644 --- a/Code/Mantid/Framework/API/test/FileBackedExperimentInfoTest.h +++ b/Code/Mantid/Framework/API/test/FileBackedExperimentInfoTest.h @@ -33,10 +33,10 @@ public: } m_inMemoryExptInfo = boost::make_shared<ExperimentInfo>(); - m_nexusFile = boost::make_shared< ::NeXus::File >(m_filename, NXACC_READ); - m_nexusFile->openGroup("mantid_workspace_1", "NXentry"); + ::NeXus::File nxFile(m_filename, NXACC_READ); + nxFile.openGroup("mantid_workspace_1", "NXentry"); std::string paramString; - m_inMemoryExptInfo->loadExperimentInfoNexus(m_nexusFile.get(), paramString); + m_inMemoryExptInfo->loadExperimentInfoNexus(&nxFile, paramString); m_inMemoryExptInfo->readParameterMap(paramString); } @@ -215,27 +215,20 @@ public: // Failure tests //------------------------------------------------------------------------------------------------ void test_runtime_error_generated_when_unable_to_load_from_file() { - // Load the file we want to use - ::NeXus::File nexusFile(m_filename, NXACC_READ); - // Create the file backed experiment info, shouldn't be loaded yet - FileBackedExperimentInfo fileBacked(&nexusFile, "/not/right/path"); + FileBackedExperimentInfo fileBacked(m_filename, "/not/right/path"); TS_ASSERT_THROWS(fileBacked.toString(), std::runtime_error); } private: Mantid::API::ExperimentInfo_sptr createTestObject() { - // Load the file we want to use - ::NeXus::File nexusFile(m_filename, NXACC_READ); // Create the file backed experiment info, shouldn't be loaded yet. - // Manipulate it through - // the interface - return boost::make_shared<FileBackedExperimentInfo>(m_nexusFile.get(), + // Manipulate it through the interface + return boost::make_shared<FileBackedExperimentInfo>(m_filename, "/mantid_workspace_1"); } - boost::shared_ptr< ::NeXus::File > m_nexusFile; Mantid::API::ExperimentInfo_sptr m_inMemoryExptInfo; std::string m_filename; };