Skip to content

Commit

Permalink
Checkpoint workspace iterator removal.
Browse files Browse the repository at this point in the history
Refs #8983
  • Loading branch information
martyngigg committed Mar 3, 2014
1 parent d94ee81 commit 9cecd2c
Show file tree
Hide file tree
Showing 8 changed files with 76 additions and 90 deletions.
10 changes: 3 additions & 7 deletions Code/Mantid/Framework/API/inc/MantidAPI/MatrixWorkspace.h
Expand Up @@ -4,17 +4,17 @@
//----------------------------------------------------------------------
// Includes
//----------------------------------------------------------------------
#include <boost/scoped_ptr.hpp>
#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 <boost/scoped_ptr.hpp>

namespace Mantid
{
Expand Down Expand Up @@ -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<LocatedDataRef, MatrixWorkspace> iterator;
/// Typedef for the const workspace_iterator to use with a Workspace
typedef workspace_iterator<const LocatedDataRef, const MatrixWorkspace> const_iterator;
/// Initialize
void initialize(const std::size_t &NVectors, const std::size_t &XLength, const std::size_t &YLength);
/// Delete
Expand Down
6 changes: 0 additions & 6 deletions Code/Mantid/Framework/API/src/MatrixWorkspace.cpp
Expand Up @@ -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"
Expand Down Expand Up @@ -1630,11 +1629,6 @@ namespace Mantid
} // namespace API
} // Namespace Mantid


///\cond TEMPLATE
template MANTID_API_DLL class Mantid::API::workspace_iterator<Mantid::API::LocatedDataRef,Mantid::API::MatrixWorkspace>;
template MANTID_API_DLL class Mantid::API::workspace_iterator<const Mantid::API::LocatedDataRef, const Mantid::API::MatrixWorkspace>;

namespace Mantid
{
namespace Kernel
Expand Down
120 changes: 64 additions & 56 deletions Code/Mantid/Framework/Algorithms/src/CorrectToFile.cpp
Expand Up @@ -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<int64_t>(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);
}
}
Expand Down
12 changes: 9 additions & 3 deletions Code/Mantid/Framework/Algorithms/src/Qxy.cpp
Expand Up @@ -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";
Expand Down
Expand Up @@ -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<API::LocatedDataRef, RebinnedOutput> iterator;
/// Typedef for the const workspace_iterator to use with a RebinnedOutput
typedef API::workspace_iterator<const API::LocatedDataRef, const RebinnedOutput> const_iterator;

/// Class constructor.
RebinnedOutput();
Expand Down
Expand Up @@ -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<API::LocatedDataRef, Workspace2D> iterator;
/// Typedef for the const workspace_iterator to use with a Workspace2D
typedef API::workspace_iterator<const API::LocatedDataRef, const Workspace2D> const_iterator;

/**
Gets the name of the workspace type
Expand Down
Expand Up @@ -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<API::LocatedDataRef, WorkspaceSingleValue> iterator;
/// Typedef for the const workspace_iterator to use with a WorkspaceSingleValue
typedef API::workspace_iterator<const API::LocatedDataRef, const WorkspaceSingleValue> const_iterator;

/** Gets the name of the workspace type
* @return Standard string name */
Expand Down
6 changes: 0 additions & 6 deletions Code/Mantid/Framework/DataObjects/src/EventWorkspace.cpp
Expand Up @@ -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"
Expand Down Expand Up @@ -945,10 +943,6 @@ namespace DataObjects
} // namespace Mantid


///\cond TEMPLATE
template DLLExport class Mantid::API::workspace_iterator<Mantid::API::LocatedDataRef, Mantid::DataObjects::EventWorkspace>;
template DLLExport class Mantid::API::workspace_iterator<const Mantid::API::LocatedDataRef, const Mantid::DataObjects::EventWorkspace>;

template DLLExport class Mantid::API::WorkspaceProperty<Mantid::DataObjects::EventWorkspace>;

namespace Mantid
Expand Down

0 comments on commit 9cecd2c

Please sign in to comment.