Commit 1e6af932 authored by Hahn, Steven's avatar Hahn, Steven
Browse files

Refs #14988. Ran modernize-loop-convert on Algorithms and CurveFitting

parent 8c6c7909
......@@ -135,9 +135,8 @@ void AbsorptionCorrection::exec() {
// If sample not at origin, shift cached positions.
const V3D samplePos = m_inputWS->getInstrument()->getSample()->getPos();
if (samplePos != V3D(0, 0, 0)) {
for (auto it = m_elementPositions.begin(); it != m_elementPositions.end();
++it) {
(*it) += samplePos;
for (auto &m_elementPosition : m_elementPositions) {
m_elementPosition += samplePos;
}
}
......
......@@ -103,8 +103,8 @@ Mantid::Kernel::TimeSeriesProperty<double> *AddLogDerivative::makeDerivative(
DateAndTime start = input->nthTime(0);
std::vector<DateAndTime> timeFull;
timeFull.reserve(times.size());
for (size_t i = 0; i < times.size(); i++)
timeFull.push_back(start + times[i]);
for (double time : times)
timeFull.push_back(start + time);
// Create the TSP out of it
auto out = new TimeSeriesProperty<double>(name);
......
......@@ -91,10 +91,10 @@ public:
double difc = 0.;
double difa = 0.;
double tzero = 0.;
for (auto row = rows.begin(); row != rows.end(); ++row) {
difc += m_difcCol->toDouble(*row);
difa += m_difaCol->toDouble(*row);
tzero += m_tzeroCol->toDouble(*row);
for (value_type row : rows) {
difc += m_difcCol->toDouble(row);
difa += m_difaCol->toDouble(row);
tzero += m_tzeroCol->toDouble(row);
}
if (rows.size() > 1) {
double norm = 1. / static_cast<double>(rows.size());
......@@ -125,8 +125,8 @@ private:
std::set<size_t> getRow(const std::set<detid_t> &detIds) {
std::set<size_t> rows;
for (auto detId = detIds.begin(); detId != detIds.end(); ++detId) {
auto rowIter = m_detidToRow.find(*detId);
for (value_type detId : detIds) {
auto rowIter = m_detidToRow.find(detId);
if (rowIter != m_detidToRow.end()) { // skip if not found
rows.insert(rowIter->second);
}
......
......@@ -171,12 +171,12 @@ void ChangeTimeZero::shiftTimeOfLogs(Mantid::API::MatrixWorkspace_sptr ws,
// 2. string properties: here we change the values if they are ISO8601 times
auto logs = ws->mutableRun().getLogData();
Progress prog(this, startProgress, stopProgress, logs.size());
for (auto iter = logs.begin(); iter != logs.end(); ++iter) {
if (isTimeSeries(*iter)) {
shiftTimeInLogForTimeSeries(ws, *iter, timeShift);
for (auto &log : logs) {
if (isTimeSeries(log)) {
shiftTimeInLogForTimeSeries(ws, log, timeShift);
} else if (auto stringProperty =
dynamic_cast<PropertyWithValue<std::string> *>(*iter)) {
dynamic_cast<PropertyWithValue<std::string> *>(log)) {
shiftTimeOfLogForStringProperty(stringProperty, timeShift);
}
......
......@@ -163,8 +163,8 @@ void ChopData::exec() {
// Create workspace group that holds output workspaces
WorkspaceGroup_sptr wsgroup = WorkspaceGroup_sptr(new WorkspaceGroup());
for (auto it = workspaces.begin(); it != workspaces.end(); ++it) {
wsgroup->addWorkspace(*it);
for (auto &workspace : workspaces) {
wsgroup->addWorkspace(workspace);
}
// set the output property
setProperty("OutputWorkspace", wsgroup);
......
......@@ -74,15 +74,15 @@ void ClearInstrumentParameters::exec() {
ParameterMap::pmap paramsToKeep;
// Go through all the parameters, keep a hold of any we don't want to clear.
for (auto paramIt = params->begin(); paramIt != params->end(); ++paramIt) {
for (auto &paramIt : *params) {
// Are we keeping the location parameters?
const std::string pName = (*paramIt).second->name();
const std::string pName = paramIt.second->name();
if (!clearLocationParams &&
(pName == "x" || pName == "y" || pName == "z" ||
pName == "r-position" || pName == "t-position" ||
pName == "p-position" || pName == "rotx" || pName == "roty" ||
pName == "rotz")) {
paramsToKeep.insert(*paramIt);
paramsToKeep.insert(paramIt);
}
}
......@@ -90,9 +90,8 @@ void ClearInstrumentParameters::exec() {
params->clear();
// Add any parameters we're keeping back into the parameter map.
for (auto paramIt = paramsToKeep.begin(); paramIt != paramsToKeep.end();
++paramIt) {
params->add((*paramIt).first, (*paramIt).second);
for (auto &paramIt : paramsToKeep) {
params->add(paramIt.first, paramIt.second);
}
}
......
......@@ -216,8 +216,7 @@ void CompareWorkspaces::processGroups(
const std::vector<Property *> &allProps = this->getProperties();
std::vector<Property *> nonDefaultProps;
nonDefaultProps.reserve(allProps.size());
for (size_t i = 0; i < allProps.size(); ++i) {
Property *p = allProps[i];
for (auto p : allProps) {
const std::string &propName = p->name();
// Skip those not set and the input workspaces
if (p->isDefault() || propName == "Workspace1" || propName == "Workspace2")
......
......@@ -131,8 +131,8 @@ void ConvertEmptyToTof::exec() {
std::map<int, int> eppMap =
findElasticPeakPositions(spectraIndices, channelIndices);
for (auto it = eppMap.begin(); it != eppMap.end(); ++it) {
g_log.debug() << "Spectra idx =" << it->first << ", epp=" << it->second
for (auto &it : eppMap) {
g_log.debug() << "Spectra idx =" << it.first << ", epp=" << it.second
<< std::endl;
}
......@@ -168,10 +168,10 @@ void ConvertEmptyToTof::validateSpectraIndices(std::vector<int> &v) {
for (unsigned int i = 0; i < nHist; ++i)
v[i] = i;
} else {
for (auto it = v.begin(); it != v.end(); ++it) {
if (*it < 0 || static_cast<size_t>(*it) >= nHist) {
for (int &it : v) {
if (it < 0 || static_cast<size_t>(it) >= nHist) {
throw std::runtime_error("Spectra index out of limits: " +
boost::lexical_cast<std::string>(*it));
boost::lexical_cast<std::string>(it));
}
}
}
......@@ -193,10 +193,10 @@ void ConvertEmptyToTof::validateChannelIndices(std::vector<int> &v) {
for (unsigned int i = 0; i < blockSize; ++i)
v[i] = i;
} else {
for (auto it = v.begin(); it != v.end(); ++it) {
if (*it < 0 || static_cast<size_t>(*it) >= blockSize) {
for (int &it : v) {
if (it < 0 || static_cast<size_t>(it) >= blockSize) {
throw std::runtime_error("Channel index out of limits: " +
boost::lexical_cast<std::string>(*it));
boost::lexical_cast<std::string>(it));
}
}
}
......@@ -219,9 +219,8 @@ std::map<int, int> ConvertEmptyToTof::findElasticPeakPositions(
g_log.information() << "Peak detection, search for peak " << std::endl;
for (auto it = spectraIndices.begin(); it != spectraIndices.end(); ++it) {
for (int spectrumIndex : spectraIndices) {
int spectrumIndex = *it;
const Mantid::MantidVec &thisSpecY = m_inputWS->dataY(spectrumIndex);
int minChannelIndex = *(channelIndices.begin());
......@@ -399,9 +398,9 @@ ConvertEmptyToTof::findAverageEppAndEpTof(const std::map<int, int> &eppMap) {
std::vector<int> eppList;
double firstL2 = getL2(m_inputWS, eppMap.begin()->first);
for (auto it = eppMap.begin(); it != eppMap.end(); ++it) {
for (const auto &it : eppMap) {
double l2 = getL2(m_inputWS, it->first);
double l2 = getL2(m_inputWS, it.first);
if (!areEqual(l2, firstL2, 0.0001)) {
g_log.error() << "firstL2=" << firstL2 << " , "
<< "l2=" << l2 << std::endl;
......@@ -414,9 +413,9 @@ ConvertEmptyToTof::findAverageEppAndEpTof(const std::map<int, int> &eppMap) {
epTofList.push_back(
(calculateTOF(l1, wavelength) + calculateTOF(l2, wavelength)) *
1e6); // microsecs
eppList.push_back(it->first);
eppList.push_back(it.first);
g_log.debug() << "WS index = " << it->first << ", l1 = " << l1
g_log.debug() << "WS index = " << it.first << ", l1 = " << l1
<< ", l2 = " << l2
<< ", TOF(l1+l2) = " << *(epTofList.end() - 1) << std::endl;
}
......
......@@ -91,8 +91,7 @@ void CopyLogs::exec() {
*/
void CopyLogs::mergeReplaceExisting(
const std::vector<Kernel::Property *> &inputLogs, Run &outputRun) {
for (auto iter = inputLogs.begin(); iter != inputLogs.end(); ++iter) {
Kernel::Property *prop = *iter;
for (auto prop : inputLogs) {
// if the log exists, remove and replace it
if (outputRun.hasProperty(prop->name())) {
outputRun.removeLogData(prop->name());
......@@ -107,8 +106,7 @@ void CopyLogs::mergeReplaceExisting(
*/
void CopyLogs::mergeKeepExisting(
const std::vector<Kernel::Property *> &inputLogs, Run &outputRun) {
for (auto iter = inputLogs.begin(); iter != inputLogs.end(); ++iter) {
Kernel::Property *prop = *iter;
for (auto prop : inputLogs) {
// add the log only if it doesn't already exist
if (!outputRun.hasProperty(prop->name())) {
outputRun.addLogData(prop->clone());
......@@ -125,13 +123,13 @@ void CopyLogs::wipeExisting(const std::vector<Kernel::Property *> &inputLogs,
auto outputLogs = outputRun.getLogData();
// remove each of the logs from the second workspace
for (auto iter = outputLogs.begin(); iter != outputLogs.end(); ++iter) {
outputRun.removeLogData((*iter)->name());
for (auto &outputLog : outputLogs) {
outputRun.removeLogData(outputLog->name());
}
// add all the logs from the new workspace
for (auto iter = inputLogs.begin(); iter != inputLogs.end(); ++iter) {
outputRun.addLogData((*iter)->clone());
for (auto inputLog : inputLogs) {
outputRun.addLogData(inputLog->clone());
}
}
......
......@@ -164,8 +164,8 @@ void CorelliCrossCorrelate::exec() {
int offset_int = getProperty("TimingOffset");
const int64_t offset = static_cast<int64_t>(offset_int);
for (unsigned long i = 0; i < tdc.size(); ++i)
tdc[i] += offset;
for (auto &i : tdc)
i += offset;
// Determine period from chopper frequency.
auto motorSpeed = dynamic_cast<TimeSeriesProperty<double> *>(
......
......@@ -80,9 +80,9 @@ void CreateCalFileByNames::exec() {
// Assign incremental number to each group
std::map<std::string, int> group_map;
int index = 0;
for (auto it = vgroups.begin(); it != vgroups.end(); ++it) {
boost::trim(*it);
group_map[(*it)] = ++index;
for (auto &vgroup : vgroups) {
boost::trim(vgroup);
group_map[vgroup] = ++index;
}
// Not needed anymore
......@@ -221,9 +221,9 @@ void CreateCalFileByNames::saveGroupingFile(const std::string &filename,
}
} else //
{
for (auto it = instrcalib.cbegin(); it != instrcalib.cend(); ++it)
writeCalEntry(outfile, (*it).first, ((*it).second).first, 0.0, 1,
((*it).second).second);
for (const auto &it : instrcalib)
writeCalEntry(outfile, it.first, (it.second).first, 0.0, 1,
(it.second).second);
}
// Closing
......
......@@ -223,9 +223,9 @@ void CreateDummyCalFile::saveGroupingFile(const std::string &filename,
}
} else //
{
for (auto it = instrcalib.cbegin(); it != instrcalib.cend(); ++it)
writeCalEntry(outfile, (*it).first, ((*it).second).first, 0.0, 1,
((*it).second).second);
for (const auto &it : instrcalib)
writeCalEntry(outfile, it.first, (it.second).first, 0.0, 1,
(it.second).second);
}
// Closing
......
......@@ -246,9 +246,9 @@ void makeGroupingByNames(std::string GroupNames, Instrument_const_sptr inst,
// Trim and assign incremental number to each group
std::map<std::string, int> group_map;
int index = 0;
for (auto it = vgroups.begin(); it != vgroups.end(); ++it) {
boost::trim(*it);
group_map[(*it)] = ++index;
for (auto &vgroup : vgroups) {
boost::trim(vgroup);
group_map[vgroup] = ++index;
}
// Find Detectors that belong to groups
......
......@@ -93,27 +93,24 @@ void CreateLogPropertyTable::exec() {
this->getProperty("LogPropertyNames");
// Make sure all workspaces contain the properties.
for (auto matrixWs = matrixWsList.begin(); matrixWs != matrixWsList.end();
++matrixWs) {
const Run &run = matrixWs->get()->run();
const std::string wsName = matrixWs->get()->getName();
for (const auto &matrixWs : matrixWsList) {
const Run &run = matrixWs.get()->run();
const std::string wsName = matrixWs.get()->getName();
// Throw if a run does not have a property.
for (auto propName = propNames.begin(); propName != propNames.end();
++propName)
if (!run.hasProperty(*propName))
for (const auto &propName : propNames)
if (!run.hasProperty(propName))
throw std::runtime_error("\"" + wsName +
"\" does not have a run property of \"" +
*propName + "\".");
propName + "\".");
}
// Set up output table.
boost::shared_ptr<ITableWorkspace> outputTable =
WorkspaceFactory::Instance().createTable();
// One column for each property.
for (auto propName = propNames.begin(); propName != propNames.end();
++propName)
outputTable->addColumn("str", *propName);
for (const auto &propName : propNames)
outputTable->addColumn("str", propName);
// One row for each workspace.
for (size_t i = 0; i < matrixWsList.size(); ++i)
outputTable->appendRow();
......@@ -132,13 +129,12 @@ void CreateLogPropertyTable::exec() {
TableRow row = outputTable->getRow(i);
MatrixWorkspace_sptr matrixWs = matrixWsList[i];
for (auto propName = propNames.begin(); propName != propNames.end();
++propName) {
Property *prop = matrixWs->run().getProperty(*propName);
for (const auto &propName : propNames) {
Property *prop = matrixWs->run().getProperty(propName);
std::stringstream propValue;
if (prop->type().find("TimeValue") != std::string::npos) {
propValue << matrixWs->run().getLogAsSingleValue(*propName,
propValue << matrixWs->run().getLogAsSingleValue(propName,
timeSeriesStat);
} else {
propValue << prop->value();
......@@ -174,12 +170,12 @@ retrieveMatrixWsList(const std::vector<std::string> &wsNames,
std::vector<MatrixWorkspace_sptr> matrixWsList;
// Get all the workspaces which are to be inspected for log proeprties.
for (auto wsName = wsNames.begin(); wsName != wsNames.end(); ++wsName) {
for (const auto &wsName : wsNames) {
WorkspaceGroup_sptr wsGroup = boost::dynamic_pointer_cast<WorkspaceGroup>(
AnalysisDataService::Instance().retrieve(*wsName));
AnalysisDataService::Instance().retrieve(wsName));
MatrixWorkspace_sptr matrixWs =
boost::dynamic_pointer_cast<MatrixWorkspace>(
AnalysisDataService::Instance().retrieve(*wsName));
AnalysisDataService::Instance().retrieve(wsName));
if (wsGroup) {
const std::vector<std::string> childNames = wsGroup->getNames();
......@@ -191,20 +187,18 @@ retrieveMatrixWsList(const std::vector<std::string> &wsNames,
// Retrieve pointers to all the child workspaces.
std::vector<MatrixWorkspace_sptr> childWsList;
for (auto childName = childNames.begin(); childName != childNames.end();
++childName) {
for (const auto &childName : childNames) {
childWsList.push_back(
AnalysisDataService::Instance().retrieveWS<MatrixWorkspace>(
*childName));
childName));
}
// Deal with child workspaces according to policy.
switch (groupPolicy) {
case ALL: {
// Append all the children to the list.
for (auto childWs = childWsList.begin(); childWs != childWsList.end();
++childWs)
matrixWsList.push_back(*childWs);
for (auto &childWs : childWsList)
matrixWsList.push_back(childWs);
break;
}
case FIRST:
......@@ -275,8 +269,8 @@ std::set<std::string> getAllGroupPolicyNames() {
const std::map<std::string, GroupPolicy> &map = getGroupPolicyMap();
std::set<std::string> groupPolicyNames;
for (auto policy = map.begin(); policy != map.end(); ++policy)
groupPolicyNames.insert(policy->first);
for (const auto &policy : map)
groupPolicyNames.insert(policy.first);
return groupPolicyNames;
}
......@@ -330,8 +324,8 @@ std::set<std::string> getAllStatisticTypeNames() {
const std::map<std::string, Math::StatisticType> &map = getStatisticTypeMap();
std::set<std::string> statisticTypeNames;
for (auto policy = map.begin(); policy != map.end(); ++policy)
statisticTypeNames.insert(policy->first);
for (const auto &policy : map)
statisticTypeNames.insert(policy.first);
return statisticTypeNames;
}
......
......@@ -108,11 +108,11 @@ void CreateLogTimeCorrection::getInstrumentSetup() {
// 2. Get detector IDs
std::vector<detid_t> detids = m_instrument->getDetectorIDs(true);
for (size_t i = 0; i < detids.size(); ++i) {
IDetector_const_sptr detector = m_instrument->getDetector(detids[i]);
for (int &detid : detids) {
IDetector_const_sptr detector = m_instrument->getDetector(detid);
V3D detpos = detector->getPos();
double l2 = detpos.distance(samplepos);
m_l2map.insert(make_pair(detids[i], l2));
m_l2map.insert(make_pair(detid, l2));
}
// 3. Output information
......
......@@ -269,8 +269,8 @@ bool CreatePSDBleedMask::performBleedTest(
void CreatePSDBleedMask::maskTube(const std::vector<int> &tubeIndices,
API::MatrixWorkspace_sptr workspace) {
const double deadValue(1.0); // delete the data
for (auto citr = tubeIndices.cbegin(); citr != tubeIndices.cend(); ++citr) {
workspace->dataY(*citr)[0] = deadValue;
for (int tubeIndice : tubeIndices) {
workspace->dataY(tubeIndice)[0] = deadValue;
}
}
}
......
......@@ -109,9 +109,8 @@ void CreateSampleWorkspace::init() {
m_preDefinedFunctionmap.insert(
std::pair<std::string, std::string>("User Defined", ""));
std::vector<std::string> functionOptions;
for (auto iterator = m_preDefinedFunctionmap.begin();
iterator != m_preDefinedFunctionmap.end(); iterator++) {
functionOptions.push_back(iterator->first);
for (auto &iterator : m_preDefinedFunctionmap) {
functionOptions.push_back(iterator.first);
}
declareProperty("Function", "One Peak",
boost::make_shared<StringListValidator>(functionOptions),
......
......@@ -619,10 +619,8 @@ DetectorDiagnostic::calculateMedian(const API::MatrixWorkspace_sptr input,
std::vector<double> medianvec;
g_log.debug("Calculating the median count rate of the spectra");
for (size_t j = 0; j < indexmap.size(); ++j) {
for (auto hists : indexmap) {
std::vector<double> medianInput;
std::vector<size_t> hists = indexmap.at(j);
const int nhists = static_cast<int>(hists.size());
// The maximum possible length is that of workspace length
medianInput.reserve(nhists);
......@@ -635,19 +633,19 @@ DetectorDiagnostic::calculateMedian(const API::MatrixWorkspace_sptr input,
}
PARALLEL_FOR1(input)
for (int i = 0; i < static_cast<int>(hists.size()); ++i) {
for (unsigned long hist : hists) {
PARALLEL_START_INTERUPT_REGION
if (checkForMask) {
const std::set<detid_t> &detids =
input->getSpectrum(hists[i])->getDetectorIDs();
input->getSpectrum(hist)->getDetectorIDs();
if (instrument->isDetectorMasked(detids))
continue;
if (instrument->isMonitor(detids))
continue;
}
const double yValue = input->readY(hists[i])[0];
const double yValue = input->readY(hist)[0];
if (yValue < 0.0) {
throw std::out_of_range("Negative number of counts found, could be "
"corrupted raw counts or solid angle data");
......
......@@ -245,8 +245,8 @@ void DiffractionFocussing2::exec() {
m_matrixInputW->maskedBins(i);
// Now iterate over the list, adjusting the weights for the affected
// bins
for (auto it = mask.cbegin(); it != mask.cend(); ++it) {
const double currentX = Xin[(*it).first];
for (const auto &it : mask) {
const double currentX = Xin[it.first];
// Add an intermediate bin with full weight if masked bins aren't
// consecutive
if (weight_bins.back() != currentX) {
......@@ -255,8 +255,8 @@ void DiffractionFocussing2::exec() {
}
// The weight for this masked bin is 1 - the degree to which this bin
// is masked
weights.push_back(1.0 - (*it).second);
weight_bins.push_back(Xin[(*it).first + 1]);
weights.push_back(1.0 - it.second);
weight_bins.push_back(Xin[it.first + 1]);
}
// Add on a final bin with full weight if masking doesn't go up to the
// end
......@@ -368,8 +368,8 @@ void DiffractionFocussing2::execEvent() {
const vector<size_t> &indices = this->m_wsIndices[group];
totalHistProcess += static_cast<int>(indices.size());
for (auto index = indices.cbegin(); index != indices.cend(); ++index) {
size_required[iGroup] += m_eventW->getEventList(*index).getNumberEvents();
for (unsigned long indice : indices) {
size_required[iGroup] += m_eventW->getEventList(indice).getNumberEvents();
}
prog->report(1, "Pre-counting");
}
......@@ -454,9 +454,7 @@ void DiffractionFocussing2::execEvent() {
PARALLEL_START_INTERUPT_REGION
const int group = this->m_validGroups[iGroup];
const std::vector<size_t> &indices = this->m_wsIndices[group];
for (size_t i = 0; i < indices.size(); i++) {
size_t wi = indices[i];
for (unsigned long wi : indices) {
// In workspace index iGroup, put what was in the OLD workspace index wi
out->getOrAddEventList(iGroup) += m_eventW->getEventList(wi);
......
......@@ -515,9 +515,7 @@ void FilterEvents::createOutputWorkspaces() {
// Determine the minimum group index number
int minwsgroup = INT_MAX;
for (auto groupit = m_workGroupIndexes.begin();
groupit != m_workGroupIndexes.end(); ++groupit) {
int wsgroup = *groupit;
for (value_type wsgroup : m_workGroupIndexes) {
if (wsgroup < minwsgroup && wsgroup >= 0)
minwsgroup = wsgroup;
}
......@@ -1035,8 +1033,7 @@ void FilterEvents::filterEventsByVectorSplitters(double progressamount) {
void FilterEvents::generateSplitters(int wsindex,
Kernel::TimeSplitterType &splitters) {
splitters.clear();
for (size_t isp = 0; isp < m_splitters.size(); ++isp) {
Kernel::SplittingInterval splitter = m_splitters[isp];
for (auto splitter : m_splitters) {
int index = splitter.index();
if (index == wsindex) {
splitters.push_back(splitter);
......@@ -1060,8 +1057,7 @@ void FilterEvents::splitLog(EventWorkspace_sptr eventws, std::string logname,
<< std::endl;
return;
} else {
for (size_t i = 0; i < splitters.size(); ++i) {