Unverified Commit 0bc884fc authored by DannyHindson's avatar DannyHindson Committed by GitHub
Browse files

Merge pull request #32531 from DavidFair/cppcheck_cache

Cppcheck cache
parents 3ee31c71 30f7d72e
...@@ -48,7 +48,7 @@ public: ...@@ -48,7 +48,7 @@ public:
virtual ~ImplicitFunctionParameter() = default; virtual ~ImplicitFunctionParameter() = default;
protected: protected:
bool m_isValid; bool m_isValid{false};
std::string parameterXMLTemplate(const std::string &valueXMLtext) const { std::string parameterXMLTemplate(const std::string &valueXMLtext) const {
using namespace Poco::XML; using namespace Poco::XML;
......
...@@ -387,7 +387,7 @@ void CorrectTOFAxis::averageL2AndEPP(const API::SpectrumInfo &spectrumInfo, doub ...@@ -387,7 +387,7 @@ void CorrectTOFAxis::averageL2AndEPP(const API::SpectrumInfo &spectrumInfo, doub
double eppSum = 0; double eppSum = 0;
size_t n = 0; size_t n = 0;
const auto indexCount = static_cast<int64_t>(m_workspaceIndices.size()); const auto indexCount = static_cast<int64_t>(m_workspaceIndices.size());
// cppcheck-suppress syntaxError
PRAGMA_OMP(parallel for if (m_eppTable->threadSafe()) PRAGMA_OMP(parallel for if (m_eppTable->threadSafe())
reduction(+: n, l2Sum, eppSum)) reduction(+: n, l2Sum, eppSum))
for (int64_t i = 0; i < indexCount; ++i) { for (int64_t i = 0; i < indexCount; ++i) {
......
...@@ -616,7 +616,7 @@ void CreateGroupingWorkspace::exec() { ...@@ -616,7 +616,7 @@ void CreateGroupingWorkspace::exec() {
sortnames = true; sortnames = true;
GroupNames = ""; GroupNames = "";
int maxRecurseDepth = this->getProperty("MaxRecursionDepth"); int maxRecurseDepth = this->getProperty("MaxRecursionDepth");
// cppcheck-suppress syntaxError
PRAGMA_OMP(parallel for schedule(dynamic, 1) ) PRAGMA_OMP(parallel for schedule(dynamic, 1) )
for (int num = 0; num < 300; ++num) { for (int num = 0; num < 300; ++num) {
PARALLEL_START_INTERUPT_REGION PARALLEL_START_INTERUPT_REGION
......
...@@ -371,7 +371,7 @@ void DiffractionFocussing2::execEvent() { ...@@ -371,7 +371,7 @@ void DiffractionFocussing2::execEvent() {
int chunkSize = 200; int chunkSize = 200;
int end = (totalHistProcess / chunkSize) + 1; int end = (totalHistProcess / chunkSize) + 1;
// cppcheck-suppress syntaxError
PRAGMA_OMP(parallel for schedule(dynamic, 1) ) PRAGMA_OMP(parallel for schedule(dynamic, 1) )
for (int wiChunk = 0; wiChunk < end; wiChunk++) { for (int wiChunk = 0; wiChunk < end; wiChunk++) {
PARALLEL_START_INTERUPT_REGION PARALLEL_START_INTERUPT_REGION
......
...@@ -990,9 +990,6 @@ int FindPeaks::findPeakBackground(const MatrixWorkspace_sptr &input, int spectru ...@@ -990,9 +990,6 @@ int FindPeaks::findPeakBackground(const MatrixWorkspace_sptr &input, int spectru
// Local check whether FindPeakBackground gives a reasonable value // Local check whether FindPeakBackground gives a reasonable value
vecpeakrange.resize(2); vecpeakrange.resize(2);
/// @todo Remove this cppcheck suppression when #13950 is fixed
// cppcheck-suppress knownConditionTrueFalse
if (fitresult > 0) { if (fitresult > 0) {
// Use FitPeakBackgroud's result // Use FitPeakBackgroud's result
size_t i_peakmin, i_peakmax; size_t i_peakmin, i_peakmax;
......
...@@ -850,7 +850,6 @@ std::vector<std::shared_ptr<FitPeaksAlgorithm::PeakFitResult>> FitPeaks::fitPeak ...@@ -850,7 +850,6 @@ std::vector<std::shared_ptr<FitPeaksAlgorithm::PeakFitResult>> FitPeaks::fitPeak
const int nThreads = FrameworkManager::Instance().getNumOMPThreads(); const int nThreads = FrameworkManager::Instance().getNumOMPThreads();
size_t chunkSize = num_fit_result / nThreads; size_t chunkSize = num_fit_result / nThreads;
// cppcheck-suppress syntaxError
PRAGMA_OMP(parallel for schedule(dynamic, 1) ) PRAGMA_OMP(parallel for schedule(dynamic, 1) )
for (int ithread = 0; ithread < nThreads; ithread++) { for (int ithread = 0; ithread < nThreads; ithread++) {
PARALLEL_START_INTERUPT_REGION PARALLEL_START_INTERUPT_REGION
......
...@@ -1071,7 +1071,7 @@ void GenerateEventsFilter::makeMultipleFiltersByValuesParallel(const map<size_t, ...@@ -1071,7 +1071,7 @@ void GenerateEventsFilter::makeMultipleFiltersByValuesParallel(const map<size_t,
} }
// Create event filters/splitters in parallel // Create event filters/splitters in parallel
// cppcheck-suppress syntaxError
PRAGMA_OMP(parallel for schedule(dynamic, 1) ) PRAGMA_OMP(parallel for schedule(dynamic, 1) )
for (int i = 0; i < numThreads; ++i) { for (int i = 0; i < numThreads; ++i) {
PARALLEL_START_INTERUPT_REGION PARALLEL_START_INTERUPT_REGION
......
...@@ -533,7 +533,7 @@ void PDCalibration::exec() { ...@@ -533,7 +533,7 @@ void PDCalibration::exec() {
// Scan the table containing the fit parameters for every peak, retrieve the // Scan the table containing the fit parameters for every peak, retrieve the
// parameters for peaks that were successfully fitting, then use this info // parameters for peaks that were successfully fitting, then use this info
// to obtain difc, difa, and tzero for each pixel // to obtain difc, difa, and tzero for each pixel
// cppcheck-suppress syntaxError
PRAGMA_OMP(parallel for schedule(dynamic, 1)) PRAGMA_OMP(parallel for schedule(dynamic, 1))
for (int wkspIndex = 0; wkspIndex < NUMHIST; ++wkspIndex) { for (int wkspIndex = 0; wkspIndex < NUMHIST; ++wkspIndex) {
PARALLEL_START_INTERUPT_REGION PARALLEL_START_INTERUPT_REGION
......
...@@ -452,7 +452,7 @@ public: ...@@ -452,7 +452,7 @@ public:
const auto &yValues = outWS->histogram(i).y(); const auto &yValues = outWS->histogram(i).y();
for (size_t j = 0; j < yValues.size(); ++j) { for (size_t j = 0; j < yValues.size(); ++j) {
if (specOutInfo.isMonitor(i)) if (specOutInfo.isMonitor(i))
// cppcheck-suppress syntaxError
TS_ASSERT_DELTA(yValues[j], double(j + 1) / 15.0, 1e-12) TS_ASSERT_DELTA(yValues[j], double(j + 1) / 15.0, 1e-12)
else else
TS_ASSERT_DELTA(yValues[j], 2.0 / 15.0, 1e-12) TS_ASSERT_DELTA(yValues[j], 2.0 / 15.0, 1e-12)
......
...@@ -82,7 +82,7 @@ void SCDCalibratePanels::exec() { ...@@ -82,7 +82,7 @@ void SCDCalibratePanels::exec() {
MyPanels.insert("East"); MyPanels.insert("East");
MyPanels.insert("West"); MyPanels.insert("West");
int maxRecurseDepth = 4; int maxRecurseDepth = 4;
// cppcheck-suppress syntaxError
PRAGMA_OMP(parallel for schedule(dynamic, 1) ) PRAGMA_OMP(parallel for schedule(dynamic, 1) )
for (int num = 1; num < 64; ++num) { for (int num = 1; num < 64; ++num) {
PARALLEL_START_INTERUPT_REGION PARALLEL_START_INTERUPT_REGION
......
...@@ -28,20 +28,14 @@ public: ...@@ -28,20 +28,14 @@ public:
/// Constructor with vector of DateAndTime /// Constructor with vector of DateAndTime
BankPulseTimes(const std::vector<Mantid::Types::Core::DateAndTime> &times); BankPulseTimes(const std::vector<Mantid::Types::Core::DateAndTime> &times);
/// Destructor
~BankPulseTimes();
/// Equals /// Equals
bool equals(size_t otherNumPulse, const std::string &otherStartTime); bool equals(size_t otherNumPulse, const std::string &otherStartTime);
/// String describing the start time /// String describing the start time
std::string startTime; std::string startTime;
/// Size of the array of pulse times
size_t numPulses;
/// Array of the pulse times /// Array of the pulse times
Mantid::Types::Core::DateAndTime *pulseTimes; std::vector<Mantid::Types::Core::DateAndTime> pulseTimes;
/// Vector of period numbers corresponding to each pulse /// Vector of period numbers corresponding to each pulse
std::vector<int> periodNumbers; std::vector<int> periodNumbers;
......
...@@ -151,6 +151,10 @@ public: ...@@ -151,6 +151,10 @@ public:
FastReadOnlyFile(const char *filename); FastReadOnlyFile(const char *filename);
~FastReadOnlyFile(); ~FastReadOnlyFile();
// Prevent copying of a file handle
FastReadOnlyFile(const FastReadOnlyFile &) = delete;
FastReadOnlyFile &operator=(FastReadOnlyFile) = delete;
// properties // properties
void *handle() const; void *handle() const;
......
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
#include <nexus/NeXusFile.hpp> #include <nexus/NeXusFile.hpp>
#include <climits> #include <climits>
#include <memory>
namespace Mantid { namespace Mantid {
namespace DataHandling { namespace DataHandling {
...@@ -52,7 +53,7 @@ private: ...@@ -52,7 +53,7 @@ private:
/// Overwrites Algorithm method /// Overwrites Algorithm method
void exec() override; void exec() override;
ISISRAW2 m_isisRaw; std::unique_ptr<ISISRAW2> m_isisRaw;
NXhandle handle; NXhandle handle;
FILE *rawFile; FILE *rawFile;
std::vector<int> monitorData; std::vector<int> monitorData;
......
...@@ -39,32 +39,28 @@ BankPulseTimes::BankPulseTimes(::NeXus::File &file, const std::vector<int> &pNum ...@@ -39,32 +39,28 @@ BankPulseTimes::BankPulseTimes(::NeXus::File &file, const std::vector<int> &pNum
file.getData(seconds); file.getData(seconds);
file.closeData(); file.closeData();
// Now create the pulseTimes // Now create the pulseTimes
numPulses = seconds.size(); if (seconds.size() == 0)
if (numPulses == 0)
throw std::runtime_error("event_time_zero field has no data!"); throw std::runtime_error("event_time_zero field has no data!");
pulseTimes = new Mantid::Types::Core::DateAndTime[numPulses]; std::transform(seconds.cbegin(), seconds.cend(), std::back_inserter(pulseTimes),
for (size_t i = 0; i < numPulses; i++) [start](double seconds) { return start + seconds; });
pulseTimes[i] = start + seconds[i];
} else if (heldTimeZeroType == ::NeXus::UINT64) { } else if (heldTimeZeroType == ::NeXus::UINT64) {
std::vector<uint64_t> nanoseconds; std::vector<uint64_t> nanoseconds;
file.getData(nanoseconds); file.getData(nanoseconds);
file.closeData(); file.closeData();
// Now create the pulseTimes // Now create the pulseTimes
numPulses = nanoseconds.size(); if (nanoseconds.size() == 0)
if (numPulses == 0)
throw std::runtime_error("event_time_zero field has no data!"); throw std::runtime_error("event_time_zero field has no data!");
pulseTimes = new Mantid::Types::Core::DateAndTime[numPulses]; std::transform(nanoseconds.cbegin(), nanoseconds.cend(), std::back_inserter(pulseTimes),
for (size_t i = 0; i < numPulses; i++) [start](int64_t nanoseconds) { return start + nanoseconds; });
pulseTimes[i] = start + int64_t(nanoseconds[i]);
} else { } else {
throw std::invalid_argument("Unsupported type for event_time_zero"); throw std::invalid_argument("Unsupported type for event_time_zero");
} }
// Ensure that we always have a consistency between nPulses and // Ensure that we always have a consistency between nPulses and
// periodNumbers containers // periodNumbers containers
if (numPulses != pNumbers.size()) { if (pulseTimes.size() != pNumbers.size()) {
periodNumbers = std::vector<int>(numPulses, FirstPeriod); periodNumbers = std::vector<int>(pulseTimes.size(), FirstPeriod);
; ;
} }
} }
...@@ -75,19 +71,12 @@ BankPulseTimes::BankPulseTimes(::NeXus::File &file, const std::vector<int> &pNum ...@@ -75,19 +71,12 @@ BankPulseTimes::BankPulseTimes(::NeXus::File &file, const std::vector<int> &pNum
* @param times * @param times
*/ */
BankPulseTimes::BankPulseTimes(const std::vector<Mantid::Types::Core::DateAndTime> &times) { BankPulseTimes::BankPulseTimes(const std::vector<Mantid::Types::Core::DateAndTime> &times) {
numPulses = times.size(); if (times.size() == 0)
pulseTimes = nullptr;
if (numPulses == 0)
return; return;
pulseTimes = new Mantid::Types::Core::DateAndTime[numPulses];
periodNumbers = std::vector<int>(numPulses, FirstPeriod); // TODO we are fixing this at 1 period for all
for (size_t i = 0; i < numPulses; i++)
pulseTimes[i] = times[i];
}
//---------------------------------------------------------------------------------------------- pulseTimes = times;
/** Destructor */ periodNumbers = std::vector<int>(pulseTimes.size(), FirstPeriod); // TODO we are fixing this at 1 period for all
BankPulseTimes::~BankPulseTimes() { delete[] this->pulseTimes; } }
//---------------------------------------------------------------------------------------------- //----------------------------------------------------------------------------------------------
/** Comparison. Is this bank's pulse times array the same as another one. /** Comparison. Is this bank's pulse times array the same as another one.
...@@ -99,5 +88,5 @@ BankPulseTimes::~BankPulseTimes() { delete[] this->pulseTimes; } ...@@ -99,5 +88,5 @@ BankPulseTimes::~BankPulseTimes() { delete[] this->pulseTimes; }
* reloaded. * reloaded.
*/ */
bool BankPulseTimes::equals(size_t otherNumPulse, const std::string &otherStartTime) { bool BankPulseTimes::equals(size_t otherNumPulse, const std::string &otherStartTime) {
return ((this->startTime == otherStartTime) && (this->numPulses == otherNumPulse)); return ((this->startTime == otherStartTime) && (this->pulseTimes.size() == otherNumPulse));
} }
...@@ -377,7 +377,7 @@ void CreateChunkingFromInstrument::exec() { ...@@ -377,7 +377,7 @@ void CreateChunkingFromInstrument::exec() {
// search the instrument for the bank names // search the instrument for the bank names
int maxRecurseDepth = this->getProperty(PARAM_MAX_RECURSE); int maxRecurseDepth = this->getProperty(PARAM_MAX_RECURSE);
map<string, vector<string>> grouping; map<string, vector<string>> grouping;
// cppcheck-suppress syntaxError
PRAGMA_OMP(parallel for schedule(dynamic, 1) ) PRAGMA_OMP(parallel for schedule(dynamic, 1) )
for (int num = 0; num < maxBankNum; ++num) { for (int num = 0; num < maxBankNum; ++num) {
PARALLEL_START_INTERUPT_REGION PARALLEL_START_INTERUPT_REGION
......
...@@ -871,7 +871,7 @@ void FilterEventsByLogValuePreNexus::procEvents(DataObjects::EventWorkspace_sptr ...@@ -871,7 +871,7 @@ void FilterEventsByLogValuePreNexus::procEvents(DataObjects::EventWorkspace_sptr
g_log.information() << "Processing input event preNexus by " << numThreads << " threads" g_log.information() << "Processing input event preNexus by " << numThreads << " threads"
<< " in " << numBlocks << " blocks. " << " in " << numBlocks << " blocks. "
<< "\n"; << "\n";
// cppcheck-suppress syntaxError
PRAGMA_OMP( parallel for schedule(dynamic, 1) if (m_parallelProcessing) ) PRAGMA_OMP( parallel for schedule(dynamic, 1) if (m_parallelProcessing) )
for (int i = 0; i < int(numThreads); i++) { for (int i = 0; i < int(numThreads); i++) {
// This is the partial workspace we are about to create (if in parallel) // This is the partial workspace we are about to create (if in parallel)
......
...@@ -154,7 +154,7 @@ void EventAssignerFixedWavelength::addEventImpl(size_t id, int64_t pulse, double ...@@ -154,7 +154,7 @@ void EventAssignerFixedWavelength::addEventImpl(size_t id, int64_t pulse, double
m_eventVectors[id]->emplace_back(m_wavelength); m_eventVectors[id]->emplace_back(m_wavelength);
} }
// FastReadOnlyFile // ISISRawOnlyFile
#ifdef _WIN32 #ifdef _WIN32
FastReadOnlyFile::FastReadOnlyFile(const char *filename) { FastReadOnlyFile::FastReadOnlyFile(const char *filename) {
m_handle = CreateFileA(filename, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); m_handle = CreateFileA(filename, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
......
...@@ -55,7 +55,7 @@ void LoadBankFromDiskTask::loadPulseTimes(::NeXus::File &file) { ...@@ -55,7 +55,7 @@ void LoadBankFromDiskTask::loadPulseTimes(::NeXus::File &file) {
return; return;
} }
std::string thisStartTime; std::string thisStartTime;
size_t thisNumPulses = 0; size_t thispulseTimes = 0;
// If the offset is not present, use Unix epoch // If the offset is not present, use Unix epoch
if (!file.hasAttr("offset")) { if (!file.hasAttr("offset")) {
thisStartTime = "1970-01-01T00:00:00Z"; thisStartTime = "1970-01-01T00:00:00Z";
...@@ -66,13 +66,13 @@ void LoadBankFromDiskTask::loadPulseTimes(::NeXus::File &file) { ...@@ -66,13 +66,13 @@ void LoadBankFromDiskTask::loadPulseTimes(::NeXus::File &file) {
} }
if (!file.getInfo().dims.empty()) if (!file.getInfo().dims.empty())
thisNumPulses = file.getInfo().dims[0]; thispulseTimes = file.getInfo().dims[0];
file.closeData(); file.closeData();
// Now, we look through existing ones to see if it is already loaded // Now, we look through existing ones to see if it is already loaded
// thisBankPulseTimes = NULL; // thisBankPulseTimes = NULL;
for (auto &bankPulseTime : m_loader.m_bankPulseTimes) { for (auto &bankPulseTime : m_loader.m_bankPulseTimes) {
if (bankPulseTime->equals(thisNumPulses, thisStartTime)) { if (bankPulseTime->equals(thispulseTimes, thisStartTime)) {
thisBankPulseTimes = bankPulseTime; thisBankPulseTimes = bankPulseTime;
return; return;
} }
...@@ -131,7 +131,7 @@ void LoadBankFromDiskTask::prepareEventId(::NeXus::File &file, int64_t &start_ev ...@@ -131,7 +131,7 @@ void LoadBankFromDiskTask::prepareEventId(::NeXus::File &file, int64_t &start_ev
stop_event = dim0; stop_event = dim0;
// Handle the time filtering by changing the start/end offsets. // Handle the time filtering by changing the start/end offsets.
for (size_t i = 0; i < thisBankPulseTimes->numPulses; i++) { for (size_t i = 0; i < thisBankPulseTimes->pulseTimes.size(); i++) {
if (thisBankPulseTimes->pulseTimes[i] >= m_loader.alg->filter_time_start) { if (thisBankPulseTimes->pulseTimes[i] >= m_loader.alg->filter_time_start) {
start_event = static_cast<int64_t>(event_index[i]); start_event = static_cast<int64_t>(event_index[i]);
break; // stop looking break; // stop looking
...@@ -150,7 +150,7 @@ void LoadBankFromDiskTask::prepareEventId(::NeXus::File &file, int64_t &start_ev ...@@ -150,7 +150,7 @@ void LoadBankFromDiskTask::prepareEventId(::NeXus::File &file, int64_t &start_ev
start_event = 0; start_event = 0;
stop_event = dim0; stop_event = dim0;
} else { } else {
for (size_t i = 0; i < thisBankPulseTimes->numPulses; i++) { for (size_t i = 0; i < thisBankPulseTimes->pulseTimes.size(); i++) {
if (thisBankPulseTimes->pulseTimes[i] > m_loader.alg->filter_time_stop) { if (thisBankPulseTimes->pulseTimes[i] > m_loader.alg->filter_time_stop) {
stop_event = event_index[i]; stop_event = event_index[i];
break; break;
...@@ -353,7 +353,7 @@ void LoadBankFromDiskTask::run() { ...@@ -353,7 +353,7 @@ void LoadBankFromDiskTask::run() {
// The event_index should be the same length as the pulse times from DAS // The event_index should be the same length as the pulse times from DAS
// logs. // logs.
if (event_index.size() != thisBankPulseTimes->numPulses) if (event_index.size() != thisBankPulseTimes->pulseTimes.size())
m_loader.alg->getLogger().warning() << "Bank " << entry_name m_loader.alg->getLogger().warning() << "Bank " << entry_name
<< " has a mismatch between the number of event_index entries " << " has a mismatch between the number of event_index entries "
"and the number of pulse times in event_time_zero.\n"; "and the number of pulse times in event_time_zero.\n";
......
...@@ -985,7 +985,7 @@ void LoadEventNexus::loadEvents(API::Progress *const prog, const bool monitors) ...@@ -985,7 +985,7 @@ void LoadEventNexus::loadEvents(API::Progress *const prog, const bool monitors)
filter_time_start = Types::Core::DateAndTime::minimum(); filter_time_start = Types::Core::DateAndTime::minimum();
filter_time_stop = Types::Core::DateAndTime::maximum(); filter_time_stop = Types::Core::DateAndTime::maximum();
if (m_allBanksPulseTimes->numPulses > 0) { if (m_allBanksPulseTimes->pulseTimes.size() > 0) {
// If not specified, use the limits of doubles. Otherwise, convert from // If not specified, use the limits of doubles. Otherwise, convert from
// seconds to absolute PulseTime // seconds to absolute PulseTime
if (filter_time_start_sec != EMPTY_DBL()) { if (filter_time_start_sec != EMPTY_DBL()) {
......
...@@ -718,7 +718,7 @@ void LoadEventPreNexus2::procEvents(DataObjects::EventWorkspace_sptr &workspace) ...@@ -718,7 +718,7 @@ void LoadEventPreNexus2::procEvents(DataObjects::EventWorkspace_sptr &workspace)
partWorkspaces.resize(numThreads); partWorkspaces.resize(numThreads);
buffers.resize(numThreads); buffers.resize(numThreads);
eventVectors = new EventVector_pt *[numThreads]; eventVectors = new EventVector_pt *[numThreads];
// cppcheck-suppress syntaxError
PRAGMA_OMP( parallel for if (parallelProcessing) ) PRAGMA_OMP( parallel for if (parallelProcessing) )
for (int i = 0; i < int(numThreads); i++) { for (int i = 0; i < int(numThreads); i++) {
// This is the partial workspace we are about to create (if in parallel) // This is the partial workspace we are about to create (if in parallel)
......
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