Commit 8de22e32 authored by Matthew Bowles's avatar Matthew Bowles
Browse files

initial fit for single/multi ion/spectra Re #20358

parent c3d1dd66
......@@ -560,13 +560,13 @@ int SaveToSNSHistogramNexus::WriteGroup(int is_definition) {
}
//---------------------------------------------------------------------------------------
if (data_label == "data" && (bank != "")) {
if (data_label == "data" && (!bank.empty())) {
if (this->WriteDataGroup(bank, is_definition) != NX_OK)
return NX_ERROR;
;
}
//---------------------------------------------------------------------------------------
else if (data_label == "time_of_flight" && (bank != "")) {
else if (data_label == "time_of_flight" && (!bank.empty())) {
// Get the original info
if (NXgetinfo(inId, &dataRank, dataDimensions, &dataType) != NX_OK)
return NX_ERROR;
......
......@@ -4403,7 +4403,7 @@ void EventList::splitByPulseTimeWithMatrix(
}
// Split
if (vec_target.size() == 0) {
if (vec_target.empty()) {
// No splitter: copy all events to group workspace = -1
(*outputs[-1]) = (*this);
} else {
......
......@@ -130,6 +130,7 @@ MDHistoWorkspace::~MDHistoWorkspace() {
void MDHistoWorkspace::init(
std::vector<Mantid::Geometry::MDHistoDimension_sptr> &dimensions) {
std::vector<IMDDimension_sptr> dim2;
dim2.reserve(dimensions.size());
for (auto &dimension : dimensions)
dim2.push_back(boost::dynamic_pointer_cast<IMDDimension>(dimension));
this->init(dim2);
......
......@@ -156,20 +156,19 @@ void PeaksWorkspace::removePeak(const int peakNum) {
void PeaksWorkspace::removePeaks(std::vector<int> badPeaks) {
if (badPeaks.empty())
return;
std::sort(badPeaks.begin(), badPeaks.end());
auto index = peaks.begin();
auto end = peaks.end();
auto result = index;
for (int i = 0; index < end; ++index, ++i) {
// if index of peak is not in badPeaks
if (!std::binary_search(badPeaks.begin(), badPeaks.end(), i)) {
// include in result
*result = std::move(*index);
++result;
}
}
// erase peaks outside of result
peaks.erase(result, peaks.end());
// if index of peak is in badPeaks remove
int ip = -1;
auto it =
std::remove_if(peaks.begin(), peaks.end(), [&ip, badPeaks](Peak &pk) {
(void)pk;
ip++;
for (auto ibp = badPeaks.begin(); ibp != badPeaks.end(); ++ibp) {
if (*ibp == ip)
return true;
}
return false;
});
peaks.erase(it, peaks.end());
}
//---------------------------------------------------------------------------------------------
......
......@@ -31,7 +31,7 @@ ProductOfCyclicGroups::getGeneratedGroup(const std::string &generators) const {
std::vector<Group_const_sptr> ProductOfCyclicGroups::getFactorGroups(
const std::vector<SymmetryOperation> &symmetryOperations) const {
std::vector<Group_const_sptr> groups;
groups.reserve(symmetryOperations.size());
for (const auto &symmetryOperation : symmetryOperations) {
groups.push_back(
GroupFactory::create<CyclicGroup>(symmetryOperation.identifier()));
......
......@@ -313,7 +313,7 @@ std::string SymmetryElementMirrorGenerator::determineSymbol(
* proper symbol, so the general symbol "g" is used for these cases.
* Examples can be found in No. 227 (Fd-3m).
*/
if (symbol == "") {
if (symbol.empty()) {
return "g";
}
......
......@@ -32,6 +32,7 @@ SymmetryOperationFactoryImpl::createSymOps(const std::string &identifiers) {
std::vector<SymmetryOperation> SymmetryOperationFactoryImpl::createSymOps(
const std::vector<std::string> &identifiers) {
std::vector<SymmetryOperation> symOps;
symOps.reserve(identifiers.size());
for (const auto &identifier : identifiers) {
symOps.push_back(createSymOp(boost::trim_copy(identifier)));
}
......
......@@ -1282,7 +1282,7 @@ void InstrumentDefinitionParser::createDetectorOrMonitor(
std::stringstream ss1, ss2;
ss1 << idList.vec.size();
ss2 << idList.counted;
if (idList.idname == "") {
if (idList.idname.empty()) {
g_log.error("No list of detector IDs found for location element " + name);
throw Kernel::Exception::InstrumentDefinitionError(
"Detector location element " + name + " has no idlist.", filename);
......
......@@ -93,8 +93,10 @@ void MDGeometryXMLParser::execute() {
throw std::invalid_argument("Cannot determine x-dimension mapping.");
}
m_xDimension = *xDimensionIt;
vecNonMappedDims.erase(std::remove_if(
vecNonMappedDims.begin(), vecNonMappedDims.end(), findID(xDimId)));
vecNonMappedDims.erase(std::remove_if(vecNonMappedDims.begin(),
vecNonMappedDims.end(),
findID(xDimId)),
vecNonMappedDims.end());
}
Poco::XML::Element *yDimensionElement = geometryXMLElement->getChildElement(
......@@ -112,8 +114,10 @@ void MDGeometryXMLParser::execute() {
throw std::invalid_argument("Cannot determine y-dimension mapping.");
}
m_yDimension = *yDimensionIt;
vecNonMappedDims.erase(std::remove_if(
vecNonMappedDims.begin(), vecNonMappedDims.end(), findID(yDimId)));
vecNonMappedDims.erase(std::remove_if(vecNonMappedDims.begin(),
vecNonMappedDims.end(),
findID(yDimId)),
vecNonMappedDims.end());
}
Poco::XML::Element *zDimensionElement = geometryXMLElement->getChildElement(
......@@ -131,8 +135,10 @@ void MDGeometryXMLParser::execute() {
throw std::invalid_argument("Cannot determine z-dimension mapping.");
}
m_zDimension = *zDimensionIt;
vecNonMappedDims.erase(std::remove_if(
vecNonMappedDims.begin(), vecNonMappedDims.end(), findID(zDimId)));
vecNonMappedDims.erase(std::remove_if(vecNonMappedDims.begin(),
vecNonMappedDims.end(),
findID(zDimId)),
vecNonMappedDims.end());
}
Poco::XML::Element *tDimensionElement = geometryXMLElement->getChildElement(
......@@ -150,8 +156,10 @@ void MDGeometryXMLParser::execute() {
}
m_tDimension = *tDimensionIt;
if (!vecNonMappedDims.empty()) {
vecNonMappedDims.erase(std::remove_if(
vecNonMappedDims.begin(), vecNonMappedDims.end(), findID(tDimId)));
vecNonMappedDims.erase(std::remove_if(vecNonMappedDims.begin(),
vecNonMappedDims.end(),
findID(tDimId)),
vecNonMappedDims.end());
}
}
m_vecNonMappedDims = vecNonMappedDims; // Copy with strong guarantee.
......
......@@ -24,7 +24,7 @@ CountStandardDeviations::CountStandardDeviations(
throw std::logic_error("CountStandardDeviations: Cannot construct from "
"FrequencyStandardDeviations -- BinEdges are NULL.");
if ((frequencies.size() + 1) != edges.size())
if (frequencies.size() != 0 || edges.size() != 0)
if (!frequencies.empty() || !edges.empty())
throw std::logic_error("CountStandardDeviations: Cannot construct from "
"FrequencyStandardDeviations -- BinEdges size "
"does not "
......
......@@ -23,7 +23,7 @@ CountVariances::CountVariances(FrequencyVariances &&frequencies,
throw std::logic_error("CountVariances: Cannot construct from "
"FrequencyVariances -- BinEdges are NULL.");
if ((frequencies.size() + 1) != edges.size())
if (frequencies.size() != 0 || edges.size() != 0)
if (!frequencies.empty() || !edges.empty())
throw std::logic_error("CountVariances: Cannot construct from "
"FrequencyVariances -- BinEdges size does not "
"match.");
......
......@@ -17,7 +17,7 @@ Counts::Counts(Frequencies &&frequencies, const BinEdges &edges) {
throw std::logic_error(
"Counts: Cannot construct from Frequencies -- BinEdges are NULL.");
if ((frequencies.size() + 1) != edges.size())
if (frequencies.size() != 0 || edges.size() != 0)
if (!frequencies.empty() || !edges.empty())
throw std::logic_error("Counts: Cannot construct from Frequencies -- "
"BinEdges size does not match.");
// Cannot move frequencies private data since it is of different type.
......
......@@ -17,7 +17,7 @@ Frequencies::Frequencies(Counts &&counts, const BinEdges &edges) {
throw std::logic_error(
"Frequencies: Cannot construct from Counts -- BinEdges are NULL.");
if ((counts.size() + 1) != edges.size())
if (counts.size() != 0 || edges.size() != 0)
if (!counts.empty() || !edges.empty())
throw std::logic_error("Frequencies: Cannot construct from Counts -- "
"BinEdges size does not match.");
// Cannot move counts private data since it is of different type.
......
......@@ -23,7 +23,7 @@ FrequencyStandardDeviations::FrequencyStandardDeviations(
throw std::logic_error("FrequencyStandardDeviations: Cannot construct from "
"CountStandardDeviations -- BinEdges are NULL.");
if ((counts.size() + 1) != edges.size())
if (counts.size() != 0 || edges.size() != 0)
if (!counts.empty() || !edges.empty())
throw std::logic_error("FrequencyStandardDeviations: Cannot construct "
"from CountStandardDeviations -- BinEdges size "
"does not match.");
......
......@@ -23,7 +23,7 @@ FrequencyVariances::FrequencyVariances(CountVariances &&counts,
throw std::logic_error("FrequencyVariances: Cannot construct from "
"CountVariances -- BinEdges are NULL.");
if ((counts.size() + 1) != edges.size())
if (counts.size() != 0 || edges.size() != 0)
if (!counts.empty() || !edges.empty())
throw std::logic_error("FrequencyVariances: Cannot construct from "
"CountVariances -- BinEdges size does not match.");
// Cannot move counts private data since it is of different type.
......
#include "MantidHistogramData/Histogram.h"
#include <sstream>
namespace Mantid {
namespace HistogramData {
......@@ -251,8 +252,12 @@ template <> void Histogram::checkSize(const BinEdges &binEdges) const {
// 0 points -> 0 edges, otherwise edges are 1 more than points.
if (xMode() == XMode::Points && target > 0)
target++;
if (target != binEdges.size())
throw std::logic_error("Histogram: size mismatch of BinEdges\n");
if (target != binEdges.size()) {
std::stringstream msg;
msg << "Histogram: size mismatch of BinEdges: (" << target
<< " != " << binEdges.size() << ")";
throw std::logic_error(msg.str());
}
}
/** Resets the size of the internal x, dx, y, and e data structures
......
......@@ -10,7 +10,7 @@ Points::Points(const BinEdges &edges) {
return;
if (edges.size() == 1)
throw std::logic_error("Points: Cannot construct from BinEdges of size 1");
if (edges.size() == 0) {
if (edges.empty()) {
m_data = Kernel::make_cow<HistogramX>(0);
return;
}
......
......@@ -271,7 +271,7 @@ TYPE &PropertyWithValue<TYPE>::operator=(const TYPE &value) {
m_value = value;
}
std::string problem = this->isValid();
if (problem == "") {
if (problem.empty()) {
return m_value;
} else if (problem == "_alias") {
m_value = getValueForAlias(value);
......
......@@ -74,7 +74,7 @@ std::string CompositeValidator::check(const boost::any &value) const {
std::string error = (*itr)->check(value);
// exit on the first error, to avoid passing doing more tests on invalid
// objects that could fail
if (error != "")
if (!error.empty())
return error;
}
// there were no errors
......
......@@ -372,7 +372,7 @@ void ConfigServiceImpl::loadConfig(const std::string &filename,
bool good = readFile(filename, temp);
// check if we have failed to open the file
if ((!good) || (temp == "")) {
if ((!good) || (temp.empty())) {
if (filename == getUserPropertiesDir() + m_user_properties_file_name) {
// write out a fresh file
createUserPropertiesFile();
......@@ -382,7 +382,7 @@ void ConfigServiceImpl::loadConfig(const std::string &filename,
}
// store the property string
if ((append) && (m_PropertyString != "")) {
if ((append) && (!m_PropertyString.empty())) {
m_PropertyString = m_PropertyString + "\n" + temp;
} else {
m_PropertyString = temp;
......
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