Skip to content

Commit

Permalink
Merge pull request #38766 from peterfpeterson/38332_LoadILLDiffractio…
Browse files Browse the repository at this point in the history
…n_refactor

Refactor LoadHelper to use NeXus::File
  • Loading branch information
rosswhitfield authored Feb 3, 2025
2 parents 110aa7a + 514b1e8 commit 3eb3f10
Show file tree
Hide file tree
Showing 14 changed files with 220 additions and 263 deletions.
5 changes: 3 additions & 2 deletions Framework/DataHandling/inc/MantidDataHandling/LoadHelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "MantidDataHandling/DllConfig.h"
#include "MantidKernel/Quat.h"
#include "MantidNexus/NexusClasses.h"
#include "MantidNexusCpp/NeXusFile.hpp"

namespace Mantid {

Expand All @@ -27,7 +28,7 @@ std::vector<double> getTimeBinningFromNexusPath(const Mantid::NeXus::NXEntry &,
double calculateEnergy(double);
double calculateTOF(double, double);
double getInstrumentProperty(const API::MatrixWorkspace_sptr &, const std::string &);
void addNexusFieldsToWsRun(NXhandle nxfileID, API::Run &runDetails, const std::string &entryName = "",
void addNexusFieldsToWsRun(::NeXus::File &filehandle, API::Run &runDetails, const std::string &entryName = "",
bool useFullPath = false);
std::string dateTimeInIsoFormat(const std::string &);

Expand Down Expand Up @@ -57,7 +58,7 @@ NeXus::NXDouble getDoubleDataset(const NeXus::NXEntry &, const std::string &);

void replaceZeroErrors(const API::MatrixWorkspace_sptr &, double);

void recurseAndAddNexusFieldsToWsRun(NXhandle nxfileID, API::Run &runDetails, const std::string &parent_name,
void recurseAndAddNexusFieldsToWsRun(::NeXus::File &filehandle, API::Run &runDetails, const std::string &parent_name,
const std::string &parent_class, int level, bool useFullPath);
} // namespace LoadHelper
} // namespace DataHandling
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,12 @@ class MANTID_DATAHANDLING_DLL LoadILLIndirect2 : public API::IFileLoader<Kernel:
void init() override;
void exec() override;

void loadDataDetails(NeXus::NXEntry &entry);
void loadDataDetails(const NeXus::NXEntry &entry);
void initWorkSpace();
void setInstrumentName(const NeXus::NXEntry &firstEntry, const std::string &instrumentNamePath);
std::string getDataPath(const NeXus::NXEntry &entry);
void loadNexusEntriesIntoProperties(const std::string &nexusfilename);
void loadDataIntoWorkspace(NeXus::NXEntry &entry);
void loadDataIntoWorkspace(const NeXus::NXEntry &entry);
void loadDiffractionData(NeXus::NXEntry &entry);
void moveComponent(const std::string &, double);
void moveSingleDetectors(const NeXus::NXEntry &entry);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ class MANTID_DATAHANDLING_DLL LoadILLSANS : public API::IFileLoader<Kernel::Nexu
const MultichannelType type = MultichannelType::TOF);
size_t loadDataFromD16ScanMonitors(const NeXus::NXEntry &firstEntry, size_t firstIndex,
const std::vector<double> &binning);
size_t loadDataFromTubes(NeXus::NXInt &, const std::vector<double> &, size_t,
size_t loadDataFromTubes(NeXus::NXInt const &, const std::vector<double> &, size_t,
const MultichannelType type = MultichannelType::TOF);
void runLoadInstrument();
void moveDetectorsD33(const DetectorPosition &);
Expand Down
13 changes: 7 additions & 6 deletions Framework/DataHandling/src/LoadEventNexus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
#include "MantidKernel/UnitFactory.h"
#include "MantidKernel/VisibleWhenProperty.h"
#include "MantidNexus/NexusIOHelper.h"
#include "MantidNexusCpp/NeXusException.hpp"
#include "MantidNexusCpp/NeXusFile.hpp"

#include <H5Cpp.h>
#include <boost/format.hpp>
Expand Down Expand Up @@ -947,13 +949,12 @@ void LoadEventNexus::loadEvents(API::Progress *const prog, const bool monitors)
}
} else {
prog->doReport("Loading all logs");
// Open NeXus file
NXhandle nxHandle;
NXstatus nxStat = NXopen(m_filename.c_str(), NXACC_READ, &nxHandle);

if (nxStat != NXstatus::NX_ERROR) {
try {
// Open NeXus file
::NeXus::File nxHandle(m_filename, NXACC_READ);
LoadHelper::addNexusFieldsToWsRun(nxHandle, m_ws->mutableRun(), "", true);
NXclose(&nxHandle);
} catch (const ::NeXus::Exception &e) {
g_log.debug() << "Failed to open nexus file \"" << m_filename << "\" in read mode: " << e.what() << "\n";
}
}
} else {
Expand Down
Loading

0 comments on commit 3eb3f10

Please sign in to comment.