From 1745107ebe8dc8edfd1e9e0c4485fb07ae3a6181 Mon Sep 17 00:00:00 2001 From: Applin Date: Wed, 30 Oct 2024 14:41:33 +0000 Subject: [PATCH 1/6] Use Load algorithm instead of LoadMuonNexus so it finds correct algo --- Testing/SystemTests/tests/framework/ISISMuonAnalysis.py | 4 ++-- .../SystemTests/tests/framework/ISISMuonAnalysisGrouping.py | 4 ++-- Testing/SystemTests/tests/framework/MuonKerenFittingTest.py | 4 ++-- Testing/SystemTests/tests/framework/MuonProcessTest.py | 4 ++-- docs/source/algorithms/ApplyMuonDetectorGroupPairing-v1.rst | 4 ++-- docs/source/algorithms/ApplyMuonDetectorGrouping-v1.rst | 4 ++-- .../algorithms/LoadAndApplyMuonDetectorGrouping-v1.rst | 4 ++-- docs/source/algorithms/MuonProcess-v1.rst | 6 +++--- 8 files changed, 17 insertions(+), 17 deletions(-) diff --git a/Testing/SystemTests/tests/framework/ISISMuonAnalysis.py b/Testing/SystemTests/tests/framework/ISISMuonAnalysis.py index ff370ae98f05..d017cba06ea1 100644 --- a/Testing/SystemTests/tests/framework/ISISMuonAnalysis.py +++ b/Testing/SystemTests/tests/framework/ISISMuonAnalysis.py @@ -8,7 +8,7 @@ import math import systemtesting from mantid.api import mtd -from mantid.simpleapi import AsymmetryCalc, CloneWorkspace, CropWorkspace, GroupDetectors, GroupWorkspaces, LoadMuonNexus, Rebin +from mantid.simpleapi import AsymmetryCalc, CloneWorkspace, CropWorkspace, GroupDetectors, GroupWorkspaces, Load, Rebin from abc import ABCMeta, abstractmethod @@ -51,7 +51,7 @@ def runTest(self): outputWS = self.instr_name + str(self.sample_run) # Load - LoadMuonNexus(Filename=self.file_name, OutputWorkspace="MuonAnalysis") + Load(Filename=self.file_name, OutputWorkspace="MuonAnalysis") # Group, Crop, Clone if self.period_data: diff --git a/Testing/SystemTests/tests/framework/ISISMuonAnalysisGrouping.py b/Testing/SystemTests/tests/framework/ISISMuonAnalysisGrouping.py index 3fde45c082e1..7e613c4f2eef 100644 --- a/Testing/SystemTests/tests/framework/ISISMuonAnalysisGrouping.py +++ b/Testing/SystemTests/tests/framework/ISISMuonAnalysisGrouping.py @@ -6,7 +6,7 @@ # SPDX - License - Identifier: GPL - 3.0 + # pylint: disable=no-init,attribute-defined-outside-init,too-many-instance-attributes,too-few-public-methods import systemtesting -from mantid.simpleapi import CloneWorkspace, CropWorkspace, GroupDetectors, GroupWorkspaces, LoadMuonNexus, Logarithm, RemoveExpDecay +from mantid.simpleapi import CloneWorkspace, CropWorkspace, GroupDetectors, GroupWorkspaces, Load, Logarithm, RemoveExpDecay from abc import ABCMeta, abstractmethod @@ -47,7 +47,7 @@ def runTest(self): outputWS = self.instr_name + str(self.sample_run) # Load - LoadMuonNexus(Filename=self.file_name, OutputWorkspace="MuonAnalysis") + Load(Filename=self.file_name, OutputWorkspace="MuonAnalysis") # Group, Crop, Clone if self.period_data: diff --git a/Testing/SystemTests/tests/framework/MuonKerenFittingTest.py b/Testing/SystemTests/tests/framework/MuonKerenFittingTest.py index 7cfac4a6dce0..1ca5500ddece 100644 --- a/Testing/SystemTests/tests/framework/MuonKerenFittingTest.py +++ b/Testing/SystemTests/tests/framework/MuonKerenFittingTest.py @@ -7,7 +7,7 @@ # pylint: disable=no-init,attribute-defined-outside-init,too-few-public-methods import systemtesting from mantid.api import mtd -from mantid.simpleapi import Fit, LoadMuonNexus, MuonProcess +from mantid.simpleapi import Fit, Load, MuonProcess class MuonKerenFittingTest(systemtesting.MantidSystemTest): @@ -15,7 +15,7 @@ class MuonKerenFittingTest(systemtesting.MantidSystemTest): def runTest(self): # Load dataset - LoadMuonNexus(Filename="MUT00053591.nxs", DetectorGroupingTable="gp", OutputWorkspace="MUT53591") + Load(Filename="MUT00053591.nxs", DetectorGroupingTable="gp", OutputWorkspace="MUT53591") # Process like MuonAnalysis interface would MuonProcess( diff --git a/Testing/SystemTests/tests/framework/MuonProcessTest.py b/Testing/SystemTests/tests/framework/MuonProcessTest.py index f11979dd2b3a..8e102716bacb 100644 --- a/Testing/SystemTests/tests/framework/MuonProcessTest.py +++ b/Testing/SystemTests/tests/framework/MuonProcessTest.py @@ -7,7 +7,7 @@ # pylint: disable=no-init import systemtesting from mantid.api import mtd, WorkspaceFactory -from mantid.simpleapi import LoadMuonNexus, MuonProcess +from mantid.simpleapi import Load, MuonProcess class MuonProcessTest(systemtesting.MantidSystemTest): @@ -27,7 +27,7 @@ def runTest(self): deadTimes.addRow([i, i * 0.01]) mtd.addOrReplace("MuonProcess_DeadTimes", deadTimes) - load_result = LoadMuonNexus(Filename="MUSR00015192", OutputWorkspace="MuonProcess_Loaded") + load_result = Load(Filename="MUSR00015192", OutputWorkspace="MuonProcess_Loaded") loaded_time_zero = load_result[2] MuonProcess( diff --git a/docs/source/algorithms/ApplyMuonDetectorGroupPairing-v1.rst b/docs/source/algorithms/ApplyMuonDetectorGroupPairing-v1.rst index e525b5362d54..3b37cd8db32f 100644 --- a/docs/source/algorithms/ApplyMuonDetectorGroupPairing-v1.rst +++ b/docs/source/algorithms/ApplyMuonDetectorGroupPairing-v1.rst @@ -75,8 +75,8 @@ Usage OverwriteExisting=True) # Load the data - LoadMuonNexus( Filename='MUSR00015193.nxs', - OutputWorkspace='MuonAnalysis') + Load(Filename='MUSR00015193.nxs', + OutputWorkspace='MuonAnalysis') # Create two detector groupings ApplyMuonDetectorGrouping( diff --git a/docs/source/algorithms/ApplyMuonDetectorGrouping-v1.rst b/docs/source/algorithms/ApplyMuonDetectorGrouping-v1.rst index a5e37c99eb13..d358ffe0b201 100644 --- a/docs/source/algorithms/ApplyMuonDetectorGrouping-v1.rst +++ b/docs/source/algorithms/ApplyMuonDetectorGrouping-v1.rst @@ -70,8 +70,8 @@ Usage OverwriteExisting=True) # Load the data - LoadMuonNexus( Filename='MUSR00015193.nxs', - OutputWorkspace='MuonAnalysis') + Load(Filename='MUSR00015193.nxs', + OutputWorkspace='MuonAnalysis') ApplyMuonDetectorGrouping( InputWorkspace='MuonAnalysis', diff --git a/docs/source/algorithms/LoadAndApplyMuonDetectorGrouping-v1.rst b/docs/source/algorithms/LoadAndApplyMuonDetectorGrouping-v1.rst index f18a83f33545..fcfbd5eea3b7 100644 --- a/docs/source/algorithms/LoadAndApplyMuonDetectorGrouping-v1.rst +++ b/docs/source/algorithms/LoadAndApplyMuonDetectorGrouping-v1.rst @@ -74,8 +74,8 @@ Usage OverwriteExisting=True) # Load the data - LoadMuonNexus( Filename='MUSR00015189.nxs', - OutputWorkspace='MuonAnalysis') + Load(Filename='MUSR00015189.nxs', + OutputWorkspace='MuonAnalysis') LoadAndApplyMuonDetectorGrouping( Filename='MUSRGrouping.xml', diff --git a/docs/source/algorithms/MuonProcess-v1.rst b/docs/source/algorithms/MuonProcess-v1.rst index f8666232b8c7..8c2e811f46b4 100644 --- a/docs/source/algorithms/MuonProcess-v1.rst +++ b/docs/source/algorithms/MuonProcess-v1.rst @@ -75,9 +75,9 @@ Usage .. testcode:: ExPairAsymmetry # Begin by loading data into a workspace to process - load_result = LoadMuonNexus(Filename = "MUSR0015189.nxs", - DetectorGroupingTable = "grouping", - OutputWorkspace = "loadedWS") + load_result = Load(Filename="MUSR0015189.nxs", + DetectorGroupingTable="grouping", + OutputWorkspace = "loadedWS") loaded_time_zero = load_result[2] # time zero loaded from file grouping = mtd['grouping'] # detector grouping loaded from file grouping = grouping.getItem(0) # grouping here is a WorkspaceGroup - use table for first period From 821b7968e60bea765a5407c9ccf1229b87c47ab9 Mon Sep 17 00:00:00 2001 From: Applin Date: Mon, 18 Nov 2024 18:22:13 +0000 Subject: [PATCH 2/6] Remove confidence check from LoadMuonNexus2 algorithm --- .../inc/MantidDataHandling/LoadMuonNexus2.h | 2 - Framework/DataHandling/src/LoadMuonNexus2.cpp | 51 ------------------- 2 files changed, 53 deletions(-) diff --git a/Framework/DataHandling/inc/MantidDataHandling/LoadMuonNexus2.h b/Framework/DataHandling/inc/MantidDataHandling/LoadMuonNexus2.h index 48edcddc4a24..081e67f421c8 100644 --- a/Framework/DataHandling/inc/MantidDataHandling/LoadMuonNexus2.h +++ b/Framework/DataHandling/inc/MantidDataHandling/LoadMuonNexus2.h @@ -70,8 +70,6 @@ class MANTID_DATAHANDLING_DLL LoadMuonNexus2 : public LoadMuonNexus { private: /// Overwrites Algorithm method void exec() override; - /// Execute this version of the algorithm - void doExec(); HistogramData::Histogram loadData(const Mantid::HistogramData::BinEdges &edges, const Mantid::NeXus::NXInt &counts, int period, int spec); diff --git a/Framework/DataHandling/src/LoadMuonNexus2.cpp b/Framework/DataHandling/src/LoadMuonNexus2.cpp index 08b907f265a3..b3f5afd59011 100644 --- a/Framework/DataHandling/src/LoadMuonNexus2.cpp +++ b/Framework/DataHandling/src/LoadMuonNexus2.cpp @@ -53,13 +53,6 @@ using Mantid::HistogramData::Histogram; using namespace Mantid::NeXus; using Mantid::Types::Core::DateAndTime; -namespace { -inline std::string getLoadAlgName(int confidence1, int confidenceV2) { - return confidence1 > confidenceV2 ? "LoadMuonNexus" : "LoadMuonNexusV2"; -} -} // namespace - -/// Empty default constructor LoadMuonNexus2::LoadMuonNexus2() : LoadMuonNexus() {} /** Executes the right version of the Muon nexus loader @@ -68,50 +61,6 @@ LoadMuonNexus2::LoadMuonNexus2() : LoadMuonNexus() {} *values */ void LoadMuonNexus2::exec() { - LoadMuonNexus1 load1; - LoadMuonNexusV2 loadV2; - load1.initialize(); - loadV2.initialize(); - - std::string filePath = getPropertyValue("Filename"); - Kernel::NexusDescriptor descriptor(filePath); - int confidence1 = load1.confidence(descriptor); - int confidence2 = this->confidence(descriptor); - int confidenceV2 = 0; - // If the file is hdf5 then we can possibly use LoadMuonNexusV2 - // To check this we'll have to create an HDF5 descriptor for the file. - if (Kernel::NexusDescriptor::isReadable(filePath, Kernel::NexusDescriptor::Version5)) { - Kernel::NexusHDF5Descriptor descriptorHDF5(filePath); - confidenceV2 = loadV2.confidence(descriptorHDF5); - }; - - // if none can load the file throw - if (confidence1 < 80 && confidence2 < 80 && confidenceV2 < 80) { - throw Kernel::Exception::FileError("Cannot open the file ", filePath); - } - // Now pick the correct alg - if (confidence2 > std::max(confidence1, confidenceV2)) { - // Use this loader - doExec(); - } else { - // Version 1 or V2 - auto childAlg = createChildAlgorithm(getLoadAlgName(confidence1, confidenceV2), 0, 1, true, 1); - auto loader = std::dynamic_pointer_cast(childAlg); - loader->copyPropertiesFrom(*this); - loader->executeAsChildAlg(); - this->copyPropertiesFrom(*loader); - API::Workspace_sptr outWS = loader->getProperty("OutputWorkspace"); - setProperty("OutputWorkspace", outWS); - } -} - -/** Read in a muon nexus file of the version 2. - * - * @throw Exception::FileError If the Nexus file cannot be found/opened - * @throw std::invalid_argument If the optional properties are set to invalid - *values - */ -void LoadMuonNexus2::doExec() { // Create the root Nexus class NXRoot root(getPropertyValue("Filename")); From ebdc3cbf4d1f2a44e900c829b8845f46d84dfe54 Mon Sep 17 00:00:00 2001 From: Applin Date: Tue, 29 Oct 2024 15:32:28 +0000 Subject: [PATCH 3/6] Update tests to use generic Load algorithm --- Framework/DataHandling/src/LoadNexus.cpp | 4 +- Framework/Muon/test/AlphaCalcTest.h | 37 +++++++++++-------- Framework/Muon/test/ApplyDeadTimeCorrTest.h | 32 ++++++++-------- Framework/Muon/test/AsymmetryCalcTest.h | 37 ++++++++----------- .../WorkflowAlgorithms/test/MuonProcessTest.h | 7 ++-- .../dead_time_corrections_model_test.py | 8 ++-- 6 files changed, 61 insertions(+), 64 deletions(-) diff --git a/Framework/DataHandling/src/LoadNexus.cpp b/Framework/DataHandling/src/LoadNexus.cpp index 448b8e85abb0..3c0dcfce6c3b 100644 --- a/Framework/DataHandling/src/LoadNexus.cpp +++ b/Framework/DataHandling/src/LoadNexus.cpp @@ -112,7 +112,9 @@ void LoadNexus::exec() { } void LoadNexus::runLoadMuonNexus() { - auto loadMuonNexus = createChildAlgorithm("LoadMuonNexus", 0., 1.); + // The Load algorithm will choose the correct LoadMuonNexus algorithm + auto loadMuonNexus = createChildAlgorithm("Load", 0., 1.); + // Pass through the same input filename loadMuonNexus->setPropertyValue("Filename", m_filename); // Set the workspace property diff --git a/Framework/Muon/test/AlphaCalcTest.h b/Framework/Muon/test/AlphaCalcTest.h index 80ef047dde98..80113c7dc97d 100644 --- a/Framework/Muon/test/AlphaCalcTest.h +++ b/Framework/Muon/test/AlphaCalcTest.h @@ -12,6 +12,7 @@ #include "MantidAPI/IAlgorithm.h" #include "MantidAPI/Workspace.h" #include "MantidDataHandling/GroupDetectors.h" +#include "MantidDataHandling/Load.h" #include "MantidDataHandling/LoadInstrument.h" #include "MantidDataHandling/LoadMuonNexus2.h" #include "MantidDataObjects/Workspace2D.h" @@ -33,15 +34,9 @@ class AlphaCalcTest : public CxxTest::TestSuite { } void testCalAlphaManySpectra() { - // system("pause"); - // Load the muon nexus file - loader.initialize(); - loader.setPropertyValue("Filename", "emu00006473.nxs"); - loader.setPropertyValue("OutputWorkspace", "EMU6473"); - TS_ASSERT_THROWS_NOTHING(loader.execute()); - TS_ASSERT_EQUALS(loader.isExecuted(), true); + auto const workspace = loadFile("emu00006473.nxs"); - alphaCalc.setPropertyValue("InputWorkspace", "EMU6473"); + alphaCalc.setProperty("InputWorkspace", workspace); alphaCalc.setPropertyValue("ForwardSpectra", "1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16"); alphaCalc.setPropertyValue("BackwardSpectra", "17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32"); alphaCalc.setPropertyValue("FirstGoodValue", "0.3"); @@ -56,14 +51,9 @@ class AlphaCalcTest : public CxxTest::TestSuite { } void testCalAlphaTwoSpectra() { - // Load the muon nexus file - loader.initialize(); - loader.setPropertyValue("Filename", "emu00006473.nxs"); - loader.setPropertyValue("OutputWorkspace", "EMU6473"); - TS_ASSERT_THROWS_NOTHING(loader.execute()); - TS_ASSERT_EQUALS(loader.isExecuted(), true); + auto const workspace = loadFile("emu00006473.nxs"); - alphaCalc.setPropertyValue("InputWorkspace", "EMU6473"); + alphaCalc.setProperty("InputWorkspace", workspace); alphaCalc.setPropertyValue("ForwardSpectra", "1"); alphaCalc.setPropertyValue("BackwardSpectra", "17"); alphaCalc.setPropertyValue("FirstGoodValue", "0.3"); @@ -92,6 +82,21 @@ class AlphaCalcTest : public CxxTest::TestSuite { void test_incorrect_spectra_numbers() {} private: + MatrixWorkspace_sptr loadFile(std::string const &filename) { + Mantid::DataHandling::Load loader; + loader.initialize(); + loader.setChild(true); + loader.setPropertyValue("Filename", filename); + + TS_ASSERT_THROWS_NOTHING(loader.execute()); + TS_ASSERT_EQUALS(loader.isExecuted(), true); + + TS_ASSERT_EQUALS("LoadMuonNexus", loader.getPropertyValue("LoaderName")); + TS_ASSERT_EQUALS("1", loader.getPropertyValue("LoaderVersion")); + + Workspace_sptr outWS = loader.getProperty("OutputWorkspace"); + return std::dynamic_pointer_cast(outWS); + } + AlphaCalc alphaCalc; - Mantid::DataHandling::LoadMuonNexus2 loader; }; diff --git a/Framework/Muon/test/ApplyDeadTimeCorrTest.h b/Framework/Muon/test/ApplyDeadTimeCorrTest.h index 02bcf0b9e3f2..69018f2ce54c 100644 --- a/Framework/Muon/test/ApplyDeadTimeCorrTest.h +++ b/Framework/Muon/test/ApplyDeadTimeCorrTest.h @@ -12,7 +12,7 @@ #include "MantidAPI/IAlgorithm.h" #include "MantidAPI/TableRow.h" #include "MantidAPI/Workspace.h" -#include "MantidDataHandling/LoadMuonNexus2.h" +#include "MantidDataHandling/Load.h" #include "MantidDataObjects/TableWorkspace.h" #include "MantidDataObjects/Workspace2D.h" #include "MantidFrameworkTestHelpers/WorkspaceCreationHelper.h" @@ -42,7 +42,7 @@ class ApplyDeadTimeCorrTest : public CxxTest::TestSuite { } void testExec() { - MatrixWorkspace_sptr inputWs = loadDataFromFile(); + auto const inputWs = loadFile("emu00006473.nxs"); auto deadTimes = makeDeadTimeTable(32); ApplyDeadTimeCorr applyDeadTime; @@ -80,7 +80,7 @@ class ApplyDeadTimeCorrTest : public CxxTest::TestSuite { } void testDifferentSize() { - MatrixWorkspace_sptr inputWs = loadDataFromFile(); + auto const inputWs = loadFile("emu00006473.nxs"); // Bigger row count than file (expect to fail) auto deadTimes = makeDeadTimeTable(64); @@ -99,7 +99,7 @@ class ApplyDeadTimeCorrTest : public CxxTest::TestSuite { } void testSelectedSpectrum() { - MatrixWorkspace_sptr inputWs = loadDataFromFile(); + auto const inputWs = loadFile("emu00006473.nxs"); std::shared_ptr deadTimes = std::make_shared(); deadTimes->addColumn("int", "Spectrum Number"); @@ -173,7 +173,7 @@ class ApplyDeadTimeCorrTest : public CxxTest::TestSuite { // Test that algorithm throws if input workspace does not contain number of // good frames void testNoGoodfrmPresent() { - MatrixWorkspace_sptr inputWs = loadDataFromFile(); + auto const inputWs = loadFile("emu00006473.nxs"); auto deadTimes = makeDeadTimeTable(32); auto &run = inputWs->mutableRun(); @@ -207,22 +207,20 @@ class ApplyDeadTimeCorrTest : public CxxTest::TestSuite { return deadTimes; } - /** - * Loads data from the test data file - * @returns :: Workspace with loaded data - */ - MatrixWorkspace_sptr loadDataFromFile() { - Mantid::DataHandling::LoadMuonNexus2 loader; + MatrixWorkspace_sptr loadFile(std::string const &filename) { + Mantid::DataHandling::Load loader; loader.initialize(); loader.setChild(true); - loader.setPropertyValue("Filename", "emu00006473.nxs"); - loader.setPropertyValue("OutputWorkspace", "__NotUsed"); + loader.setPropertyValue("Filename", filename); + TS_ASSERT_THROWS_NOTHING(loader.execute()); TS_ASSERT_EQUALS(loader.isExecuted(), true); - Workspace_sptr data = loader.getProperty("OutputWorkspace"); - auto matrixWS = std::dynamic_pointer_cast(data); - TS_ASSERT(data); - return matrixWS; + + TS_ASSERT_EQUALS("LoadMuonNexus", loader.getPropertyValue("LoaderName")); + TS_ASSERT_EQUALS("1", loader.getPropertyValue("LoaderVersion")); + + Workspace_sptr outWS = loader.getProperty("OutputWorkspace"); + return std::dynamic_pointer_cast(outWS); } /// Test dead time value diff --git a/Framework/Muon/test/AsymmetryCalcTest.h b/Framework/Muon/test/AsymmetryCalcTest.h index bc39a805d56b..f8f12499e7f6 100644 --- a/Framework/Muon/test/AsymmetryCalcTest.h +++ b/Framework/Muon/test/AsymmetryCalcTest.h @@ -14,6 +14,7 @@ #include "MantidAPI/Workspace.h" #include "MantidAPI/WorkspaceGroup.h" #include "MantidDataHandling/GroupDetectors.h" +#include "MantidDataHandling/Load.h" #include "MantidDataHandling/LoadInstrument.h" #include "MantidDataHandling/LoadMuonNexus2.h" #include "MantidDataObjects/Workspace2D.h" @@ -58,15 +59,12 @@ class AsymmetryCalcTest : public CxxTest::TestSuite { } void testExecuteOnDataFile() { - MatrixWorkspace_sptr data; - TS_ASSERT_THROWS_NOTHING(data = loadDataFile()); - TS_ASSERT(data); + auto const workspace = loadFile("emu00006473.nxs"); AsymmetryCalc asymCalc; try { asymCalc.initialize(); asymCalc.setChild(true); - asymCalc.setProperty("InputWorkspace", data); - asymCalc.setPropertyValue("OutputWorkspace", "__Unused"); + asymCalc.setProperty("InputWorkspace", workspace); asymCalc.setPropertyValue("Alpha", "1.0"); asymCalc.setPropertyValue("ForwardSpectra", "1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16"); asymCalc.setPropertyValue("BackwardSpectra", "17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32"); @@ -166,24 +164,19 @@ class AsymmetryCalcTest : public CxxTest::TestSuite { } private: - /// Load data from file - MatrixWorkspace_sptr loadDataFile() { - Mantid::DataHandling::LoadMuonNexus2 loader; + MatrixWorkspace_sptr loadFile(std::string const &filename) { + Mantid::DataHandling::Load loader; loader.initialize(); loader.setChild(true); - loader.setPropertyValue("Filename", "emu00006473.nxs"); - loader.setPropertyValue("OutputWorkspace", "__Unused"); - loader.execute(); - if (loader.isExecuted()) { - Workspace_sptr outWS = loader.getProperty("OutputWorkspace"); - auto matrixWS = std::dynamic_pointer_cast(outWS); - if (matrixWS) { - return matrixWS; - } else { - throw std::runtime_error("Failed to cast loaded workspace"); - } - } else { - throw std::runtime_error("Failed to load test data file"); - } + loader.setPropertyValue("Filename", filename); + + TS_ASSERT_THROWS_NOTHING(loader.execute()); + TS_ASSERT_EQUALS(loader.isExecuted(), true); + + TS_ASSERT_EQUALS("LoadMuonNexus", loader.getPropertyValue("LoaderName")); + TS_ASSERT_EQUALS("1", loader.getPropertyValue("LoaderVersion")); + + Workspace_sptr outWS = loader.getProperty("OutputWorkspace"); + return std::dynamic_pointer_cast(outWS); } }; diff --git a/Framework/WorkflowAlgorithms/test/MuonProcessTest.h b/Framework/WorkflowAlgorithms/test/MuonProcessTest.h index 072a562a8770..c305d70f6ddb 100644 --- a/Framework/WorkflowAlgorithms/test/MuonProcessTest.h +++ b/Framework/WorkflowAlgorithms/test/MuonProcessTest.h @@ -8,14 +8,14 @@ #include +#include "MantidAPI/MatrixWorkspace.h" #include "MantidAPI/ScopedWorkspace.h" #include "MantidAPI/TableRow.h" -#include "MantidDataHandling/LoadMuonNexus2.h" +#include "MantidDataHandling/Load.h" #include "MantidDataObjects/TableWorkspace.h" #include "MantidWorkflowAlgorithms/MuonProcess.h" -using Mantid::DataHandling::LoadMuonNexus2; using Mantid::WorkflowAlgorithms::MuonProcess; using namespace Mantid::Kernel; @@ -555,11 +555,10 @@ class MuonProcessTest : public CxxTest::TestSuite { */ std::unique_ptr loadData(const std::string &filename) { auto data = std::make_unique(); - LoadMuonNexus2 load; + Mantid::DataHandling::Load load; load.initialize(); load.setChild(true); load.setPropertyValue("Filename", filename); - load.setPropertyValue("OutputWorkspace", "__notused"); load.setPropertyValue("DetectorGroupingTable", "__notused"); load.execute(); data->workspace = load.getProperty("OutputWorkspace"); diff --git a/qt/python/mantidqtinterfaces/test/Muon/corrections_tab_widget/dead_time_corrections_model_test.py b/qt/python/mantidqtinterfaces/test/Muon/corrections_tab_widget/dead_time_corrections_model_test.py index 9c191445f0fb..52a99cde839d 100644 --- a/qt/python/mantidqtinterfaces/test/Muon/corrections_tab_widget/dead_time_corrections_model_test.py +++ b/qt/python/mantidqtinterfaces/test/Muon/corrections_tab_widget/dead_time_corrections_model_test.py @@ -8,7 +8,7 @@ from unittest import mock from mantid.api import AnalysisDataService, FrameworkManager -from mantid.simpleapi import LoadMuonNexus +from mantid.simpleapi import Load from mantidqtinterfaces.Muon.GUI.Common.corrections_tab_widget.corrections_model import CorrectionsModel from mantidqtinterfaces.Muon.GUI.Common.corrections_tab_widget.dead_time_corrections_model import DeadTimeCorrectionsModel @@ -73,7 +73,7 @@ def test_that_set_dead_time_source_to_none_will_set_the_expected_data_in_the_con def test_that_dead_times_average_will_return_the_expected_dead_time_average_and_range(self): dead_time_table_name = "dead_time_table" - LoadMuonNexus(Filename="MUSR00022725.nxs", OutputWorkspace="output_ws", DeadTimeTable=dead_time_table_name) + Load(Filename="MUSR00022725.nxs", OutputWorkspace="output_ws", DeadTimeTable=dead_time_table_name) self.model.set_dead_time_source_to_from_ads(dead_time_table_name) @@ -87,7 +87,7 @@ def test_that_validate_selected_dead_time_workspace_will_return_an_empty_string_ self.model._data_context.current_workspace.getNumberHistograms = mock.Mock(return_value=64) dead_time_table_name = "dead_time_table" - LoadMuonNexus(Filename="MUSR00022725.nxs", OutputWorkspace="output_ws", DeadTimeTable=dead_time_table_name) + Load(Filename="MUSR00022725.nxs", OutputWorkspace="output_ws", DeadTimeTable=dead_time_table_name) self.assertEqual(self.model.validate_selected_dead_time_workspace(dead_time_table_name), "") @@ -95,7 +95,7 @@ def test_that_validate_selected_dead_time_workspace_returns_an_error_message_whe self.model._data_context.current_workspace.getNumberHistograms = mock.Mock(return_value=62) dead_time_table_name = "dead_time_table" - LoadMuonNexus(Filename="MUSR00022725.nxs", OutputWorkspace="output_ws", DeadTimeTable=dead_time_table_name) + Load(Filename="MUSR00022725.nxs", OutputWorkspace="output_ws", DeadTimeTable=dead_time_table_name) self.assertEqual( self.model.validate_selected_dead_time_workspace(dead_time_table_name), From e3a0c970483c97370ffa8e89358568d221421b0f Mon Sep 17 00:00:00 2001 From: Applin Date: Tue, 29 Oct 2024 09:48:56 +0000 Subject: [PATCH 4/6] Fix cppcheck warnings in LoadMuonNexus HDF4 algorithms --- .../inc/MantidDataHandling/LoadMuonNexus1.h | 23 ++++--------------- .../inc/MantidDataHandling/LoadMuonNexus2.h | 9 +------- Framework/DataHandling/src/LoadMuonNexus1.cpp | 15 ++++++------ .../CMake/CppCheck_Suppressions.txt.in | 12 ---------- 4 files changed, 14 insertions(+), 45 deletions(-) diff --git a/Framework/DataHandling/inc/MantidDataHandling/LoadMuonNexus1.h b/Framework/DataHandling/inc/MantidDataHandling/LoadMuonNexus1.h index 6853e4e79c4f..53a323884327 100644 --- a/Framework/DataHandling/inc/MantidDataHandling/LoadMuonNexus1.h +++ b/Framework/DataHandling/inc/MantidDataHandling/LoadMuonNexus1.h @@ -54,22 +54,7 @@ together based on the groupings in the NeXus file. */ class MANTID_DATAHANDLING_DLL LoadMuonNexus1 : public LoadMuonNexus { public: - /// Default constructor LoadMuonNexus1(); - /// Algorithm's name for identification overriding a virtual method - const std::string name() const override { return "LoadMuonNexus"; } - /// Summary of algorithms purpose - const std::string summary() const override { - return "The LoadMuonNexus algorithm will read the given NeXus Muon data " - "file Version 1 and use the results to populate the named " - "workspace. LoadMuonNexus may be invoked by LoadNexus if it is " - "given a NeXus file of this type."; - } - - /// Algorithm's version for identification overriding a virtual method - int version() const override { return 1; } - /// Algorithm's category for identification overriding a virtual method - const std::string category() const override { return "DataHandling\\Nexus;Muon\\DataHandling"; } /// Returns a confidence value that this algorithm can load a file int confidence(Kernel::NexusDescriptor &descriptor) const override; @@ -79,7 +64,7 @@ class MANTID_DATAHANDLING_DLL LoadMuonNexus1 : public LoadMuonNexus { void exec() override; private: - void loadData(size_t hist, specnum_t &i, specnum_t specNo, MuonNexusReader &nxload, const int64_t lengthIn, + void loadData(size_t hist, specnum_t const &i, specnum_t specNo, MuonNexusReader &nxload, const int64_t lengthIn, const DataObjects::Workspace2D_sptr &localWorkspace); void runLoadMappingTable(DataObjects::Workspace2D_sptr); void runLoadLog(const DataObjects::Workspace2D_sptr &); @@ -91,14 +76,16 @@ class MANTID_DATAHANDLING_DLL LoadMuonNexus1 : public LoadMuonNexus { void loadDeadTimes(Mantid::NeXus::NXRoot &root); /// Creates Dead Time Table using all the data between begin and end - DataObjects::TableWorkspace_sptr createDeadTimeTable(std::vector specToLoad, std::vector deadTimes); + DataObjects::TableWorkspace_sptr createDeadTimeTable(std::vector const &specToLoad, + std::vector const &deadTimes); /// Loads detector grouping information API::Workspace_sptr loadDetectorGrouping(Mantid::NeXus::NXRoot &root, const Mantid::Geometry::Instrument_const_sptr &inst); /// Creates Detector Grouping Table using all the data from the range - DataObjects::TableWorkspace_sptr createDetectorGroupingTable(std::vector specToLoad, std::vector grouping); + DataObjects::TableWorkspace_sptr createDetectorGroupingTable(std::vector const &specToLoad, + std::vector const &grouping); }; } // namespace DataHandling diff --git a/Framework/DataHandling/inc/MantidDataHandling/LoadMuonNexus2.h b/Framework/DataHandling/inc/MantidDataHandling/LoadMuonNexus2.h index 081e67f421c8..0d40616718fd 100644 --- a/Framework/DataHandling/inc/MantidDataHandling/LoadMuonNexus2.h +++ b/Framework/DataHandling/inc/MantidDataHandling/LoadMuonNexus2.h @@ -46,11 +46,8 @@ together based on the groupings in the NeXus file. */ class MANTID_DATAHANDLING_DLL LoadMuonNexus2 : public LoadMuonNexus { public: - /// Default constructor LoadMuonNexus2(); - /// Algorithm's name for identification overriding a virtual method - const std::string name() const override { return "LoadMuonNexus"; } - /// Summary of algorithms purpose + const std::string summary() const override { return "The LoadMuonNexus algorithm will read the given NeXus Muon data " "file Version 2 and use the results to populate the named " @@ -58,17 +55,13 @@ class MANTID_DATAHANDLING_DLL LoadMuonNexus2 : public LoadMuonNexus { "given a NeXus file of this type."; } - /// Algorithm's version for identification overriding a virtual method int version() const override { return 2; } const std::vector seeAlso() const override { return {"LoadNexus"}; } - /// Algorithm's category for identification overriding a virtual method - const std::string category() const override { return "DataHandling\\Nexus;Muon\\DataHandling"; } /// Returns a confidence value that this algorithm can load a file int confidence(Kernel::NexusDescriptor &descriptor) const override; private: - /// Overwrites Algorithm method void exec() override; HistogramData::Histogram loadData(const Mantid::HistogramData::BinEdges &edges, const Mantid::NeXus::NXInt &counts, diff --git a/Framework/DataHandling/src/LoadMuonNexus1.cpp b/Framework/DataHandling/src/LoadMuonNexus1.cpp index 95310b0e4603..3c5494204395 100644 --- a/Framework/DataHandling/src/LoadMuonNexus1.cpp +++ b/Framework/DataHandling/src/LoadMuonNexus1.cpp @@ -516,7 +516,7 @@ Workspace_sptr LoadMuonNexus1::loadDetectorGrouping(NXRoot &root, const Geometry [&groupingData](const auto spec) { return groupingData[spec - 1]; }); } else { // User selected an entry number - for (auto &spec : specToLoad) { + for (auto const &spec : specToLoad) { int index = spec - 1 + static_cast((m_entrynumber - 1) * m_numberOfSpectra); grouping.emplace_back(groupingData[index]); } @@ -548,7 +548,7 @@ Workspace_sptr LoadMuonNexus1::loadDetectorGrouping(NXRoot &root, const Geometry // Get the grouping grouping.clear(); - for (auto &spec : specToLoad) { + for (auto const &spec : specToLoad) { int index = spec - 1 + i * static_cast(m_numberOfSpectra); grouping.emplace_back(groupingData[index]); } @@ -601,7 +601,8 @@ Workspace_sptr LoadMuonNexus1::loadDetectorGrouping(NXRoot &root, const Geometry * @param deadTimes :: vector containing the corresponding dead times * @return Dead Time Table create using the data */ -TableWorkspace_sptr LoadMuonNexus1::createDeadTimeTable(std::vector specToLoad, std::vector deadTimes) { +TableWorkspace_sptr LoadMuonNexus1::createDeadTimeTable(std::vector const &specToLoad, + std::vector const &deadTimes) { TableWorkspace_sptr deadTimeTable = std::dynamic_pointer_cast(WorkspaceFactory::Instance().createTable("TableWorkspace")); @@ -623,8 +624,8 @@ TableWorkspace_sptr LoadMuonNexus1::createDeadTimeTable(std::vector specToL * @param grouping :: Vector containing corresponding grouping * @return Detector Grouping Table create using the data */ -TableWorkspace_sptr LoadMuonNexus1::createDetectorGroupingTable(std::vector specToLoad, - std::vector grouping) { +TableWorkspace_sptr LoadMuonNexus1::createDetectorGroupingTable(std::vector const &specToLoad, + std::vector const &grouping) { auto detectorGroupingTable = std::dynamic_pointer_cast(WorkspaceFactory::Instance().createTable("TableWorkspace")); @@ -638,7 +639,7 @@ TableWorkspace_sptr LoadMuonNexus1::createDetectorGroupingTable(std::vector groupingMap[grouping[i]].emplace_back(specToLoad[i]); } - for (auto &group : groupingMap) { + for (auto const &group : groupingMap) { if (group.first != 0) // Skip 0 group { TableRow newRow = detectorGroupingTable->appendRow(); @@ -658,7 +659,7 @@ TableWorkspace_sptr LoadMuonNexus1::createDetectorGroupingTable(std::vector * @param localWorkspace :: A pointer to the workspace in which the data will * be stored */ -void LoadMuonNexus1::loadData(size_t hist, specnum_t &i, specnum_t specNo, MuonNexusReader &nxload, +void LoadMuonNexus1::loadData(size_t hist, specnum_t const &i, specnum_t specNo, MuonNexusReader &nxload, const int64_t lengthIn, const DataObjects::Workspace2D_sptr &localWorkspace) { // Read in a spectrum // Put it into a vector, discarding the 1st entry, which is rubbish diff --git a/buildconfig/CMake/CppCheck_Suppressions.txt.in b/buildconfig/CMake/CppCheck_Suppressions.txt.in index 6fd27652014d..833c3b0ef2dd 100644 --- a/buildconfig/CMake/CppCheck_Suppressions.txt.in +++ b/buildconfig/CMake/CppCheck_Suppressions.txt.in @@ -635,18 +635,6 @@ constVariableReference:${CMAKE_SOURCE_DIR}/Framework/DataHandling/src/LoadMuonSt stlIfStrFind:${CMAKE_SOURCE_DIR}/Framework/DataHandling/src/LoadRKH.cpp:521 knownConditionTrueFalse:${CMAKE_SOURCE_DIR}/Framework/DataHandling/src/LoadNexusMonitors2.cpp:452 uselessOverride:${CMAKE_SOURCE_DIR}/Framework/DataHandling/inc/MantidDataHandling/LoadNexusProcessed2.h:38 -uselessOverride:${CMAKE_SOURCE_DIR}/Framework/DataHandling/inc/MantidDataHandling/LoadMuonNexus1.h:60 -uselessOverride:${CMAKE_SOURCE_DIR}/Framework/DataHandling/inc/MantidDataHandling/LoadMuonNexus1.h:62 -uselessOverride:${CMAKE_SOURCE_DIR}/Framework/DataHandling/inc/MantidDataHandling/LoadMuonNexus1.h:70 -uselessOverride:${CMAKE_SOURCE_DIR}/Framework/DataHandling/inc/MantidDataHandling/LoadMuonNexus1.h:72 -uselessOverride:${CMAKE_SOURCE_DIR}/Framework/DataHandling/inc/MantidDataHandling/LoadMuonNexus2.h:52 -uselessOverride:${CMAKE_SOURCE_DIR}/Framework/DataHandling/inc/MantidDataHandling/LoadMuonNexus2.h:65 -passedByValue:${CMAKE_SOURCE_DIR}/Framework/DataHandling/src/LoadMuonNexus1.cpp:604 -passedByValue:${CMAKE_SOURCE_DIR}/Framework/DataHandling/src/LoadMuonNexus1.cpp:627 -constVariableReference:${CMAKE_SOURCE_DIR}/Framework/DataHandling/src/LoadMuonNexus1.cpp:519 -constVariableReference:${CMAKE_SOURCE_DIR}/Framework/DataHandling/src/LoadMuonNexus1.cpp:551 -constVariableReference:${CMAKE_SOURCE_DIR}/Framework/DataHandling/src/LoadMuonNexus1.cpp:641 -constParameterReference:${CMAKE_SOURCE_DIR}/Framework/DataHandling/src/LoadMuonNexus1.cpp:661 constParameterReference:${CMAKE_SOURCE_DIR}/Framework/DataHandling/src/LoadTBL.cpp:133 constVariableReference:${CMAKE_SOURCE_DIR}/Framework/DataHandling/src/LoadPreNexus.cpp:244 returnByReference:${CMAKE_SOURCE_DIR}/Framework/DataHandling/inc/MantidDataHandling/LoadSpiceXML2DDet.h:30 From 38878229bd9de410d31ba0b88d8aed34dc1b9bab Mon Sep 17 00:00:00 2001 From: Applin Date: Tue, 19 Nov 2024 10:12:05 +0000 Subject: [PATCH 5/6] Use Load algorithm to choose correct LoadMuonNexus algorithm in doc tests --- docs/source/algorithms/ApplyDeadTimeCorr-v1.rst | 4 ++-- docs/source/algorithms/LoadMuonNexus-v2.rst | 12 ++++++------ docs/source/algorithms/MuonGroupDetectors-v1.rst | 6 +++--- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/docs/source/algorithms/ApplyDeadTimeCorr-v1.rst b/docs/source/algorithms/ApplyDeadTimeCorr-v1.rst index 8825e255de92..7c54d6d72340 100644 --- a/docs/source/algorithms/ApplyDeadTimeCorr-v1.rst +++ b/docs/source/algorithms/ApplyDeadTimeCorr-v1.rst @@ -45,7 +45,7 @@ Usage .. testcode:: ExCustomDeadTimes # Load single period of a MUSR run - input = LoadMuonNexus('MUSR0015189.nxs', EntryNumber=1) + input = Load('MUSR0015189.nxs', EntryNumber=1) # Remove uninteresting bins input = CropWorkspace('input', XMin=0.55, XMax=12) @@ -81,7 +81,7 @@ Output: .. testcode:: ExLoadedDeadTimes # Load a MUSR run - input = LoadMuonNexus('MUSR0015189.nxs', DeadTimeTable='dead_times') + input = Load('MUSR0015189.nxs', DeadTimeTable='dead_times') # Remove uninteresting bins input = CropWorkspace('input', XMin=0.55, XMax=12) diff --git a/docs/source/algorithms/LoadMuonNexus-v2.rst b/docs/source/algorithms/LoadMuonNexus-v2.rst index 7363d4c8ee90..775f4e7bc49d 100644 --- a/docs/source/algorithms/LoadMuonNexus-v2.rst +++ b/docs/source/algorithms/LoadMuonNexus-v2.rst @@ -153,9 +153,9 @@ Version 1 ######### Version 1 supports the loading version 1.0 of the muon nexus format. -This is still in active use, if the current version of LoadMuonNexus -detects that it has been asked to load a previous version muon nexus -file it will call the previous version of the algorithm to perform the +This is still in active use, if the Load algorithm detects that it +has been asked to load a previous version muon nexus file it will +call the previous version of the LoadMuonNexus algorithm to perform the task. See :ref:`algm-LoadMuonNexus-v1` for more details about version 1. @@ -172,7 +172,7 @@ Usage .. testcode:: LoadMuonNexusOnePeriod # Load MUSR dataset - ws = LoadMuonNexus(Filename="MUSR00015189.nxs",EntryNumber=1) + ws = Load(Filename="MUSR00015189.nxs",EntryNumber=1) print("Workspace has {} spectra".format(ws[0].getNumberHistograms())) Output: @@ -186,7 +186,7 @@ Output: .. testcode:: ExLoadMuonNexusSomeSpectra # Load some spectra - ws = LoadMuonNexus(Filename="MUSR00015189.nxs",SpectrumMin=5,SpectrumMax=10,EntryNumber=1) + ws = Load(Filename="MUSR00015189.nxs",SpectrumMin=5,SpectrumMax=10,EntryNumber=1) print("Workspace has {} spectra".format(ws[0].getNumberHistograms())) Output: @@ -200,7 +200,7 @@ Output: .. testcode:: ExLoadDeadTimeTable # Load some spectra - ws = LoadMuonNexus(Filename="emu00006473.nxs",SpectrumMin=5,SpectrumMax=10,DeadTimeTable="deadTimeTable") + ws = Load(Filename="emu00006473.nxs",SpectrumMin=5,SpectrumMax=10,DeadTimeTable="deadTimeTable") tab = mtd['deadTimeTable'] for i in range(0,tab.rowCount()): print("{} {:.12f}".format(tab.cell(i,0), tab.cell(i,1))) diff --git a/docs/source/algorithms/MuonGroupDetectors-v1.rst b/docs/source/algorithms/MuonGroupDetectors-v1.rst index 9a9549927230..ffe78fa01d22 100644 --- a/docs/source/algorithms/MuonGroupDetectors-v1.rst +++ b/docs/source/algorithms/MuonGroupDetectors-v1.rst @@ -32,7 +32,7 @@ Usage .. testcode:: ExGroupMUSR # Load first period of a MUSR data file - ws = LoadMuonNexus('MUSR00015189.nxs', EntryNumber=1) + ws = Load('MUSR00015189.nxs', EntryNumber=1) # Create a table with some custom grouping grouping = CreateEmptyTableWorkspace() @@ -65,10 +65,10 @@ Output: .. testcode:: ExGroupingFromNexus # Load MUSR grouping from the Nexus file - __unused_ws = LoadMuonNexus('MUSR00015189.nxs', DetectorGroupingTable='grouping') + __unused_ws = Load('MUSR00015189.nxs', DetectorGroupingTable='grouping') # Load data from a different MUSR file - ws = LoadMuonNexus('MUSR00015190.nxs') + ws = Load('MUSR00015190.nxs') # Use grouping from one file to group data from different file grouped = MuonGroupDetectors('ws', 'grouping') From d012adf66ab863d21ae07744628926130f01df65 Mon Sep 17 00:00:00 2001 From: Applin Date: Tue, 19 Nov 2024 11:37:39 +0000 Subject: [PATCH 6/6] Add release note and fix doc typo --- docs/source/concepts/NexusFile.rst | 2 +- docs/source/release/v6.12.0/Muon/Algorithms/Bugfixes/38407.rst | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) create mode 100644 docs/source/release/v6.12.0/Muon/Algorithms/Bugfixes/38407.rst diff --git a/docs/source/concepts/NexusFile.rst b/docs/source/concepts/NexusFile.rst index b4258db6c22a..fd951a06b39a 100644 --- a/docs/source/concepts/NexusFile.rst +++ b/docs/source/concepts/NexusFile.rst @@ -27,7 +27,7 @@ Hence there are two principal types of NEXUS files loaded by Mantid ISIS uses two versions of Nexus files for muon histogram data: - Muon Nexus file v1, which is loaded by :ref:`LoadMuonNexus v1` and - - Muon Nexus file v2, which is loaded by :ref:`LoadEventNexus v2`. + - Muon Nexus file v2, which is loaded by :ref:`LoadMuonNexus v2`. As well as Nexus files loaded by Mantid, there is a kind of Nexus file, diff --git a/docs/source/release/v6.12.0/Muon/Algorithms/Bugfixes/38407.rst b/docs/source/release/v6.12.0/Muon/Algorithms/Bugfixes/38407.rst new file mode 100644 index 000000000000..889b1605c38f --- /dev/null +++ b/docs/source/release/v6.12.0/Muon/Algorithms/Bugfixes/38407.rst @@ -0,0 +1 @@ +- The :ref:`LoadMuonNexus v2` algorithm no longer chooses a different Muon loader if appropriate. Users should call the :ref:`Load ` algorithm directly if they want the appropriate loader to be chosen for them.