From fe26fe14558a210cd4ee5cf0c2ceb4bea629e87b Mon Sep 17 00:00:00 2001 From: Roman Tolchenov Date: Fri, 24 Apr 2015 09:41:10 +0100 Subject: [PATCH] Re #11619. Renamed and moved the algorithm. --- .../Framework/Algorithms/CMakeLists.txt | 3 ++ .../MantidAlgorithms/RemoveMaskedSpectra.h} | 23 ++++---- .../src/RemoveMaskedSpectra.cpp} | 52 +++++++++++-------- .../test/RemoveMaskedSpectraTest.h} | 22 ++++---- .../Framework/DataHandling/CMakeLists.txt | 3 -- ...Mask-v1.rst => RemoveMaskedSpectra-v1.rst} | 8 +-- 6 files changed, 60 insertions(+), 51 deletions(-) rename Code/Mantid/Framework/{DataHandling/inc/MantidDataHandling/CropWorkspaceByMask.h => Algorithms/inc/MantidAlgorithms/RemoveMaskedSpectra.h} (68%) rename Code/Mantid/Framework/{DataHandling/src/CropWorkspaceByMask.cpp => Algorithms/src/RemoveMaskedSpectra.cpp} (74%) rename Code/Mantid/Framework/{DataHandling/test/CropWorkspaceByMaskTest.h => Algorithms/test/RemoveMaskedSpectraTest.h} (67%) rename Code/Mantid/docs/source/algorithms/{CropWorkspaceByMask-v1.rst => RemoveMaskedSpectra-v1.rst} (81%) diff --git a/Code/Mantid/Framework/Algorithms/CMakeLists.txt b/Code/Mantid/Framework/Algorithms/CMakeLists.txt index ea536a108201..65ffed80db68 100644 --- a/Code/Mantid/Framework/Algorithms/CMakeLists.txt +++ b/Code/Mantid/Framework/Algorithms/CMakeLists.txt @@ -197,6 +197,7 @@ set ( SRC_FILES src/RemoveBins.cpp src/RemoveExpDecay.cpp src/RemoveLowResTOF.cpp + src/RemoveMaskedSpectra.cpp src/RemovePromptPulse.cpp src/RemoveWorkspaceHistory.cpp src/RenameWorkspace.cpp @@ -455,6 +456,7 @@ set ( INC_FILES inc/MantidAlgorithms/RemoveBins.h inc/MantidAlgorithms/RemoveExpDecay.h inc/MantidAlgorithms/RemoveLowResTOF.h + inc/MantidAlgorithms/RemoveMaskedSpectra.h inc/MantidAlgorithms/RemovePromptPulse.h inc/MantidAlgorithms/RemoveWorkspaceHistory.h inc/MantidAlgorithms/RenameWorkspace.h @@ -706,6 +708,7 @@ set ( TEST_FILES RemoveBinsTest.h RemoveExpDecayTest.h RemoveLowResTOFTest.h + RemoveMaskedSpectraTest.h RemovePromptPulseTest.h RemoveWorkspaceHistoryTest.h RenameWorkspaceTest.h diff --git a/Code/Mantid/Framework/DataHandling/inc/MantidDataHandling/CropWorkspaceByMask.h b/Code/Mantid/Framework/Algorithms/inc/MantidAlgorithms/RemoveMaskedSpectra.h similarity index 68% rename from Code/Mantid/Framework/DataHandling/inc/MantidDataHandling/CropWorkspaceByMask.h rename to Code/Mantid/Framework/Algorithms/inc/MantidAlgorithms/RemoveMaskedSpectra.h index 0bb6410aa565..278be3d8abe4 100644 --- a/Code/Mantid/Framework/DataHandling/inc/MantidDataHandling/CropWorkspaceByMask.h +++ b/Code/Mantid/Framework/Algorithms/inc/MantidAlgorithms/RemoveMaskedSpectra.h @@ -1,14 +1,13 @@ -#ifndef MANTID_DATAHANDLING_CROPWORKSPACEBYMASK_H_ -#define MANTID_DATAHANDLING_CROPWORKSPACEBYMASK_H_ +#ifndef MANTID_ALGORITHMS_REMOVEMASKEDSPECTRA_H_ +#define MANTID_ALGORITHMS_REMOVEMASKEDSPECTRA_H_ #include "MantidKernel/System.h" #include "MantidAPI/Algorithm.h" namespace Mantid { -namespace DataHandling { +namespace Algorithms { -/** CropWorkspaceByMask crops a MatrixWorkspace by a mask. It removes all masked - spectra. +/** RemoveMaskedSpectra removes all masked spectra. Copyright © 2015 ISIS Rutherford Appleton Laboratory, NScD Oak Ridge National Laboratory & European Spallation Source @@ -31,10 +30,10 @@ namespace DataHandling { File change history is stored at: Code Documentation is available at: */ -class DLLExport CropWorkspaceByMask : public API::Algorithm { +class DLLExport RemoveMaskedSpectra : public API::Algorithm { public: - CropWorkspaceByMask(); - virtual ~CropWorkspaceByMask(); + RemoveMaskedSpectra(); + virtual ~RemoveMaskedSpectra(); virtual const std::string name() const; virtual int version() const; @@ -44,11 +43,11 @@ class DLLExport CropWorkspaceByMask : public API::Algorithm { private: void init(); void exec(); - /// Fill in a vector with spectra indices to be extracted. - void makeIndexList(std::vector& indices, const API::MatrixWorkspace* maskedWorkspace); + void makeIndexList(std::vector &indices, + const API::MatrixWorkspace *maskedWorkspace); }; -} // namespace DataHandling +} // namespace Algorithms } // namespace Mantid -#endif /* MANTID_DATAHANDLING_CROPWORKSPACEBYMASK_H_ */ \ No newline at end of file +#endif /* MANTID_ALGORITHMS_REMOVEMASKEDSPECTRA_H_ */ \ No newline at end of file diff --git a/Code/Mantid/Framework/DataHandling/src/CropWorkspaceByMask.cpp b/Code/Mantid/Framework/Algorithms/src/RemoveMaskedSpectra.cpp similarity index 74% rename from Code/Mantid/Framework/DataHandling/src/CropWorkspaceByMask.cpp rename to Code/Mantid/Framework/Algorithms/src/RemoveMaskedSpectra.cpp index 24eb68351922..fc6abed8ff18 100644 --- a/Code/Mantid/Framework/DataHandling/src/CropWorkspaceByMask.cpp +++ b/Code/Mantid/Framework/Algorithms/src/RemoveMaskedSpectra.cpp @@ -1,48 +1,51 @@ -#include "MantidDataHandling/CropWorkspaceByMask.h" +#include "MantidAlgorithms/RemoveMaskedSpectra.h" #include "MantidDataObjects/MaskWorkspace.h" #include "MantidAPI/WorkspaceFactory.h" namespace Mantid { -namespace DataHandling { +namespace Algorithms { using namespace Kernel; using namespace API; // Register the algorithm into the AlgorithmFactory -DECLARE_ALGORITHM(CropWorkspaceByMask) +DECLARE_ALGORITHM(RemoveMaskedSpectra) //---------------------------------------------------------------------------------------------- -/// Constructor -CropWorkspaceByMask::CropWorkspaceByMask() {} +/** Constructor + */ +RemoveMaskedSpectra::RemoveMaskedSpectra() {} //---------------------------------------------------------------------------------------------- -/// Destructor -CropWorkspaceByMask::~CropWorkspaceByMask() {} +/** Destructor + */ +RemoveMaskedSpectra::~RemoveMaskedSpectra() {} //---------------------------------------------------------------------------------------------- /// Algorithms name for identification. @see Algorithm::name -const std::string CropWorkspaceByMask::name() const { - return "CropWorkspaceByMask"; +const std::string RemoveMaskedSpectra::name() const { + return "RemoveMaskedSpectra"; } /// Algorithm's version for identification. @see Algorithm::version -int CropWorkspaceByMask::version() const { return 1; }; +int RemoveMaskedSpectra::version() const { return 1; }; /// Algorithm's category for identification. @see Algorithm::category -const std::string CropWorkspaceByMask::category() const { +const std::string RemoveMaskedSpectra::category() const { return "Transforms\\Splitting"; } /// Algorithm's summary for use in the GUI and help. @see Algorithm::summary -const std::string CropWorkspaceByMask::summary() const { +const std::string RemoveMaskedSpectra::summary() const { return "Extracts unmasked spectra from a workspace and places them in a new " "workspace."; } //---------------------------------------------------------------------------------------------- -/// Initialize the algorithm's properties. -void CropWorkspaceByMask::init() { +/** Initialize the algorithm's properties. + */ +void RemoveMaskedSpectra::init() { declareProperty( new WorkspaceProperty<>("InputWorkspace", "", Direction::Input), "An input workspace."); @@ -58,12 +61,17 @@ void CropWorkspaceByMask::init() { } //---------------------------------------------------------------------------------------------- -/// Execute the algorithm. -void CropWorkspaceByMask::exec() { +/** Execute the algorithm. + */ +void RemoveMaskedSpectra::exec() { MatrixWorkspace_sptr inputWorkspace = getProperty("InputWorkspace"); MatrixWorkspace_sptr maskedWorkspace = getProperty("MaskedWorkspace"); - if ( !maskedWorkspace ) maskedWorkspace = inputWorkspace; + if (!maskedWorkspace){ + maskedWorkspace = inputWorkspace; + } else if (inputWorkspace->getNumberHistograms() != maskedWorkspace->getNumberHistograms()) { + throw std::runtime_error("Masked workspace has a different number of spectra."); + } std::vector indices; makeIndexList(indices, maskedWorkspace.get()); @@ -72,19 +80,22 @@ void CropWorkspaceByMask::exec() { size_t nSpectra = indices.size(); // Number of bins/data points in the cropped workspace. size_t nBins = inputWorkspace->blocksize(); - size_t histogram = inputWorkspace->isHistogramData()? 1 : 0; + size_t histogram = inputWorkspace->isHistogramData() ? 1 : 0; // Create the output workspace MatrixWorkspace_sptr outputWorkspace = WorkspaceFactory::Instance().create( inputWorkspace, nSpectra, nBins, nBins - histogram); + for (size_t i = 0; i < nSpectra; ++i) { + auto j = indices[i]; + } } //---------------------------------------------------------------------------------------------- /// Fill in a vector with spectra indices to be extracted. /// @param indices :: A reference to a vector to fill with the indices. /// @param maskedWorkspace :: A workspace with masking information. -void CropWorkspaceByMask::makeIndexList( +void RemoveMaskedSpectra::makeIndexList( std::vector &indices, const API::MatrixWorkspace *maskedWorkspace) { auto mask = dynamic_cast(maskedWorkspace); if (mask) { @@ -101,7 +112,6 @@ void CropWorkspaceByMask::makeIndexList( } catch (Exception::NotFoundError &) { continue; } - if (det->isMasked()) { indices.push_back(i); } @@ -109,5 +119,5 @@ void CropWorkspaceByMask::makeIndexList( } } -} // namespace DataHandling +} // namespace Algorithms } // namespace Mantid \ No newline at end of file diff --git a/Code/Mantid/Framework/DataHandling/test/CropWorkspaceByMaskTest.h b/Code/Mantid/Framework/Algorithms/test/RemoveMaskedSpectraTest.h similarity index 67% rename from Code/Mantid/Framework/DataHandling/test/CropWorkspaceByMaskTest.h rename to Code/Mantid/Framework/Algorithms/test/RemoveMaskedSpectraTest.h index 60f3e58d9acf..b0e27bdc6340 100644 --- a/Code/Mantid/Framework/DataHandling/test/CropWorkspaceByMaskTest.h +++ b/Code/Mantid/Framework/Algorithms/test/RemoveMaskedSpectraTest.h @@ -1,25 +1,25 @@ -#ifndef MANTID_DATAHANDLING_CROPWORKSPACEBYMASKTEST_H_ -#define MANTID_DATAHANDLING_CROPWORKSPACEBYMASKTEST_H_ +#ifndef MANTID_ALGORITHMS_REMOVEMASKEDSPECTRATEST_H_ +#define MANTID_ALGORITHMS_REMOVEMASKEDSPECTRATEST_H_ #include -#include "MantidDataHandling/CropWorkspaceByMask.h" +#include "MantidAlgorithms/RemoveMaskedSpectra.h" -using Mantid::DataHandling::CropWorkspaceByMask; +using Mantid::Algorithms::RemoveMaskedSpectra; using namespace Mantid::API; -class CropWorkspaceByMaskTest : public CxxTest::TestSuite +class RemoveMaskedSpectraTest : public CxxTest::TestSuite { public: // This pair of boilerplate methods prevent the suite being created statically // This means the constructor isn't called when running other tests - static CropWorkspaceByMaskTest *createSuite() { return new CropWorkspaceByMaskTest(); } - static void destroySuite( CropWorkspaceByMaskTest *suite ) { delete suite; } + static RemoveMaskedSpectraTest *createSuite() { return new RemoveMaskedSpectraTest(); } + static void destroySuite( RemoveMaskedSpectraTest *suite ) { delete suite; } void test_Init() { - CropWorkspaceByMask alg; + RemoveMaskedSpectra alg; TS_ASSERT_THROWS_NOTHING( alg.initialize() ) TS_ASSERT( alg.isInitialized() ) } @@ -27,9 +27,9 @@ class CropWorkspaceByMaskTest : public CxxTest::TestSuite void test_exec() { // Name of the output workspace. - std::string outWSName("CropWorkspaceByMaskTest_OutputWS"); + std::string outWSName("RemoveMaskedSpectraTest_OutputWS"); - CropWorkspaceByMask alg; + RemoveMaskedSpectra alg; TS_ASSERT_THROWS_NOTHING( alg.initialize() ) TS_ASSERT( alg.isInitialized() ) TS_ASSERT_THROWS_NOTHING( alg.setPropertyValue("REPLACE_PROPERTY_NAME_HERE!!!!", "value") ); @@ -58,4 +58,4 @@ class CropWorkspaceByMaskTest : public CxxTest::TestSuite }; -#endif /* MANTID_DATAHANDLING_CROPWORKSPACEBYMASKTEST_H_ */ \ No newline at end of file +#endif /* MANTID_ALGORITHMS_REMOVEMASKEDSPECTRATEST_H_ */ \ No newline at end of file diff --git a/Code/Mantid/Framework/DataHandling/CMakeLists.txt b/Code/Mantid/Framework/DataHandling/CMakeLists.txt index f453d1d8ab59..af5345906910 100644 --- a/Code/Mantid/Framework/DataHandling/CMakeLists.txt +++ b/Code/Mantid/Framework/DataHandling/CMakeLists.txt @@ -7,7 +7,6 @@ set ( SRC_FILES src/CreateModeratorModel.cpp src/CreateSampleShape.cpp src/CreateSimulationWorkspace.cpp - src/CropWorkspaceByMask.cpp src/DefineGaugeVolume.cpp src/DeleteTableRows.cpp src/DetermineChunking.cpp @@ -162,7 +161,6 @@ set ( INC_FILES inc/MantidDataHandling/CreateModeratorModel.h inc/MantidDataHandling/CreateSampleShape.h inc/MantidDataHandling/CreateSimulationWorkspace.h - inc/MantidDataHandling/CropWorkspaceByMask.h inc/MantidDataHandling/DefineGaugeVolume.h inc/MantidDataHandling/DeleteTableRows.h inc/MantidDataHandling/DetermineChunking.h @@ -316,7 +314,6 @@ set ( TEST_FILES CreateModeratorModelTest.h CreateSampleShapeTest.h CreateSimulationWorkspaceTest.h - CropWorkspaceByMaskTest.h DefineGaugeVolumeTest.h DeleteTableRowsTest.h DetermineChunkingTest.h diff --git a/Code/Mantid/docs/source/algorithms/CropWorkspaceByMask-v1.rst b/Code/Mantid/docs/source/algorithms/RemoveMaskedSpectra-v1.rst similarity index 81% rename from Code/Mantid/docs/source/algorithms/CropWorkspaceByMask-v1.rst rename to Code/Mantid/docs/source/algorithms/RemoveMaskedSpectra-v1.rst index 5e2638fc66ec..265bf191f539 100644 --- a/Code/Mantid/docs/source/algorithms/CropWorkspaceByMask-v1.rst +++ b/Code/Mantid/docs/source/algorithms/RemoveMaskedSpectra-v1.rst @@ -20,23 +20,23 @@ Usage autotestdata\UsageData and the following tag unindented .. include:: ../usagedata-note.txt -**Example - CropWorkspaceByMask** +**Example - RemoveMaskedSpectra** -.. testcode:: CropWorkspaceByMaskExample +.. testcode:: RemoveMaskedSpectraExample # Create a host workspace ws = CreateWorkspace(DataX=range(0,3), DataY=(0,2)) or ws = CreateSampleWorkspace() - wsOut = CropWorkspaceByMask() + wsOut = RemoveMaskedSpectra() # Print the result print "The output workspace has %i spectra" % wsOut.getNumberHistograms() Output: -.. testoutput:: CropWorkspaceByMaskExample +.. testoutput:: RemoveMaskedSpectraExample The output workspace has ?? spectra