Commit 08088625 authored by David Fairbrother's avatar David Fairbrother
Browse files

Hand-fix some cppcheck warnings

Hand-fixes some cppcheck warnings, this was work prior to fixing the
cppcheck target.
parent 453bf557
......@@ -1569,6 +1569,7 @@ void Algorithm::copyNonWorkspaceProperties(IAlgorithm *alg, int periodNum) {
const auto &props = this->getProperties();
for (const auto &prop : props) {
if (prop) {
auto *wsProp = dynamic_cast<IWorkspaceProperty *>(prop);
// Copy the property using the string
if (!wsProp)
......
......@@ -7,6 +7,7 @@
#include "MantidAPI/CatalogManager.h"
#include "MantidAPI/CatalogFactory.h"
#include "MantidAPI/CompositeCatalog.h"
#include "MantidAPI/FunctionFactory.h"
#include "MantidKernel/ConfigService.h"
#include "MantidKernel/FacilityInfo.h"
......@@ -105,9 +106,10 @@ void CatalogManagerImpl::destroyCatalog(const std::string &sessionID) {
std::vector<CatalogSession_sptr> CatalogManagerImpl::getActiveSessions() {
std::vector<CatalogSession_sptr> sessions;
sessions.reserve(m_activeCatalogs.size());
for (const auto &activeCatalog : m_activeCatalogs) {
sessions.emplace_back(activeCatalog.first);
}
std::transform(m_activeCatalogs.begin(), m_activeCatalogs.end(),
std::back_inserter(sessions),
[](const auto &activeCatalog) { return activeCatalog.first; });
return sessions;
}
......
......@@ -25,7 +25,14 @@ CompositeDomainMD::CompositeDomainMD(IMDWorkspace_const_sptr ws,
size_t maxDomainSize)
: m_iterator(ws->createIterator()) {
m_totalSize = m_iterator->getDataSize();
size_t nParts = m_totalSize / maxDomainSize + 1;
size_t maxDomainSizeDiv = maxDomainSize + 1;
if (maxDomainSizeDiv == 0) {
throw std::runtime_error(
"Attempted to use a maximum domain size that equals 0");
}
size_t nParts = m_totalSize / maxDomainSizeDiv;
m_domains.resize(nParts);
for (size_t i = 0; i < nParts - 1; ++i) {
size_t start = i * maxDomainSize;
......
......@@ -944,8 +944,10 @@ std::vector<std::string> ExperimentInfo::getResourceFilenames(
std::vector<std::string> pathNames;
if (!matchingFiles.empty()) {
pathNames.reserve(matchingFiles.size());
for (auto &elem : matchingFiles)
pathNames.emplace_back(std::move(elem.second));
std::transform(matchingFiles.begin(), matchingFiles.end(),
std::back_inserter(pathNames),
[](const auto &elem) { return elem.second; });
} else {
pathNames.emplace_back(std::move(mostRecentFile));
}
......
......@@ -1361,9 +1361,10 @@ IFunction_sptr IFunction::getFunction(std::size_t) const {
std::vector<std::string> IFunction::getAttributeNames() const {
std::vector<std::string> names;
names.reserve(m_attrs.size());
for (const auto &attr : m_attrs) {
names.emplace_back(attr.first);
}
std::transform(m_attrs.begin(), m_attrs.end(), std::back_inserter(names),
[](const auto &attr) { return attr.first; });
return names;
}
......
......@@ -75,6 +75,7 @@ Indexing::SpectrumIndexSet IndexProperty::getIndices() const {
static_cast<Indexing::SpectrumNumber>(static_cast<int32_t>(max)));
}
} else {
// cppcheck-suppress constArgument
MSVC_DIAG_OFF(4244);
switch (type) {
case IndexType::WorkspaceIndex:
......
......@@ -1237,9 +1237,10 @@ MatrixWorkspace::maskedBinsIndices(const size_t &workspaceIndex) const {
auto maskedBins = it->second;
std::vector<size_t> maskedIds;
maskedIds.reserve(maskedBins.size());
for (const auto &mb : maskedBins) {
maskedIds.emplace_back(mb.first);
}
std::transform(maskedBins.begin(), maskedBins.end(),
std::back_inserter(maskedIds),
[](const auto &mb) { return mb.first; });
return maskedIds;
}
......@@ -1939,7 +1940,8 @@ MatrixWorkspace::findY(double value,
if (std::isnan(value)) {
for (int64_t i = idx.first; i < numHists; ++i) {
const auto &Y = this->y(i);
// cppcheck-suppress syntaxError
// https://trac.cppcheck.net/ticket/9237 if init buggy with cppcheck
// cppcheck-suppress stlIfFind
if (auto it = std::find_if(std::next(Y.begin(), idx.second), Y.end(),
[](double v) { return std::isnan(v); });
it != Y.end()) {
......@@ -1950,6 +1952,7 @@ MatrixWorkspace::findY(double value,
} else {
for (int64_t i = idx.first; i < numHists; ++i) {
const auto &Y = this->y(i);
// cppcheck-suppress stlIfFind
if (auto it = std::find(std::next(Y.begin(), idx.second), Y.end(), value);
it != Y.end()) {
out = {i, std::distance(Y.begin(), it)};
......
......@@ -202,9 +202,8 @@ bool ParameterTie::isConstant() const { return m_varMap.empty(); }
std::vector<ParameterReference> ParameterTie::getRHSParameters() const {
std::vector<ParameterReference> out;
out.reserve(m_varMap.size());
for (auto &&varPair : m_varMap) {
out.emplace_back(varPair.second);
}
std::transform(m_varMap.begin(), m_varMap.end(), std::back_inserter(out),
[](auto &&varPair) { return varPair.second; });
return out;
}
......
......@@ -191,9 +191,11 @@ std::vector<std::string> WorkspaceGroup::getNames() const {
std::vector<std::string> out;
std::lock_guard<std::recursive_mutex> _lock(m_mutex);
out.reserve(m_workspaces.size());
for (const auto &workspace : m_workspaces) {
out.emplace_back(workspace->getName());
}
std::transform(m_workspaces.begin(), m_workspaces.end(),
std::back_inserter(out),
[](const auto &ws) { return ws->getName(); });
return out;
}
......
......@@ -336,7 +336,7 @@ public:
const FunctionDomain1D &d0 =
static_cast<const FunctionDomain1D &>(domain.getDomain(0));
for (size_t i = 0; i < 9; ++i) {
TS_ASSERT_EQUALS(values.getCalculated(i), A + B * d0[i]);
TS_ASSERT_DELTA(values.getCalculated(i), A + B * d0[i], 1e-6);
}
A = multi.getFunction(0)->getParameter("A") +
......@@ -346,7 +346,7 @@ public:
const FunctionDomain1D &d1 =
static_cast<const FunctionDomain1D &>(domain.getDomain(1));
for (size_t i = 9; i < 19; ++i) {
TS_ASSERT_EQUALS(values.getCalculated(i), A + B * d1[i - 9]);
TS_ASSERT_DELTA(values.getCalculated(i), A + B * d1[i - 9], 1e-6);
}
A = multi.getFunction(0)->getParameter("A") +
......@@ -356,7 +356,7 @@ public:
const FunctionDomain1D &d2 =
static_cast<const FunctionDomain1D &>(domain.getDomain(2));
for (size_t i = 19; i < 30; ++i) {
TS_ASSERT_EQUALS(values.getCalculated(i), A + B * d2[i - 19]);
TS_ASSERT_DELTA(values.getCalculated(i), A + B * d2[i - 19], 1e-6);
}
}
......
......@@ -103,8 +103,9 @@ Mantid::Kernel::TimeSeriesProperty<double> *AddLogDerivative::makeDerivative(
DateAndTime start = input->nthTime(0);
std::vector<DateAndTime> timeFull;
timeFull.reserve(times.size());
for (const double time : times)
timeFull.emplace_back(start + time);
std::transform(times.begin(), times.end(), std::back_inserter(timeFull),
[&start](const double time) { return start + time; });
// Create the TSP out of it
auto out = new TimeSeriesProperty<double>(name);
......
......@@ -146,9 +146,9 @@ void CalculateDynamicRange::exec() {
}
if (!dets.empty()) {
detIDs.reserve(dets.size());
for (const auto &det : dets) {
detIDs.emplace_back(det->getID());
}
std::transform(dets.begin(), dets.end(), std::back_inserter(detIDs),
[](const auto &det) { return det->getID(); });
const auto indices = workspace->getIndicesFromDetectorIDs(detIDs);
calculateQMinMax(workspace, indices, compName);
}
......
......@@ -91,7 +91,6 @@ CalculatePlaczekSelfScattering::validateInputs() {
void CalculatePlaczekSelfScattering::exec() {
const API::MatrixWorkspace_sptr inWS = getProperty("InputWorkspace");
const API::MatrixWorkspace_sptr incidentWS = getProperty("IncidentSpecta");
API::MatrixWorkspace_sptr outWS = getProperty("OutputWorkspace");
constexpr double factor =
1.0 / 1.66053906660e-27; // atomic mass unit-kilogram relationship
constexpr double neutronMass = factor * 1.674927471e-27; // neutron mass
......@@ -99,11 +98,15 @@ void CalculatePlaczekSelfScattering::exec() {
// of each species
auto atomSpecies = getSampleSpeciesInfo(inWS);
// calculate summation term w/ neutron mass over molecular mass ratio
double summationTerm = 0.0;
for (auto atom : atomSpecies) {
summationTerm += atom.second["concentration"] * atom.second["bSqrdBar"] *
auto sumLambda = [&neutronMass](double sum, auto &atom) {
return sum + atom.second["concentration"] * atom.second["bSqrdBar"] *
neutronMass / atom.second["mass"];
}
};
double summationTerm =
std::accumulate(atomSpecies.begin(), atomSpecies.end(), 0.0, sumLambda);
// get incident spectrum and 1st derivative
const MantidVec xLambda = incidentWS->readX(0);
const MantidVec incident = incidentWS->readY(0);
......
......@@ -54,8 +54,8 @@ void ChangeBinOffset::exec() {
this->for_each<Indices::FromProperty>(
*outputW, std::make_tuple(MatrixWorkspaceAccess::x),
[offset](std::vector<double> &dataX) {
for (auto &x : dataX)
x += offset;
std::transform(dataX.begin(), dataX.end(), dataX.begin(),
[offset](double x) { return x + offset; });
});
}
}
......
......@@ -82,12 +82,11 @@ void ChangeTimeZero::exec() {
// Set up remaining progress points
const double progressStartShiftTimeLogs = progressStopCreateOutputWs;
double progressStopShiftTimeLogs = progressStartShiftTimeLogs;
if (boost::dynamic_pointer_cast<Mantid::API::IEventWorkspace>(out_ws)) {
progressStopShiftTimeLogs = progressStartShiftTimeLogs + 0.1;
} else {
progressStopShiftTimeLogs = 1.0;
}
double progressStopShiftTimeLogs =
boost::dynamic_pointer_cast<Mantid::API::IEventWorkspace>(out_ws)
? progressStartShiftTimeLogs + 0.1
: 1.0;
const double progressStartShiftNeutrons = progressStopShiftTimeLogs;
const double progressStopShiftNeutrons = 1.0;
......
......@@ -238,9 +238,10 @@ MatrixWorkspace_sptr ConvertSpectrumAxis2::createOutputWorkspace(
create<MatrixWorkspace>(*inputWS, m_indexMap.size(), hist);
std::vector<double> axis;
axis.reserve(m_indexMap.size());
for (const auto &it : m_indexMap) {
axis.emplace_back(it.first);
}
std::transform(m_indexMap.begin(), m_indexMap.end(),
std::back_inserter(axis),
[](const auto &it) { return it.first; });
newAxis = std::make_unique<NumericAxis>(std::move(axis));
} else {
// If there is no reordering we can simply clone.
......
......@@ -157,8 +157,9 @@ void CorelliCrossCorrelate::exec() {
int offset_int = getProperty("TimingOffset");
const auto offset = static_cast<int64_t>(offset_int);
for (auto &timing : tdc)
timing += offset;
std::transform(tdc.begin(), tdc.end(), tdc.begin(),
[offset](auto timing) { return timing + offset; });
// Determine period from chopper frequency.
auto motorSpeed = dynamic_cast<TimeSeriesProperty<double> *>(
......
......@@ -110,9 +110,6 @@ void CreateDummyCalFile::exec() {
std::string filename = getProperty("CalFilename");
// Plan to overwrite file, so do not check if it exists
const bool overwrite = false;
int number = 0;
Progress prog(this, 0.0, 0.8, assemblies.size());
while (!assemblies.empty()) // Travel the tree from the instrument point
......@@ -128,12 +125,7 @@ void CreateDummyCalFile::exec() {
currentIComp);
if (currentDet.get()) // Is detector
{
if (overwrite) // Map will contains udet as the key
instrcalib[currentDet->getID()] =
std::make_pair(number++, top_group);
else // Map will contains the entry number as the key
instrcalib[number++] =
std::make_pair(currentDet->getID(), top_group);
instrcalib[number++] = std::make_pair(currentDet->getID(), top_group);
} else // Is an assembly, push in the queue
{
currentchild =
......@@ -151,6 +143,8 @@ void CreateDummyCalFile::exec() {
prog.report();
}
// Write the results in a file
// Plan to overwrite file, so do not check if it exists
const bool overwrite = false;
saveGroupingFile(filename, overwrite);
progress(0.2);
}
......
......@@ -195,9 +195,12 @@ retrieveMatrixWsList(const std::vector<std::string> &wsNames,
// Retrieve pointers to all the child workspaces.
std::vector<MatrixWorkspace_sptr> childWsList;
childWsList.reserve(childNames.size());
for (const auto &childName : childNames) {
childWsList.emplace_back(ADS.retrieveWS<MatrixWorkspace>(childName));
}
std::transform(childNames.begin(), childNames.end(),
std::back_inserter(childWsList),
[&ADS](const auto &childName) {
return ADS.retrieveWS<MatrixWorkspace>(childName);
});
// Deal with child workspaces according to policy.
switch (groupPolicy) {
......
......@@ -95,11 +95,11 @@ void EQSANSCorrectFrame::exec() {
double newTOF = tof + m_framesOffsetTime;
// TOF values smaller than that of the fastest neutrons have been
// 'folded' by the data acquisition system. They must be shifted
double minTOF = m_minTOF * pathToPixelFactor;
if (newTOF < minTOF)
double scaledMinTOF = m_minTOF * pathToPixelFactor;
if (newTOF < scaledMinTOF)
newTOF += m_frameWidth;
// Events from the skipped pulse are delayed by one pulse period
if (m_isFrameSkipping && newTOF > minTOF + m_pulsePeriod)
if (m_isFrameSkipping && newTOF > scaledMinTOF + m_pulsePeriod)
newTOF += m_pulsePeriod;
return newTOF;
}
......
Markdown is supported
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