Skip to content

Commit

Permalink
cppcheck fixes from pr job
Browse files Browse the repository at this point in the history
  • Loading branch information
jhaigh0 committed Apr 25, 2024
1 parent 6af7b9a commit f2a750c
Show file tree
Hide file tree
Showing 15 changed files with 41 additions and 54 deletions.
9 changes: 5 additions & 4 deletions Framework/API/src/IFunction.cpp
Expand Up @@ -418,7 +418,7 @@ IConstraint *IFunction::getConstraint(size_t i) const {
void IFunction::removeConstraint(const std::string &parName) {
size_t iPar = parameterIndex(parName);
const auto it = std::find_if(m_constraints.cbegin(), m_constraints.cend(),
[&iPar](const auto &constraint) { return constraint->getLocalIndex == iPar; });
[&iPar](const auto &constraint) { return iPar == constraint->getLocalIndex(); });
if (it != m_constraints.cend()) {
m_constraints.erase(it);
}
Expand Down Expand Up @@ -455,7 +455,7 @@ void IFunction::setUpForFit() {
std::string IFunction::writeConstraints() const {
std::ostringstream stream;
bool first = true;
for (auto &constrint : m_constraints) {
for (const auto &constrint : m_constraints) {
if (constrint->isDefault())
continue;
if (!first) {
Expand Down Expand Up @@ -729,7 +729,7 @@ std::string IFunction::Attribute::asUnquotedString() const {
if (*(attr.begin()) == '\"')
unquoted = std::string(attr.begin() + 1, attr.end() - 1);
if (*(unquoted.end() - 1) == '\"')
unquoted = std::string(unquoted.begin(), unquoted.end() - 1);
unquoted.resize(unquoted.size() - 1);

return unquoted;
}
Expand Down Expand Up @@ -1673,7 +1673,8 @@ IPropertyManager::getValue<std::shared_ptr<Mantid::API::IFunction>>(const std::s
template <>
MANTID_API_DLL std::shared_ptr<const Mantid::API::IFunction>
IPropertyManager::getValue<std::shared_ptr<const Mantid::API::IFunction>>(const std::string &name) const {
auto *prop = dynamic_cast<PropertyWithValue<std::shared_ptr<Mantid::API::IFunction>> *>(getPointerToProperty(name));
const auto *prop =
dynamic_cast<PropertyWithValue<std::shared_ptr<Mantid::API::IFunction>> *>(getPointerToProperty(name));
if (prop) {
return prop->operator()();
} else {
Expand Down
2 changes: 1 addition & 1 deletion Framework/Algorithms/inc/MantidAlgorithms/FitPeaks.h
Expand Up @@ -214,7 +214,7 @@ class MANTID_ALGORITHMS_DLL FitPeaks final : public API::Algorithm {
const std::shared_ptr<FitPeaksAlgorithm::PeakFitResult> &fit_result);

/// calculate peak+background for fitted
void calculateFittedPeaks(std::vector<std::shared_ptr<FitPeaksAlgorithm::PeakFitResult>> fit_results);
void calculateFittedPeaks(const std::vector<std::shared_ptr<FitPeaksAlgorithm::PeakFitResult>> &fit_results);

/// Get the parameter name for peak height (I or height or etc)
std::string getPeakHeightParameterName(const API::IPeakFunction_const_sptr &peak_function);
Expand Down
4 changes: 2 additions & 2 deletions Framework/Algorithms/src/ConvertUnits.cpp
Expand Up @@ -318,7 +318,7 @@ MatrixWorkspace_sptr ConvertUnits::convertQuickly(const API::MatrixWorkspace_con
if (commonBoundaries) {
// Calculate the new (common) X values
std::transform(outputWS->mutableX(0).cbegin(), outputWS->mutableX(0).cend(), outputWS->mutableX(0).begin(),
[&](auto &x) { return factor * std::pow(x, power); });
[&](const auto &x) { return factor * std::pow(x, power); });

auto xVals = outputWS->sharedX(0);

Expand All @@ -345,7 +345,7 @@ MatrixWorkspace_sptr ConvertUnits::convertQuickly(const API::MatrixWorkspace_con
PARALLEL_START_INTERRUPT_REGION
if (!commonBoundaries) {
std::transform(outputWS->mutableX(k).cbegin(), outputWS->mutableX(k).cend(), outputWS->mutableX(k).begin(),
[&](auto &x) { return factor * std::pow(x, power); });
[&](const auto &x) { return factor * std::pow(x, power); });
}
// Convert the events themselves if necessary.
if (m_inputEvents) {
Expand Down
4 changes: 2 additions & 2 deletions Framework/Algorithms/src/FitPeaks.cpp
Expand Up @@ -497,7 +497,7 @@ std::map<std::string, std::string> FitPeaks::validateInputs() {
// check that the supplied names are in the function
// it is acceptable to be missing parameters
const bool failed = std::any_of(suppliedParameterNames.cbegin(), suppliedParameterNames.cend(),
[&functionParameterNames](const auto &parNme) {
[&functionParameterNames](const auto &parName) {
return std::find(functionParameterNames.begin(), functionParameterNames.end(),
parName) == functionParameterNames.end();
});
Expand Down Expand Up @@ -1470,7 +1470,7 @@ bool FitPeaks::processSinglePeakFitResult(size_t wsindex, size_t peakindex, cons
* fitted parameter
* table
*/
void FitPeaks::calculateFittedPeaks(std::vector<std::shared_ptr<FitPeaksAlgorithm::PeakFitResult>> fit_results) {
void FitPeaks::calculateFittedPeaks(const std::vector<std::shared_ptr<FitPeaksAlgorithm::PeakFitResult>> &fit_results) {
// check
if (!m_fittedParamTable)
throw std::runtime_error("No parameters");
Expand Down
2 changes: 1 addition & 1 deletion Framework/CurveFitting/src/Functions/ProcessBackground.cpp
Expand Up @@ -503,7 +503,7 @@ void ProcessBackground::selectFromGivenFunction() {

auto bkgdorder = static_cast<int>(parmap.size() - 1); // A0 - A(n) total n+1 parameters
bkgdfunc->setAttributeValue("n", bkgdorder);
for (auto &mit : parmap) {
for (const auto &mit : parmap) {
string parname = mit.first;
double parvalue = mit.second;
bkgdfunc->setParameter(parname, parvalue);
Expand Down
4 changes: 2 additions & 2 deletions Framework/DataHandling/inc/MantidDataHandling/LoadHelper.h
Expand Up @@ -55,8 +55,8 @@ NeXus::NXDouble getDoubleDataset(const NeXus::NXEntry &, const std::string &);

void replaceZeroErrors(const API::MatrixWorkspace_sptr &, double);

void recurseAndAddNexusFieldsToWsRun(NXhandle nxfileID, API::Run &runDetails, std::string &parent_name,
std::string &parent_class, int level, bool useFullPath);
void recurseAndAddNexusFieldsToWsRun(NXhandle nxfileID, API::Run &runDetails, const std::string &parent_name,
const std::string &parent_class, int level, bool useFullPath);
} // namespace LoadHelper
} // namespace DataHandling
} // namespace Mantid
Expand Up @@ -68,7 +68,7 @@ class MANTID_DATAHANDLING_DLL LoadRawHelper : public API::IFileLoader<Kernel::Fi
static bool isIncludeMonitors(const std::string &monitorOption);

static void ProcessLoadMonitorOptions(bool &bincludeMonitors, bool &bseparateMonitors, bool &bexcludeMonitors,
API::Algorithm *const pAlgo);
const API::Algorithm *pAlgo);
/// creates monitor workspace
static void createMonitorWorkspace(DataObjects::Workspace2D_sptr &monws_sptr,
const DataObjects::Workspace2D_sptr &normalws_sptr,
Expand Down
2 changes: 1 addition & 1 deletion Framework/DataHandling/src/DetermineChunking.cpp
Expand Up @@ -142,7 +142,7 @@ void DetermineChunking::exec() {
string dataDir;
LoadPreNexus lp;
lp.parseRuninfo(filename, dataDir, eventFilenames);
for (auto &eventFilename : eventFilenames) {
for (const auto &eventFilename : eventFilenames) {
BinaryFile<DasEvent> eventfile(dataDir + eventFilename);
// Factor of 2 for compression
wkspSizeGiB += static_cast<double>(eventfile.getNumElements()) * 48.0 * BYTES_TO_GiB;
Expand Down
2 changes: 1 addition & 1 deletion Framework/DataHandling/src/LoadDetectorsGroupingFile.cpp
Expand Up @@ -264,7 +264,7 @@ void LoadDetectorsGroupingFile::setByDetectors() {
const detid2index_map indexmap = m_groupWS->getDetectorIDToWorkspaceIndexMap(true);

// 2. Set GroupingWorkspace
for (auto &detectorMap : m_groupDetectorsMap) {
for (const auto &detectorMap : m_groupDetectorsMap) {
g_log.debug() << "Group ID = " << detectorMap.first << '\n';

for (auto detid : detectorMap.second) {
Expand Down
5 changes: 3 additions & 2 deletions Framework/DataHandling/src/LoadHelper.cpp
Expand Up @@ -163,8 +163,9 @@ void LoadHelper::addNexusFieldsToWsRun(NXhandle nxfileID, API::Run &runDetails,
* @param useFullPath :: use full path to entry in nexus tree to generate the log entry name in Mantid
*
*/
void LoadHelper::recurseAndAddNexusFieldsToWsRun(NXhandle nxfileID, API::Run &runDetails, std::string &parent_name,
std::string &parent_class, int level, bool useFullPath) {
void LoadHelper::recurseAndAddNexusFieldsToWsRun(NXhandle nxfileID, API::Run &runDetails,
const std::string &parent_name, const std::string &parent_class,
int level, bool useFullPath) {
// Classes
NXstatus getnextentry_status; ///< return status
int datatype; ///< NX data type if a dataset, e.g. NX_CHAR, NX_FLOAT32, see
Expand Down
4 changes: 2 additions & 2 deletions Framework/DataHandling/src/LoadILLPolarizationFactors.cpp
Expand Up @@ -79,7 +79,7 @@ std::string cleanse_comments(const std::string &l) {
}

/// Removes whitspace from 'l'.
void cleanse_whitespace(std::string &l) { l.erase(std::remove_if(l.begin(), l.end(), !isblank), l.end()); }
void cleanse_whitespace(std::string &l) { l.erase(std::remove_if(l.begin(), l.end(), isspace), l.end()); }

/// Returns true if `l` contains the limits array.
bool contains_limits(const std::string &l) { return l.find("_limits") != std::string::npos; }
Expand Down Expand Up @@ -144,7 +144,7 @@ std::map<Factor, FactorDefinition> parse(std::istream &in) {
} catch (std::exception &e) {
throw std::runtime_error(std::string("Unknown exception: ") + e.what());
}
l = cleanse_whitespace(l);
cleanse_whitespace(l);
l = cleanse_comments(l);
if (l.empty())
continue;
Expand Down
1 change: 0 additions & 1 deletion Framework/DataHandling/src/LoadNexusMonitors2.cpp
Expand Up @@ -176,7 +176,6 @@ void LoadNexusMonitors2::exec() {

// open the correct entry
using string_map_t = std::map<std::string, std::string>;
string_map_t::const_iterator it;
string_map_t entries = file.getEntries();

if (m_top_entry_name.empty()) {
Expand Down
6 changes: 3 additions & 3 deletions Framework/DataHandling/src/LoadRawHelper.cpp
Expand Up @@ -998,7 +998,7 @@ void LoadRawHelper::calculateWorkspacesizes(const std::vector<specnum_t> &monito
} else if (m_interval || m_bmspeclist) {
if (m_interval) {
int msize = std::count_if(monitorSpecList.cbegin(), monitorSpecList.cend(),
[](const auto &spec) { return (spec >= m_spec_min && spec < m_spec_min); });
[](const auto &spec) { return (spec >= m_spec_min && spec < m_spec_max); });
monitorwsSpecs = msize;
normalwsSpecs = m_total_specs - monitorwsSpecs;
g_log.debug() << "normalwsSpecs when m_interval true is " << normalwsSpecs << " monitorwsSpecs is "
Expand Down Expand Up @@ -1055,7 +1055,7 @@ void LoadRawHelper::loadSpectra(FILE *file, const int &period, const int &total_

int64_t histCurrent = -1;
int64_t wsIndex = 0;
auto &isisRawRef = isisRaw();
const auto &isisRawRef = isisRaw();
auto numberOfPeriods = static_cast<int64_t>(isisRawRef.t_nper);
auto histTotal = static_cast<double>(total_specs * numberOfPeriods);
int64_t noTimeRegimes = getNumberofTimeRegimes();
Expand Down Expand Up @@ -1198,7 +1198,7 @@ bool LoadRawHelper::isSeparateMonitors(const std::string &monitorOption) { retur
* property.
*/
void LoadRawHelper::ProcessLoadMonitorOptions(bool &bincludeMonitors, bool &bseparateMonitors, bool &bexcludeMonitors,
API::Algorithm *pAlgo) {
const API::Algorithm *pAlgo) {
// process monitor option
std::string monitorOption = pAlgo->getProperty("LoadMonitors");
if (monitorOption == "1")
Expand Down
4 changes: 2 additions & 2 deletions Framework/Geometry/src/Instrument.cpp
Expand Up @@ -753,7 +753,7 @@ void Instrument::getBoundingBox(BoundingBox &assemblyBox) const {
m_cachedBoundingBox = new BoundingBox();
ComponentID sourceID = getSource()->getComponentID();
// Loop over the children and define a box large enough for all of them
for (auto component : m_children) {
for (const auto component : m_children) {
BoundingBox compBox;
if (component && component->getComponentID() != sourceID) {
component->getBoundingBox(compBox);
Expand Down Expand Up @@ -793,7 +793,7 @@ std::shared_ptr<const std::vector<IObjComponent_const_sptr>> Instrument::getPlot
void Instrument::appendPlottable(const CompAssembly &ca, std::vector<IObjComponent_const_sptr> &lst) const {
for (int i = 0; i < ca.nelements(); i++) {
IComponent *c = ca[i].get();
auto *a = dynamic_cast<CompAssembly *>(c);
const auto *a = dynamic_cast<CompAssembly *>(c);
if (a)
appendPlottable(*a, lst);
else {
Expand Down

0 comments on commit f2a750c

Please sign in to comment.