From 9cecd2c99618d5366e82305edd9a9576416798f3 Mon Sep 17 00:00:00 2001 From: Martyn Gigg Date: Mon, 10 Feb 2014 17:31:47 +0000 Subject: [PATCH] Checkpoint workspace iterator removal. Refs #8983 --- .../API/inc/MantidAPI/MatrixWorkspace.h | 10 +- .../Framework/API/src/MatrixWorkspace.cpp | 6 - .../Algorithms/src/CorrectToFile.cpp | 120 ++++++++++-------- Code/Mantid/Framework/Algorithms/src/Qxy.cpp | 12 +- .../inc/MantidDataObjects/RebinnedOutput.h | 4 - .../inc/MantidDataObjects/Workspace2D.h | 4 - .../MantidDataObjects/WorkspaceSingleValue.h | 4 - .../DataObjects/src/EventWorkspace.cpp | 6 - 8 files changed, 76 insertions(+), 90 deletions(-) diff --git a/Code/Mantid/Framework/API/inc/MantidAPI/MatrixWorkspace.h b/Code/Mantid/Framework/API/inc/MantidAPI/MatrixWorkspace.h index b99e24e874af..7183da5e5f71 100644 --- a/Code/Mantid/Framework/API/inc/MantidAPI/MatrixWorkspace.h +++ b/Code/Mantid/Framework/API/inc/MantidAPI/MatrixWorkspace.h @@ -4,17 +4,17 @@ //---------------------------------------------------------------------- // Includes //---------------------------------------------------------------------- -#include #include "MantidAPI/DllConfig.h" +#include "MantidAPI/Axis.h" #include "MantidAPI/ExperimentInfo.h" #include "MantidAPI/IMDWorkspace.h" -#include "MantidAPI/Axis.h" #include "MantidAPI/ISpectrum.h" #include "MantidAPI/MatrixWSIndexCalculator.h" #include "MantidAPI/Run.h" #include "MantidAPI/Sample.h" #include "MantidAPI/SpectraDetectorTypes.h" -#include "MantidAPI/WorkspaceIterator.h" + +#include namespace Mantid { @@ -68,10 +68,6 @@ namespace Mantid // The Workspace Factory create-from-parent method needs direct access to the axes. friend class WorkspaceFactoryImpl; - /// Typedef for the workspace_iterator to use with a Workspace - typedef workspace_iterator iterator; - /// Typedef for the const workspace_iterator to use with a Workspace - typedef workspace_iterator const_iterator; /// Initialize void initialize(const std::size_t &NVectors, const std::size_t &XLength, const std::size_t &YLength); /// Delete diff --git a/Code/Mantid/Framework/API/src/MatrixWorkspace.cpp b/Code/Mantid/Framework/API/src/MatrixWorkspace.cpp index 69856a537b80..e05545273ced 100644 --- a/Code/Mantid/Framework/API/src/MatrixWorkspace.cpp +++ b/Code/Mantid/Framework/API/src/MatrixWorkspace.cpp @@ -3,7 +3,6 @@ #include "MantidAPI/SpectraAxis.h" #include "MantidAPI/MatrixWorkspaceMDIterator.h" #include "MantidAPI/SpectrumDetectorMapping.h" -#include "MantidAPI/WorkspaceIteratorCode.h" #include "MantidGeometry/Instrument/Detector.h" #include "MantidGeometry/Instrument/DetectorGroup.h" #include "MantidGeometry/Instrument/NearestNeighboursFactory.h" @@ -1630,11 +1629,6 @@ namespace Mantid } // namespace API } // Namespace Mantid - -///\cond TEMPLATE -template MANTID_API_DLL class Mantid::API::workspace_iterator; -template MANTID_API_DLL class Mantid::API::workspace_iterator; - namespace Mantid { namespace Kernel diff --git a/Code/Mantid/Framework/Algorithms/src/CorrectToFile.cpp b/Code/Mantid/Framework/Algorithms/src/CorrectToFile.cpp index 56b4bd2b6254..410ca89edcdf 100644 --- a/Code/Mantid/Framework/Algorithms/src/CorrectToFile.cpp +++ b/Code/Mantid/Framework/Algorithms/src/CorrectToFile.cpp @@ -90,69 +90,77 @@ void CorrectToFile::exec() const bool divide = (operation == "Divide") ? true : false; double Yfactor,correctError; - const size_t nOutSpec = outputWS->getNumberHistograms(); + const int64_t nOutSpec = static_cast(outputWS->getNumberHistograms()); + const size_t nbins = outputWS->blocksize(); // Set the progress bar Progress prg(this,0/*LOAD_TIME*/,1.0, nOutSpec); - MatrixWorkspace::iterator outIt(*outputWS); - for (MatrixWorkspace::const_iterator inIt(*toCorrect); inIt != inIt.end(); ++inIt,++outIt) + for(int64_t i = 0; i < nOutSpec; ++i) { - const double currentX = histogramData ? (inIt->X()+inIt->X2())/2.0 : inIt->X(); - // Find out the index of the first correction point after this value - MantidVec::const_iterator pos = std::lower_bound(Xcor.begin(),Xcor.end(),currentX); - const size_t index = pos-Xcor.begin(); - if ( index == Xcor.size() ) - { - // If we're past the end of the correction factors vector, use the last point - Yfactor = Ycor[index-1]; - correctError = Ecor[index-1]; - } - else if (index) - { - // Calculate where between the two closest points our current X value is - const double fraction = (currentX-Xcor[index-1])/(Xcor[index]-Xcor[index-1]); - // Now linearly interpolate to find the correction factors to use - Yfactor = Ycor[index-1] + fraction*(Ycor[index]-Ycor[index-1]); - correctError = Ecor[index-1] + fraction*(Ecor[index]-Ecor[index-1]); - } - else - { - // If we're before the start of the correction factors vector, use the first point - Yfactor = Ycor[0]; - correctError = Ecor[0]; - } + MantidVec & xOut = outputWS->dataX(i); + MantidVec & yOut = outputWS->dataY(i); + MantidVec & eOut = outputWS->dataE(i); - // Now do the correction on the current point - if (divide) - { - outIt->Y() = inIt->Y()/Yfactor; - // the proportional error is equal to the sum of the proportional errors - // re-arrange so that you don't get infinity if leftY==0. Sa = error on a, etc. - // c = a/b - // (Sa/a)2 + (Sb/b)2 = (Sc/c)2 - // (Sa c/a)2 + (Sb c/b)2 = (Sc)2 - // = (Sa 1/b)2 + (Sb (a/b2))2 - // (Sc)2 = (1/b)2( (Sa)2 + (Sb a/b)2 ) - outIt->E() = sqrt( pow(inIt->E(), 2) + - pow( inIt->Y()*correctError/Yfactor, 2) )/Yfactor; - } - else + const MantidVec & xIn = toCorrect->readX(i); + const MantidVec & yIn = toCorrect->readY(i); + const MantidVec & eIn = toCorrect->readE(i); + + for(size_t j = 0; j < nbins; ++j) { - outIt->Y() = inIt->Y()*Yfactor; - // error multiplying two uncorrelated numbers, re-arrange so that you don't get infinity if leftY or rightY == 0 - // Sa = error on a, etc. - // c = a*b - // (Sa/a)2 + (Sb/b)2 = (Sc/c)2 - // (Sc)2 = (Sa c/a)2 + (Sb c/b)2 = (Sa b)2 + (Sb a)2 - outIt->E() = sqrt( pow(inIt->E()*Yfactor, 2) - + pow(correctError*inIt->Y(), 2) ); + const double currentX = histogramData ? (xIn[j] + xIn[j+1])/2.0 : xIn[j]; + // Find out the index of the first correction point after this value + MantidVec::const_iterator pos = std::lower_bound(Xcor.begin(),Xcor.end(),currentX); + const size_t index = pos-Xcor.begin(); + if ( index == Xcor.size() ) + { + // If we're past the end of the correction factors vector, use the last point + Yfactor = Ycor[index-1]; + correctError = Ecor[index-1]; + } + else if (index) + { + // Calculate where between the two closest points our current X value is + const double fraction = (currentX-Xcor[index-1])/(Xcor[index]-Xcor[index-1]); + // Now linearly interpolate to find the correction factors to use + Yfactor = Ycor[index-1] + fraction*(Ycor[index]-Ycor[index-1]); + correctError = Ecor[index-1] + fraction*(Ecor[index]-Ecor[index-1]); + } + else + { + // If we're before the start of the correction factors vector, use the first point + Yfactor = Ycor[0]; + correctError = Ecor[0]; + } + + // Now do the correction on the current point + if (divide) + { + yOut[j] = yIn[j]/Yfactor; + // the proportional error is equal to the sum of the proportional errors + // re-arrange so that you don't get infinity if leftY==0. Sa = error on a, etc. + // c = a/b + // (Sa/a)2 + (Sb/b)2 = (Sc/c)2 + // (Sa c/a)2 + (Sb c/b)2 = (Sc)2 + // = (Sa 1/b)2 + (Sb (a/b2))2 + // (Sc)2 = (1/b)2( (Sa)2 + (Sb a/b)2 ) + eOut[j] = sqrt( pow(eIn[j], 2) + pow( yIn[j]*correctError/Yfactor, 2) )/Yfactor; + } + else + { + yOut[j] = yIn[j]*Yfactor; + // error multiplying two uncorrelated numbers, re-arrange so that you don't get infinity if leftY or rightY == 0 + // Sa = error on a, etc. + // c = a*b + // (Sa/a)2 + (Sb/b)2 = (Sc/c)2 + // (Sc)2 = (Sa c/a)2 + (Sb c/b)2 = (Sa b)2 + (Sb a)2 + eOut[j] = sqrt(pow(eIn[j]*Yfactor, 2) + pow(correctError*yIn[j], 2) ); + } + + + // Copy X value over + xOut[j] = xIn[j]; } - - - // Copy X value over - outIt->X() = inIt->X(); - if (histogramData) outIt->X2() = inIt->X2(); - + if (histogramData) xOut[nbins] = xIn[nbins]; prg.report("CorrectToFile: applying " + operation); } } diff --git a/Code/Mantid/Framework/Algorithms/src/Qxy.cpp b/Code/Mantid/Framework/Algorithms/src/Qxy.cpp index 2a816b7c1648..112f2469e89f 100644 --- a/Code/Mantid/Framework/Algorithms/src/Qxy.cpp +++ b/Code/Mantid/Framework/Algorithms/src/Qxy.cpp @@ -299,12 +299,18 @@ void Qxy::exec() // Count of the number of empty cells - MatrixWorkspace::const_iterator wsIt(*outputWorkspace); + const size_t nhist = outputWorkspace->getNumberHistograms(); + const size_t nbins = outputWorkspace->blocksize(); int emptyBins = 0; - for (;wsIt != wsIt.end(); ++wsIt) + for(size_t i = 0; i < nhist; ++i) { - if (wsIt->Y() < 1.0e-12) ++emptyBins; + const auto & yOut = outputWorkspace->readY(i); + for(size_t j = 0; j < nbins; ++j) + { + if (yOut[j] < 1.0e-12) ++emptyBins; + } } + // Log the number of empty bins g_log.notice() << "There are a total of " << emptyBins << " (" << (100*emptyBins)/(outputWorkspace->size()) << "%) empty Q bins.\n"; diff --git a/Code/Mantid/Framework/DataObjects/inc/MantidDataObjects/RebinnedOutput.h b/Code/Mantid/Framework/DataObjects/inc/MantidDataObjects/RebinnedOutput.h index 87ba6fde2e63..f01e260e58c4 100644 --- a/Code/Mantid/Framework/DataObjects/inc/MantidDataObjects/RebinnedOutput.h +++ b/Code/Mantid/Framework/DataObjects/inc/MantidDataObjects/RebinnedOutput.h @@ -50,10 +50,6 @@ namespace DataObjects class DLLExport RebinnedOutput : public Workspace2D { public: - /// Typedef for the workspace_iterator to use with a RebinnedOutput - typedef API::workspace_iterator iterator; - /// Typedef for the const workspace_iterator to use with a RebinnedOutput - typedef API::workspace_iterator const_iterator; /// Class constructor. RebinnedOutput(); diff --git a/Code/Mantid/Framework/DataObjects/inc/MantidDataObjects/Workspace2D.h b/Code/Mantid/Framework/DataObjects/inc/MantidDataObjects/Workspace2D.h index 95956d586fb8..bd407b59a888 100644 --- a/Code/Mantid/Framework/DataObjects/inc/MantidDataObjects/Workspace2D.h +++ b/Code/Mantid/Framework/DataObjects/inc/MantidDataObjects/Workspace2D.h @@ -53,10 +53,6 @@ namespace DataObjects class DLLExport Workspace2D : public API::MatrixWorkspace { public: - /// Typedef for the workspace_iterator to use with a Workspace2D - typedef API::workspace_iterator iterator; - /// Typedef for the const workspace_iterator to use with a Workspace2D - typedef API::workspace_iterator const_iterator; /** Gets the name of the workspace type diff --git a/Code/Mantid/Framework/DataObjects/inc/MantidDataObjects/WorkspaceSingleValue.h b/Code/Mantid/Framework/DataObjects/inc/MantidDataObjects/WorkspaceSingleValue.h index 4321e75174e8..a4fbda2bfcd7 100644 --- a/Code/Mantid/Framework/DataObjects/inc/MantidDataObjects/WorkspaceSingleValue.h +++ b/Code/Mantid/Framework/DataObjects/inc/MantidDataObjects/WorkspaceSingleValue.h @@ -47,10 +47,6 @@ namespace DataObjects class DLLExport WorkspaceSingleValue : public API::MatrixWorkspace { public: - /// Typedef for the workspace_iterator to use with a WorkspaceSingleValue - typedef API::workspace_iterator iterator; - /// Typedef for the const workspace_iterator to use with a WorkspaceSingleValue - typedef API::workspace_iterator const_iterator; /** Gets the name of the workspace type * @return Standard string name */ diff --git a/Code/Mantid/Framework/DataObjects/src/EventWorkspace.cpp b/Code/Mantid/Framework/DataObjects/src/EventWorkspace.cpp index 39dcd3d554c1..f5e476f15f4e 100644 --- a/Code/Mantid/Framework/DataObjects/src/EventWorkspace.cpp +++ b/Code/Mantid/Framework/DataObjects/src/EventWorkspace.cpp @@ -3,8 +3,6 @@ #include "MantidAPI/LocatedDataRef.h" #include "MantidAPI/MemoryManager.h" #include "MantidAPI/Progress.h" -#include "MantidAPI/WorkspaceIterator.h" -#include "MantidAPI/WorkspaceIteratorCode.h" #include "MantidAPI/WorkspaceProperty.h" #include "MantidAPI/WorkspaceFactory.h" #include "MantidDataObjects/EventWorkspace.h" @@ -945,10 +943,6 @@ namespace DataObjects } // namespace Mantid -///\cond TEMPLATE -template DLLExport class Mantid::API::workspace_iterator; -template DLLExport class Mantid::API::workspace_iterator; - template DLLExport class Mantid::API::WorkspaceProperty; namespace Mantid