diff --git a/Framework/Algorithms/src/ConjoinXRuns.cpp b/Framework/Algorithms/src/ConjoinXRuns.cpp index b9fc326800d0c28120bc9f78085fd9a4785ba6d1..fa05dd89b3656bba8134a41d599e1111544ce7ea 100644 --- a/Framework/Algorithms/src/ConjoinXRuns.cpp +++ b/Framework/Algorithms/src/ConjoinXRuns.cpp @@ -113,13 +113,21 @@ std::map<std::string, std::string> ConjoinXRuns::validateInputs() { getProperty(INPUT_WORKSPACE_PROPERTY); m_logEntry = getPropertyValue(SAMPLE_LOG_X_AXIS_PROPERTY); - // find if there are workspaces that are not Matrix or not a point-data - for (const auto &input : RunCombinationHelper::unWrapGroups(inputs_given)) { + std::vector<std::string> workspaces; + try { // input workspace must be a group or a MatrixWorkspace + workspaces = RunCombinationHelper::unWrapGroups(inputs_given); + } catch (const std::exception &e) { + issues[INPUT_WORKSPACE_PROPERTY] = std::string(e.what()); + } + + // find if there are grouped workspaces that are not Matrix or not a + // point-data + for (const auto &input : workspaces) { MatrixWorkspace_sptr ws = AnalysisDataService::Instance().retrieveWS<MatrixWorkspace>(input); if (!ws) { issues[INPUT_WORKSPACE_PROPERTY] += - "Workspace " + ws->getName() + " is not a MatrixWorkspace\n"; + "Workspace " + input + " is not a MatrixWorkspace\n"; } else if (ws->isHistogramData()) { issues[INPUT_WORKSPACE_PROPERTY] += "Workspace " + ws->getName() + " is not a point-data\n"; @@ -182,7 +190,8 @@ std::string ConjoinXRuns::checkLogEntry(MatrixWorkspace_sptr ws) const { try { run.getLogAsSingleValue(m_logEntry); - // try if numeric time series, then the size must match to the blocksize + // try if numeric time series, then the size must match to the + // blocksize const int blocksize = static_cast<int>(ws->blocksize()); TimeSeriesProperty<double> *timeSeriesDouble(nullptr); diff --git a/Framework/Algorithms/src/RunCombinationHelpers/RunCombinationHelper.cpp b/Framework/Algorithms/src/RunCombinationHelpers/RunCombinationHelper.cpp index 4f8ae81b93dc3130e2744df0dec37505e93362a3..a3cbf2177f064d8da22db9d5cfa53ce168849bdf 100644 --- a/Framework/Algorithms/src/RunCombinationHelpers/RunCombinationHelper.cpp +++ b/Framework/Algorithms/src/RunCombinationHelpers/RunCombinationHelper.cpp @@ -21,6 +21,8 @@ using namespace Kernel; * @param inputs : input workspaces vector [including] group workspaces (all must * be on ADS) * @return : the flat vector of the input workspaces +* @throw : std::runtime_error if the input workspaces are neither groups nor +* MatrixWorkspaces */ std::vector<std::string> RunCombinationHelper::unWrapGroups(const std::vector<std::string> &inputs) { @@ -33,8 +35,15 @@ RunCombinationHelper::unWrapGroups(const std::vector<std::string> &inputs) { std::vector<std::string> group = wsgroup->getNames(); outputs.insert(outputs.end(), group.begin(), group.end()); } else { - // single workspace - outputs.push_back(input); + // MatrixWorkspace + MatrixWorkspace_sptr matrixws = + AnalysisDataService::Instance().retrieveWS<MatrixWorkspace>(input); + if (matrixws) + outputs.push_back(matrixws->getName()); + else + throw(std::runtime_error( + "The input " + input + + " is neither a WorkspaceGroup nor a MatrixWorkspace")); } } return outputs; diff --git a/Framework/Algorithms/test/ConjoinXRunsTest.h b/Framework/Algorithms/test/ConjoinXRunsTest.h index fd1e397fdc023c13b3409f3dc3fe9a8e0d96696f..2e80a05ce3c93058f731be580536879708192da9 100644 --- a/Framework/Algorithms/test/ConjoinXRunsTest.h +++ b/Framework/Algorithms/test/ConjoinXRunsTest.h @@ -4,10 +4,13 @@ #include <cxxtest/TestSuite.h> #include "MantidAPI/Axis.h" +#include "MantidAPI/ITableWorkspace.h" #include "MantidAPI/MatrixWorkspace.h" +#include "MantidAPI/WorkspaceFactory.h" #include "MantidAlgorithms/AddSampleLog.h" #include "MantidAlgorithms/AddTimeSeriesLog.h" #include "MantidAlgorithms/ConjoinXRuns.h" +#include "MantidAlgorithms/GroupWorkspaces.h" #include "MantidHistogramData/Counts.h" #include "MantidHistogramData/HistogramDx.h" #include "MantidHistogramData/HistogramE.h" @@ -20,6 +23,7 @@ using Mantid::Algorithms::ConjoinXRuns; using Mantid::Algorithms::AddSampleLog; using Mantid::Algorithms::AddTimeSeriesLog; +using Mantid::Algorithms::GroupWorkspaces; using Mantid::HistogramData::Counts; using Mantid::HistogramData::HistogramDx; using Mantid::HistogramData::HistogramE; @@ -96,6 +100,23 @@ public: TSM_ASSERT_EQUALS("Dx and y values are the same", out->dx(0).rawData(), y); } + void testTableInputWorkspaceInGroup() { + auto table = WorkspaceFactory::Instance().createTable("TableWorkspace"); + storeWS("table", table); + + GroupWorkspaces group; + group.initialize(); + group.setProperty("InputWorkspaces", + std::vector<std::string>{"table", "ws1"}); + group.setProperty("OutputWorkspace", "group"); + group.execute(); + m_testee.setProperty("InputWorkspaces", "group"); + m_testee.setProperty("OutputWorkspace", "out"); + TS_ASSERT_THROWS_EQUALS(m_testee.execute(), const std::runtime_error &e, + std::string(e.what()), + "Some invalid Properties found"); + } + void testWSWithoutDxValues() { // Workspaces have 5 spectra must be point data MatrixWorkspace_sptr ws0 = create2DWorkspace123(5, 3); // 3 points diff --git a/Framework/Algorithms/test/RunCombinationHelperTest.h b/Framework/Algorithms/test/RunCombinationHelperTest.h index 154f72f6e45db91f3c45b0b4f9cf854e5b245218..161f8352b93e34b544c5eb6f1f3e2a4b3324af84 100644 --- a/Framework/Algorithms/test/RunCombinationHelperTest.h +++ b/Framework/Algorithms/test/RunCombinationHelperTest.h @@ -7,7 +7,9 @@ #include "MantidAPI/FrameworkManager.h" #include "MantidAPI/Axis.h" +#include "MantidAPI/ITableWorkspace.h" #include "MantidAPI/MatrixWorkspace.h" +#include "MantidAPI/WorkspaceFactory.h" #include "MantidGeometry/Instrument/DetectorInfo.h" #include "MantidHistogramData/HistogramDx.h" #include "MantidAlgorithms/CreateSampleWorkspace.h" @@ -20,6 +22,7 @@ using Mantid::Algorithms::RunCombinationHelper; using Mantid::Algorithms::GroupWorkspaces; using Mantid::Algorithms::CreateSampleWorkspace; using namespace Mantid::API; +using namespace Mantid::DataObjects; using namespace Mantid::HistogramData; using namespace Mantid::Kernel; using namespace WorkspaceCreationHelper; @@ -40,6 +43,21 @@ public: m_testee.setReferenceProperties(m_reference); } + void testUnwraping_throws() { + + auto ws1 = create2DWorkspace(2, 3); + storeWS("ws1", ws1); + auto table = WorkspaceFactory::Instance().createTable("TableWorkspace"); + storeWS("table", table); + + TS_ASSERT_THROWS_EQUALS( + m_testee.unWrapGroups(std::vector<std::string>{"ws1", "table"}), + const std::runtime_error &e, std::string(e.what()), + "The input table is neither a WorkspaceGroup nor a MatrixWorkspace"); + + removeWS("ws1"); + } + void testUnwraping() { MatrixWorkspace_sptr ws1 = create2DWorkspace(2, 3); diff --git a/Framework/SINQ/test/PoldiIndexKnownCompoundsTest.h b/Framework/SINQ/test/PoldiIndexKnownCompoundsTest.h index 302ef9bc8294228df0a9c860c3078b5ae7149a1d..70bc0dee4e5eb7e85904a3dcabee7ec7092867a5 100644 --- a/Framework/SINQ/test/PoldiIndexKnownCompoundsTest.h +++ b/Framework/SINQ/test/PoldiIndexKnownCompoundsTest.h @@ -37,13 +37,13 @@ public: /* In this test, peaks from PoldiMockInstrumentHelpers (Silicon) * are indexed using theoretical Si-peaks. */ - WorkspaceCreationHelper::storeWS( - "measured_SI", - PoldiPeakCollectionHelpers::createPoldiPeakTableWorkspace()); - WorkspaceCreationHelper::storeWS( - "Si", + auto wsMeasuredSi = + PoldiPeakCollectionHelpers::createPoldiPeakTableWorkspace(); + WorkspaceCreationHelper::storeWS("measured_SI", wsMeasuredSi); + auto wsSi = PoldiPeakCollectionHelpers::createTheoreticalPeakCollectionSilicon() - ->asTableWorkspace()); + ->asTableWorkspace(); + WorkspaceCreationHelper::storeWS("Si", wsSi); std::string outWSName("PoldiIndexKnownCompoundsTest_OutputWS"); @@ -670,8 +670,8 @@ private: void storeRandomWorkspaces(const std::vector<std::string> &wsNames) { for (const auto &wsName : wsNames) { - WorkspaceCreationHelper::storeWS( - wsName, WorkspaceCreationHelper::create1DWorkspaceRand(10, true)); + auto ws = WorkspaceCreationHelper::create1DWorkspaceRand(10, true); + WorkspaceCreationHelper::storeWS(wsName, ws); } } diff --git a/Framework/TestHelpers/inc/MantidTestHelpers/WorkspaceCreationHelper.h b/Framework/TestHelpers/inc/MantidTestHelpers/WorkspaceCreationHelper.h index b809b285196480bfad27e427ea4cab8e043d3e03..9db2c01f27a2e83d045340b26ed94185767c4809 100644 --- a/Framework/TestHelpers/inc/MantidTestHelpers/WorkspaceCreationHelper.h +++ b/Framework/TestHelpers/inc/MantidTestHelpers/WorkspaceCreationHelper.h @@ -106,8 +106,14 @@ struct EPPTableRow { FitStatus fitStatus = FitStatus::SUCCESS; }; -/// Adds a workspace to the ADS -void storeWS(const std::string &name, Mantid::API::Workspace_sptr ws); +/** + * Adds a workspace to the ADS + * @param name :: The name of the workspace + * @param ws :: The workspace object + */ +template <typename WSType> void storeWS(const std::string &name, WSType &ws) { + Mantid::API::AnalysisDataService::Instance().add(name, ws); +} /// Deletes a workspace void removeWS(const std::string &name); /// Returns a workspace of a given type diff --git a/Framework/TestHelpers/src/WorkspaceCreationHelper.cpp b/Framework/TestHelpers/src/WorkspaceCreationHelper.cpp index f90803a4cd50029c21fc21f821a9b6073e9b8080..5a8efb136bc5f352a5af9abaca6ebc24b40d166a 100644 --- a/Framework/TestHelpers/src/WorkspaceCreationHelper.cpp +++ b/Framework/TestHelpers/src/WorkspaceCreationHelper.cpp @@ -72,14 +72,6 @@ EPPTableRow::EPPTableRow(const int index, const double peakCentre_, : workspaceIndex(index), peakCentre(peakCentre_), sigma(sigma_), height(height_), fitStatus(fitStatus_) {} -/** - * @param name :: The name of the workspace - * @param ws :: The workspace object - */ -void storeWS(const std::string &name, Mantid::API::Workspace_sptr ws) { - Mantid::API::AnalysisDataService::Instance().add(name, ws); -} - /** * Deletes a workspace * @param name :: The name of the workspace