Skip to content

Commit

Permalink
Fix cppcheck warnings and remove unused headers
Browse files Browse the repository at this point in the history
  • Loading branch information
peterfpeterson committed Dec 10, 2024
1 parent 83ebb0b commit 7d1de1e
Show file tree
Hide file tree
Showing 21 changed files with 75 additions and 113 deletions.
19 changes: 7 additions & 12 deletions Framework/API/src/Run.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)) {
Expand Down Expand Up @@ -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<double> *log = nullptr;
Kernel::TimeSeriesProperty<double> const *log = nullptr;

if (this->hasProperty(logname)) {
try {
log = dynamic_cast<Kernel::TimeSeriesProperty<double> *>(this->getProperty(logname));
log = dynamic_cast<Kernel::TimeSeriesProperty<double> 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");
Expand All @@ -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<Kernel::FilteredTimeSeriesProperty<double> *>(this->getProperty(logname));
if (filteredLog)
if (const auto *filteredLog =
dynamic_cast<Kernel::FilteredTimeSeriesProperty<double> *>(this->getProperty(logname)))
timeroi.update_or_replace_intersection(filteredLog->getTimeROI());

if (timeroi.useAll()) {
Expand Down Expand Up @@ -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<double> *charge_log =
dynamic_cast<PropertyWithValue<double> *>(this->getProperty("proton_charge"));
if (charge_log) {
if (const auto *charge_log = dynamic_cast<PropertyWithValue<double> *>(this->getProperty("proton_charge"))) {
this->setProtonCharge(boost::lexical_cast<double>(charge_log->value()));
}
}
Expand Down Expand Up @@ -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<double> *charge_log =
dynamic_cast<PropertyWithValue<double> *>(this->getProperty("proton_charge"));
if (charge_log) {
if (const auto *charge_log = dynamic_cast<PropertyWithValue<double> *>(this->getProperty("proton_charge"))) {
this->setProtonCharge(boost::lexical_cast<double>(charge_log->value()));
}
}
Expand Down
1 change: 1 addition & 0 deletions Framework/Algorithms/inc/MantidAlgorithms/MergeRuns.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include "MantidDataObjects/EventWorkspace.h"
#include "MantidGeometry/Instrument/DetectorInfo.h"

#include <list>
#include <optional>

namespace Mantid {
Expand Down
20 changes: 11 additions & 9 deletions Framework/DataHandling/inc/MantidDataHandling/SaveISISNexus.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::string> &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);

Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 <climits>
// clang-format off
Expand Down
8 changes: 2 additions & 6 deletions Framework/DataHandling/src/DetermineChunking.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 <nexus/NeXusFile.hpp>
Expand All @@ -26,7 +23,6 @@

#include <Poco/File.h>
#include <exception>
#include <fstream>
#include <set>
#include <vector>

Expand Down Expand Up @@ -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");
Expand Down
4 changes: 2 additions & 2 deletions Framework/DataHandling/src/LoadEmptyInstrument.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 &) {
}
}

Expand Down
28 changes: 11 additions & 17 deletions Framework/DataHandling/src/LoadHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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());
}
Expand All @@ -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) {
Expand Down Expand Up @@ -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
Expand All @@ -193,15 +188,15 @@ 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;
int dims[4] = {0, 0, 0, 0};
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
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion Framework/DataHandling/src/LoadMcStasNexus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
20 changes: 11 additions & 9 deletions Framework/DataHandling/src/SaveISISNexus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand All @@ -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();
}
Expand All @@ -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();
}
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -370,7 +370,9 @@ void SaveISISNexus::putAttr(const char *name, const std::string &value) {
NXputattr(handle, name, buff.get(), static_cast<int>(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); }

Expand Down Expand Up @@ -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();
Expand All @@ -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");
Expand Down
2 changes: 1 addition & 1 deletion Framework/DataHandling/src/SaveToSNSHistogramNexus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down
Loading

0 comments on commit 7d1de1e

Please sign in to comment.