Commit aeb640fc authored by Matthew Bowles's avatar Matthew Bowles
Browse files

replaced calls to removePeak within loops Re #19472

parent ec485749
......@@ -72,6 +72,8 @@ public:
*/
virtual void removePeak(int peakNum) = 0;
virtual void removePeaks(const std::vector<int>& badPeaks) = 0;
//---------------------------------------------------------------------------------------------
/** Add a peak to the list
* @param ipeak :: Peak object to add (copy) into this.
......
......@@ -38,6 +38,7 @@ private:
void integrate();
void integrateEvent();
int findPixelID(std::string bankName, int col, int row);
void removeEdgePeaks(Mantid::DataObjects::PeaksWorkspace_sptr& peakWS, const int& edge);
Geometry::Instrument_const_sptr inst;
/// Input 2D Workspace
......
......@@ -169,17 +169,7 @@ void CentroidPeaks::integrate() {
}
PARALLEL_CHECK_INTERUPT_REGION
for (int i = int(peakWS->getNumberPeaks()) - 1; i >= 0; --i) {
// Get a direct ref to that peak.
auto &peak = peakWS->getPeak(i);
int col = peak.getCol();
int row = peak.getRow();
std::string bankName = peak.getBankName();
if (edgePixel(inst, bankName, col, row, Edge)) {
peakWS->removePeak(i);
}
}
removeEdgePeaks(peakWS, Edge);
// Save the output
setProperty("OutPeaksWorkspace", peakWS);
......@@ -299,17 +289,8 @@ void CentroidPeaks::integrateEvent() {
}
PARALLEL_CHECK_INTERUPT_REGION
for (int i = int(peakWS->getNumberPeaks()) - 1; i >= 0; --i) {
// Get a direct ref to that peak.
auto &peak = peakWS->getPeak(i);
int col = peak.getCol();
int row = peak.getRow();
std::string bankName = peak.getBankName();
removeEdgePeaks(peakWS, Edge);
if (edgePixel(inst, bankName, col, row, Edge)) {
peakWS->removePeak(i);
}
}
// Save the output
setProperty("OutPeaksWorkspace", peakWS);
}
......@@ -357,5 +338,21 @@ int CentroidPeaks::findPixelID(std::string bankName, int col, int row) {
}
}
void CentroidPeaks::removeEdgePeaks(Mantid::DataObjects::PeaksWorkspace_sptr& peakWS, const int& edge) {
std::vector<int> badPeaks;
for (int i = int(peakWS->getNumberPeaks()) - 1; i >= 0; --i) {
// Get a direct ref to that peak.
auto &peak = peakWS->getPeak(i);
int col = peak.getCol();
int row = peak.getRow();
std::string bankName = peak.getBankName();
if (edgePixel(inst, bankName, col, row, edge)) {
badPeaks.push_back(i);
}
}
peakWS->removePeaks(badPeaks);
}
} // namespace Mantid
} // namespace Crystal
......@@ -75,6 +75,7 @@ void DiffPeaksWorkspaces::exec() {
Progress progress(this, 0.0, 1.0, rhsPeaks.size());
std::vector<int> badPeaks;
// Loop over the peaks in the second workspace, searching for a match in the
// first
for (const auto &currentPeak : rhsPeaks) {
......@@ -88,14 +89,14 @@ void DiffPeaksWorkspaces::exec() {
{
// As soon as we find a match, remove it from the output and move onto
// the next rhs peak
output->removePeak(j);
badPeaks.push_back(j);
break;
}
}
progress.report();
}
output->removePeaks(badPeaks);
setProperty("OutputWorkspace", output);
}
......
......@@ -77,15 +77,17 @@ void OptimizeLatticeForCellType::exec() {
DataObjects::PeaksWorkspace_sptr ws = getProperty("PeaksWorkspace");
Geometry::Instrument_const_sptr inst = ws->getInstrument();
std::vector<int> badPeaks;
std::vector<DataObjects::PeaksWorkspace_sptr> runWS;
if (edge > 0) {
for (int i = int(ws->getNumberPeaks()) - 1; i >= 0; --i) {
const std::vector<Peak> &peaks = ws->getPeaks();
if (edgePixel(inst, peaks[i].getBankName(), peaks[i].getCol(),
peaks[i].getRow(), edge)) {
ws->removePeak(i);
badPeaks.push_back(i);
}
}
ws->removePeaks(badPeaks);
}
runWS.push_back(ws);
......
......@@ -101,6 +101,7 @@ void PeakIntegration::exec() {
int NumberPeaks = peaksW->getNumberPeaks();
int MinPeaks = 0;
std::vector<int> badPeaks;
for (int i = NumberPeaks - 1; i >= 0; i--) {
Peak &peak = peaksW->getPeaks()[i];
int pixelID = peak.getDetectorID();
......@@ -111,12 +112,13 @@ void PeakIntegration::exec() {
size_t wi = wiEntry->second;
if ((matchRun && peak.getRunNumber() != inputW->getRunNumber()) ||
wi >= Numberwi)
peaksW->removePeak(i);
badPeaks.push_back(i);
} else // This is for appending peak workspaces when running
// SNSSingleCrystalReduction one bank at at time
if (i + 1 > MinPeaks)
MinPeaks = i + 1;
}
peaksW->removePeaks(badPeaks);
NumberPeaks = peaksW->getNumberPeaks();
if (NumberPeaks <= 0) {
g_log.error(
......
......@@ -604,9 +604,11 @@ void SaveHKL::exec() {
out.flush();
out.close();
// delete banned peaks
std::vector<int> badPeaks;
for (auto it = banned.crbegin(); it != banned.crend(); ++it) {
peaksW->removePeak(static_cast<int>(*it));
badPeaks.push_back(static_cast<int>(*it));
}
peaksW->removePeaks(badPeaks);
setProperty("OutputWorkspace", peaksW);
}
/**
......
......@@ -2,6 +2,7 @@
// Includes
//----------------------------------------------------------------------
#include "MantidDataHandling/DeleteTableRows.h"
#include "MantidDataObjects/Peak.h"
#include "MantidAPI/IWorkspaceProperty.h"
#include "MantidAPI/ITableWorkspace.h"
#include "MantidAPI/IPeaksWorkspace.h"
......@@ -38,16 +39,18 @@ void DeleteTableRows::exec() {
std::vector<size_t> rows = getProperty("Rows");
// sort the row indices in reverse order
std::set<size_t, std::greater<size_t>> sortedRows(rows.begin(), rows.end());
std::vector<int> badPeaks;
auto it = sortedRows.begin();
for (; it != sortedRows.end(); ++it) {
if (*it >= tw->rowCount())
continue;
if (pw) {
pw->removePeak(static_cast<int>(*it));
badPeaks.push_back(static_cast<int>(*it));
} else {
tw->removeRow(*it);
}
}
pw->removePeaks(badPeaks);
setProperty("TableWorkspace", tw);
}
......
......@@ -98,7 +98,7 @@ public:
int getNumberPeaks() const override;
std::string getConvention() const override;
void removePeak(int peakNum) override;
void removePeaks(const std::vector<Peak*>& it);
void removePeaks(const std::vector<int>& badPeaks);
void addPeak(const Geometry::IPeak &peak) override;
/// Move a peak object into this peaks workspace
void addPeak(Peak &&peak);
......
......@@ -151,13 +151,23 @@ void PeaksWorkspace::removePeak(const int peakNum) {
}
/** Removes multiple peaks
* @param badPeaks Pointers to peaks to be removed
* @param badPeaks peaks to be removed
*/
void PeaksWorkspace::removePeaks(const std::vector<Peak*>& badPeaks) {
peaks.erase(remove_if(peaks.begin(), peaks.end(),
[&badPeaks] (const Mantid::DataObjects::Peak& peak)
{return std::find(badPeaks.begin(), badPeaks.end(), &peak) != badPeaks.end(); }),
peaks.end());
void PeaksWorkspace::removePeaks(const std::vector<int>& badPeaks) {
int i = 0;
auto first = peaks.begin();
auto result = first;
for (Peak p : peaks)
{
if (std::find(badPeaks.begin(), badPeaks.end(), i) == badPeaks.end())
{
*result = std::move(*first);
++result;
}
++first;
++i;
}
peaks.erase(result, peaks.end());
}
//---------------------------------------------------------------------------------------------
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment