diff --git a/Framework/Algorithms/inc/MantidAlgorithms/WorkspaceJoiners.h b/Framework/Algorithms/inc/MantidAlgorithms/WorkspaceJoiners.h index 1b9165ba8c114e0a54014a92082a98f429ef8f96..e662c06aad1f4e044d3cc6bd770eaaed4583a4e3 100644 --- a/Framework/Algorithms/inc/MantidAlgorithms/WorkspaceJoiners.h +++ b/Framework/Algorithms/inc/MantidAlgorithms/WorkspaceJoiners.h @@ -52,8 +52,9 @@ public: protected: API::MatrixWorkspace_sptr execWS2D(const API::MatrixWorkspace &ws1, const API::MatrixWorkspace &ws2); - API::MatrixWorkspace_sptr execEvent(); - + DataObjects::EventWorkspace_sptr + execEvent(const DataObjects::EventWorkspace &eventWs1, + const DataObjects::EventWorkspace &eventWs2); using Mantid::API::Algorithm::validateInputs; void validateInputs(const API::MatrixWorkspace &ws1, const API::MatrixWorkspace &ws2, const bool checkBinning); @@ -66,10 +67,6 @@ protected: API::MatrixWorkspace &output) = 0; API::Progress *m_progress; ///< Progress reporting object - DataObjects::EventWorkspace_const_sptr - event_ws1; ///< First event workspace input. - DataObjects::EventWorkspace_const_sptr - event_ws2; ///< Second event workspace input. }; } // namespace Algorithms diff --git a/Framework/Algorithms/src/AppendSpectra.cpp b/Framework/Algorithms/src/AppendSpectra.cpp index 6400881d9d21d6696e7349cd05e5cc38e8a3943f..9907957643a72de0ed100950a959d4327305179d 100644 --- a/Framework/Algorithms/src/AppendSpectra.cpp +++ b/Framework/Algorithms/src/AppendSpectra.cpp @@ -43,8 +43,7 @@ void AppendSpectra::init() { declareProperty("Number", 1, boost::make_shared<BoundedValidator<int>>(1, EMPTY_INT()), - "Append the spectra from InputWorkspace2 multiple times (for " - "MatrixWorkspaces only)"); + "Append the spectra from InputWorkspace2 multiple times."); declareProperty(make_unique<WorkspaceProperty<>>("OutputWorkspace", "", Direction::Output), @@ -60,12 +59,14 @@ void AppendSpectra::exec() { // Retrieve the input workspaces MatrixWorkspace_const_sptr ws1 = getProperty("InputWorkspace1"); MatrixWorkspace_const_sptr ws2 = getProperty("InputWorkspace2"); - event_ws1 = boost::dynamic_pointer_cast<const EventWorkspace>(ws1); - event_ws2 = boost::dynamic_pointer_cast<const EventWorkspace>(ws2); + DataObjects::EventWorkspace_const_sptr eventWs1 = + boost::dynamic_pointer_cast<const EventWorkspace>(ws1); + DataObjects::EventWorkspace_const_sptr eventWs2 = + boost::dynamic_pointer_cast<const EventWorkspace>(ws2); // Make sure that we are not mis-matching EventWorkspaces and other types of // workspaces - if (((event_ws1) && (!event_ws2)) || ((!event_ws1) && (event_ws2))) { + if (((eventWs1) && (!eventWs2)) || ((!eventWs1) && (eventWs2))) { const std::string message("Only one of the input workspaces are of type " "EventWorkspace; please use matching workspace " "types (both EventWorkspace's or both " @@ -82,28 +83,28 @@ void AppendSpectra::exec() { const bool mergeLogs = getProperty("MergeLogs"); const int number = getProperty("Number"); + MatrixWorkspace_sptr output; - if (event_ws1 && event_ws2) { + if (eventWs1 && eventWs2) { // Both are event workspaces. Use the special method - MatrixWorkspace_sptr output = this->execEvent(); - if (number > 1) - g_log.warning("Number property is ignored for event workspaces"); - if (mergeLogs) - combineLogs(ws1->run(), ws2->run(), output->mutableRun()); - // Set the output workspace - setProperty("OutputWorkspace", output); - return; + DataObjects::EventWorkspace_sptr eOutput = + this->execEvent(*eventWs1, *eventWs2); + for (int i = 1; i < number; i++) { + eOutput = this->execEvent(*eOutput, *eventWs2); + } + output = boost::static_pointer_cast<MatrixWorkspace>(eOutput); + } else { // So it is a workspace 2D. + // The only restriction, even with ValidateInputs=false + if (ws1->blocksize() != ws2->blocksize()) + throw std::runtime_error( + "Workspace2D's must have the same number of bins."); + + output = execWS2D(*ws1, *ws2); + for (int i = 1; i < number; i++) { + output = execWS2D(*output, *ws2); + } } - // So it is a workspace 2D. - - // The only restriction, even with ValidateInputs=false - if (ws1->blocksize() != ws2->blocksize()) - throw std::runtime_error( - "Workspace2D's must have the same number of bins."); - MatrixWorkspace_sptr output = execWS2D(*ws1, *ws2); - for (int i = 1; i < number; i++) - output = execWS2D(*output, *ws2); if (mergeLogs) combineLogs(ws1->run(), ws2->run(), output->mutableRun()); diff --git a/Framework/Algorithms/src/ConjoinWorkspaces.cpp b/Framework/Algorithms/src/ConjoinWorkspaces.cpp index 37f2fd807fc2a21ea73407fefea9ea6780037e09..cf39d7d45a6cb3c08ed30e00e0e5f0882a27b89a 100644 --- a/Framework/Algorithms/src/ConjoinWorkspaces.cpp +++ b/Framework/Algorithms/src/ConjoinWorkspaces.cpp @@ -46,12 +46,14 @@ void ConjoinWorkspaces::exec() { // Retrieve the input workspaces MatrixWorkspace_const_sptr ws1 = getProperty("InputWorkspace1"); MatrixWorkspace_const_sptr ws2 = getProperty("InputWorkspace2"); - event_ws1 = boost::dynamic_pointer_cast<const EventWorkspace>(ws1); - event_ws2 = boost::dynamic_pointer_cast<const EventWorkspace>(ws2); + DataObjects::EventWorkspace_const_sptr eventWs1 = + boost::dynamic_pointer_cast<const EventWorkspace>(ws1); + DataObjects::EventWorkspace_const_sptr eventWs2 = + boost::dynamic_pointer_cast<const EventWorkspace>(ws2); // Make sure that we are not mis-matching EventWorkspaces and other types of // workspaces - if (((event_ws1) && (!event_ws2)) || ((!event_ws1) && (event_ws2))) { + if (((eventWs1) && (!eventWs2)) || ((!eventWs1) && (eventWs2))) { const std::string message("Only one of the input workspaces are of type " "EventWorkspace; please use matching workspace " "types (both EventWorkspace's or both " @@ -60,9 +62,9 @@ void ConjoinWorkspaces::exec() { throw std::invalid_argument(message); } - if (event_ws1 && event_ws2) { - this->validateInputs(*event_ws1, *event_ws2, false); - auto output = conjoinEvents(*event_ws1, *event_ws2); + if (eventWs1 && eventWs2) { + this->validateInputs(*eventWs1, *eventWs2, false); + auto output = conjoinEvents(*eventWs1, *eventWs2); setYUnitAndLabel(*output); // Set the result workspace to the first input setProperty("InputWorkspace1", output); @@ -150,7 +152,7 @@ ConjoinWorkspaces::conjoinEvents(const DataObjects::EventWorkspace &ws1, } // Both are event workspaces. Use the special method - auto output = this->execEvent(); + auto output = this->execEvent(ws1, ws2); // Copy the history from the original workspace output->history().addHistory(ws1.getHistory()); diff --git a/Framework/Algorithms/src/WorkspaceJoiners.cpp b/Framework/Algorithms/src/WorkspaceJoiners.cpp index f2483b3c7432688297a386ccbd3127d36640060b..ff4ec7e077d76bc1c78b3559af55230dafdef003 100644 --- a/Framework/Algorithms/src/WorkspaceJoiners.cpp +++ b/Framework/Algorithms/src/WorkspaceJoiners.cpp @@ -118,44 +118,46 @@ MatrixWorkspace_sptr WorkspaceJoiners::execWS2D(const MatrixWorkspace &ws1, * @throw std::invalid_argument If the input workspaces do not meet the * requirements of this algorithm */ -MatrixWorkspace_sptr WorkspaceJoiners::execEvent() { +DataObjects::EventWorkspace_sptr +WorkspaceJoiners::execEvent(const DataObjects::EventWorkspace &eventWs1, + const DataObjects::EventWorkspace &eventWs2) { // Create the output workspace const size_t totalHists = - event_ws1->getNumberHistograms() + event_ws2->getNumberHistograms(); + eventWs1.getNumberHistograms() + eventWs2.getNumberHistograms(); auto output = - create<EventWorkspace>(*event_ws1, totalHists, event_ws1->binEdges(0)); + create<EventWorkspace>(eventWs1, totalHists, eventWs1.binEdges(0)); // Initialize the progress reporting object m_progress = new API::Progress(this, 0.0, 1.0, totalHists); - const int64_t &nhist1 = event_ws1->getNumberHistograms(); + const int64_t &nhist1 = eventWs1.getNumberHistograms(); for (int64_t i = 0; i < nhist1; ++i) { - output->getSpectrum(i) = event_ws1->getSpectrum(i); + output->getSpectrum(i) = eventWs1.getSpectrum(i); m_progress->report(); } // For second loop we use the offset from the first - const int64_t &nhist2 = event_ws2->getNumberHistograms(); - const auto &spectrumInfo = event_ws2->spectrumInfo(); + const int64_t &nhist2 = eventWs2.getNumberHistograms(); + const auto &spectrumInfo = eventWs2.spectrumInfo(); auto &outSpectrumInfo = output->mutableSpectrumInfo(); for (int64_t j = 0; j < nhist2; ++j) { // This is the workspace index at which we assign in the output - int64_t output_wi = j + nhist1; - output->getSpectrum(output_wi) = event_ws2->getSpectrum(j); + int64_t outputWi = j + nhist1; + output->getSpectrum(outputWi) = eventWs2.getSpectrum(j); // Propagate spectrum masking. First workspace will have been done by the // factory if (spectrumInfo.hasDetectors(j) && spectrumInfo.isMasked(j)) { - output->getSpectrum(output_wi).clearData(); + output->getSpectrum(outputWi).clearData(); PARALLEL_CRITICAL(setMaskedEvent) { - outSpectrumInfo.setMasked(output_wi, true); + outSpectrumInfo.setMasked(outputWi, true); } } m_progress->report(); } - fixSpectrumNumbers(*event_ws1, *event_ws2, *output); + fixSpectrumNumbers(eventWs1, eventWs2, *output); return std::move(output); } diff --git a/Framework/Algorithms/test/AppendSpectraTest.h b/Framework/Algorithms/test/AppendSpectraTest.h index bdf76d8bb2498ba35fc46c279ebc108e8bce12cc..2b43a0d444ae5b0ddf7af9746d3bc4e5c6d42cea 100644 --- a/Framework/Algorithms/test/AppendSpectraTest.h +++ b/Framework/Algorithms/test/AppendSpectraTest.h @@ -178,7 +178,7 @@ public: } //---------------------------------------------------------------------------------------------- - void doTest(bool event, bool combineLogs = false) { + void doTest(bool event, bool combineLogs = false, int number = 1) { MatrixWorkspace_sptr ws1, ws2, out; int numBins = 20; @@ -212,6 +212,7 @@ public: TS_ASSERT_THROWS_NOTHING(alg.setPropertyValue("InputWorkspace1", ws1Name)); TS_ASSERT_THROWS_NOTHING(alg.setPropertyValue("InputWorkspace2", ws2Name)); TS_ASSERT_THROWS_NOTHING(alg.setPropertyValue("OutputWorkspace", ws1Name)); + TS_ASSERT_THROWS_NOTHING(alg.setProperty("Number", number)); if (combineLogs) alg.setProperty("MergeLogs", true); TS_ASSERT_THROWS_NOTHING(alg.execute();) @@ -224,7 +225,7 @@ public: if (!out) return; - TS_ASSERT_EQUALS(out->getNumberHistograms(), 15); + TS_ASSERT_EQUALS(out->getNumberHistograms(), 10 + 5 * number); TS_ASSERT_EQUALS(out->blocksize(), numBins); for (size_t wi = 0; wi < out->getNumberHistograms(); wi++) { @@ -246,6 +247,8 @@ public: void test_events() { doTest(true); } + void test_number_events() { doTest(true, true, 3); } + void test_2D() { doTest(false); } void test_events_mergeLogs() { doTest(true, true); } diff --git a/docs/source/release/v3.14.0/framework.rst b/docs/source/release/v3.14.0/framework.rst index 68ff8bc001e92b240993eaa2de48a6452c9f8036..c04833e09f9b3532e839b4aee22c4f6bf2f9c31c 100644 --- a/docs/source/release/v3.14.0/framework.rst +++ b/docs/source/release/v3.14.0/framework.rst @@ -42,7 +42,7 @@ New Algorithms Improvements ############ - +- :ref:`AppendSpectra <algm-AppendSpectra>` can append now multiple times the same event workspace. Bugfixes ########