Skip to content

Commit

Permalink
Merge pull request #38406 from robertapplin/38332-move-nexus-reading-…
Browse files Browse the repository at this point in the history
…code-to-nexus-library

Move `H5Util` file to Mantid::Nexus library
  • Loading branch information
peterfpeterson authored Nov 21, 2024
2 parents 36d1383 + f39c5c2 commit dbfc55f
Show file tree
Hide file tree
Showing 36 changed files with 369 additions and 392 deletions.
3 changes: 0 additions & 3 deletions Framework/DataHandling/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ set(SRC_FILES
src/GenerateGroupingPowder2.cpp
src/GroupDetectors.cpp
src/GroupDetectors2.cpp
src/H5Util.cpp
src/ISISDataArchive.cpp
src/ISISJournal.cpp
src/ISISJournalGetExperimentRuns.cpp
Expand Down Expand Up @@ -251,7 +250,6 @@ set(INC_FILES
inc/MantidDataHandling/GenerateGroupingPowder2.h
inc/MantidDataHandling/GroupDetectors.h
inc/MantidDataHandling/GroupDetectors2.h
inc/MantidDataHandling/H5Util.h
inc/MantidDataHandling/ISISDataArchive.h
inc/MantidDataHandling/ISISJournal.h
inc/MantidDataHandling/ISISJournalGetExperimentRuns.h
Expand Down Expand Up @@ -475,7 +473,6 @@ set(TEST_FILES
GenerateGroupingPowder2Test.h
GroupDetectors2Test.h
GroupDetectorsTest.h
H5UtilTest.h
ISISDataArchiveTest.h
ISISJournalGetExperimentRunsTest.h
ISISJournalTest.h
Expand Down
2 changes: 2 additions & 0 deletions Framework/DataHandling/inc/MantidDataHandling/LoadHelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@
// SPDX - License - Identifier: GPL - 3.0 +
#pragma once

#include "MantidAPI/MatrixWorkspace_fwd.h"
#include "MantidAPI/Run.h"
#include "MantidDataHandling/DllConfig.h"
#include "MantidKernel/Quat.h"
#include "MantidNexus/NexusClasses.h"

namespace Mantid {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,8 @@ class MANTID_DATAHANDLING_DLL LoadISISNexus2 : public API::IFileLoader<Kernel::N
void validateMultiPeriodLogs(const Mantid::API::MatrixWorkspace_sptr &);

// build the list of spectra numbers to load and include in the spectra list
void buildSpectraInd2SpectraNumMap(bool range_supplied, bool hasSpectraList, DataBlockComposite &dataBlockComposite);
void buildSpectraInd2SpectraNumMap(bool range_supplied, bool hasSpectraList,
const DataBlockComposite &dataBlockComposite);

/// Check if any of the spectra block ranges overlap
void checkOverlappingSpectraRange();
Expand Down Expand Up @@ -171,8 +172,8 @@ class MANTID_DATAHANDLING_DLL LoadISISNexus2 : public API::IFileLoader<Kernel::N
boost::scoped_ptr< ::NeXus::File> m_nexusFile;
// clang-format on

bool findSpectraDetRangeInFile(NeXus::NXEntry &entry, std::vector<specnum_t> &spectrum_index, int64_t ndets,
int64_t n_vms_compat_spectra, std::map<specnum_t, std::string> &monitors,
bool findSpectraDetRangeInFile(const NeXus::NXEntry &entry, std::vector<specnum_t> &spectrum_index, int64_t ndets,
int64_t n_vms_compat_spectra, const std::map<specnum_t, std::string> &monitors,
bool excludeMonitors, bool separateMonitors);

/// Check if is the file is a multiple time regime file
Expand Down
4 changes: 2 additions & 2 deletions Framework/DataHandling/inc/MantidDataHandling/LoadMLZ.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,14 @@ class MANTID_DATAHANDLING_DLL LoadMLZ : public API::IFileLoader<Kernel::NexusDes

std::vector<std::vector<int>> getMonitorInfo(NeXus::NXEntry &firstEntry);

void initWorkSpace(NeXus::NXEntry &entry);
void initWorkspace(const NeXus::NXEntry &entry);
void initInstrumentSpecific();
void loadRunDetails(NeXus::NXEntry &entry);
void loadExperimentDetails(const NeXus::NXEntry &entry);

NeXus::NXData loadNexusFileData(NeXus::NXEntry &entry);
void maskDetectors(const NeXus::NXEntry &entry);
void loadDataIntoTheWorkSpace(NeXus::NXEntry &entry); //, int ElasticPeakPosition = -1);
void loadDataIntoTheWorkSpace(const NeXus::NXEntry &entry); //, int ElasticPeakPosition = -1);

void runLoadInstrument();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include "MantidAPI/ITableWorkspace_fwd.h"
#include "MantidAPI/MatrixWorkspace_fwd.h"
#include "MantidAPI/NexusFileLoader.h"
#include "MantidAPI/Sample.h"
#include "MantidDataHandling/DllConfig.h"
#include "MantidHistogramData/BinEdges.h"
#include "MantidKernel/cow_ptr.h"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class MANTID_DATAHANDLING_DLL LoadSINQFocus : public API::IFileLoader<Kernel::Ne
void init() override;
void exec() override;
void setInstrumentName(const NeXus::NXEntry &entry);
void initWorkSpace(NeXus::NXEntry &);
void initWorkSpace(const NeXus::NXEntry &);
void loadDataIntoTheWorkSpace(NeXus::NXEntry &);
/// Calculate error for y
static double calculateError(double in) { return sqrt(in); }
Expand Down
4 changes: 3 additions & 1 deletion Framework/DataHandling/src/DataBlockComposite.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@
// SPDX - License - Identifier: GPL - 3.0 +
#include "MantidDataHandling/DataBlockComposite.h"
#include "MantidDataHandling/DataBlockGenerator.h"

#include <algorithm>
#include <cassert>
#include <numeric>

namespace {

Expand Down Expand Up @@ -380,7 +382,7 @@ void DataBlockComposite::removeSpectra(DataBlockComposite &toRemove) {
// Now create the new intervals which don't include the removeInterval
// values
std::vector<SpectrumPair> newIntervals;
for (auto &originalInterval : originalIntervals) {
for (const auto &originalInterval : originalIntervals) {
// Find all relevant remove intervals. In principal this could
// be made more efficient.
auto currentRemovalIntervals =
Expand Down
3 changes: 2 additions & 1 deletion Framework/DataHandling/src/LoadDiffCal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
#include "MantidAPI/Progress.h"
#include "MantidAPI/Run.h"
#include "MantidAPI/TableRow.h"
#include "MantidDataHandling/H5Util.h"
#include "MantidDataHandling/LoadCalFile.h"
#include "MantidDataObjects/GroupingWorkspace.h"
#include "MantidDataObjects/MaskWorkspace.h"
Expand All @@ -21,6 +20,7 @@
#include "MantidKernel/Exception.h"
#include "MantidKernel/OptionalBool.h"
#include "MantidKernel/Unit.h"
#include "MantidNexus/H5Util.h"

#include <H5Cpp.h>
#include <cmath>
Expand All @@ -44,6 +44,7 @@ using Mantid::Kernel::PropertyWithValue;
using Mantid::Kernel::Exception::FileError;

using namespace H5;
using namespace NeXus;

namespace {
enum class CalibFilenameExtensionEnum { H5, HD5, HDF, CAL, enum_count };
Expand Down
2 changes: 1 addition & 1 deletion Framework/DataHandling/src/LoadILLDiffraction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
#include "MantidAPI/RegisterFileLoader.h"
#include "MantidAPI/Run.h"
#include "MantidAPI/WorkspaceFactory.h"
#include "MantidDataHandling/H5Util.h"
#include "MantidDataHandling/LoadHelper.h"
#include "MantidDataObjects/ScanningWorkspaceBuilder.h"
#include "MantidGeometry/Instrument/ComponentHelper.h"
Expand All @@ -22,6 +21,7 @@
#include "MantidKernel/ListValidator.h"
#include "MantidKernel/PropertyWithValue.h"
#include "MantidKernel/TimeSeriesProperty.h"
#include "MantidNexus/H5Util.h"

#include <H5Cpp.h>
#include <Poco/Path.h>
Expand Down
10 changes: 6 additions & 4 deletions Framework/DataHandling/src/LoadISISNexus2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include "MantidAPI/Axis.h"
#include "MantidAPI/FileProperty.h"
#include "MantidAPI/RegisterFileLoader.h"
#include "MantidAPI/Sample.h"
#include "MantidAPI/WorkspaceFactory.h"
#include "MantidGeometry/Instrument.h"
#include "MantidGeometry/Instrument/Detector.h"
Expand Down Expand Up @@ -604,7 +605,7 @@ below have to be processed rather then spectra list
intervals
**/
void LoadISISNexus2::buildSpectraInd2SpectraNumMap(bool range_supplied, bool hasSpectraList,
DataBlockComposite &dataBlockComposite) {
const DataBlockComposite &dataBlockComposite) {

if (range_supplied || hasSpectraList || true) {
auto generator = dataBlockComposite.getGenerator();
Expand Down Expand Up @@ -943,9 +944,10 @@ double LoadISISNexus2::dblSqrt(double in) { return sqrt(in); }
* (contain different number of time channels)
*
*/
bool LoadISISNexus2::findSpectraDetRangeInFile(NXEntry &entry, std::vector<specnum_t> &spectrum_index, int64_t ndets,
int64_t n_vms_compat_spectra, std::map<specnum_t, std::string> &monitors,
bool excludeMonitors, bool separateMonitors) {
bool LoadISISNexus2::findSpectraDetRangeInFile(const NXEntry &entry, std::vector<specnum_t> &spectrum_index,
int64_t ndets, int64_t n_vms_compat_spectra,
const std::map<specnum_t, std::string> &monitors, bool excludeMonitors,
bool separateMonitors) {
size_t nmons = monitors.size();

if (nmons > 0) {
Expand Down
1 change: 1 addition & 0 deletions Framework/DataHandling/src/LoadInstrumentFromNexus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
//----------------------------------------------------------------------
#include "MantidDataHandling/LoadInstrumentFromNexus.h"
#include "MantidAPI/FileProperty.h"
#include "MantidAPI/MatrixWorkspace.h"
#include "MantidGeometry/Instrument.h"
#include "MantidGeometry/Instrument/CompAssembly.h"
#include "MantidGeometry/Instrument/Component.h"
Expand Down
7 changes: 4 additions & 3 deletions Framework/DataHandling/src/LoadMLZ.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "MantidAPI/MatrixWorkspace.h"
#include "MantidAPI/Progress.h"
#include "MantidAPI/RegisterFileLoader.h"
#include "MantidAPI/Sample.h"
#include "MantidAPI/SpectrumInfo.h"
#include "MantidAPI/WorkspaceFactory.h"
#include "MantidDataHandling/LoadHelper.h"
Expand Down Expand Up @@ -77,7 +78,7 @@ void LoadMLZ::exec() {
loadInstrumentDetails(dataFirstEntry);
loadTimeDetails(dataFirstEntry);

initWorkSpace(dataFirstEntry);
initWorkspace(dataFirstEntry);

// load the instrument from the IDF
runLoadInstrument();
Expand Down Expand Up @@ -169,7 +170,7 @@ void LoadMLZ::loadInstrumentDetails(const NeXus::NXEntry &firstEntry) {
* @param entry :: The Nexus entry
*
*/
void LoadMLZ::initWorkSpace(NeXus::NXEntry &entry) //, const std::vector<std::vector<int> >&monitors)
void LoadMLZ::initWorkspace(const NeXus::NXEntry &entry) //, const std::vector<std::vector<int> >&monitors)
{
// read in the data
NXData dataGroup = entry.openNXData("data");
Expand Down Expand Up @@ -352,7 +353,7 @@ void LoadMLZ::loadExperimentDetails(const NXEntry &entry) {
*
* @param entry :: The Nexus entry
*/
void LoadMLZ::loadDataIntoTheWorkSpace(NeXus::NXEntry &entry) {
void LoadMLZ::loadDataIntoTheWorkSpace(const NeXus::NXEntry &entry) {
// read in the data
NXData dataGroup = entry.openNXData("data");
NXInt data = dataGroup.openIntData();
Expand Down
3 changes: 2 additions & 1 deletion Framework/DataHandling/src/LoadMcStas.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@
#include "MantidAPI/RegisterFileLoader.h"
#include "MantidAPI/WorkspaceFactory.h"
#include "MantidAPI/WorkspaceGroup.h"
#include "MantidDataHandling/H5Util.h"
#include "MantidDataHandling/LoadEventNexus.h"
#include "MantidGeometry/Instrument.h"
#include "MantidGeometry/Instrument/InstrumentDefinitionParser.h"
#include "MantidKernel/RegexStrings.h"
#include "MantidKernel/Strings.h"
#include "MantidKernel/Unit.h"
#include "MantidKernel/UnitFactory.h"
#include "MantidNexus/H5Util.h"

#include <H5Cpp.h>
#include <boost/algorithm/string.hpp>
Expand All @@ -29,6 +29,7 @@ namespace Mantid::DataHandling {
using namespace Kernel;
using namespace API;
using namespace DataObjects;
using namespace NeXus;

// Register the algorithm into the AlgorithmFactory
DECLARE_NEXUS_HDF5_FILELOADER_ALGORITHM(LoadMcStas)
Expand Down
7 changes: 5 additions & 2 deletions Framework/DataHandling/src/LoadMuonNexus2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@
// Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
// SPDX - License - Identifier: GPL - 3.0 +
#include "MantidDataHandling/LoadMuonNexus2.h"

#include "MantidAPI/Axis.h"
#include "MantidAPI/FileProperty.h"
#include "MantidAPI/Progress.h"
#include "MantidAPI/RegisterFileLoader.h"
#include "MantidAPI/Run.h"
#include "MantidAPI/Sample.h"
#include "MantidAPI/WorkspaceFactory.h"
#include "MantidAPI/WorkspaceGroup.h"
#include "MantidDataHandling/LoadMuonNexus1.h"
Expand All @@ -24,6 +26,7 @@
#include "MantidKernel/UnitFactory.h"
#include "MantidKernel/UnitLabelTypes.h"
#include "MantidNexus/NexusClasses.h"

#include <Poco/Path.h>
#include <memory>
// clang-format off
Expand Down Expand Up @@ -145,7 +148,7 @@ void LoadMuonNexus2::doExec() {

std::string detectorName;
// Only the first NXdata found
for (auto &group : entry.groups()) {
for (const auto &group : entry.groups()) {
std::string className = group.nxclass;
if (className == "NXdata") {
detectorName = group.nxname;
Expand Down Expand Up @@ -483,7 +486,7 @@ std::map<int, std::set<int>> LoadMuonNexus2::loadDetectorMapping(const Mantid::N
NXEntry entry = root.openEntry(m_entry_name);
const std::string detectorName = [&entry]() {
// Only the first NXdata found
for (auto &group : entry.groups()) {
for (const auto &group : entry.groups()) {
std::string className = group.nxclass;
if (className == "NXdata") {
return group.nxname;
Expand Down
Loading

0 comments on commit dbfc55f

Please sign in to comment.