Mantid
Loading...
Searching...
No Matches
FileBackedExperimentInfo.cpp
Go to the documentation of this file.
1// Mantid Repository : https://github.com/mantidproject/mantid
2//
3// Copyright © 2018 ISIS Rutherford Appleton Laboratory UKRI,
4// NScD Oak Ridge National Laboratory, European Spallation Source,
5// Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
6// SPDX - License - Identifier: GPL - 3.0 +
9
10#include <sstream>
11
12// clang-format off
13#include <nexus/NeXusFile.hpp>
14#include <nexus/NeXusException.hpp>
15#include <utility>
16// clang-format on
17
18namespace Mantid::API {
19
20namespace {
22Kernel::Logger g_log("FileBackedExperimentInfo");
23} // namespace
24
30FileBackedExperimentInfo::FileBackedExperimentInfo(std::string filename, std::string nxpath)
31 : ExperimentInfo(), m_loaded(false), m_filename(std::move(filename)), m_nxpath(std::move(nxpath)) {}
32
39
45 if (m_loaded)
46 return;
48}
49
54 try {
55 ::NeXus::File nxFile(m_filename);
56 nxFile.openPath(m_nxpath);
57 // The loadExperimentInfo calls things such as mutableSample()
58 // and if m_loaded is not true then this function is
59 // will be called recursively.
60 m_loaded = true;
61
62 std::string parameterStr;
63 const_cast<FileBackedExperimentInfo *>(this)->loadExperimentInfoNexus(m_filename, &nxFile, parameterStr);
64 const_cast<FileBackedExperimentInfo *>(this)->readParameterMap(parameterStr);
65 } catch (::NeXus::Exception &exc) {
66 std::ostringstream os;
67 os << "Unable to load experiment information from NeXus file: " << exc.what() << "\n";
68 throw std::runtime_error(os.str());
69 }
70}
71
72} // namespace Mantid::API
This class is shared by a few Workspace types and holds information related to a particular experimen...
void readParameterMap(const std::string &parameterStr)
Populate the parameter map given a string.
void loadExperimentInfoNexus(const std::string &nxFilename, ::NeXus::File *file, std::string &parameterStr, const Mantid::Kernel::NexusHDF5Descriptor &fileInfo, const std::string &prefix)
Implements a lazy-loading mechanism for the experimental information stored in a NeXus file.
ExperimentInfo * cloneExperimentInfo() const override
This clones the FileBackedExperimentInfo and will not cause a load of the information.
FileBackedExperimentInfo(std::string filename, std::string nxpath)
Create an object based on a NeXus file and path.
void populateIfNotLoaded() const override
Check if the object has been populated and load the information if it has not.
void populateFromFile() const
Populate this object with the data from the file.
Kernel::Logger g_log("ExperimentInfo")
static logger object
STL namespace.