From 7d1de1eaacee1b4d090983422e1ac5ff6ea5286f Mon Sep 17 00:00:00 2001 From: Pete Peterson Date: Mon, 9 Dec 2024 16:17:40 -0500 Subject: [PATCH] Fix cppcheck warnings and remove unused headers --- Framework/API/src/Run.cpp | 19 +++++-------- .../inc/MantidAlgorithms/MergeRuns.h | 1 + .../inc/MantidDataHandling/SaveISISNexus.h | 20 +++++++------ .../SaveToSNSHistogramNexus.h | 2 +- .../DataHandling/src/DetermineChunking.cpp | 8 ++---- .../DataHandling/src/LoadEmptyInstrument.cpp | 4 +-- Framework/DataHandling/src/LoadHelper.cpp | 28 ++++++++----------- .../DataHandling/src/LoadMcStasNexus.cpp | 2 +- Framework/DataHandling/src/SaveISISNexus.cpp | 20 +++++++------ .../src/SaveToSNSHistogramNexus.cpp | 2 +- .../src/LeanElasticPeaksWorkspace.cpp | 17 ++++------- Framework/DataObjects/src/PeaksWorkspace.cpp | 22 ++++++--------- .../Geometry/src/Crystal/OrientedLattice.cpp | 6 ++-- .../inc/MantidMDAlgorithms/MergeMDFiles.h | 2 -- Framework/MDAlgorithms/src/LoadMD.cpp | 1 - Framework/MDAlgorithms/src/MergeMDFiles.cpp | 3 +- Framework/Nexus/src/NexusFileIO.cpp | 5 ++-- .../SINQ/inc/MantidSINQ/LoadFlexiNexus.h | 9 ++---- Framework/SINQ/src/LoadFlexiNexus.cpp | 3 +- Framework/SINQ/test/LoadFlexiNexusTest.h | 1 + .../CMake/CppCheck_Suppressions.txt.in | 13 --------- 21 files changed, 75 insertions(+), 113 deletions(-) diff --git a/Framework/API/src/Run.cpp b/Framework/API/src/Run.cpp index 76d83ad2ca48..7e56694b6be5 100644 --- a/Framework/API/src/Run.cpp +++ b/Framework/API/src/Run.cpp @@ -6,7 +6,6 @@ // SPDX - License - Identifier: GPL - 3.0 + #include "MantidAPI/Run.h" #include "MantidGeometry/Instrument/Goniometer.h" -#include "MantidKernel/DateAndTime.h" #include "MantidKernel/FilteredTimeSeriesProperty.h" #include "MantidKernel/Matrix.h" #include "MantidKernel/PropertyManager.h" @@ -197,7 +196,7 @@ Run &Run::operator+=(const Run &rhs) { for (const auto &name : ADDABLE) { if (rhs.m_manager->existsProperty(name)) { // get a pointer to the property on the right-hand side workspace - Property *right = rhs.m_manager->getProperty(name); + const Property *right = rhs.m_manager->getProperty(name); // now deal with the left-hand side if (m_manager->existsProperty(name)) { @@ -280,11 +279,11 @@ double Run::getProtonCharge() const { * If "proton_charge" is not found, the value is not stored */ void Run::integrateProtonCharge(const std::string &logname) const { - Kernel::TimeSeriesProperty *log = nullptr; + Kernel::TimeSeriesProperty const *log = nullptr; if (this->hasProperty(logname)) { try { - log = dynamic_cast *>(this->getProperty(logname)); + log = dynamic_cast const *>(this->getProperty(logname)); } catch (Exception::NotFoundError &) { g_log.warning(logname + " log was not found. The value of the total proton " "charge has not been set"); @@ -299,8 +298,8 @@ void Run::integrateProtonCharge(const std::string &logname) const { // get a copy of the run's TimeROI for selecting values Kernel::TimeROI timeroi = this->getTimeROI(); // If the proton charge series is filtered, fetch its TimeROI and use it to update `timeRoi` - auto filteredLog = dynamic_cast *>(this->getProperty(logname)); - if (filteredLog) + if (const auto *filteredLog = + dynamic_cast *>(this->getProperty(logname))) timeroi.update_or_replace_intersection(filteredLog->getTimeROI()); if (timeroi.useAll()) { @@ -696,9 +695,7 @@ void Run::loadNexus(::NeXus::File *file, const std::string &group, const Mantid: if (this->hasProperty("proton_charge")) { // Old files may have a proton_charge field, single value. // Modern files (e.g. SNS) have a proton_charge TimeSeriesProperty. - PropertyWithValue *charge_log = - dynamic_cast *>(this->getProperty("proton_charge")); - if (charge_log) { + if (const auto *charge_log = dynamic_cast *>(this->getProperty("proton_charge"))) { this->setProtonCharge(boost::lexical_cast(charge_log->value())); } } @@ -729,9 +726,7 @@ void Run::loadNexus(::NeXus::File *file, const std::string &group, bool keepOpen if (this->hasProperty("proton_charge")) { // Old files may have a proton_charge field, single value. // Modern files (e.g. SNS) have a proton_charge TimeSeriesProperty. - PropertyWithValue *charge_log = - dynamic_cast *>(this->getProperty("proton_charge")); - if (charge_log) { + if (const auto *charge_log = dynamic_cast *>(this->getProperty("proton_charge"))) { this->setProtonCharge(boost::lexical_cast(charge_log->value())); } } diff --git a/Framework/Algorithms/inc/MantidAlgorithms/MergeRuns.h b/Framework/Algorithms/inc/MantidAlgorithms/MergeRuns.h index 77e400be8005..710387ba3f74 100644 --- a/Framework/Algorithms/inc/MantidAlgorithms/MergeRuns.h +++ b/Framework/Algorithms/inc/MantidAlgorithms/MergeRuns.h @@ -13,6 +13,7 @@ #include "MantidDataObjects/EventWorkspace.h" #include "MantidGeometry/Instrument/DetectorInfo.h" +#include #include namespace Mantid { diff --git a/Framework/DataHandling/inc/MantidDataHandling/SaveISISNexus.h b/Framework/DataHandling/inc/MantidDataHandling/SaveISISNexus.h index 20b1aff2fe37..5ae7a0db01c9 100644 --- a/Framework/DataHandling/inc/MantidDataHandling/SaveISISNexus.h +++ b/Framework/DataHandling/inc/MantidDataHandling/SaveISISNexus.h @@ -76,19 +76,19 @@ class MANTID_DATAHANDLING_DLL SaveISISNexus final : public API::Algorithm { NXlink time_of_flight_raw_link; int *getMonitorData(int period, int imon); - void saveInt(const char *name, void *data, int size = 1); - void saveChar(const char *name, void *data, int size); - void saveFloat(const char *name, void *data, int size); - void saveIntOpen(const char *name, void *data, int size = 1); - void saveCharOpen(const char *name, void *data, int size); - void saveFloatOpen(const char *name, void *data, int size); + void saveInt(const char *name, const void *data, const int size = 1); + void saveChar(const char *name, const void *data, const int size); + void saveFloat(const char *name, const void *data, const int size); + void saveIntOpen(const char *name, const void *data, const int size = 1); + void saveCharOpen(const char *name, const void *data, const int size); + void saveFloatOpen(const char *name, const void *data, const int size); int saveStringVectorOpen(const char *name, const std::vector &str_vec, int max_str_size = -1); void saveString(const char *name, const std::string &str); void saveStringOpen(const char *name, const std::string &str); inline void close() { NXclosedata(handle); } ///< close an open dataset. inline void closegroup() { NXclosegroup(handle); } ///< close an open group. void putAttr(const char *name, const std::string &value); - void putAttr(const char *name, char *value, int size); + void putAttr(const char *name, const char *value, const int size); void putAttr(const char *name, int value, int size = 1); void toISO8601(std::string &str); @@ -119,9 +119,11 @@ class MANTID_DATAHANDLING_DLL SaveISISNexus final : public API::Algorithm { /// Write runlog void runlog(); /// write one run log - void write_runlog(const char *name, void *times, void *data, int type, int size, const std::string &units); + void write_runlog(const char *name, const void *times, const void *data, const int type, const int size, + const std::string &units); /// write NXlog - void write_logOpen(const char *name, void *times, void *data, int type, int size, const std::string &units); + void write_logOpen(const char *name, const void *times, const void *data, const int type, const int size, + const std::string &units); /// Write selog void selog(); /// Write notes from LOG_STRUCT diff --git a/Framework/DataHandling/inc/MantidDataHandling/SaveToSNSHistogramNexus.h b/Framework/DataHandling/inc/MantidDataHandling/SaveToSNSHistogramNexus.h index 0d5779cd8636..a1abafdc964d 100644 --- a/Framework/DataHandling/inc/MantidDataHandling/SaveToSNSHistogramNexus.h +++ b/Framework/DataHandling/inc/MantidDataHandling/SaveToSNSHistogramNexus.h @@ -12,7 +12,7 @@ #include "MantidAPI/Sample.h" #include "MantidDataHandling/DllConfig.h" #include "MantidDataObjects/EventWorkspace.h" -#include "MantidDataObjects/Workspace2D.h" +#include "MantidDataObjects/Workspace2D_fwd.h" #include "MantidGeometry/Instrument/RectangularDetector.h" #include // clang-format off diff --git a/Framework/DataHandling/src/DetermineChunking.cpp b/Framework/DataHandling/src/DetermineChunking.cpp index a441f9c1b426..4deba6162e16 100644 --- a/Framework/DataHandling/src/DetermineChunking.cpp +++ b/Framework/DataHandling/src/DetermineChunking.cpp @@ -10,14 +10,11 @@ #include "MantidAPI/ITableWorkspace.h" #include "MantidAPI/TableRow.h" #include "MantidAPI/WorkspaceFactory.h" -#include "MantidDataHandling/LoadEventNexus.h" #include "MantidDataHandling/LoadPreNexus.h" #include "MantidDataHandling/LoadRawHelper.h" #include "MantidDataHandling/LoadTOFRawNexus.h" #include "MantidKernel/BinaryFile.h" #include "MantidKernel/BoundedValidator.h" -#include "MantidKernel/System.h" -#include "MantidKernel/VisibleWhenProperty.h" // clang-format off #include @@ -26,7 +23,6 @@ #include #include -#include #include #include @@ -160,11 +156,11 @@ void DetermineChunking::exec() { std::string classType = "NXevent_data"; size_t total_events = 0; for (; it != entries.end(); ++it) { - std::string entry_name(it->first); - std::string entry_class(it->second); + const std::string entry_class(it->second); if (entry_class == classType) { if (!isEmpty(maxChunk)) { try { + const std::string entry_name(it->first); // Get total number of events for each bank file.openGroup(entry_name, entry_class); file.openData("total_counts"); diff --git a/Framework/DataHandling/src/LoadEmptyInstrument.cpp b/Framework/DataHandling/src/LoadEmptyInstrument.cpp index c27a5086274a..a7e6d667fa5a 100644 --- a/Framework/DataHandling/src/LoadEmptyInstrument.cpp +++ b/Framework/DataHandling/src/LoadEmptyInstrument.cpp @@ -54,11 +54,11 @@ std::string LoadEmptyInstrument::retrieveValidInstrumentFilenameExtension(const // Test a possible double extension if (!pre_ext.empty()) { - std::string double_ext{pre_ext + ext}; try { + const std::string double_ext{pre_ext + ext}; FilenameExtension fne(double_ext); return fne.c_str(); - } catch (std::runtime_error &) { + } catch (const std::runtime_error &) { } } diff --git a/Framework/DataHandling/src/LoadHelper.cpp b/Framework/DataHandling/src/LoadHelper.cpp index 5d5f89bdff3c..4a325efba4a5 100644 --- a/Framework/DataHandling/src/LoadHelper.cpp +++ b/Framework/DataHandling/src/LoadHelper.cpp @@ -11,7 +11,6 @@ #include "MantidDataHandling/LoadHelper.h" #include "MantidAPI/AlgorithmManager.h" #include "MantidAPI/MatrixWorkspace.h" -#include "MantidAPI/SpectrumInfo.h" #include "MantidGeometry/Instrument.h" #include "MantidGeometry/Instrument/ComponentInfo.h" #include "MantidKernel/OptionalBool.h" @@ -126,8 +125,7 @@ double LoadHelper::getInstrumentProperty(const API::MatrixWorkspace_sptr &worksp */ void LoadHelper::addNexusFieldsToWsRun(NXhandle nxfileID, API::Run &runDetails, const std::string &entryName, bool useFullPath) { - int datatype; - char nxname[NX_MAXNAMELEN], nxclass[NX_MAXNAMELEN]; + char nxname[NX_MAXNAMELEN]; if (!entryName.empty()) { strcpy(nxname, entryName.c_str()); } @@ -137,7 +135,8 @@ void LoadHelper::addNexusFieldsToWsRun(NXhandle nxfileID, API::Run &runDetails, // by default we begin the parse on the first entry (entry0), // or from a chosen entryName. This allow to avoid the // bogus entries that follows. - + int datatype; + char nxclass[NX_MAXNAMELEN]; NXstatus getnextentry_status = NXgetnextentry(nxfileID, nxname, nxclass, &datatype); if (getnextentry_status == NX_OK) { if ((NXopengroup(nxfileID, nxname, nxclass)) == NX_OK) { @@ -165,24 +164,20 @@ void LoadHelper::recurseAndAddNexusFieldsToWsRun(NXhandle nxfileID, API::Run &ru 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 + int datatype; ///< NX data type if a dataset, e.g. NX_CHAR, NX_FLOAT32, see /// napi.h - char nxname[NX_MAXNAMELEN], nxclass[NX_MAXNAMELEN]; + char nxname[NX_MAXNAMELEN]; nxname[0] = '0'; + char nxclass[NX_MAXNAMELEN]; nxclass[0] = '0'; bool has_entry = true; // follows getnextentry_status while (has_entry) { - getnextentry_status = NXgetnextentry(nxfileID, nxname, nxclass, &datatype); + const NXstatus getnextentry_status = NXgetnextentry(nxfileID, nxname, nxclass, &datatype); if (getnextentry_status == NX_OK) { - NXstatus opengroup_status; - NXstatus opendata_status; - NXstatus getinfo_status; - std::string property_name = (parent_name.empty() ? nxname : parent_name + "." + nxname); - if ((opengroup_status = NXopengroup(nxfileID, nxname, nxclass)) == NX_OK) { + if (NXopengroup(nxfileID, nxname, nxclass) == NX_OK) { if (std::string(nxclass) != "ILL_data_scan_vars" && std::string(nxclass) != "NXill_data_scan_vars") { // Go down to one level, if the group is known to nexus std::string p_nxname = useFullPath ? property_name : nxname; // current names can be useful for next level @@ -193,7 +188,7 @@ void LoadHelper::recurseAndAddNexusFieldsToWsRun(NXhandle nxfileID, API::Run &ru NXclosegroup(nxfileID); } // if(NXopengroup - else if ((opendata_status = NXopendata(nxfileID, nxname)) == NX_OK) { + else if (NXopendata(nxfileID, nxname) == NX_OK) { if (parent_class != "NXData" && parent_class != "NXMonitor" && std::string(nxname) != "data") { // create a property int rank = 0; @@ -201,7 +196,7 @@ void LoadHelper::recurseAndAddNexusFieldsToWsRun(NXhandle nxfileID, API::Run &ru int type; // Get the value - if ((getinfo_status = NXgetinfo(nxfileID, &rank, dims, &type)) == NX_OK) { + if (NXgetinfo(nxfileID, &rank, dims, &type) == NX_OK) { // Note, we choose to only build properties on small float arrays // filter logic is below bool build_small_float_array = false; // default @@ -257,8 +252,7 @@ void LoadHelper::recurseAndAddNexusFieldsToWsRun(NXhandle nxfileID, API::Run &ru int units_len = NX_MAXNAMELEN; int units_type = NX_CHAR; - char unitsAttrName[] = "units"; - units_status = NXgetattr(nxfileID, unitsAttrName, units_sbuf, &units_len, &units_type); + units_status = NXgetattr(nxfileID, std::string("units").c_str(), units_sbuf, &units_len, &units_type); if ((type == NX_FLOAT32) || (type == NX_FLOAT64)) { // Mantid numerical properties are double only. double property_double_value = 0.0; diff --git a/Framework/DataHandling/src/LoadMcStasNexus.cpp b/Framework/DataHandling/src/LoadMcStasNexus.cpp index ddbcf71cdb25..0df3a171606a 100644 --- a/Framework/DataHandling/src/LoadMcStasNexus.cpp +++ b/Framework/DataHandling/src/LoadMcStasNexus.cpp @@ -97,7 +97,7 @@ void LoadMcStasNexus::exec() { // Find the axis names auto nxdataEntries = nxFile.getEntries(); std::string axis1Name, axis2Name; - for (auto &nxdataEntry : nxdataEntries) { + for (const auto &nxdataEntry : nxdataEntries) { if (nxdataEntry.second == "NXparameters") continue; nxFile.openData(nxdataEntry.first); diff --git a/Framework/DataHandling/src/SaveISISNexus.cpp b/Framework/DataHandling/src/SaveISISNexus.cpp index 109a3624bd64..9206406c37c9 100644 --- a/Framework/DataHandling/src/SaveISISNexus.cpp +++ b/Framework/DataHandling/src/SaveISISNexus.cpp @@ -225,7 +225,7 @@ void SaveISISNexus::exec() { * @param data Pointer to the data source * @param size size of the data in sizeof(int) */ -void SaveISISNexus::saveInt(const char *name, void *data, int size) { +void SaveISISNexus::saveInt(const char *name, const void *data, const int size) { saveIntOpen(name, data, size); close(); } @@ -236,7 +236,7 @@ void SaveISISNexus::saveInt(const char *name, void *data, int size) { * @param data Pointer to the data source * @param size size of the data in sizeof(char) */ -void SaveISISNexus::saveChar(const char *name, void *data, int size) { +void SaveISISNexus::saveChar(const char *name, const void *data, const int size) { saveCharOpen(name, data, size); close(); } @@ -247,7 +247,7 @@ void SaveISISNexus::saveChar(const char *name, void *data, int size) { * @param data Pointer to the data source * @param size size of the data in sizeof(float) */ -void SaveISISNexus::saveFloat(const char *name, void *data, int size) { +void SaveISISNexus::saveFloat(const char *name, const void *data, const int size) { saveFloatOpen(name, data, size); close(); } @@ -258,7 +258,7 @@ void SaveISISNexus::saveFloat(const char *name, void *data, int size) { * @param data Pointer to the data source * @param size size of the data in sizeof(int) */ -void SaveISISNexus::saveIntOpen(const char *name, void *data, int size) { +void SaveISISNexus::saveIntOpen(const char *name, const void *data, const int size) { int dim[1]; dim[0] = size; // If we aren't going to anything with the status, then don't bother asking @@ -274,7 +274,7 @@ void SaveISISNexus::saveIntOpen(const char *name, void *data, int size) { * @param data Pointer to the data source * @param size size of the data in sizeof(char) */ -void SaveISISNexus::saveCharOpen(const char *name, void *data, int size) { +void SaveISISNexus::saveCharOpen(const char *name, const void *data, const int size) { int dim[1]; dim[0] = size; // If we aren't going to anything with the status, then don't bother asking @@ -290,7 +290,7 @@ void SaveISISNexus::saveCharOpen(const char *name, void *data, int size) { * @param data Pointer to the data source * @param size size of the data in sizeof(float) */ -void SaveISISNexus::saveFloatOpen(const char *name, void *data, int size) { +void SaveISISNexus::saveFloatOpen(const char *name, const void *data, const int size) { int dim[1]; dim[0] = size; // If we aren't going to anything with the status, then don't bother asking @@ -370,7 +370,9 @@ void SaveISISNexus::putAttr(const char *name, const std::string &value) { NXputattr(handle, name, buff.get(), static_cast(value.size()), NX_CHAR); } -void SaveISISNexus::putAttr(const char *name, char *value, int size) { NXputattr(handle, name, value, size, NX_CHAR); } +void SaveISISNexus::putAttr(const char *name, const char *value, const int size) { + NXputattr(handle, name, value, size, NX_CHAR); +} void SaveISISNexus::putAttr(const char *name, int value, int size) { NXputattr(handle, name, &value, size, NX_INT32); } @@ -861,7 +863,7 @@ void SaveISISNexus::runlog() { * @param size The size of the data * @param units The units of the data */ -void SaveISISNexus::write_runlog(const char *name, void *times, void *data, int type, int size, +void SaveISISNexus::write_runlog(const char *name, const void *times, const void *data, const int type, const int size, const std::string &units) { write_logOpen(name, times, data, type, size, units); closegroup(); @@ -876,7 +878,7 @@ void SaveISISNexus::write_runlog(const char *name, void *times, void *data, int * @param size The size of the data * @param units The units of the data */ -void SaveISISNexus::write_logOpen(const char *name, void *times, void *data, int type, int size, +void SaveISISNexus::write_logOpen(const char *name, const void *times, const void *data, const int type, const int size, const std::string &units) { NXmakegroup(handle, name, "NXlog"); NXopengroup(handle, name, "NXlog"); diff --git a/Framework/DataHandling/src/SaveToSNSHistogramNexus.cpp b/Framework/DataHandling/src/SaveToSNSHistogramNexus.cpp index 5f8a97f3625c..3ed402023829 100644 --- a/Framework/DataHandling/src/SaveToSNSHistogramNexus.cpp +++ b/Framework/DataHandling/src/SaveToSNSHistogramNexus.cpp @@ -389,7 +389,6 @@ int SaveToSNSHistogramNexus::WriteOutDataOrErrors(const Geometry::RectangularDet */ int SaveToSNSHistogramNexus::WriteDataGroup(const std::string &bank, int is_definition) { int dataType, dataRank, dataDimensions[NX_MAXRANK]; - NXname nxName; void *dataBuffer; if (NXgetinfo(inId, &dataRank, dataDimensions, &dataType) != NX_OK) @@ -405,6 +404,7 @@ int SaveToSNSHistogramNexus::WriteDataGroup(const std::string &bank, int is_defi return NX_ERROR; if (NXgetdata(inId, dataBuffer) != NX_OK) return NX_ERROR; + NXname nxName; if (NXcompmakedata(outId, nxName, dataType, dataRank, dataDimensions, NX_COMP_LZW, dataDimensions) != NX_OK) return NX_ERROR; if (NXopendata(outId, nxName) != NX_OK) diff --git a/Framework/DataObjects/src/LeanElasticPeaksWorkspace.cpp b/Framework/DataObjects/src/LeanElasticPeaksWorkspace.cpp index 2d5b2c56dfa6..a9a21918412b 100644 --- a/Framework/DataObjects/src/LeanElasticPeaksWorkspace.cpp +++ b/Framework/DataObjects/src/LeanElasticPeaksWorkspace.cpp @@ -14,12 +14,8 @@ #include "MantidKernel/Logger.h" #include "MantidKernel/UnitConversion.h" -// clang-format off -#include -#include -// clang-format on - #include +#include using namespace Mantid::API; using namespace Mantid::Kernel; @@ -132,7 +128,7 @@ void LeanElasticPeaksWorkspace::removePeaks(std::vector badPeaks) { return; // if index of peak is in badPeaks remove int ip = -1; - auto it = std::remove_if(m_peaks.begin(), m_peaks.end(), [&ip, badPeaks](LeanElasticPeak &pk) { + auto it = std::remove_if(m_peaks.begin(), m_peaks.end(), [&ip, badPeaks](const LeanElasticPeak &pk) { (void)pk; ip++; return std::any_of(badPeaks.cbegin(), badPeaks.cend(), [ip](int badPeak) { return badPeak == ip; }); @@ -146,7 +142,7 @@ void LeanElasticPeaksWorkspace::removePeaks(std::vector badPeaks) { */ void LeanElasticPeaksWorkspace::addPeak(const Geometry::IPeak &ipeak) { if (dynamic_cast(&ipeak)) { - m_peaks.emplace_back((const LeanElasticPeak &)ipeak); + m_peaks.emplace_back(static_cast(ipeak)); } else { m_peaks.emplace_back(LeanElasticPeak(ipeak)); } @@ -617,7 +613,7 @@ void LeanElasticPeaksWorkspace::saveNexus(::NeXus::File *file) const { toNexus[ii * maxShapeJSONLength + ic] = ' '; } - file->putData((void *)(toNexus)); + file->putData(static_cast(toNexus)); delete[] toNexus; file->putAttr("units", "Not known"); // Units may need changing when known @@ -710,9 +706,8 @@ IPropertyManager::getValue( template <> DLLExport Mantid::DataObjects::LeanElasticPeaksWorkspace_const_sptr IPropertyManager::getValue(const std::string &name) const { - auto *prop = dynamic_cast *>( - getPointerToProperty(name)); - if (prop) { + if (const auto *prop = dynamic_cast *>( + getPointerToProperty(name))) { return prop->operator()(); } else { std::string message = "Attempt to assign property " + name + diff --git a/Framework/DataObjects/src/PeaksWorkspace.cpp b/Framework/DataObjects/src/PeaksWorkspace.cpp index 29e68a69fc49..5369a4cad165 100644 --- a/Framework/DataObjects/src/PeaksWorkspace.cpp +++ b/Framework/DataObjects/src/PeaksWorkspace.cpp @@ -14,12 +14,8 @@ #include "MantidKernel/Logger.h" #include "MantidKernel/UnitConversion.h" -// clang-format off -#include -#include -// clang-format on - #include +#include using namespace Mantid::API; using namespace Mantid::Kernel; @@ -142,8 +138,8 @@ void PeaksWorkspace::removePeaks(std::vector badPeaks) { return; // if index of peak is in badPeaks remove int ip = -1; - auto it = std::remove_if(m_peaks.begin(), m_peaks.end(), [&ip, badPeaks](Peak &pk) { - (void)pk; + auto it = std::remove_if(m_peaks.begin(), m_peaks.end(), [&ip, badPeaks](const Peak &pk) { + UNUSED_ARG(pk); ip++; return std::any_of(badPeaks.cbegin(), badPeaks.cend(), [ip](int badPeak) { return badPeak == ip; }); }); @@ -156,7 +152,7 @@ void PeaksWorkspace::removePeaks(std::vector badPeaks) { */ void PeaksWorkspace::addPeak(const Geometry::IPeak &ipeak) { if (dynamic_cast(&ipeak)) { - m_peaks.emplace_back((const Peak &)ipeak); + m_peaks.emplace_back(static_cast(ipeak)); } else { m_peaks.emplace_back(Peak(ipeak)); } @@ -914,7 +910,7 @@ void PeaksWorkspace::saveNexus(::NeXus::File *file) const { toNexus[ii * maxShapeJSONLength + ic] = ' '; } - file->putData((void *)(toNexus)); + file->putData(static_cast(toNexus)); delete[] toNexus; file->putAttr("units", "Not known"); // Units may need changing when known @@ -966,8 +962,8 @@ namespace Mantid::Kernel { template <> DLLExport Mantid::DataObjects::PeaksWorkspace_sptr IPropertyManager::getValue(const std::string &name) const { - auto *prop = dynamic_cast *>(getPointerToProperty(name)); - if (prop) { + if (const auto *prop = + dynamic_cast *>(getPointerToProperty(name))) { return *prop; } else { std::string message = @@ -979,8 +975,8 @@ IPropertyManager::getValue(const std:: template <> DLLExport Mantid::DataObjects::PeaksWorkspace_const_sptr IPropertyManager::getValue(const std::string &name) const { - auto *prop = dynamic_cast *>(getPointerToProperty(name)); - if (prop) { + if (const auto *prop = + dynamic_cast *>(getPointerToProperty(name))) { return prop->operator()(); } else { std::string message = diff --git a/Framework/Geometry/src/Crystal/OrientedLattice.cpp b/Framework/Geometry/src/Crystal/OrientedLattice.cpp index 8eae637d4614..e011a2adfc94 100644 --- a/Framework/Geometry/src/Crystal/OrientedLattice.cpp +++ b/Framework/Geometry/src/Crystal/OrientedLattice.cpp @@ -5,7 +5,6 @@ // Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS // SPDX - License - Identifier: GPL - 3.0 + #include "MantidGeometry/Crystal/OrientedLattice.h" -#include "MantidKernel/Exception.h" #include @@ -233,7 +232,7 @@ const DblMatrix &OrientedLattice::setUFromVectors(const V3D &u, const V3D &v) { bwVec /= norm; // 2nd unit vector, perpendicular to Bu, in the Bu,Bv plane bvVec = bwVec.cross_prod(buVec); - DblMatrix tau(3, 3), lab(3, 3), U(3, 3); + DblMatrix tau(3, 3), lab(3, 3); /*lab = U tau / 0 1 0 \ /bu[0] bv[0] bw[0]\ | 0 0 1 | = U |bu[1] bv[1] bw[1]| @@ -252,8 +251,7 @@ const DblMatrix &OrientedLattice::setUFromVectors(const V3D &u, const V3D &v) { tau[2][1] = bvVec[2]; tau[2][2] = bwVec[2]; tau.Invert(); - U = lab * tau; - this->setU(U); + this->setU(lab * tau); return getU(); } diff --git a/Framework/MDAlgorithms/inc/MantidMDAlgorithms/MergeMDFiles.h b/Framework/MDAlgorithms/inc/MantidMDAlgorithms/MergeMDFiles.h index 1284c45a4159..eadacb7a04c5 100644 --- a/Framework/MDAlgorithms/inc/MantidMDAlgorithms/MergeMDFiles.h +++ b/Framework/MDAlgorithms/inc/MantidMDAlgorithms/MergeMDFiles.h @@ -9,10 +9,8 @@ #include "MantidAPI/Algorithm.h" #include "MantidAPI/IMDEventWorkspace_fwd.h" #include "MantidDataObjects/MDBoxFlatTree.h" -#include "MantidDataObjects/MDEventWorkspace.h" #include "MantidMDAlgorithms/DllConfig.h" #include -#include namespace Mantid { namespace MDAlgorithms { diff --git a/Framework/MDAlgorithms/src/LoadMD.cpp b/Framework/MDAlgorithms/src/LoadMD.cpp index 58b6955a3b62..e163479cded8 100644 --- a/Framework/MDAlgorithms/src/LoadMD.cpp +++ b/Framework/MDAlgorithms/src/LoadMD.cpp @@ -29,7 +29,6 @@ #include "MantidKernel/MDUnitFactory.h" #include "MantidKernel/Memory.h" #include "MantidKernel/PropertyWithValue.h" -#include "MantidKernel/System.h" #include "MantidMDAlgorithms/SetMDFrame.h" #include #include diff --git a/Framework/MDAlgorithms/src/MergeMDFiles.cpp b/Framework/MDAlgorithms/src/MergeMDFiles.cpp index 4c8c82d55372..1227b60d2ae7 100644 --- a/Framework/MDAlgorithms/src/MergeMDFiles.cpp +++ b/Framework/MDAlgorithms/src/MergeMDFiles.cpp @@ -10,13 +10,14 @@ #include "MantidDataObjects/BoxControllerNeXusIO.h" #include "MantidDataObjects/MDBoxBase.h" #include "MantidDataObjects/MDEventFactory.h" +#include "MantidDataObjects/MDEventWorkspace.h" #include "MantidKernel/CPUTimer.h" #include "MantidKernel/Strings.h" -#include "MantidKernel/System.h" #include "MantidKernel/VectorHelper.h" #include #include +#include using namespace Mantid::Kernel; using namespace Mantid::API; diff --git a/Framework/Nexus/src/NexusFileIO.cpp b/Framework/Nexus/src/NexusFileIO.cpp index 7e3ef0b74886..c873e3404a24 100644 --- a/Framework/Nexus/src/NexusFileIO.cpp +++ b/Framework/Nexus/src/NexusFileIO.cpp @@ -1223,10 +1223,10 @@ int getNexusEntryTypes(const std::string &fileName, std::vector &en NXopengroup(fileH, entry.c_str(), "NXentry"); // loop through field names in this entry while ((NXgetnextentry(fileH, nxname, nxclass, &nxdatatype)) == NX_OK) { - std::string nxc(nxclass), nxn(nxname); // if a data field - if (nxc == "SDS") + if (std::string(nxclass) == "SDS") { // if one of the two names we are looking for + const std::string nxn(nxname); if (nxn == "definition" || nxn == "analysis") { NXopendata(fileH, nxname); stat = NXgetinfo(fileH, &rank, dims, &type); @@ -1245,6 +1245,7 @@ int getNexusEntryTypes(const std::string &fileName, std::vector &en NXclosegroup(fileH); break; } + } } } NXclose(&fileH); diff --git a/Framework/SINQ/inc/MantidSINQ/LoadFlexiNexus.h b/Framework/SINQ/inc/MantidSINQ/LoadFlexiNexus.h index 601820802d6e..20eb682a4079 100644 --- a/Framework/SINQ/inc/MantidSINQ/LoadFlexiNexus.h +++ b/Framework/SINQ/inc/MantidSINQ/LoadFlexiNexus.h @@ -27,16 +27,11 @@ #pragma once #include "MantidAPI/Algorithm.h" +#include "MantidAPI/ExperimentInfo.h" +#include "MantidGeometry/MDGeometry/MDHistoDimension.h" #include "MantidSINQ/DllConfig.h" -// clang-format off #include -#include -// clang-format on - -#include "MantidDataObjects/Workspace2D.h" -#include "MantidGeometry/MDGeometry/MDHistoDimension.h" -#include class MANTID_SINQ_DLL LoadFlexiNexus : public Mantid::API::Algorithm { public: diff --git a/Framework/SINQ/src/LoadFlexiNexus.cpp b/Framework/SINQ/src/LoadFlexiNexus.cpp index ea20aa3127e8..8013a4d852b2 100644 --- a/Framework/SINQ/src/LoadFlexiNexus.cpp +++ b/Framework/SINQ/src/LoadFlexiNexus.cpp @@ -11,13 +11,14 @@ #include "MantidAPI/Sample.h" #include "MantidAPI/WorkspaceFactory.h" #include "MantidDataObjects/MDHistoWorkspace.h" +#include "MantidDataObjects/Workspace2D.h" #include "MantidGeometry/MDGeometry/MDTypes.h" #include "MantidKernel/ArrayProperty.h" #include "MantidKernel/Utils.h" #include - #include +#include #include // Register the algorithm into the AlgorithmFactory diff --git a/Framework/SINQ/test/LoadFlexiNexusTest.h b/Framework/SINQ/test/LoadFlexiNexusTest.h index 2b2da659b4cb..3da17774f78e 100644 --- a/Framework/SINQ/test/LoadFlexiNexusTest.h +++ b/Framework/SINQ/test/LoadFlexiNexusTest.h @@ -8,6 +8,7 @@ #include "MantidAPI/AnalysisDataService.h" #include "MantidAPI/IMDHistoWorkspace.h" +#include "MantidAPI/MatrixWorkspace.h" #include "MantidAPI/Run.h" #include "MantidGeometry/MDGeometry/IMDDimension.h" #include "MantidKernel/Property.h" diff --git a/buildconfig/CMake/CppCheck_Suppressions.txt.in b/buildconfig/CMake/CppCheck_Suppressions.txt.in index b5e0122d02de..e1a9865c1c8a 100644 --- a/buildconfig/CMake/CppCheck_Suppressions.txt.in +++ b/buildconfig/CMake/CppCheck_Suppressions.txt.in @@ -367,9 +367,6 @@ knownConditionTrueFalse:${CMAKE_SOURCE_DIR}/Framework/API/src/Sample.cpp:338 knownConditionTrueFalse:${CMAKE_SOURCE_DIR}/Framework/API/src/Sample.cpp:347 constVariablePointer:${CMAKE_SOURCE_DIR}/Framework/API/src/Run.cpp:200 constVariablePointer:${CMAKE_SOURCE_DIR}/Framework/API/src/Run.cpp:283 -constVariablePointer:${CMAKE_SOURCE_DIR}/Framework/API/src/Run.cpp:302 -constVariablePointer:${CMAKE_SOURCE_DIR}/Framework/API/src/Run.cpp:699 -constVariablePointer:${CMAKE_SOURCE_DIR}/Framework/API/src/Run.cpp:732 constVariablePointer:${CMAKE_SOURCE_DIR}/Framework/API/src/NumericAxisValidator.cpp:26 nullPointerRedundantCheck:${CMAKE_SOURCE_DIR}/Framework/API/src/ExperimentInfo.cpp:889 constVariableReference:${CMAKE_SOURCE_DIR}/Framework/API/src/ExperimentInfo.cpp:140 @@ -591,13 +588,11 @@ comparisonOfFuncReturningBoolError:${CMAKE_SOURCE_DIR}/Framework/Kernel/inc/Mant comparisonOfFuncReturningBoolError:${CMAKE_SOURCE_DIR}/Framework/Kernel/inc/MantidKernel/BoundedValidator.h:156 returnByReference:${CMAKE_SOURCE_DIR}/Framework/DataHandling/inc/MantidDataHandling/LoadEmptyInstrument.h:65 knownConditionTrueFalse:${CMAKE_SOURCE_DIR}/Framework/DataHandling/src/LoadAscii2.cpp:211 -variableScope:${CMAKE_SOURCE_DIR}/Framework/DataHandling/src/LoadEmptyInstrument.cpp:57 duplicateConditionalAssign:${CMAKE_SOURCE_DIR}/Framework/DataHandling/src/LoadCalFile.cpp:307 constParameterPointer:${CMAKE_SOURCE_DIR}/Framework/DataHandling/src/LoadCalFile.cpp:57 uselessOverride:${CMAKE_SOURCE_DIR}/Framework/DataHandling/inc/MantidDataHandling/LoadDNSEvent.h:44 passedByValue:${CMAKE_SOURCE_DIR}/Framework/DataHandling/inc/MantidDataHandling/BitStream.h:30 cstyleCast:${CMAKE_SOURCE_DIR}/Framework/DataHandling/src/LoadANSTOHelper.cpp:210 -variableScope:${CMAKE_SOURCE_DIR}/Framework/DataHandling/src/DetermineChunking.cpp:163 uselessCallsSubstr:${CMAKE_SOURCE_DIR}/Framework/DataHandling/src/LoadFITS.cpp:547 uninitMemberVarPrivate:${CMAKE_SOURCE_DIR}/Framework/DataHandling/inc/MantidDataHandling/LoadHFIRSANS.h:124 uninitMemberVarPrivate:${CMAKE_SOURCE_DIR}/Framework/DataHandling/inc/MantidDataHandling/LoadHFIRSANS.h:125 @@ -710,10 +705,6 @@ constVariablePointer:${CMAKE_SOURCE_DIR}/Framework/DataHandling/src/SaveToSNSHis constParameterPointer:${CMAKE_SOURCE_DIR}/Framework/DataHandling/src/SaveToSNSHistogramNexus.cpp:661 constVariablePointer:${CMAKE_SOURCE_DIR}/Framework/DataObjects/src/GroupingWorkspace.cpp:153 constVariablePointer:${CMAKE_SOURCE_DIR}/Framework/DataObjects/src/SplittersWorkspace.cpp:89 -cstyleCast:${CMAKE_SOURCE_DIR}/Framework/DataObjects/src/LeanElasticPeaksWorkspace.cpp:149 -cstyleCast:${CMAKE_SOURCE_DIR}/Framework/DataObjects/src/LeanElasticPeaksWorkspace.cpp:620 -constParameterReference:${CMAKE_SOURCE_DIR}/Framework/DataObjects/src/LeanElasticPeaksWorkspace.cpp:135 -constVariablePointer:${CMAKE_SOURCE_DIR}/Framework/DataObjects/src/LeanElasticPeaksWorkspace.cpp:713 knownConditionTrueFalse:${CMAKE_SOURCE_DIR}/Framework/DataHandling/src/SaveNexusProcessed.cpp:575 virtualCallInConstructor:${CMAKE_SOURCE_DIR}/Framework/DataObjects/inc/MantidDataObjects/TableWorkspace.h:199 constVariableReference:${CMAKE_SOURCE_DIR}/Framework/DataObjects/src/TableWorkspace.cpp:253 @@ -730,10 +721,6 @@ constVariablePointer:${CMAKE_SOURCE_DIR}/Framework/DataObjects/src/MaskWorkspace returnByReference:${CMAKE_SOURCE_DIR}/Framework/Geometry/inc/MantidGeometry/Crystal/BraggScattererInCrystalStructure.h:35 returnByReference:${CMAKE_SOURCE_DIR}/Framework/Geometry/inc/MantidGeometry/Crystal/SpaceGroupFactory.h:45 returnByReference:${CMAKE_SOURCE_DIR}/Framework/Geometry/inc/MantidGeometry/Crystal/SpaceGroupFactory.h:46 -cstyleCast:${CMAKE_SOURCE_DIR}/Framework/DataObjects/src/PeaksWorkspace.cpp:159 -cstyleCast:${CMAKE_SOURCE_DIR}/Framework/DataObjects/src/PeaksWorkspace.cpp:917 -constParameterReference:${CMAKE_SOURCE_DIR}/Framework/DataObjects/src/PeaksWorkspace.cpp:145 -constVariablePointer:${CMAKE_SOURCE_DIR}/Framework/DataObjects/src/PeaksWorkspace.cpp:982 constVariableReference:${CMAKE_SOURCE_DIR}/Framework/DataObjects/src/EventWorkspace.cpp:448 constVariablePointer:${CMAKE_SOURCE_DIR}/Framework/DataObjects/src/EventWorkspace.cpp:712 constVariablePointer:${CMAKE_SOURCE_DIR}/Framework/DataObjects/src/EventWorkspace.cpp:738