From cc92f48699375297f1909d1f293c259f1b816c67 Mon Sep 17 00:00:00 2001 From: James Clarke Date: Fri, 3 May 2024 16:00:59 +0100 Subject: [PATCH] Remove validator on input workspace This validator does not work when the type is specified explicitly as being a WorkspaceGroup, so instead we'll have to to check for wavelength in validateInputs(). --- .../PolarizerEfficiency.cpp | 28 +++++++++---------- .../PolarizerEfficiencyTest.h | 6 ++-- 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/Framework/Algorithms/src/PolarizationCorrections/PolarizerEfficiency.cpp b/Framework/Algorithms/src/PolarizationCorrections/PolarizerEfficiency.cpp index c4b1ff85db56..7c6e8a596b1d 100644 --- a/Framework/Algorithms/src/PolarizationCorrections/PolarizerEfficiency.cpp +++ b/Framework/Algorithms/src/PolarizationCorrections/PolarizerEfficiency.cpp @@ -7,6 +7,7 @@ #include "MantidAlgorithms/PolarizationCorrections/PolarizerEfficiency.h" #include "MantidAPI/AnalysisDataService.h" +#include "MantidAPI/Axis.h" #include "MantidAPI/FileProperty.h" #include "MantidAPI/HistogramValidator.h" #include "MantidAPI/ITableWorkspace.h" @@ -17,6 +18,7 @@ #include "MantidKernel/BoundedValidator.h" #include "MantidKernel/CompositeValidator.h" #include "MantidKernel/ListValidator.h" +#include "MantidKernel/Unit.h" #include #include @@ -37,12 +39,8 @@ static const std::string OUTPUT_FILE_PATH = "OutputFilePath"; } // namespace PropertyNames void PolarizerEfficiency::init() { - // Declare required input parameters for algorithm and do some validation here - auto validator = std::make_shared(); - validator->add("Wavelength"); - validator->add(); declareProperty( - std::make_unique>(PropertyNames::INPUT_WORKSPACE, "", Direction::Input, validator), + std::make_unique>(PropertyNames::INPUT_WORKSPACE, "", Direction::Input), "Input group workspace to use for polarization calculation"); const auto &wavelengthValidator = std::make_shared("Wavelength"); declareProperty(std::make_unique>(PropertyNames::ANALYSER_EFFICIENCY, "", @@ -69,18 +67,20 @@ std::map PolarizerEfficiency::validateInputs() { std::map errorList; const WorkspaceGroup_sptr inputWorkspace = getProperty(PropertyNames::INPUT_WORKSPACE); if (inputWorkspace == nullptr) { - errorList[PropertyNames::INPUT_WORKSPACE] = "The input workspace is not a workspace group." + errorList[PropertyNames::INPUT_WORKSPACE] = "The input workspace is not a workspace group."; return errorList; } - const auto &ws = AnalysisDataService::Instance().retrieve(inputWorkspaceName); - if (!ws->isGroup()) { - errorList[PropertyNames::INPUT_WORKSPACE] = "The input workspace is not a group workspace."; - } else { - const auto &wsGroup = std::dynamic_pointer_cast(ws); - if (wsGroup->size() != 4) { - errorList[PropertyNames::INPUT_WORKSPACE] = - "The input group workspace must have four periods corresponding to the four spin configurations."; + if (inputWorkspace->size() != 4) { + errorList[PropertyNames::INPUT_WORKSPACE] = + "The input group workspace must have four periods corresponding to the four spin configurations."; + } + + for (size_t i = 0; i < inputWorkspace->size(); ++i) { + const MatrixWorkspace_sptr stateWs = std::dynamic_pointer_cast(inputWorkspace->getItem(i)); + Unit_const_sptr unit = stateWs->getAxis(0)->unit(); + if (unit->unitID() != "Wavelength") { + errorList[PropertyNames::INPUT_WORKSPACE] = "All input workspaces must be in units of Wavelength."; } } diff --git a/Framework/Algorithms/test/PolarizationCorrections/PolarizerEfficiencyTest.h b/Framework/Algorithms/test/PolarizationCorrections/PolarizerEfficiencyTest.h index ba7331a1e225..a8a8ee954f2f 100644 --- a/Framework/Algorithms/test/PolarizationCorrections/PolarizerEfficiencyTest.h +++ b/Framework/Algorithms/test/PolarizationCorrections/PolarizerEfficiencyTest.h @@ -52,8 +52,7 @@ class PolarizerEfficiencyTest : public CxxTest::TestSuite { auto polariserEfficiency = AlgorithmManager::Instance().create("PolarizerEfficiency"); polariserEfficiency->initialize(); - polariserEfficiency->setProperty("InputWorkspace", ws1->getName()); - TS_ASSERT_THROWS(polariserEfficiency->execute(), const std::runtime_error &); + TS_ASSERT_THROWS(polariserEfficiency->setProperty("InputWorkspace", ws1), const std::invalid_argument &); } void testGroupWorkspaceWithWrongSize() { @@ -89,7 +88,8 @@ class PolarizerEfficiencyTest : public CxxTest::TestSuite { auto wsGrp = createExampleGroupWorkspace("wsGrp", "TOF"); auto polariserEfficiency = AlgorithmManager::Instance().create("PolarizerEfficiency"); polariserEfficiency->initialize(); - TS_ASSERT_THROWS(polariserEfficiency->setProperty("InputWorkspace", wsGrp->getName()), std::invalid_argument &); + polariserEfficiency->setProperty("InputWorkspace", wsGrp); + TS_ASSERT_THROWS(polariserEfficiency->execute(), const std::runtime_error &); } void testExampleCalculation() {