diff --git a/Framework/Algorithms/src/MaskBins.cpp b/Framework/Algorithms/src/MaskBins.cpp index 48d53e6ecb2b3d31e00387df4b21438c81efd572..e964c3687154f3b11db6c3fa6b2d7c1372e352bc 100644 --- a/Framework/Algorithms/src/MaskBins.cpp +++ b/Framework/Algorithms/src/MaskBins.cpp @@ -64,6 +64,9 @@ void MaskBins::exec() { // Copy indices from legacy property std::vector<int64_t> 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."); @@ -93,8 +96,7 @@ void MaskBins::exec() { this->findIndices(X, startBin, endBin); } - const int numHists = static_cast<int>(indexSet.size()); - 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 @@ -119,14 +121,10 @@ 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 PARALLEL_FOR_IF(Kernel::threadSafe(*outputWS)) for (int i = 0; i < static_cast<int>(indexSet.size()); // NOLINT ++i) { diff --git a/Framework/DataHandling/inc/MantidDataHandling/LoadISISNexus2.h b/Framework/DataHandling/inc/MantidDataHandling/LoadISISNexus2.h index fa4c6c961299213cf19aa2ff19d569929549cbb5..2954b9871a857df3bbdb390ee345ad5fa9332fcc 100644 --- a/Framework/DataHandling/inc/MantidDataHandling/LoadISISNexus2.h +++ b/Framework/DataHandling/inc/MantidDataHandling/LoadISISNexus2.h @@ -147,6 +147,9 @@ private: void buildSpectraInd2SpectraNumMap(bool range_supplied, bool hasSpectraList, DataBlockComposite &dataBlockComposite); + /// Check if any of the spectra block ranges overlap + void checkOverlappingSpectraRange(); + /// The name and path of the input file std::string m_filename; /// The instrument name from Nexus diff --git a/Framework/DataHandling/src/LoadISISNexus2.cpp b/Framework/DataHandling/src/LoadISISNexus2.cpp index 370fef1cfddfd85ff5f1e05cee7436f52b0cfdf9..9f3a54baf0b857cd1f84b789cc2f9cfc01f5e0eb 100644 --- a/Framework/DataHandling/src/LoadISISNexus2.cpp +++ b/Framework/DataHandling/src/LoadISISNexus2.cpp @@ -696,18 +696,6 @@ void LoadISISNexus2::buildSpectraInd2SpectraNumMap( } } -namespace { -/// Compare two spectra blocks for ordering -bool compareSpectraBlocks(const LoadISISNexus2::SpectraBlock &block1, - const LoadISISNexus2::SpectraBlock &block2) { - bool res = block1.last < block2.first; - if (!res) { - assert(block2.last < block1.first); - } - return res; -} -} - /** * Analyze the spectra ranges and prepare a list contiguous blocks. Each monitor * must be @@ -738,7 +726,11 @@ LoadISISNexus2::prepareSpectraBlocks(std::map<int64_t, std::string> &monitors, // sort and check for overlapping if (m_spectraBlocks.size() > 1) { std::sort(m_spectraBlocks.begin(), m_spectraBlocks.end(), - compareSpectraBlocks); + [](const LoadISISNexus2::SpectraBlock &block1, + const LoadISISNexus2::SpectraBlock &block2) { + return block1.last < block2.first; + }); + checkOverlappingSpectraRange(); } // Remove monitors that have been used. @@ -765,14 +757,34 @@ LoadISISNexus2::prepareSpectraBlocks(std::map<int64_t, std::string> &monitors, } /** -* Load a given period into the workspace -* @param period :: The period number to load (starting from 1) -* @param entry :: The opened root entry node for accessing the monitor and data -* nodes -* @param local_workspace :: The workspace to place the data in -* @param update_spectra2det_mapping :: reset spectra-detector map to the one -* calculated earlier. (Warning! -- this map has to be calculated correctly!) -*/ + * Check if any spectra block ranges overlap. + * + * Iterate over the sorted list of spectra blocks and check + * if the last element of the preceeding block is less than + * the first element of the next block. + */ +void LoadISISNexus2::checkOverlappingSpectraRange() { + for (size_t i = 1; i < m_spectraBlocks.size(); ++i) { + const auto &block1 = m_spectraBlocks[i - 1]; + const auto &block2 = m_spectraBlocks[i]; + if (block1.first > block1.last && block2.first > block2.last) + throw std::runtime_error("LoadISISNexus2: inconsistent spectra ranges"); + if (block1.last >= block2.first) { + throw std::runtime_error( + "LoadISISNexus2: the range of SpectraBlocks must not overlap"); + } + } +} + +/** + * Load a given period into the workspace + * @param period :: The period number to load (starting from 1) + * @param entry :: The opened root entry node for accessing the monitor and data + * nodes + * @param local_workspace :: The workspace to place the data in + * @param update_spectra2det_mapping :: reset spectra-detector map to the one + * calculated earlier. (Warning! -- this map has to be calculated correctly!) + */ void LoadISISNexus2::loadPeriodData( int64_t period, NXEntry &entry, DataObjects::Workspace2D_sptr &local_workspace, 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 ------------------