diff --git a/Framework/Algorithms/inc/MantidAlgorithms/BinaryOperation.h b/Framework/Algorithms/inc/MantidAlgorithms/BinaryOperation.h index 16b3392f45c303a2504dcb688b80f617cb5be066..09131b4b35ac9cd2fc37208f9dccf83829ecacce 100644 --- a/Framework/Algorithms/inc/MantidAlgorithms/BinaryOperation.h +++ b/Framework/Algorithms/inc/MantidAlgorithms/BinaryOperation.h @@ -218,6 +218,10 @@ protected: bool m_AllowDifferentNumberSpectra{false}; /// Flag to clear RHS workspace in binary operation bool m_ClearRHSWorkspace{false}; + /// Cache for LHS workspace's blocksize + size_t m_lhsBlocksize; + /// Cache for RHS workspace's blocksize + size_t m_rhsBlocksize; //------ Requirements ----------- diff --git a/Framework/Algorithms/src/ApplyFloodWorkspace.cpp b/Framework/Algorithms/src/ApplyFloodWorkspace.cpp index cd2294d7d2aad6fc6ad20e89ad5a257179efee4b..f737002dee067dec5607d93336b620f0cb6035fa 100644 --- a/Framework/Algorithms/src/ApplyFloodWorkspace.cpp +++ b/Framework/Algorithms/src/ApplyFloodWorkspace.cpp @@ -43,6 +43,7 @@ MatrixWorkspace_sptr makeEqualSizes(const MatrixWorkspace_sptr &input, auto newFlood = WorkspaceFactory::Instance().create(flood, input->getNumberHistograms()); auto const table = BinaryOperation::buildBinaryOperationTable(input, flood); + auto const floodBlocksize = flood->blocksize(); const ISpectrum *missingSpectrum = nullptr; for (size_t i = 0; i < table->size(); ++i) { auto const j = (*table)[i]; @@ -50,8 +51,8 @@ MatrixWorkspace_sptr makeEqualSizes(const MatrixWorkspace_sptr &input, if (missingSpectrum) { newFlood->getSpectrum(i).copyDataFrom(*missingSpectrum); } else { - newFlood->dataY(i).assign(flood->blocksize(), 1.0); - newFlood->dataE(i).assign(flood->blocksize(), 0.0); + newFlood->dataY(i).assign(floodBlocksize, 1.0); + newFlood->dataE(i).assign(floodBlocksize, 0.0); missingSpectrum = &newFlood->getSpectrum(i); } } else { diff --git a/Framework/Algorithms/src/BinaryOperation.cpp b/Framework/Algorithms/src/BinaryOperation.cpp index ae226187b58f2fc88543aadfbce4fbab127b9e1b..4e7f8a22583a7588e4aeb52075be70be50fd4851 100644 --- a/Framework/Algorithms/src/BinaryOperation.cpp +++ b/Framework/Algorithms/src/BinaryOperation.cpp @@ -151,6 +151,9 @@ void BinaryOperation::exec() { m_rhs = getProperty(inputPropName2()); m_AllowDifferentNumberSpectra = getProperty("AllowDifferentNumberSpectra"); + m_lhsBlocksize = m_lhs->blocksize(); + m_rhsBlocksize = m_rhs->blocksize(); + // Special handling for 1-WS and 1/WS. if (this->handleSpecialDivideMinus()) return; @@ -185,6 +188,7 @@ void BinaryOperation::exec() { // Flip the workspaces left and right std::swap(m_lhs, m_rhs); std::swap(m_elhs, m_erhs); + std::swap(m_lhsBlocksize, m_rhsBlocksize); } // Check that the input workspaces are compatible @@ -264,7 +268,7 @@ void BinaryOperation::exec() { } // Single column on rhs; if the RHS is an event workspace with one bin, it is // treated as a scalar. - else if ((m_rhs->blocksize() == 1) && !m_do2D_even_for_SingleColumn_on_rhs) { + else if ((m_rhsBlocksize == 1) && !m_do2D_even_for_SingleColumn_on_rhs) { doSingleColumn(); } else // The two are both 2D and should be the same size (except if LHS is an // event workspace) @@ -318,15 +322,15 @@ bool BinaryOperation::checkCompatibility( const std::string rhs_unitID = (rhs_unit ? rhs_unit->unitID() : ""); // Check the workspaces have the same units and distribution flag - if (lhs_unitID != rhs_unitID && lhs->blocksize() > 1 && - rhs->blocksize() > 1) { + if (lhs_unitID != rhs_unitID && m_lhsBlocksize > 1 && m_rhsBlocksize > 1) { g_log.error("The two workspace are not compatible because they have " "different units on the X axis."); return false; } // Check the size compatibility - std::string checkSizeCompatibilityResult = checkSizeCompatibility(lhs, rhs); + const std::string checkSizeCompatibilityResult = + checkSizeCompatibility(lhs, rhs); if (!checkSizeCompatibilityResult.empty()) { throw std::invalid_argument(checkSizeCompatibilityResult); } @@ -383,7 +387,7 @@ std::string BinaryOperation::checkSizeCompatibility( } // Otherwise they must match both ways, or horizontally or vertically with the // other rhs dimension=1 - if (rhs->blocksize() == 1 && + if (m_rhsBlocksize == 1 && lhs->getNumberHistograms() == rhs->getNumberHistograms()) return ""; // Past this point, we require the X arrays to match. Note this only checks @@ -395,7 +399,7 @@ std::string BinaryOperation::checkSizeCompatibility( const size_t rhsSpec = rhs->getNumberHistograms(); - if (lhs->blocksize() == rhs->blocksize()) { + if (m_lhsBlocksize == m_rhsBlocksize) { if (rhsSpec == 1 || lhs->getNumberHistograms() == rhsSpec) { return ""; } else { diff --git a/Framework/Algorithms/src/Divide.cpp b/Framework/Algorithms/src/Divide.cpp index 5393477f442f2c18a22f70348f2907f88819968c..e1b6af0bf6944cfa74a7e06e886ab8838d6f1641 100644 --- a/Framework/Algorithms/src/Divide.cpp +++ b/Framework/Algorithms/src/Divide.cpp @@ -89,7 +89,7 @@ void Divide::setOutputUnits(const API::MatrixWorkspace_const_sptr lhs, } // If the Y units match, then the output will be a distribution and will be // dimensionless - else if (lhs->YUnit() == rhs->YUnit() && rhs->blocksize() > 1) { + else if (lhs->YUnit() == rhs->YUnit() && m_rhsBlocksize > 1) { out->setYUnit(""); out->setDistribution(true); } @@ -205,11 +205,10 @@ std::string Divide::checkSizeCompatibility( // If RHS only has one value (1D vertical), the number of histograms needs to // match. // Each lhs spectrum will be divided by that scalar - // std::cout << "rhs->blocksize() " << rhs->blocksize() << '\n'; // Are we allowing the division by different # of spectra, using detector IDs // to match up? if (m_AllowDifferentNumberSpectra || - (rhs->blocksize() == 1 && + (m_rhsBlocksize == 1 && lhs->getNumberHistograms() == rhs->getNumberHistograms())) { return ""; } diff --git a/Framework/Algorithms/src/Multiply.cpp b/Framework/Algorithms/src/Multiply.cpp index 83bc720760c45e84931a616593b3e8803041f3d7..f078e9affbf8a9d884dedc6a42cf0ca44593fae9 100644 --- a/Framework/Algorithms/src/Multiply.cpp +++ b/Framework/Algorithms/src/Multiply.cpp @@ -123,7 +123,7 @@ void Multiply::checkRequirements() { m_flipSides = (m_rhs->size() > m_lhs->size()); // Both are vertical columns with one bin? - if ((m_rhs->blocksize() == 1) && (m_lhs->blocksize() == 1)) { + if ((m_rhsBlocksize == 1) && (m_lhsBlocksize == 1)) { // Flip it if the RHS is event and you could keep events if (m_erhs && !m_elhs) m_flipSides = true; @@ -177,7 +177,7 @@ std::string Multiply::checkSizeCompatibility( // RHS only has one value (1D vertical), so the number of histograms needs // to match. // Each lhs spectrum will be divided by that scalar - if (rhs->blocksize() == 1 && + if (m_rhsBlocksize == 1 && lhs->getNumberHistograms() == rhs->getNumberHistograms()) return ""; diff --git a/Framework/Algorithms/src/NormaliseToMonitor.cpp b/Framework/Algorithms/src/NormaliseToMonitor.cpp index 42548ea8bf45fe88602208c960acedb18b78f72d..45234084a9e6f121ab0682724761e4554e5de038 100644 --- a/Framework/Algorithms/src/NormaliseToMonitor.cpp +++ b/Framework/Algorithms/src/NormaliseToMonitor.cpp @@ -697,6 +697,7 @@ void NormaliseToMonitor::normaliseBinByBin( const auto &inputSpecInfo = inputWorkspace->spectrumInfo(); const auto &monitorSpecInfo = m_monitor->spectrumInfo(); + const auto specLength = inputWorkspace->blocksize(); for (auto &workspaceIndex : m_workspaceIndexes) { // Get hold of the monitor spectrum const auto &monX = m_monitor->binEdges(workspaceIndex); @@ -711,7 +712,6 @@ void NormaliseToMonitor::normaliseBinByBin( this->normalisationFactor(monX, monY, monE); const size_t numHists = inputWorkspace->getNumberHistograms(); - auto specLength = inputWorkspace->blocksize(); // Flag set when a division by 0 is found bool hasZeroDivision = false; Progress prog(this, 0.0, 1.0, numHists); diff --git a/Framework/Algorithms/src/SofQWPolygon.cpp b/Framework/Algorithms/src/SofQWPolygon.cpp index c79f5589721f76310eb9645a423fb856c0b3034a..ddb1c0557cb680fb218a2167544c852eea3a9ab0 100644 --- a/Framework/Algorithms/src/SofQWPolygon.cpp +++ b/Framework/Algorithms/src/SofQWPolygon.cpp @@ -49,8 +49,9 @@ void SofQWPolygon::exec() { } // Progress reports & cancellation - const size_t nreports(static_cast<size_t>(inputWS->getNumberHistograms() * - inputWS->blocksize())); + const auto blocksize = inputWS->blocksize(); + const size_t nreports( + static_cast<size_t>(inputWS->getNumberHistograms() * blocksize)); m_progress = boost::shared_ptr<API::Progress>( new API::Progress(this, 0.0, 1.0, nreports)); // Compute input caches @@ -61,7 +62,7 @@ void SofQWPolygon::exec() { *inputWS, getProperty("QAxisBinning"), m_Qout, getProperty("EAxisBinning"), m_EmodeProperties); setProperty("OutputWorkspace", outputWS); - const size_t nenergyBins = inputWS->blocksize(); + const size_t nenergyBins = blocksize; const size_t nTheta = m_thetaPts.size(); const auto &X = inputWS->x(0); diff --git a/Framework/Algorithms/test/BinaryOperationTest.h b/Framework/Algorithms/test/BinaryOperationTest.h index 8b54ea141d9cf26b29a02c548e5f4fe2e3df6754..44a13b341f07609300e3acf9fb7ccf6c89d17bc7 100644 --- a/Framework/Algorithms/test/BinaryOperationTest.h +++ b/Framework/Algorithms/test/BinaryOperationTest.h @@ -47,6 +47,8 @@ public: const MatrixWorkspace_const_sptr ws2) { m_lhs = ws1; m_rhs = ws2; + m_lhsBlocksize = ws1->blocksize(); + m_rhsBlocksize = ws2->blocksize(); BinaryOperation::checkRequirements(); return BinaryOperation::checkSizeCompatibility(ws1, ws2); } diff --git a/Framework/Algorithms/test/CommutativeBinaryOperationTest.h b/Framework/Algorithms/test/CommutativeBinaryOperationTest.h index 200e1a23ff7aa847e398f1b01e6c702729123ed8..a63010961f75899e3a32376e0b5be8d3b29aee3a 100644 --- a/Framework/Algorithms/test/CommutativeBinaryOperationTest.h +++ b/Framework/Algorithms/test/CommutativeBinaryOperationTest.h @@ -39,6 +39,8 @@ public: const MatrixWorkspace_const_sptr ws2) { m_lhs = ws1; m_rhs = ws2; + m_lhsBlocksize = ws1->blocksize(); + m_rhsBlocksize = ws2->blocksize(); BinaryOperation::checkRequirements(); return CommutativeBinaryOperation::checkSizeCompatibility(ws1, ws2); } diff --git a/Framework/Crystal/src/CentroidPeaks.cpp b/Framework/Crystal/src/CentroidPeaks.cpp index 55627c3ac9b4f29e5bf245d185d51ec55b21f5e4..1bc4666055af647425ae13ae5ee98ea6f7db6759 100644 --- a/Framework/Crystal/src/CentroidPeaks.cpp +++ b/Framework/Crystal/src/CentroidPeaks.cpp @@ -95,6 +95,7 @@ void CentroidPeaks::integrate() { } } + const int inBlocksize = static_cast<int>(inWS->blocksize()); int Edge = getProperty("EdgePixels"); Progress prog(this, MinPeaks, 1.0, MaxPeaks); PARALLEL_FOR_IF(Kernel::threadSafe(*inWS, *peakWS)) @@ -154,7 +155,7 @@ void CentroidPeaks::integrate() { col = int(colcentroid / intensity); boost::algorithm::clamp(col, 0, nCols - 1); chan = int(chancentroid / intensity); - boost::algorithm::clamp(chan, 0, static_cast<int>(inWS->blocksize())); + boost::algorithm::clamp(chan, 0, inBlocksize); // Set wavelength to change tof for peak object if (!edgePixel(inst, bankName, col, row, Edge)) { diff --git a/Framework/PythonInterface/plugins/algorithms/CalibrateRectangularDetectors.py b/Framework/PythonInterface/plugins/algorithms/CalibrateRectangularDetectors.py index f8e2d32dbe5cd7b314f017ed9b44b9404eecbc16..95e057e0c84a0ddd908e7bdd5393d5d7832e380a 100644 --- a/Framework/PythonInterface/plugins/algorithms/CalibrateRectangularDetectors.py +++ b/Framework/PythonInterface/plugins/algorithms/CalibrateRectangularDetectors.py @@ -235,9 +235,9 @@ class CalibrateRectangularDetectors(PythonAlgorithm): #Find good peak for reference ymax = 0 + midBin = int(mtd[wksp].blocksize()/2) for s in range(0,mtd[wksp].getNumberHistograms()): y_s = mtd[wksp].readY(s) - midBin = int(mtd[wksp].blocksize()/2) if y_s[midBin] > ymax: refpixel = s ymax = y_s[midBin] @@ -265,9 +265,9 @@ class CalibrateRectangularDetectors(PythonAlgorithm): Params=str(self._peakmin2)+","+str(abs(self._binning[1]))+","+str(self._peakmax2)) #Find good peak for reference ymax = 0 + midBin = int(mtd[wksp].blocksize()/2) for s in range(0,mtd[wksp].getNumberHistograms()): y_s = mtd[wksp].readY(s) - midBin = int(mtd[wksp].blocksize()/2) if y_s[midBin] > ymax: refpixel = s ymax = y_s[midBin] @@ -296,9 +296,9 @@ class CalibrateRectangularDetectors(PythonAlgorithm): Params=str(self._peakmin3)+","+str(abs(self._binning[1]))+","+str(self._peakmax3)) #Find good peak for reference ymax = 0 + midBin = mtd[wksp].blocksize()/2 for s in range(0,mtd[wksp].getNumberHistograms()): y_s = mtd[wksp].readY(s) - midBin = mtd[wksp].blocksize()/2 if y_s[midBin] > ymax: refpixel = s ymax = y_s[midBin] diff --git a/Framework/PythonInterface/plugins/algorithms/EnggVanadiumCorrections.py b/Framework/PythonInterface/plugins/algorithms/EnggVanadiumCorrections.py index a20c264c8842883846d0de7114646afa42c6619f..edc703ec6b077794bf2ba5eecb5a6f64cc52b091 100644 --- a/Framework/PythonInterface/plugins/algorithms/EnggVanadiumCorrections.py +++ b/Framework/PythonInterface/plugins/algorithms/EnggVanadiumCorrections.py @@ -147,8 +147,9 @@ class EnggVanadiumCorrections(PythonAlgorithm): @param van_integration_ws :: pre-calculated integral of every spectrum for the Vanadium data @param van_curves_ws :: pre-calculated per-bank curves from the Vanadium data """ + blocksize = van_curves_ws.blocksize() for i in range(0, ws.getNumberHistograms()): - scale_factor = van_integration_ws.cell(i, 0) / van_curves_ws.blocksize() + scale_factor = van_integration_ws.cell(i, 0) / blocksize ws.setY(i, np.divide(ws.dataY(i), scale_factor)) def _apply_pix_by_pix_correction(self, ws, van_curves_ws): diff --git a/Framework/PythonInterface/plugins/algorithms/WorkflowAlgorithms/PowderDiffILLDetEffCorr.py b/Framework/PythonInterface/plugins/algorithms/WorkflowAlgorithms/PowderDiffILLDetEffCorr.py index c9e052459d42cee91fb923e2d1c3d1d270db0cbe..492b82c2ed49bc93f33a3e4dc87a1832dc145bbd 100644 --- a/Framework/PythonInterface/plugins/algorithms/WorkflowAlgorithms/PowderDiffILLDetEffCorr.py +++ b/Framework/PythonInterface/plugins/algorithms/WorkflowAlgorithms/PowderDiffILLDetEffCorr.py @@ -538,17 +538,19 @@ class PowderDiffILLDetEffCorr(PythonAlgorithm): if self._out_response: # take care of combined response end = self._bin_offset + response = mtd[response_ws] + responseBlockSize = response.blocksize() if det == self._pixel_range[1] - 1: end = self._scan_points - self._bin_offset for scan_point in range(0, self._bin_offset): - index = mtd[response_ws].blocksize() - self._bin_offset + scan_point - mtd[response_ws].dataY(0)[index] = mtd[ws].readY(0)[end + scan_point] - mtd[response_ws].dataE(0)[index] = mtd[ws].readE(0)[end + scan_point] + index = responseBlockSize - self._bin_offset + scan_point + response.dataY(0)[index] = mtd[ws].readY(0)[end + scan_point] + response.dataE(0)[index] = mtd[ws].readE(0)[end + scan_point] for scan_point in range(0, end): index = det * self._bin_offset + scan_point - mtd[response_ws].dataY(0)[index] = mtd[ref_ws].readY(0)[scan_point] - mtd[response_ws].dataE(0)[index] = mtd[ref_ws].readE(0)[scan_point] + response.dataY(0)[index] = mtd[ref_ws].readY(0)[scan_point] + response.dataE(0)[index] = mtd[ref_ws].readE(0)[scan_point] DeleteWorkspace(ws) # end of loop over pixels diff --git a/MantidPlot/src/Mantid/MantidSurfaceContourPlotGenerator.cpp b/MantidPlot/src/Mantid/MantidSurfaceContourPlotGenerator.cpp index bdcd272f94f74ca0c8910e37ebc2c5cf1f1ef543..3a795cc574bf2714da90ddc8d2151b63ccc2a7d5 100644 --- a/MantidPlot/src/Mantid/MantidSurfaceContourPlotGenerator.cpp +++ b/MantidPlot/src/Mantid/MantidSurfaceContourPlotGenerator.cpp @@ -166,10 +166,11 @@ MantidSurfaceContourPlotGenerator::createWorkspaceForGroupPlot( // If it's a contour plot, make a histo workspace. const auto xMode = graphType == Type::Contour ? Histogram::XMode::BinEdges : Histogram::XMode::Points; - const auto xSize = graphType == Type::Contour ? firstWS->blocksize() + 1 - : firstWS->blocksize(); + const auto firstBlocksize = firstWS->blocksize(); + const auto xSize = + graphType == Type::Contour ? firstBlocksize + 1 : firstBlocksize; matrixWS = Mantid::API::WorkspaceFactory::Instance().create( - firstWS, nWorkspaces, xSize, firstWS->blocksize()); + firstWS, nWorkspaces, xSize, firstBlocksize); matrixWS->setYUnitLabel(firstWS->YUnitLabel()); // For each workspace in group, add data and log values diff --git a/qt/scientific_interfaces/Indirect/ApplyAbsorptionCorrections.cpp b/qt/scientific_interfaces/Indirect/ApplyAbsorptionCorrections.cpp index f780905f3bcdaf5d78d3b5d08061a15f4a68a864..78a2d923fa8f8d3bc10d73c48d98753becbe763e 100644 --- a/qt/scientific_interfaces/Indirect/ApplyAbsorptionCorrections.cpp +++ b/qt/scientific_interfaces/Indirect/ApplyAbsorptionCorrections.cpp @@ -261,8 +261,9 @@ void ApplyAbsorptionCorrections::run() { boost::dynamic_pointer_cast<MatrixWorkspace>(corrections->getItem(i)); // Check for matching binning - if (sampleWs && (factorWs->blocksize() != sampleWs->blocksize() && - factorWs->blocksize() != 1)) { + const auto factorBlocksize = factorWs->blocksize(); + if (sampleWs && + (factorBlocksize != sampleWs->blocksize() && factorBlocksize != 1)) { int result; if (interpolateAll) { result = QMessageBox::Yes; diff --git a/qt/widgets/instrumentview/src/InstrumentActor.cpp b/qt/widgets/instrumentview/src/InstrumentActor.cpp index e62e918249fd563fc4474c136347df802659de6c..3da23f03d2c780ef5336eedfadd7b4b254d4c4cf 100644 --- a/qt/widgets/instrumentview/src/InstrumentActor.cpp +++ b/qt/widgets/instrumentview/src/InstrumentActor.cpp @@ -461,8 +461,9 @@ void InstrumentActor::sumDetectors(const std::vector<size_t> &dets, std::vector<double> &x, std::vector<double> &y, size_t size) const { Mantid::API::MatrixWorkspace_const_sptr ws = getWorkspace(); - if (size > ws->blocksize() || size == 0) { - size = ws->blocksize(); + const auto blocksize = ws->blocksize(); + if (size > blocksize || size == 0) { + size = blocksize; } if (m_ragged) {