diff --git a/Framework/API/inc/MantidAPI/Algorithm.h b/Framework/API/inc/MantidAPI/Algorithm.h index c3402241030192dbc29710df444af9770a6b9667..88ee8013221918ce495a0d7d7ada462a59ac8293 100644 --- a/Framework/API/inc/MantidAPI/Algorithm.h +++ b/Framework/API/inc/MantidAPI/Algorithm.h @@ -403,13 +403,13 @@ protected: /// versions bool m_usingBaseProcessGroups = false; - template <typename T, typename = typename std::enable_if<std::is_convertible< - T *, MatrixWorkspace *>::value>::type> - void declareWorkspaceInputProperties( - const std::string &propertyName, - const int allowedIndexTypes = IndexType::WorkspaceIndex, - PropertyMode::Type optional = PropertyMode::Type::Mandatory, - LockMode::Type lock = LockMode::Type::Lock, const std::string &doc = ""); + template <typename T, const int AllowedIndexTypes = IndexType::WorkspaceIndex, + typename... WSPropArgs, + typename = typename std::enable_if< + std::is_convertible<T *, MatrixWorkspace *>::value>::type> + void declareWorkspaceInputProperties(const std::string &propertyName, + const std::string &doc, + WSPropArgs &&... wsPropArgs); private: template <typename T1, typename T2, typename WsType> diff --git a/Framework/API/inc/MantidAPI/Algorithm.tcc b/Framework/API/inc/MantidAPI/Algorithm.tcc index e27d1538ca352652e6fe4db7de1f3eeda3dcbfb7..dfb429a918bd4c58edf0cc23928124bfe964bfa8 100644 --- a/Framework/API/inc/MantidAPI/Algorithm.tcc +++ b/Framework/API/inc/MantidAPI/Algorithm.tcc @@ -1,3 +1,6 @@ +#ifndef MANTID_API_ALGORITHM_TCC_ +#define MANTID_API_ALGORITHM_TCC_ + #include "MantidAPI/Algorithm.h" #include "MantidAPI/IndexProperty.h" #include "MantidAPI/WorkspaceProperty.h" @@ -25,34 +28,40 @@ namespace API { @param propertyName Name of property which will be reserved @param allowedIndexTypes combination of allowed index types. Default IndexType::WorkspaceIndex -@param optional Determines if workspace property is optional. Default -PropertyMode::Type::Mandatory -@param lock Determines whether or not the workspace is locked. Default -LockMode::Type::Lock +@param wsPropArgs a parameter pack of arguments forwarded to WorkspaceProperty. +Can contain PropertyMode, LockMode, and validators. @param doc Property documentation string. */ -template <typename T, typename> +template <typename T, const int AllowedIndexTypes, typename... WSPropArgs, + typename> void Algorithm::declareWorkspaceInputProperties(const std::string &propertyName, - const int allowedIndexTypes, - PropertyMode::Type optional, - LockMode::Type lock, - const std::string &doc) { + const std::string &doc, + WSPropArgs &&... wsPropArgs) { auto wsProp = Kernel::make_unique<WorkspaceProperty<T>>( - propertyName, "", Kernel::Direction::Input, optional, lock); + propertyName, "", Kernel::Direction::Input, + std::forward<WSPropArgs>(wsPropArgs)...); const auto &wsPropRef = *wsProp; declareProperty(std::move(wsProp), doc); auto indexTypePropName = IndexTypeProperty::generatePropertyName(propertyName); auto indexTypeProp = Kernel::make_unique<IndexTypeProperty>( - indexTypePropName, allowedIndexTypes); + indexTypePropName, AllowedIndexTypes); const auto &indexTypePropRef = *indexTypeProp; - declareProperty(std::move(indexTypeProp)); + declareProperty(std::move(indexTypeProp), + "The type of indices in the optional index set; For optimal " + "performance WorkspaceIndex should be preferred;"); auto indexPropName = IndexProperty::generatePropertyName(propertyName); declareProperty(Kernel::make_unique<IndexProperty>(indexPropName, wsPropRef, - indexTypePropRef)); + indexTypePropRef), + "An optional set of spectra that will be processed by the " + "algorithm; If not set, all spectra will be processed; The " + "indices in this list can be workspace indices or possibly " + "spectrum numbers, depending on the selection made for the " + "index type; Indices are entered as a comma-separated list " + "of values, and/or ranges; For example, '4,6,10-20,1000';"); m_reservedList.push_back(propertyName); m_reservedList.push_back(indexTypePropName); @@ -146,4 +155,6 @@ Algorithm::getWorkspaceAndIndices(const std::string &name) const { return std::make_tuple(ws, indexSet); } } // namespace API -} // namespace Mantid \ No newline at end of file +} // namespace Mantid + +#endif /*MANTID_API_ALGORITHM_TCC_*/ diff --git a/Framework/API/src/MatrixWorkspace.cpp b/Framework/API/src/MatrixWorkspace.cpp index 1bb2efdd5b6ab82b3d403a30af94e88027544713..3e01e7c589644a2621d4124c342b831f875d19f7 100644 --- a/Framework/API/src/MatrixWorkspace.cpp +++ b/Framework/API/src/MatrixWorkspace.cpp @@ -1,5 +1,5 @@ #include "MantidAPI/MatrixWorkspace.h" -#include "MantidAPI/Algorithm.tcc" +#include "MantidAPI/Algorithm.h" #include "MantidAPI/BinEdgeAxis.h" #include "MantidAPI/MatrixWorkspaceMDIterator.h" #include "MantidAPI/NumericAxis.h" @@ -2009,40 +2009,6 @@ void MatrixWorkspace::rebuildDetectorIDGroupings() { } // namespace API } // Namespace Mantid -// Explicit Instantiations of IndexProperty Methods in Algorithm -namespace Mantid { -namespace API { -template DLLExport void -Algorithm::declareWorkspaceInputProperties<MatrixWorkspace>( - const std::string &propertyName, const int allowedIndexTypes, - PropertyMode::Type optional, LockMode::Type lock, const std::string &doc); - -template DLLExport void -Algorithm::setWorkspaceInputProperties<MatrixWorkspace, std::vector<int>>( - const std::string &name, const MatrixWorkspace_sptr &wksp, IndexType type, - const std::vector<int> &list); - -template DLLExport void -Algorithm::setWorkspaceInputProperties<MatrixWorkspace, std::string>( - const std::string &name, const MatrixWorkspace_sptr &wksp, IndexType type, - const std::string &list); - -template DLLExport void -Algorithm::setWorkspaceInputProperties<MatrixWorkspace, std::vector<int>>( - const std::string &name, const std::string &wsName, IndexType type, - const std::vector<int> &list); - -template DLLExport void -Algorithm::setWorkspaceInputProperties<MatrixWorkspace, std::string>( - const std::string &name, const std::string &wsName, IndexType type, - const std::string &list); - -template DLLExport - std::tuple<boost::shared_ptr<MatrixWorkspace>, Indexing::SpectrumIndexSet> - Algorithm::getWorkspaceAndIndices(const std::string &name) const; -} // namespace API -} // namespace Mantid - ///\cond TEMPLATE namespace Mantid { namespace Kernel { diff --git a/Framework/API/test/AlgorithmTest.h b/Framework/API/test/AlgorithmTest.h index 188e11df23d7d487d35eb02dd020afe58965050f..3eb061f2bc32a54c1f380a353c43b794b68001b0 100644 --- a/Framework/API/test/AlgorithmTest.h +++ b/Framework/API/test/AlgorithmTest.h @@ -4,9 +4,10 @@ #include <cxxtest/TestSuite.h> #include "FakeAlgorithms.h" -#include "MantidAPI/Algorithm.h" +#include "MantidAPI/Algorithm.tcc" #include "MantidAPI/AlgorithmFactory.h" #include "MantidAPI/FrameworkManager.h" +#include "MantidAPI/HistogramValidator.h" #include "MantidAPI/WorkspaceFactory.h" #include "MantidAPI/WorkspaceGroup.h" #include "MantidAPI/WorkspaceProperty.h" @@ -171,10 +172,16 @@ public: static const std::string FAIL_MSG; void init() override { - declareWorkspaceInputProperties<MatrixWorkspace>("InputWorkspace"); + declareWorkspaceInputProperties<MatrixWorkspace>("InputWorkspace", ""); declareProperty( Mantid::Kernel::make_unique<WorkspaceProperty<MatrixWorkspace>>( "InputWorkspace2", "", Mantid::Kernel::Direction::Input)); + declareWorkspaceInputProperties< + MatrixWorkspace, IndexType::SpectrumNum | IndexType::WorkspaceIndex>( + "InputWorkspace3", ""); + declareWorkspaceInputProperties< + MatrixWorkspace, IndexType::SpectrumNum | IndexType::WorkspaceIndex>( + "InputWorkspace4", "", boost::make_shared<HistogramValidator>()); } void exec() override {} diff --git a/Framework/Algorithms/inc/MantidAlgorithms/FilterBadPulses.h b/Framework/Algorithms/inc/MantidAlgorithms/FilterBadPulses.h index 54d83ef9beab0755f58aa92586f2a055a68177d8..282ba9028e69f22de43dd48e402c6d73dec40456 100644 --- a/Framework/Algorithms/inc/MantidAlgorithms/FilterBadPulses.h +++ b/Framework/Algorithms/inc/MantidAlgorithms/FilterBadPulses.h @@ -1,11 +1,8 @@ #ifndef MANTID_ALGORITHMS_FILTERBADPULSES_H_ #define MANTID_ALGORITHMS_FILTERBADPULSES_H_ -//---------------------------------------------------------------------- -// Includes -//---------------------------------------------------------------------- #include "MantidKernel/System.h" -#include "MantidAPI/Algorithm.h" +#include "MantidAPI/ParallelAlgorithm.h" #include "MantidDataObjects/EventWorkspace.h" namespace Mantid { @@ -49,7 +46,7 @@ namespace Algorithms { File change history is stored at: <https://github.com/mantidproject/mantid>. Code Documentation is available at: <http://doxygen.mantidproject.org> */ -class DLLExport FilterBadPulses : public API::Algorithm { +class DLLExport FilterBadPulses : public API::ParallelAlgorithm { public: const std::string name() const override; /// Summary of algorithms purpose diff --git a/Framework/Algorithms/inc/MantidAlgorithms/FilterByLogValue.h b/Framework/Algorithms/inc/MantidAlgorithms/FilterByLogValue.h index 3bd51a1cd9030a62b450f9d7e322a3c825a25f15..e55acb0d7fefeb9b1b51da8010f3b27a80be6661 100644 --- a/Framework/Algorithms/inc/MantidAlgorithms/FilterByLogValue.h +++ b/Framework/Algorithms/inc/MantidAlgorithms/FilterByLogValue.h @@ -1,11 +1,8 @@ #ifndef MANTID_ALGORITHMS_FILTERBYLOGVALUE_H_ #define MANTID_ALGORITHMS_FILTERBYLOGVALUE_H_ -//---------------------------------------------------------------------- -// Includes -//---------------------------------------------------------------------- #include "MantidKernel/System.h" -#include "MantidAPI/Algorithm.h" +#include "MantidAPI/ParallelAlgorithm.h" #include "MantidDataObjects/EventWorkspace.h" namespace Mantid { @@ -33,7 +30,7 @@ namespace Algorithms { File change history is stored at: <https://github.com/mantidproject/mantid>. Code Documentation is available at: <http://doxygen.mantidproject.org> */ -class DLLExport FilterByLogValue : public API::Algorithm { +class DLLExport FilterByLogValue : public API::ParallelAlgorithm { public: /// Algorithm's name for identification overriding a virtual method const std::string name() const override { return "FilterByLogValue"; }; diff --git a/Framework/Algorithms/inc/MantidAlgorithms/MaskBins.h b/Framework/Algorithms/inc/MantidAlgorithms/MaskBins.h index 0f3db6365d1d65fdb4eabe6061f82a89a4598c87..340ae9eb9341fac432631961f0ca59cd9ee3f5f6 100644 --- a/Framework/Algorithms/inc/MantidAlgorithms/MaskBins.h +++ b/Framework/Algorithms/inc/MantidAlgorithms/MaskBins.h @@ -1,10 +1,7 @@ #ifndef MANTID_ALGORITHMS_MASKBINS_H_ #define MANTID_ALGORITHMS_MASKBINS_H_ -//---------------------------------------------------------------------- -// Includes -//---------------------------------------------------------------------- -#include "MantidAPI/Algorithm.h" +#include "MantidAPI/ParallelAlgorithm.h" #include "MantidDataObjects/EventList.h" #include "MantidDataObjects/EventWorkspace.h" @@ -55,10 +52,8 @@ namespace Algorithms { File change history is stored at: <https://github.com/mantidproject/mantid> Code Documentation is available at: <http://doxygen.mantidproject.org> */ -class DLLExport MaskBins : public API::Algorithm { +class DLLExport MaskBins : public API::ParallelAlgorithm { public: - /// Constructor - MaskBins(); /// Algorithm's name const std::string name() const override { return "MaskBins"; } /// Summary of algorithms purpose @@ -82,10 +77,10 @@ private: MantidVec::difference_type &startBin, MantidVec::difference_type &endBin); - double m_startX; ///< The range start point - double m_endX; ///< The range end point - std::vector<int> - spectra_list; ///<the list of Spectra (workspace index) to load + double m_startX{0.0}; ///< The range start point + double m_endX{0.0}; ///< The range end point + Indexing::SpectrumIndexSet + indexSet; ///<the list of Spectra (workspace index) to load }; } // namespace Algorithms diff --git a/Framework/Algorithms/inc/MantidAlgorithms/RemovePromptPulse.h b/Framework/Algorithms/inc/MantidAlgorithms/RemovePromptPulse.h index 48d73311a8624613956ef471ee5453b2466e0252..c20a915bb7ea5cb957bec73a2ab950d5193fb58f 100644 --- a/Framework/Algorithms/inc/MantidAlgorithms/RemovePromptPulse.h +++ b/Framework/Algorithms/inc/MantidAlgorithms/RemovePromptPulse.h @@ -2,7 +2,7 @@ #define MANTID_ALGORITHMS_REMOVEPROMPTPULSE_H_ #include "MantidKernel/System.h" -#include "MantidAPI/Algorithm.h" +#include "MantidAPI/ParallelAlgorithm.h" #include "MantidAPI/Run.h" namespace Mantid { @@ -34,7 +34,7 @@ namespace Algorithms { File change history is stored at: <https://github.com/mantidproject/mantid> Code Documentation is available at: <http://doxygen.mantidproject.org> */ -class DLLExport RemovePromptPulse : public API::Algorithm { +class DLLExport RemovePromptPulse : public API::ParallelAlgorithm { public: /// Algorithm's name for identification const std::string name() const override; diff --git a/Framework/Algorithms/inc/MantidAlgorithms/SortEvents.h b/Framework/Algorithms/inc/MantidAlgorithms/SortEvents.h index 126c1b8ab62865baf8254eb1c7723f12212e3273..86b09cc5acd0e11d67daf364b793a7e5e18ab601 100644 --- a/Framework/Algorithms/inc/MantidAlgorithms/SortEvents.h +++ b/Framework/Algorithms/inc/MantidAlgorithms/SortEvents.h @@ -1,10 +1,7 @@ #ifndef MANTID_ALGORITHMS_SORTEVENTS_H_ #define MANTID_ALGORITHMS_SORTEVENTS_H_ -//---------------------------------------------------------------------- -// Includes -//---------------------------------------------------------------------- -#include "MantidAPI/Algorithm.h" +#include "MantidAPI/ParallelAlgorithm.h" namespace Mantid { namespace Algorithms { @@ -42,7 +39,7 @@ namespace Algorithms { File change history is stored at: <https://github.com/mantidproject/mantid> Code Documentation is available at: <http://doxygen.mantidproject.org> */ -class DLLExport SortEvents : public API::Algorithm { +class DLLExport SortEvents : public API::ParallelAlgorithm { public: /// Algorithm's name for identification overriding a virtual method const std::string name() const override { return "SortEvents"; } diff --git a/Framework/Algorithms/src/ChangePulsetime2.cpp b/Framework/Algorithms/src/ChangePulsetime2.cpp index 216ec74ce8d14a62e11845999b81c38292f06863..68b24d2cfb531f5539fc4f5d44462c0b14f93083 100644 --- a/Framework/Algorithms/src/ChangePulsetime2.cpp +++ b/Framework/Algorithms/src/ChangePulsetime2.cpp @@ -1,4 +1,5 @@ #include "MantidAlgorithms/ChangePulsetime2.h" +#include "MantidAPI/Algorithm.tcc" #include "MantidAPI/WorkspaceFactory.h" #include "MantidDataObjects/EventWorkspace.h" #include "MantidKernel/ArrayProperty.h" @@ -19,7 +20,8 @@ using std::size_t; /** Initialize the algorithm's properties. */ void ChangePulsetime2::init() { - declareWorkspaceInputProperties<EventWorkspace>("InputWorkspace"); + declareWorkspaceInputProperties<EventWorkspace>("InputWorkspace", + "An input event workspace."); declareProperty( make_unique<PropertyWithValue<double>>("TimeOffset", Direction::Input), "Number of seconds (a float) to add to each event's pulse " diff --git a/Framework/Algorithms/src/MaskBins.cpp b/Framework/Algorithms/src/MaskBins.cpp index 41ebbe2a3716c1931584222ceca918629711768c..8212595cde6d38d37ceab6b701708bc3457af780 100644 --- a/Framework/Algorithms/src/MaskBins.cpp +++ b/Framework/Algorithms/src/MaskBins.cpp @@ -1,11 +1,9 @@ -//---------------------------------------------------------------------- -// Includes -//---------------------------------------------------------------------- #include "MantidAlgorithms/MaskBins.h" #include "MantidAPI/HistogramValidator.h" #include "MantidAPI/WorkspaceFactory.h" #include "MantidKernel/ArrayProperty.h" #include "MantidKernel/BoundedValidator.h" +#include "MantidAPI/Algorithm.tcc" #include <limits> #include <sstream> @@ -20,19 +18,15 @@ DECLARE_ALGORITHM(MaskBins) using namespace Kernel; using namespace API; -using namespace Mantid; -using Mantid::DataObjects::EventWorkspace; -using Mantid::DataObjects::EventWorkspace_sptr; -using Mantid::DataObjects::EventWorkspace_const_sptr; - -MaskBins::MaskBins() : API::Algorithm(), m_startX(0.0), m_endX(0.0) {} +using DataObjects::EventWorkspace; +using DataObjects::EventWorkspace_sptr; +using DataObjects::EventWorkspace_const_sptr; void MaskBins::init() { - declareProperty( - make_unique<WorkspaceProperty<>>( - "InputWorkspace", "", Direction::Input, - boost::make_shared<HistogramValidator>()), - "The name of the input workspace. Must contain histogram data."); + declareWorkspaceInputProperties<MatrixWorkspace>( + "InputWorkspace", + "The name of the input workspace. Must contain histogram data.", + boost::make_shared<HistogramValidator>()); declareProperty(make_unique<WorkspaceProperty<>>("OutputWorkspace", "", Direction::Output), "The name of the Workspace containing the masked bins."); @@ -47,22 +41,14 @@ void MaskBins::init() { declareProperty("XMax", std::numeric_limits<double>::max(), required, "The value to end masking at."); - // which pixels to load this->declareProperty(make_unique<ArrayProperty<int>>("SpectraList"), - "Optional: A list of individual which spectra to mask " - "(specified using the workspace index). If not set, " - "all spectra are masked. Can be entered as a " - "comma-seperated list of values, or a range (such as " - "'a-b' which will include spectra with workspace index " - "of a to b inclusively)."); + "Deprecated, use InputWorkspaceIndexSet."); } /** Execution code. * @throw std::invalid_argument If XMax is less than XMin */ void MaskBins::exec() { - MatrixWorkspace_const_sptr inputWS = getProperty("InputWorkspace"); - // Check for valid X limits m_startX = getProperty("XMin"); m_endX = getProperty("XMax"); @@ -75,23 +61,21 @@ void MaskBins::exec() { throw std::invalid_argument(msg.str()); } - //--------------------------------------------------------------------------------- - // what spectra (workspace indices) to load. Optional. - this->spectra_list = this->getProperty("SpectraList"); - if (!this->spectra_list.empty()) { - const int numHist = static_cast<int>(inputWS->getNumberHistograms()); - //--- Validate spectra list --- - for (auto wi : this->spectra_list) { - if ((wi < 0) || (wi >= numHist)) { - std::ostringstream oss; - oss << "One of the workspace indices specified, " << wi - << " is above the number of spectra in the workspace (" << numHist - << ")."; - throw std::invalid_argument(oss.str()); - } - } + // Copy indices from legacy property + std::vector<int> spectraList = this->getProperty("SpectraList"); + if (!spectraList.empty()) { + if (!isDefault("InputWorkspaceIndexSet")) + throw std::runtime_error("Cannot provide both InputWorkspaceIndexSet and " + "SpectraList at the same time."); + setProperty("InputWorkspaceIndexSet", spectraList); + g_log.warning("The 'SpectraList' property is deprecated. Use " + "'InputWorkspaceIndexSet' instead."); } + MatrixWorkspace_sptr inputWS; + std::tie(inputWS, indexSet) = + getWorkspaceAndIndices<MatrixWorkspace>("InputWorkspace"); + // Only create the output workspace if it's different to the input one MatrixWorkspace_sptr outputWS = getProperty("OutputWorkspace"); if (outputWS != inputWS) { @@ -99,16 +83,9 @@ void MaskBins::exec() { setProperty("OutputWorkspace", outputWS); } - //--------------------------------------------------------------------------------- - // Now, determine if the input workspace is actually an EventWorkspace - EventWorkspace_const_sptr eventW = - boost::dynamic_pointer_cast<const EventWorkspace>(inputWS); - - if (eventW != nullptr) { - //------- EventWorkspace --------------------------- + if (boost::dynamic_pointer_cast<const EventWorkspace>(inputWS)) { this->execEvent(); } else { - //------- MatrixWorkspace of another kind ------------- MantidVec::difference_type startBin(0), endBin(0); // If the binning is the same throughout, we only need to find the index @@ -119,27 +96,11 @@ void MaskBins::exec() { this->findIndices(X, startBin, endBin); } - const int numHists = static_cast<int>(inputWS->getNumberHistograms()); - Progress progress(this, 0.0, 1.0, numHists); + Progress progress(this, 0.0, 1.0, indexSet.size()); // Parallel running has problems with a race condition, leading to // occaisional test failures and crashes - bool useSpectraList = (!this->spectra_list.empty()); - - // Alter the for loop ending based on what we are looping on - int for_end = numHists; - if (useSpectraList) - for_end = static_cast<int>(this->spectra_list.size()); - - for (int i = 0; i < for_end; ++i) { - // Find the workspace index, either based on the spectra list or all - // spectra - int wi; - if (useSpectraList) - wi = this->spectra_list[i]; - else - wi = i; - + for (const auto wi : indexSet) { MantidVec::difference_type startBinLoop(startBin), endBinLoop(endBin); if (!commonBins) this->findIndices(outputWS->binEdges(wi), startBinLoop, endBinLoop); @@ -150,9 +111,8 @@ void MaskBins::exec() { outputWS->maskBin(wi, j); } progress.report(); - - } // ENDFOR(i) - } // ENDIFELSE(eventworkspace?) + } + } } /** Execution code for EventWorkspaces @@ -161,38 +121,20 @@ void MaskBins::execEvent() { MatrixWorkspace_sptr outputMatrixWS = getProperty("OutputWorkspace"); auto outputWS = boost::dynamic_pointer_cast<EventWorkspace>(outputMatrixWS); - // set up the progress bar - const size_t numHists = outputWS->getNumberHistograms(); - Progress progress(this, 0.0, 1.0, numHists * 2); + Progress progress(this, 0.0, 1.0, outputWS->getNumberHistograms() * 2); - // sort the events outputWS->sortAll(Mantid::DataObjects::TOF_SORT, &progress); - // Go through all histograms - if (!this->spectra_list.empty()) { - // Specific spectra were specified - PARALLEL_FOR_IF(Kernel::threadSafe(*outputWS)) - for (int i = 0; i < static_cast<int>(this->spectra_list.size()); // NOLINT - ++i) { - PARALLEL_START_INTERUPT_REGION - outputWS->getSpectrum(this->spectra_list[i]).maskTof(m_startX, m_endX); - progress.report(); - PARALLEL_END_INTERUPT_REGION - } - PARALLEL_CHECK_INTERUPT_REGION - } else { - // Do all spectra! - PARALLEL_FOR_IF(Kernel::threadSafe(*outputWS)) - for (int64_t i = 0; i < int64_t(numHists); ++i) { - PARALLEL_START_INTERUPT_REGION - outputWS->getSpectrum(i).maskTof(m_startX, m_endX); - progress.report(); - PARALLEL_END_INTERUPT_REGION - } - PARALLEL_CHECK_INTERUPT_REGION + PARALLEL_FOR_IF(Kernel::threadSafe(*outputWS)) + for (int i = 0; i < static_cast<int>(indexSet.size()); // NOLINT + ++i) { + PARALLEL_START_INTERUPT_REGION + outputWS->getSpectrum(indexSet[i]).maskTof(m_startX, m_endX); + progress.report(); + PARALLEL_END_INTERUPT_REGION } + PARALLEL_CHECK_INTERUPT_REGION - // Clear the MRU outputWS->clearMRU(); } diff --git a/Framework/Algorithms/test/ChangePulsetime2Test.h b/Framework/Algorithms/test/ChangePulsetime2Test.h index 82e15ebe9c9e8371c318eb85c936015a3416f97f..00186cc1e5882b48330ddbbcf295a6761a2e9c19 100644 --- a/Framework/Algorithms/test/ChangePulsetime2Test.h +++ b/Framework/Algorithms/test/ChangePulsetime2Test.h @@ -5,6 +5,7 @@ #include "MantidKernel/Timer.h" #include <cxxtest/TestSuite.h> +#include "MantidAPI/Algorithm.tcc" #include "MantidAlgorithms/ChangePulsetime2.h" #include "MantidDataObjects/EventWorkspace.h" #include "MantidTestHelpers/WorkspaceCreationHelper.h" diff --git a/Framework/DataHandling/inc/MantidDataHandling/CompressEvents.h b/Framework/DataHandling/inc/MantidDataHandling/CompressEvents.h index e9f1ea84fdb3b94fb84dae8ebd9e8e43bfc6e2f4..aed79f9023a03f767d8f73a7e579ae345568cabe 100644 --- a/Framework/DataHandling/inc/MantidDataHandling/CompressEvents.h +++ b/Framework/DataHandling/inc/MantidDataHandling/CompressEvents.h @@ -1,10 +1,7 @@ #ifndef MANTID_DATAHANDLING_COMPRESSEVENTS_H_ #define MANTID_DATAHANDLING_COMPRESSEVENTS_H_ -//---------------------------------------------------------------------- -// Includes -//---------------------------------------------------------------------- -#include "MantidAPI/Algorithm.h" +#include "MantidAPI/ParallelAlgorithm.h" namespace Mantid { namespace DataHandling { @@ -43,7 +40,7 @@ namespace DataHandling { File change history is stored at: <https://github.com/mantidproject/mantid>. Code Documentation is available at: <http://doxygen.mantidproject.org> */ -class DLLExport CompressEvents : public API::Algorithm { +class DLLExport CompressEvents : public API::ParallelAlgorithm { public: /// Algorithm's name for identification overriding a virtual method const std::string name() const override { return "CompressEvents"; }; diff --git a/Framework/DataHandling/src/CompressEvents.cpp b/Framework/DataHandling/src/CompressEvents.cpp index 3a8ae8b8257fc9e4b5884db7355094440ca706fb..02f1a12dfe1c726dc5b860ce4087c896b55dd48a 100644 --- a/Framework/DataHandling/src/CompressEvents.cpp +++ b/Framework/DataHandling/src/CompressEvents.cpp @@ -1,6 +1,7 @@ #include "MantidDataHandling/CompressEvents.h" #include "MantidAPI/WorkspaceFactory.h" #include "MantidDataObjects/EventWorkspace.h" +#include "MantidDataObjects/WorkspaceCreation.h" #include "MantidKernel/ArrayProperty.h" #include "MantidKernel/BoundedValidator.h" @@ -56,13 +57,7 @@ void CompressEvents::exec() { // Are we making a copy of the input workspace? if (!inplace) { - // Make a brand new EventWorkspace - outputWS = boost::dynamic_pointer_cast<EventWorkspace>( - API::WorkspaceFactory::Instance().create( - "EventWorkspace", inputWS->getNumberHistograms(), 2, 1)); - // Copy geometry over. - API::WorkspaceFactory::Instance().initializeFromParent(*inputWS, *outputWS, - false); + outputWS = create<EventWorkspace>(*inputWS, HistogramData::BinEdges(2)); // We DONT copy the data though // Loop over the histograms (detector spectra) tbb::parallel_for(tbb::blocked_range<size_t>(0, noSpectra), diff --git a/Framework/DataObjects/src/EventWorkspace.cpp b/Framework/DataObjects/src/EventWorkspace.cpp index ddbe44ba71f4d9657f2041f26522bf4513fe5f83..f4e4007c187de2c092ec45e64c891f25bb7c0450 100644 --- a/Framework/DataObjects/src/EventWorkspace.cpp +++ b/Framework/DataObjects/src/EventWorkspace.cpp @@ -1,4 +1,5 @@ #include "MantidDataObjects/EventWorkspace.h" +#include "MantidAPI/Algorithm.h" #include "MantidAPI/ISpectrum.h" #include "MantidAPI/Progress.h" #include "MantidAPI/RefAxis.h" @@ -17,7 +18,6 @@ #include "MantidKernel/MultiThreaded.h" #include "MantidKernel/TimeSeriesProperty.h" -#include "MantidAPI/Algorithm.tcc" #include "tbb/parallel_for.h" #include <limits> #include <numeric> @@ -674,45 +674,6 @@ void EventWorkspace::getIntegratedSpectra(std::vector<double> &out, } // namespace DataObjects } // namespace Mantid -// Explicit Instantiations of IndexProperty Methods in Algorithm -namespace Mantid { -namespace API { -template DLLExport void -Algorithm::declareWorkspaceInputProperties<DataObjects::EventWorkspace>( - const std::string &propertyName, const int allowedIndexTypes, - PropertyMode::Type optional, LockMode::Type lock, const std::string &doc); - -template DLLExport void -Algorithm::setWorkspaceInputProperties<DataObjects::EventWorkspace, - std::vector<int>>( - const std::string &name, const DataObjects::EventWorkspace_sptr &wksp, - IndexType type, const std::vector<int> &list); - -template DLLExport void -Algorithm::setWorkspaceInputProperties<DataObjects::EventWorkspace, - std::string>( - const std::string &name, const DataObjects::EventWorkspace_sptr &wksp, - IndexType type, const std::string &list); - -template DLLExport void -Algorithm::setWorkspaceInputProperties<DataObjects::EventWorkspace, - std::vector<int>>( - const std::string &name, const std::string &wsName, IndexType type, - const std::vector<int> &list); - -template DLLExport void -Algorithm::setWorkspaceInputProperties<DataObjects::EventWorkspace, - std::string>(const std::string &name, - const std::string &wsName, - IndexType type, - const std::string &list); - -template DLLExport std::tuple<boost::shared_ptr<DataObjects::EventWorkspace>, - Indexing::SpectrumIndexSet> -Algorithm::getWorkspaceAndIndices(const std::string &name) const; -} // namespace API -} // namespace Mantid - namespace Mantid { namespace Kernel { template <> diff --git a/docs/source/concepts/IndexProperty.rst b/docs/source/concepts/IndexProperty.rst index d06729582d201f97cb12186a3e436e1a2032e176..966cf8ebe3ba981133954926d01abc761220fec7 100644 --- a/docs/source/concepts/IndexProperty.rst +++ b/docs/source/concepts/IndexProperty.rst @@ -44,14 +44,21 @@ Property declaration is as shown below: .. code-block:: cpp - //Declare property with default settings + #include "MantidAPI/Algorithm.tcc" + + // Declare property with default settings // IndexType::WorkspaceIndex is default - declareWorkspaceInputProperties<MatrixWorkspace>("InputWorkspace"); - - //Declare all arguments - declareWorkspaceInputProperties<MatrixWorkspace>("InputWorkspace", - IndexType::SpectrumNum|IndexType::WorkspaceIndex, PropertyMode::Type::Mandatory, - LockMode::Type::Lock, "This is an input workspace with associated index handling") + declareWorkspaceInputProperties<MatrixWorkspace>( + "InputWorkspace", + "This is an input workspace with associated index handling"); + + // Declare all arguments + declareWorkspaceInputProperties<MatrixWorkspace, + IndexType::SpectrumNum | IndexType::WorkspaceIndex>( + "InputWorkspace", + "This is an input workspace with associated index handling" + /* optional PropertyMode, LockMode, and validator forwarded to WorkspaceProperty */); + Internally, a ``WorkspaceProperty`` is created along with an ``IndexTypeProperty`` for managing the workspace and the type of user-defined input index list respectively. Their names are diff --git a/docs/source/development/AlgorithmMPISupport.rst b/docs/source/development/AlgorithmMPISupport.rst index e4ce3b67b4a15af11e79947f477b19628729dce8..06d5ee74fdbab6eaa2725dd81db3aeb43169b6f4 100644 --- a/docs/source/development/AlgorithmMPISupport.rst +++ b/docs/source/development/AlgorithmMPISupport.rst @@ -454,12 +454,18 @@ Supported Algorithms ================= =============== ======== Algorithm Supported modes Comments ================= =============== ======== +CompressEvents all CreateWorkspace all +FilterBadPulses all +FilterByLogValue all LoadEventNexus Distributed storage mode of output cannot be changed via a parameter currently, min and max bin boundary are not globally the same LoadInstrument all LoadNexusLogs all LoadParameterFile all segfaults when used in unit tests with MPI threading backend due to `#9365 <https://github.com/mantidproject/mantid/issues/9365>`_, normal use should be ok +MaskBins all Rebin all min and max bin boundaries must be given explicitly +RemovePromptPulse all +SortEvents all ================= =============== ======== .. rubric:: Footnotes diff --git a/docs/source/release/v3.12.0/framework.rst b/docs/source/release/v3.12.0/framework.rst index 6b6eed76cd9adb64b0492a33f27d810a460cab79..6b9e84934a55dcd01114f7af196ae37a089f3bb1 100644 --- a/docs/source/release/v3.12.0/framework.rst +++ b/docs/source/release/v3.12.0/framework.rst @@ -27,6 +27,7 @@ Algorithms - :ref:`ConjoinWorkspaces <algm-ConjoinWorkspaces>` now supports non-constant bins. - :ref:`Fit <algm-Fit>` will now respect excluded ranges when ``CostFunction = 'Unweighted least squares'``. - :ref:`NormaliseToMonitor <algm-NormaliseToMonitor>` now supports non-constant number of bins. +- :ref:`MaskBins <algm-MaskBins>` now uses a modernized and standardized way for providing a list of workspace indices. For compatibility reasons the previous ``SpectraList`` property is still supported. Core Functionality ------------------