Commit 8acad618 authored by Hahn, Steven's avatar Hahn, Steven
Browse files

Apply changes from clang-tidy readability-container-size-empty.

parent 9f49657e
......@@ -165,7 +165,7 @@ void ConvertEmptyToTof::exec() {
*/
void ConvertEmptyToTof::validateSpectraIndices(std::vector<int> &v) {
auto nHist = m_inputWS->getNumberHistograms();
if (v.size() == 0) {
if (v.empty()) {
g_log.information("No spectrum index given. Using all spectra to calculate "
"the elastic peak.");
// use all spectra indices
......@@ -190,7 +190,7 @@ void ConvertEmptyToTof::validateSpectraIndices(std::vector<int> &v) {
*/
void ConvertEmptyToTof::validateChannelIndices(std::vector<int> &v) {
auto blockSize = m_inputWS->blocksize() + 1;
if (v.size() == 0) {
if (v.empty()) {
g_log.information("No channel index given. Using all channels (full "
"spectrum!) to calculate the elastic peak.");
// use all channel indices
......
......@@ -149,7 +149,7 @@ void ConvertUnits::exec() {
// If the units conversion has flipped the ascending direction of X, reverse
// all the vectors
if (outputWS->dataX(0).size() &&
if (!outputWS->dataX(0).empty() &&
(outputWS->dataX(0).front() > outputWS->dataX(0).back() ||
outputWS->dataX(m_numberOfSpectra / 2).front() >
outputWS->dataX(m_numberOfSpectra / 2).back())) {
......
......@@ -163,7 +163,7 @@ void ConvertUnitsUsingDetectorTable::exec() {
// If the units conversion has flipped the ascending direction of X, reverse
// all the vectors
if (outputWS->dataX(0).size() &&
if (!outputWS->dataX(0).empty() &&
(outputWS->dataX(0).front() > outputWS->dataX(0).back() ||
outputWS->dataX(m_numberOfSpectra / 2).front() >
outputWS->dataX(m_numberOfSpectra / 2).back())) {
......
......@@ -253,7 +253,7 @@ double CreateTransmissionWorkspaceAuto::checkForDefault(
auto algProperty = this->getPointerToProperty(propName);
if (algProperty->isDefault()) {
auto defaults = instrument->getNumberParameter(idf_name);
if (defaults.size() == 0) {
if (defaults.empty()) {
throw std::runtime_error("No data could be retrieved from the parameters "
"and argument wasn't provided: " +
propName);
......
......@@ -75,7 +75,7 @@ std::map<std::string, std::string> CreateWorkspace::validateInputs() {
const std::string vUnit = getProperty("VerticalAxisUnit");
const std::vector<std::string> vAxis = getProperty("VerticalAxisValues");
if (vUnit == "SpectraNumber" && vAxis.size() > 0)
if (vUnit == "SpectraNumber" && !vAxis.empty())
issues["VerticalAxisValues"] =
"Axis values cannot be provided when using a spectra axis";
......
......@@ -493,7 +493,7 @@ void DiffractionFocussing2::execEvent() {
}
// Now you set the X axis to the X you saved before.
if (group2xvector.size() > 0) {
if (!group2xvector.empty()) {
auto git = group2xvector.find(group);
if (git != group2xvector.end())
out->setX(workspaceIndex, (git->second));
......
......@@ -343,7 +343,7 @@ void ExtractMaskToTable::addToTableWorkspace(TableWorkspace_sptr outws,
}
// Exclude previously masked detectors IDs from masked detectors IDs
if (prevmaskedids.size() > 0) {
if (!prevmaskedids.empty()) {
sort(prevmaskedids.begin(), prevmaskedids.end());
maskeddetids = subtractVector(maskeddetids, prevmaskedids);
numdetids = maskeddetids.size();
......
......@@ -920,7 +920,7 @@ void FilterEvents::filterEventsBySplitters(double progressamount) {
<< "; Number of splitters = " << splitters.size() << ".\n";
// Skip output workspace has ZERO splitters
if (splitters.size() == 0) {
if (splitters.empty()) {
g_log.warning() << "[FilterEvents] Workspace " << opws->name()
<< " Indexed @ " << wsindex
<< " won't have logs splitted due to zero splitter size. "
......
......@@ -193,7 +193,7 @@ void FindPeakBackground::exec() {
if (mask[l] != mask[l - 1] && mask[l] == 1) {
peaks.push_back(cont_peak());
peaks[peaks.size() - 1].start = l + l0;
} else if (peaks.size() > 0) {
} else if (!peaks.empty()) {
size_t ipeak = peaks.size() - 1;
if (mask[l] != mask[l - 1] && mask[l] == 0) {
peaks[ipeak].stop = l + l0;
......@@ -205,7 +205,7 @@ void FindPeakBackground::exec() {
size_t min_peak, max_peak;
double a0 = 0., a1 = 0., a2 = 0.;
int goodfit;
if (peaks.size() > 0) {
if (!peaks.empty()) {
g_log.debug() << "Peaks' size = " << peaks.size()
<< " -> esitmate background. \n";
if (peaks[peaks.size() - 1].stop == 0)
......@@ -225,8 +225,8 @@ void FindPeakBackground::exec() {
goodfit = 2;
}
estimateBackground(inpX, inpY, l0, n, min_peak, max_peak,
(peaks.size() > 0), a0, a1, a2);
estimateBackground(inpX, inpY, l0, n, min_peak, max_peak, (!peaks.empty()),
a0, a1, a2);
// Add a new row
API::TableRow t = m_outPeakTableWS->getRow(0);
......
......@@ -253,7 +253,7 @@ void FindPeaks::processAlgorithmProperties() {
// Specified peak positions, which is optional
m_vecPeakCentre = getProperty("PeakPositions");
if (m_vecPeakCentre.size() > 0)
if (!m_vecPeakCentre.empty())
std::sort(m_vecPeakCentre.begin(), m_vecPeakCentre.end());
m_vecFitWindows = getProperty("FitWindows");
......
......@@ -195,7 +195,7 @@ void FitOneSinglePeak::setupGuessedFWHM(double usrwidth, int minfwhm,
// From user specified minimum value to maximim value
if (!fitwithsteppedfwhm) {
if (m_vecFWHM.size() == 0)
if (m_vecFWHM.empty())
throw runtime_error("Logic error in setup guessed FWHM. ");
m_sstream << "No FWHM is not guessed by stepped FWHM. "
<< "\n";
......@@ -1423,9 +1423,9 @@ void FitPeak::createFunctions() {
// Set background function parameter values
m_bkgdParameterNames = getProperty("BackgroundParameterNames");
if (usedefaultbkgdparorder && m_bkgdParameterNames.size() == 0) {
if (usedefaultbkgdparorder && m_bkgdParameterNames.empty()) {
m_bkgdParameterNames = m_bkgdFunc->getParameterNames();
} else if (m_bkgdParameterNames.size() == 0) {
} else if (m_bkgdParameterNames.empty()) {
throw runtime_error("In the non-default background parameter name mode, "
"user must give out parameter names. ");
}
......@@ -1456,7 +1456,7 @@ void FitPeak::createFunctions() {
// Peak parameters' names
m_peakParameterNames = getProperty("PeakParameterNames");
if (m_peakParameterNames.size() == 0) {
if (m_peakParameterNames.empty()) {
if (defaultparorder) {
// Use default peak parameter names' order
m_peakParameterNames = m_peakFunc->getParameterNames();
......
......@@ -82,7 +82,7 @@ void FixGSASInstrumentFile::exec() {
// Split "\n"
vector<string> fields;
boost::algorithm::split(fields, line, boost::algorithm::is_any_of("\n"));
if (fields.size() == 0)
if (fields.empty())
throw runtime_error("Impossible to have an empty line. ");
vec_line.push_back(fields[0]);
}
......
......@@ -380,7 +380,7 @@ void GenerateEventsFilter::setFilterByTimeOnly() {
vector<double> vec_timeintervals = this->getProperty("TimeInterval");
bool singleslot = false;
if (vec_timeintervals.size() == 0)
if (vec_timeintervals.empty())
singleslot = true;
// Progress
......@@ -1420,7 +1420,7 @@ void GenerateEventsFilter::makeMultipleFiltersByValuesPartialLog(
// To fill the blanks at the end of log to make last entry of splitter is stop
// time
// To make it non-empty
if (vecSplitTime.size() == 0) {
if (vecSplitTime.empty()) {
start = m_dblLog->nthTime(istart);
stop = m_dblLog->nthTime(iend);
lastindex = -1;
......@@ -1686,7 +1686,7 @@ void GenerateEventsFilter::addNewTimeFilterSplitter(
if (m_forFastLog) {
// For MatrixWorkspace splitter
// Start of splitter
if (m_vecSplitterTime.size() == 0) {
if (m_vecSplitterTime.empty()) {
// First splitter
m_vecSplitterTime.push_back(starttime);
} else if (m_vecSplitterTime.back() < starttime) {
......
......@@ -748,7 +748,7 @@ API::MatrixWorkspace_sptr GeneratePeaks::createOutputWorkspace() {
MatrixWorkspace_sptr
GeneratePeaks::createDataWorkspace(std::vector<double> binparameters) {
// Check validity
if (m_spectraSet.size() == 0)
if (m_spectraSet.empty())
throw std::invalid_argument(
"Input spectra list is empty. Unable to generate a new workspace.");
......
......@@ -192,7 +192,7 @@ void GetAllEi::exec() {
auto phase = m_chopper->getNumberParameter("initial_phase");
if (phase.size() == 0) {
if (phase.empty()) {
throw std::runtime_error("Can not find initial_phase parameter"
" attached to the chopper-position component");
}
......@@ -250,7 +250,7 @@ void GetAllEi::exec() {
std::vector<double> guess_opening;
this->findGuessOpeningTimes(TOF_range, TOF0, Period, guess_opening);
if (guess_opening.size() == 0) {
if (guess_opening.empty()) {
throw std::runtime_error(
"Can not find any chopper opening time within TOF range: " +
boost::lexical_cast<std::string>(TOF_range.first) + ':' +
......@@ -858,7 +858,7 @@ void GetAllEi::findBinRanges(const MantidVec &eBins, const MantidVec &signal,
}
// if array decreasing rather then increasing, indexes behave differently.
// Will it still work?
if (irangeMax.size() > 0) {
if (!irangeMax.empty()) {
if (irangeMax[0] < irangeMin[0]) {
irangeMax.swap(irangeMin);
}
......@@ -1022,7 +1022,7 @@ GetAllEi::getAvrgLogValue(const API::MatrixWorkspace_sptr &inputWS,
propertyName);
}
if (splitter.size() == 0) {
if (splitter.empty()) {
auto TimeStart = inputWS->run().startTime();
auto TimeEnd = inputWS->run().endTime();
pTimeSeries->filterByTime(TimeStart, TimeEnd);
......@@ -1193,7 +1193,7 @@ bool check_time_series_property(
if (boost::iequals(LogName, "Defined in IDF")) {
try {
auto theLogs = chopper->getStringParameter(prop_name);
if (theLogs.size() == 0) {
if (theLogs.empty()) {
if (fail)
result[prop_name] = "Can not retrieve parameter " + prop_name +
" from the instrument definition file.";
......
......@@ -293,7 +293,7 @@ void GetDetOffsetsMultiPeaks::processProperties() {
// the peak positions and where to fit
m_peakPositions = getProperty("DReference");
if (m_peakPositions.size() == 0)
if (m_peakPositions.empty())
throw std::runtime_error("There is no input referenced peak position.");
std::sort(m_peakPositions.begin(), m_peakPositions.end());
......@@ -324,7 +324,7 @@ void GetDetOffsetsMultiPeaks::processProperties() {
g_log.information(infoss.str());
if (m_fitWindows.size() == 0)
if (m_fitWindows.empty())
g_log.warning() << "Input FitWindowMaxWidth = " << maxwidth
<< " No FitWidows will be generated."
<< "\n";
......@@ -423,7 +423,7 @@ void GetDetOffsetsMultiPeaks::importFitWindowTableWorkspace(
if (spec < 0 && founduniversal) {
throw std::runtime_error("There are more than 1 universal spectrum (spec "
"< 0) in TableWorkspace.");
} else if (spec >= 0 && m_vecFitWindow[spec].size() != 0) {
} else if (spec >= 0 && !m_vecFitWindow[spec].empty()) {
std::stringstream ess;
ess << "Peak fit windows at row " << i << " has spectrum " << spec
<< ", which appears before in fit window table workspace. ";
......@@ -455,7 +455,7 @@ void GetDetOffsetsMultiPeaks::importFitWindowTableWorkspace(
} else if (founduniversal) {
// Fill the universal
for (size_t i = 0; i < m_inputWS->getNumberHistograms(); ++i)
if (m_vecFitWindow[i].size() == 0)
if (m_vecFitWindow[i].empty())
m_vecFitWindow[i] = vec_univFitWindow;
}
......
......@@ -77,7 +77,7 @@ void MaskBins::exec() {
//---------------------------------------------------------------------------------
// what spectra (workspace indices) to load. Optional.
this->spectra_list = this->getProperty("SpectraList");
if (this->spectra_list.size() > 0) {
if (!this->spectra_list.empty()) {
const int numHist = static_cast<int>(inputWS->getNumberHistograms());
//--- Validate spectra list ---
for (auto wi : this->spectra_list) {
......@@ -123,7 +123,7 @@ void MaskBins::exec() {
// Parallel running has problems with a race condition, leading to
// occaisional test failures and crashes
bool useSpectraList = (this->spectra_list.size() > 0);
bool useSpectraList = (!this->spectra_list.empty());
// Alter the for loop ending based on what we are looping on
int for_end = numHists;
......@@ -172,7 +172,7 @@ void MaskBins::execEvent() {
outputWS->sortAll(Mantid::DataObjects::TOF_SORT, &progress);
// Go through all histograms
if (this->spectra_list.size() > 0) {
if (!this->spectra_list.empty()) {
// Specific spectra were specified
PARALLEL_FOR1(outputWS)
for (int i = 0; i < static_cast<int>(this->spectra_list.size()); ++i) {
......
......@@ -252,7 +252,7 @@ MaskBinsFromTable::convertToSpectraList(API::MatrixWorkspace_sptr dataws,
}
// Sort the vector
if (wsindexvec.size() == 0)
if (wsindexvec.empty())
throw runtime_error("There is no spectrum found for input detectors list.");
sort(wsindexvec.begin(), wsindexvec.end());
......
......@@ -133,7 +133,7 @@ void MergeRuns::exec() {
* Throws an error if there is any incompatibility.
*/
void MergeRuns::buildAdditionTables() {
if (m_inEventWS.size() <= 0)
if (m_inEventWS.empty())
throw std::invalid_argument("MergeRuns: No workspaces found to merge.");
// This'll hold the addition tables.
......
......@@ -73,11 +73,11 @@ void MuonGroupDetectors::exec() {
// First pass to determine how many non-empty groups we have
for (size_t row = 0; row < table->rowCount(); ++row) {
if (table->cell<std::vector<int>>(row, 0).size() != 0)
if (!table->cell<std::vector<int>>(row, 0).empty())
nonEmptyRows.push_back(row);
}
if (nonEmptyRows.size() == 0)
if (nonEmptyRows.empty())
throw std::invalid_argument(
"Detector Grouping Table doesn't contain any non-empty groups");
......
Supports Markdown
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