From abb123e66e97da7316aad778a37edf49cbd1c10a Mon Sep 17 00:00:00 2001 From: Steven Hahn <hahnse@ornl.gov> Date: Fri, 15 Jan 2016 16:13:15 -0500 Subject: [PATCH] Refs #14988. Ran modernize-loop-convert on DataHandling. --- .../src/AppendGeometryToSNSNexus.cpp | 10 +-- .../src/CreateChunkingFromInstrument.cpp | 17 ++-- .../src/CreateSimulationWorkspace.cpp | 4 +- .../DataHandling/src/DetermineChunking.cpp | 20 ++--- .../DataHandling/src/DownloadInstrument.cpp | 11 ++- .../src/EventWorkspaceCollection.cpp | 80 +++++++++---------- .../src/FilterEventsByLogValuePreNexus.cpp | 34 ++++---- .../DataHandling/src/FindDetectorsPar.cpp | 16 ++-- .../DataHandling/src/GroupDetectors2.cpp | 70 +++++++--------- .../DataHandling/src/ISISDataArchive.cpp | 14 ++-- Framework/DataHandling/src/ISISRunLogs.cpp | 4 +- Framework/DataHandling/src/Load.cpp | 48 ++++++----- Framework/DataHandling/src/LoadAscii.cpp | 3 +- Framework/DataHandling/src/LoadAscii2.cpp | 9 +-- Framework/DataHandling/src/LoadBBY.cpp | 30 +++---- .../src/LoadDetectorsGroupingFile.cpp | 44 +++++----- Framework/DataHandling/src/LoadDiffCal.cpp | 14 ++-- Framework/DataHandling/src/LoadDspacemap.cpp | 4 +- Framework/DataHandling/src/LoadEventNexus.cpp | 67 +++++++--------- .../DataHandling/src/LoadEventPreNexus.cpp | 16 ++-- .../DataHandling/src/LoadEventPreNexus2.cpp | 20 +++-- Framework/DataHandling/src/LoadFITS.cpp | 7 +- .../src/LoadFullprofResolution.cpp | 14 ++-- .../src/LoadGSASInstrumentFile.cpp | 10 +-- .../DataHandling/src/LoadIDFFromNexus.cpp | 9 +-- Framework/DataHandling/src/LoadILL.cpp | 7 +- Framework/DataHandling/src/LoadISISNexus2.cpp | 35 ++++---- Framework/DataHandling/src/LoadInstrument.cpp | 4 +- Framework/DataHandling/src/LoadIsawDetCal.cpp | 4 +- Framework/DataHandling/src/LoadLog.cpp | 4 +- .../src/LoadLogsForSNSPulsedMagnet.cpp | 6 +- Framework/DataHandling/src/LoadMLZ.cpp | 4 +- Framework/DataHandling/src/LoadMask.cpp | 69 ++++++++-------- Framework/DataHandling/src/LoadMcStas.cpp | 42 +++++----- .../DataHandling/src/LoadMcStasNexus.cpp | 17 ++-- Framework/DataHandling/src/LoadMuonLog.cpp | 4 +- Framework/DataHandling/src/LoadMuonNexus1.cpp | 42 +++++----- Framework/DataHandling/src/LoadMuonNexus2.cpp | 9 +-- Framework/DataHandling/src/LoadNexusLogs.cpp | 6 +- .../DataHandling/src/LoadNexusMonitors2.cpp | 14 ++-- .../DataHandling/src/LoadNexusProcessed.cpp | 3 +- Framework/DataHandling/src/LoadPreNexus.cpp | 17 ++-- Framework/DataHandling/src/LoadRKH.cpp | 12 +-- .../DataHandling/src/LoadRaw/isisraw.cpp | 8 +- Framework/DataHandling/src/LoadRawHelper.cpp | 10 +-- Framework/DataHandling/src/LoadSpice2D.cpp | 10 +-- .../DataHandling/src/LoadTOFRawNexus.cpp | 7 +- .../DataHandling/src/LoadVulcanCalFile.cpp | 8 +- .../DataHandling/src/ProcessDasNexusLog.cpp | 30 ++++--- Framework/DataHandling/src/SNSDataArchive.cpp | 8 +- Framework/DataHandling/src/SaveAscii.cpp | 24 +++--- Framework/DataHandling/src/SaveAscii2.cpp | 12 +-- Framework/DataHandling/src/SaveCSV.cpp | 20 ++--- Framework/DataHandling/src/SaveCanSAS1D.cpp | 4 +- .../src/SaveDetectorsGrouping.cpp | 35 ++++---- Framework/DataHandling/src/SaveDiffCal.cpp | 4 +- .../src/SaveFullprofResolution.cpp | 4 +- .../src/SaveGSASInstrumentFile.cpp | 32 ++++---- Framework/DataHandling/src/SaveGSS.cpp | 6 +- .../DataHandling/src/SaveILLCosmosAscii.cpp | 6 +- Framework/DataHandling/src/SaveISISNexus.cpp | 12 +-- Framework/DataHandling/src/SaveIsawDetCal.cpp | 7 +- Framework/DataHandling/src/SaveNXTomo.cpp | 13 ++- .../DataHandling/src/SaveNexusProcessed.cpp | 6 +- .../DataHandling/src/SaveOpenGenieAscii.cpp | 12 +-- .../DataHandling/src/SaveParameterFile.cpp | 18 ++--- .../DataHandling/src/SaveReflCustomAscii.cpp | 6 +- Framework/DataHandling/src/SaveReflTBL.cpp | 10 +-- .../src/SaveReflThreeColumnAscii.cpp | 6 +- .../DataHandling/src/SaveSavuTomoConfig.cpp | 14 ++-- Framework/DataHandling/src/SetScalingPSD.cpp | 4 +- 71 files changed, 569 insertions(+), 641 deletions(-) diff --git a/Framework/DataHandling/src/AppendGeometryToSNSNexus.cpp b/Framework/DataHandling/src/AppendGeometryToSNSNexus.cpp index 37845303e1c..3d757f73e8b 100644 --- a/Framework/DataHandling/src/AppendGeometryToSNSNexus.cpp +++ b/Framework/DataHandling/src/AppendGeometryToSNSNexus.cpp @@ -222,11 +222,11 @@ void AppendGeometryToSNSNexus::exec() { polar_angle.reserve(dets.size()); azimuthal_angle.reserve(dets.size()); - for (std::size_t i = 0; i < dets.size(); i++) { - pixel_id.push_back(dets[i]->getID()); - distance.push_back(dets[i]->getDistance(*sample)); - azimuthal_angle.push_back(dets[i]->getPhi()); - polar_angle.push_back(ws->detectorTwoTheta(dets[i])); + for (auto &det : dets) { + pixel_id.push_back(det->getID()); + distance.push_back(det->getDistance(*sample)); + azimuthal_angle.push_back(det->getPhi()); + polar_angle.push_back(ws->detectorTwoTheta(det)); } // Write Pixel ID to file diff --git a/Framework/DataHandling/src/CreateChunkingFromInstrument.cpp b/Framework/DataHandling/src/CreateChunkingFromInstrument.cpp index 8d9337645a7..a0919061424 100644 --- a/Framework/DataHandling/src/CreateChunkingFromInstrument.cpp +++ b/Framework/DataHandling/src/CreateChunkingFromInstrument.cpp @@ -246,17 +246,17 @@ string parentName(IComponent_const_sptr comp, const string &prefix) { */ string parentName(IComponent_const_sptr comp, const vector<string> &names) { // handle the special case of the component has the name - for (auto name = names.begin(); name != names.end(); ++name) - if (name->compare(comp->getName()) == 0) - return (*name); + for (const auto &name : names) + if (name.compare(comp->getName()) == 0) + return name; // find the parent with the correct name IComponent_const_sptr parent = comp->getParent(); if (parent) { // see if this is the parent - for (auto name = names.begin(); name != names.end(); ++name) - if (name->compare(parent->getName()) == 0) - return (*name); + for (const auto &name : names) + if (name.compare(parent->getName()) == 0) + return name; // or recurse return parentName(parent, names); @@ -448,10 +448,9 @@ void CreateChunkingFromInstrument::exec() { throw std::runtime_error("Failed to find any banks in the instrument"); // fill in the table workspace - for (auto group = grouping.begin(); group != grouping.end(); ++group) { + for (auto &group : grouping) { stringstream banks; - for (auto bank = group->second.begin(); bank != group->second.end(); - ++bank) + for (auto bank = group.second.begin(); bank != group.second.end(); ++bank) banks << (*bank) << ","; // remove the trailing comma diff --git a/Framework/DataHandling/src/CreateSimulationWorkspace.cpp b/Framework/DataHandling/src/CreateSimulationWorkspace.cpp index e5a056ecfb7..eb984da2098 100644 --- a/Framework/DataHandling/src/CreateSimulationWorkspace.cpp +++ b/Framework/DataHandling/src/CreateSimulationWorkspace.cpp @@ -302,12 +302,12 @@ MantidVecPtr CreateSimulationWorkspace::createBinBoundaries() const { */ void CreateSimulationWorkspace::applyDetectorMapping() { size_t wsIndex(0); - for (auto iter = m_detGroups.begin(); iter != m_detGroups.end(); ++iter) { + for (auto &m_detGroup : m_detGroups) { ISpectrum *spectrum = m_outputWS->getSpectrum(wsIndex); spectrum->setSpectrumNo( static_cast<specid_t>(wsIndex + 1)); // Ensure a contiguous mapping spectrum->clearDetectorIDs(); - spectrum->addDetectorIDs(iter->second); + spectrum->addDetectorIDs(m_detGroup.second); ++wsIndex; } } diff --git a/Framework/DataHandling/src/DetermineChunking.cpp b/Framework/DataHandling/src/DetermineChunking.cpp index 46e4144c0ea..ef3adea7e0a 100644 --- a/Framework/DataHandling/src/DetermineChunking.cpp +++ b/Framework/DataHandling/src/DetermineChunking.cpp @@ -148,8 +148,8 @@ void DetermineChunking::exec() { string dataDir; LoadPreNexus lp; lp.parseRuninfo(filename, dataDir, eventFilenames); - for (size_t i = 0; i < eventFilenames.size(); i++) { - BinaryFile<DasEvent> eventfile(dataDir + eventFilenames[i]); + for (auto &eventFilename : eventFilenames) { + BinaryFile<DasEvent> eventfile(dataDir + eventFilename); // Factor of 2 for compression filesize += static_cast<double>(eventfile.getNumElements()) * 48.0 / (1024.0 * 1024.0 * 1024.0); @@ -326,8 +326,8 @@ std::string DetermineChunking::setTopEntryName(std::string filename) { */ FileType DetermineChunking::getFileType(const string &filename) { // check for prenexus - for (int i = 0; i < NUM_EXT_PRENEXUS; ++i) { - if (filename.find(PRENEXUS_EXT[i]) != std::string::npos) { + for (const auto &i : PRENEXUS_EXT) { + if (filename.find(i) != std::string::npos) { g_log.information() << "Determined \'" << filename << "\' is a prenexus file\n"; return PRENEXUS_FILE; @@ -335,8 +335,8 @@ FileType DetermineChunking::getFileType(const string &filename) { } // check for histogram nexus - for (int i = 0; i < NUM_EXT_HISTO_NEXUS; ++i) { - if (filename.find(HISTO_NEXUS_EXT[i]) != std::string::npos) { + for (const auto &i : HISTO_NEXUS_EXT) { + if (filename.find(i) != std::string::npos) { g_log.information() << "Determined \'" << filename << "\' is a histogram nexus file\n"; return HISTO_NEXUS_FILE; @@ -344,8 +344,8 @@ FileType DetermineChunking::getFileType(const string &filename) { } // check for event nexus - must be last because a valid extension is ".nxs" - for (int i = 0; i < NUM_EXT_EVENT_NEXUS; ++i) { - if (filename.find(EVENT_NEXUS_EXT[i]) != std::string::npos) { + for (const auto &i : EVENT_NEXUS_EXT) { + if (filename.find(i) != std::string::npos) { g_log.information() << "Determined \'" << filename << "\' is an event nexus file\n"; return EVENT_NEXUS_FILE; @@ -353,8 +353,8 @@ FileType DetermineChunking::getFileType(const string &filename) { } // check for isis raw files - for (int i = 0; i < NUM_EXT_RAW; ++i) { - if (filename.find(RAW_EXT[i]) != std::string::npos) { + for (const auto &i : RAW_EXT) { + if (filename.find(i) != std::string::npos) { g_log.information() << "Determined \'" << filename << "\' is an ISIS raw file\n"; return RAW_FILE; diff --git a/Framework/DataHandling/src/DownloadInstrument.cpp b/Framework/DataHandling/src/DownloadInstrument.cpp index 2f4aeac3240..0e5a94c696d 100644 --- a/Framework/DataHandling/src/DownloadInstrument.cpp +++ b/Framework/DataHandling/src/DownloadInstrument.cpp @@ -107,9 +107,9 @@ void DownloadInstrument::exec() { << " from the instrument repository" << std::endl; } - for (auto itMap = fileMap.begin(); itMap != fileMap.end(); ++itMap) { + for (auto &itMap : fileMap) { // download a file - doDownloadFile(itMap->first, itMap->second); + doDownloadFile(itMap.first, itMap.second); } setProperty("FileDownloadCount", static_cast<int>(fileMap.size())); @@ -180,8 +180,7 @@ DownloadInstrument::StringToStringMap DownloadInstrument::processRepository() { std::set<std::string> repoFilenames; - for (Json::ArrayIndex i = 0; i < serverContents.size(); ++i) { - const auto &serverElement = serverContents[i]; + for (auto &serverElement : serverContents) { std::string name = serverElement.get("name", "").asString(); repoFilenames.insert(name); Poco::Path filePath(localPath, name); @@ -303,8 +302,8 @@ size_t DownloadInstrument::removeOrphanedFiles( // delete any identified files try { - for (auto it = filesToDelete.begin(); it != filesToDelete.end(); ++it) { - Poco::File file(*it); + for (const auto &it : filesToDelete) { + Poco::File file(it); file.remove(); } } catch (Poco::Exception &ex) { diff --git a/Framework/DataHandling/src/EventWorkspaceCollection.cpp b/Framework/DataHandling/src/EventWorkspaceCollection.cpp index 34e6e4ed150..9a3077f4c18 100644 --- a/Framework/DataHandling/src/EventWorkspaceCollection.cpp +++ b/Framework/DataHandling/src/EventWorkspaceCollection.cpp @@ -29,9 +29,9 @@ void copyLogs(const EventWorkspace_sptr &from, EventWorkspace_sptr &to) { // from the logs, get all the properties that don't overwrite any // prop. already set in the sink workspace (like 'filename'). auto props = from->mutableRun().getLogData(); - for (size_t j = 0; j < props.size(); j++) { - if (!to->mutableRun().hasProperty(props[j]->name())) { - to->mutableRun().addLogData(props[j]->clone()); + for (auto &prop : props) { + if (!to->mutableRun().hasProperty(prop->name())) { + to->mutableRun().addLogData(prop->clone()); } } } @@ -110,8 +110,8 @@ void EventWorkspaceCollection::setNPeriods( } void EventWorkspaceCollection::reserveEventListAt(size_t wi, size_t size) { - for (size_t i = 0; i < m_WsVec.size(); ++i) { - m_WsVec[i]->getEventList(wi).reserve(size); + for (auto &i : m_WsVec) { + i->getEventList(wi).reserve(size); } } @@ -128,8 +128,8 @@ API::Workspace_sptr EventWorkspaceCollection::combinedWorkspace() { final = getSingleHeldWorkspace(); } else { auto wsg = boost::make_shared<API::WorkspaceGroup>(); - for (size_t i = 0; i < m_WsVec.size(); ++i) { - wsg->addWorkspace(m_WsVec[i]); + for (auto &i : m_WsVec) { + wsg->addWorkspace(i); } final = wsg; } @@ -160,10 +160,10 @@ EventWorkspaceCollection::getSpectrum(const size_t index) const { void EventWorkspaceCollection::setSpectrumNumbersFromUniqueSpectra( const std::set<int> uniqueSpectra) { // For each workspace, update all the spectrum numbers - for (auto ws = m_WsVec.begin(); ws != m_WsVec.end(); ++ws) { + for (auto &ws : m_WsVec) { size_t counter = 0; - for (auto it = uniqueSpectra.begin(); it != uniqueSpectra.end(); ++it) { - (*ws)->getSpectrum(counter)->setSpectrumNo(*it); + for (value_type it : uniqueSpectra) { + ws->getSpectrum(counter)->setSpectrumNo(it); ++counter; } } @@ -171,16 +171,16 @@ void EventWorkspaceCollection::setSpectrumNumbersFromUniqueSpectra( void EventWorkspaceCollection::setSpectrumNumberForAllPeriods( const size_t spectrumNumber, const specid_t specid) { - for (auto ws = m_WsVec.begin(); ws != m_WsVec.end(); ++ws) { - auto spec = (*ws)->getSpectrum(spectrumNumber); + for (auto &ws : m_WsVec) { + auto spec = ws->getSpectrum(spectrumNumber); spec->setSpectrumNo(specid); } } void EventWorkspaceCollection::setDetectorIdsForAllPeriods( const size_t spectrumNumber, const detid_t id) { - for (auto ws = m_WsVec.begin(); ws != m_WsVec.end(); ++ws) { - auto spec = (*ws)->getSpectrum(spectrumNumber); + for (auto &ws : m_WsVec) { + auto spec = ws->getSpectrum(spectrumNumber); spec->setDetectorID(id); } } @@ -228,40 +228,40 @@ Kernel::DateAndTime EventWorkspaceCollection::getFirstPulseTime() const { return m_WsVec[0]->getFirstPulseTime(); } void EventWorkspaceCollection::setAllX(Kernel::cow_ptr<MantidVec> &x) { - for (size_t i = 0; i < m_WsVec.size(); ++i) { - m_WsVec[i]->setAllX(x); + for (auto &i : m_WsVec) { + i->setAllX(x); } } size_t EventWorkspaceCollection::getNumberEvents() const { return m_WsVec[0]->getNumberEvents(); // Should be the sum across all periods? } void EventWorkspaceCollection::resizeTo(const size_t size) { - for (size_t i = 0; i < m_WsVec.size(); ++i) { - m_WsVec[i]->resizeTo(size); // Creates the EventLists + for (auto &i : m_WsVec) { + i->resizeTo(size); // Creates the EventLists } } void EventWorkspaceCollection::padSpectra(const std::vector<int32_t> &padding) { - for (size_t i = 0; i < m_WsVec.size(); ++i) { - m_WsVec[i]->padSpectra(padding); // Set detector ids and spectrum numbers + for (auto &i : m_WsVec) { + i->padSpectra(padding); // Set detector ids and spectrum numbers } } void EventWorkspaceCollection::setInstrument( const Geometry::Instrument_const_sptr &inst) { - for (size_t i = 0; i < m_WsVec.size(); ++i) { - m_WsVec[i]->setInstrument(inst); + for (auto &i : m_WsVec) { + i->setInstrument(inst); } } void EventWorkspaceCollection::setMonitorWorkspace( const boost::shared_ptr<API::MatrixWorkspace> &monitorWS) { - for (size_t i = 0; i < m_WsVec.size(); ++i) { - m_WsVec[i]->setMonitorWorkspace( + for (auto &i : m_WsVec) { + i->setMonitorWorkspace( monitorWS); // TODO, do we really set the same monitor on all periods??? } } void EventWorkspaceCollection::updateSpectraUsing( const API::SpectrumDetectorMapping &map) { - for (size_t i = 0; i < m_WsVec.size(); ++i) { - m_WsVec[i]->updateSpectraUsing(map); + for (auto &i : m_WsVec) { + i->updateSpectraUsing(map); } } @@ -271,43 +271,43 @@ DataObjects::EventList *EventWorkspaceCollection::getEventListPtr(size_t i) { } void EventWorkspaceCollection::populateInstrumentParameters() { - for (size_t i = 0; i < m_WsVec.size(); ++i) { - m_WsVec[i]->populateInstrumentParameters(); + for (auto &i : m_WsVec) { + i->populateInstrumentParameters(); } } void EventWorkspaceCollection::setGeometryFlag(const int flag) { - for (size_t i = 0; i < m_WsVec.size(); ++i) { - m_WsVec[i]->mutableSample().setGeometryFlag(flag); + for (auto &i : m_WsVec) { + i->mutableSample().setGeometryFlag(flag); } } void EventWorkspaceCollection::setThickness(const float flag) { - for (size_t i = 0; i < m_WsVec.size(); ++i) { - m_WsVec[i]->mutableSample().setThickness(flag); + for (auto &i : m_WsVec) { + i->mutableSample().setThickness(flag); } } void EventWorkspaceCollection::setHeight(const float flag) { - for (size_t i = 0; i < m_WsVec.size(); ++i) { - m_WsVec[i]->mutableSample().setHeight(flag); + for (auto &i : m_WsVec) { + i->mutableSample().setHeight(flag); } } void EventWorkspaceCollection::setWidth(const float flag) { - for (size_t i = 0; i < m_WsVec.size(); ++i) { - m_WsVec[i]->mutableSample().setWidth(flag); + for (auto &i : m_WsVec) { + i->mutableSample().setWidth(flag); } } void EventWorkspaceCollection::setTitle(std::string title) { - for (size_t i = 0; i < m_WsVec.size(); ++i) { - m_WsVec[i]->setTitle(title); + for (auto &i : m_WsVec) { + i->setTitle(title); } } void EventWorkspaceCollection::applyFilter( boost::function<void(MatrixWorkspace_sptr)> func) { - for (size_t i = 0; i < m_WsVec.size(); ++i) { - func(m_WsVec[i]); + for (auto &i : m_WsVec) { + func(i); } } diff --git a/Framework/DataHandling/src/FilterEventsByLogValuePreNexus.cpp b/Framework/DataHandling/src/FilterEventsByLogValuePreNexus.cpp index b0842ee648f..9ec0ae393dc 100644 --- a/Framework/DataHandling/src/FilterEventsByLogValuePreNexus.cpp +++ b/Framework/DataHandling/src/FilterEventsByLogValuePreNexus.cpp @@ -173,14 +173,12 @@ static string generateMappingfileName(EventWorkspace_sptr &wksp) { const string CAL("_CAL"); const size_t CAL_LEN = CAL.length(); // cache to make life easier vector<string> files; - for (size_t i = 0; i < dirs.size(); ++i) { - if ((dirs[i].length() > CAL_LEN) && - (dirs[i].compare(dirs[i].length() - CAL.length(), CAL.length(), CAL) == - 0)) { - if (Poco::File(base.path() + "/" + dirs[i] + "/calibrations/" + mapping) + for (auto &dir : dirs) { + if ((dir.length() > CAL_LEN) && + (dir.compare(dir.length() - CAL.length(), CAL.length(), CAL) == 0)) { + if (Poco::File(base.path() + "/" + dir + "/calibrations/" + mapping) .exists()) - files.push_back(base.path() + "/" + dirs[i] + "/calibrations/" + - mapping); + files.push_back(base.path() + "/" + dir + "/calibrations/" + mapping); } } @@ -515,8 +513,8 @@ void FilterEventsByLogValuePreNexus::processProperties() { m_loadOnlySomeSpectra = (this->m_spectraList.size() > 0); // Turn the spectra list into a map, for speed of access - for (auto it = m_spectraList.begin(); it != m_spectraList.end(); it++) - spectraLoadMap[*it] = true; + for (long long &it : m_spectraList) + spectraLoadMap[it] = true; //--------------------------------------------------------------------------- // Other features @@ -783,8 +781,8 @@ void FilterEventsByLogValuePreNexus::runLoadInstrument( vector<string> eventExts(EVENT_EXTS, EVENT_EXTS + NUM_EXT); std::reverse(eventExts.begin(), eventExts.end()); - for (size_t i = 0; i < eventExts.size(); ++i) { - size_t pos = instrument.find(eventExts[i]); + for (auto &eventExt : eventExts) { + size_t pos = instrument.find(eventExt); if (pos != string::npos) { instrument = instrument.substr(0, pos); break; @@ -1428,13 +1426,13 @@ void FilterEventsByLogValuePreNexus::unmaskVetoEventIndexes() { size_t numerror = 0; PRAGMA_OMP(parallel for schedule(dynamic, 1) ) - for (int i = 0; i < static_cast<int>(m_vecEventIndex.size()); ++i) { + for (unsigned long long &i : m_vecEventIndex) { PARALLEL_START_INTERUPT_REGION - uint64_t eventindex = m_vecEventIndex[i]; + uint64_t eventindex = i; if (eventindex > static_cast<uint64_t>(m_numEvents)) { uint64_t realeventindex = eventindex & VETOFLAG; - m_vecEventIndex[i] = realeventindex; + i = realeventindex; } PARALLEL_END_INTERUPT_REGION } @@ -2250,13 +2248,13 @@ void FilterEventsByLogValuePreNexus::setupPixelSpectrumMap( eventws->getInstrument()->getDetectors(detector_map); // Set up - for (auto it = detector_map.begin(); it != detector_map.end(); it++) { - if (!it->second->isMonitor()) { + for (auto &it : detector_map) { + if (!it.second->isMonitor()) { // Add non-monitor detector ID - size_t workspaceIndex = m_pixelToWkspindex[it->first]; + size_t workspaceIndex = m_pixelToWkspindex[it.first]; // this->m_pixelToWkspindex[it->first] = workspaceIndex; EventList &spec = eventws->getOrAddEventList(workspaceIndex); - spec.addDetectorID(it->first); + spec.addDetectorID(it.first); // Start the spectrum number at 1 spec.setSpectrumNo(specid_t(workspaceIndex + 1)); } diff --git a/Framework/DataHandling/src/FindDetectorsPar.cpp b/Framework/DataHandling/src/FindDetectorsPar.cpp index 54a55db2173..27f9085d0f4 100644 --- a/Framework/DataHandling/src/FindDetectorsPar.cpp +++ b/Framework/DataHandling/src/FindDetectorsPar.cpp @@ -378,16 +378,16 @@ void FindDetectorsPar::extractAndLinearize( this->detID.resize(nDetectors); nDetectors = 0; - for (size_t i = 0; i < detPar.size(); i++) { - if (detPar[i].detID < 0) + for (const auto &i : detPar) { + if (i.detID < 0) continue; - azimuthal[nDetectors] = detPar[i].azimutAngle; - polar[nDetectors] = detPar[i].polarAngle; - azimuthalWidth[nDetectors] = detPar[i].azimWidth; - polarWidth[nDetectors] = detPar[i].polarWidth; - secondaryFlightpath[nDetectors] = detPar[i].secondaryFlightPath; - detID[nDetectors] = static_cast<size_t>(detPar[i].detID); + azimuthal[nDetectors] = i.azimutAngle; + polar[nDetectors] = i.polarAngle; + azimuthalWidth[nDetectors] = i.azimWidth; + polarWidth[nDetectors] = i.polarWidth; + secondaryFlightpath[nDetectors] = i.secondaryFlightPath; + detID[nDetectors] = static_cast<size_t>(i.detID); nDetectors++; } // store caluclated value diff --git a/Framework/DataHandling/src/GroupDetectors2.cpp b/Framework/DataHandling/src/GroupDetectors2.cpp index 5fb850d4c53..95f70e10310 100644 --- a/Framework/DataHandling/src/GroupDetectors2.cpp +++ b/Framework/DataHandling/src/GroupDetectors2.cpp @@ -531,8 +531,7 @@ void GroupDetectors2::processXMLFile(std::string fname, std::vector<size_t> &wsindexes = sit->second; - for (size_t i = 0; i < detids.size(); i++) { - detid_t detid = detids[i]; + for (int detid : detids) { auto ind = detIdToWiMap.find(detid); if (ind != detIdToWiMap.end()) { size_t wsid = ind->second; @@ -560,8 +559,7 @@ void GroupDetectors2::processXMLFile(std::string fname, std::vector<size_t> &wsindexes = sit->second; - for (size_t i = 0; i < spectra.size(); i++) { - int specid = spectra[i]; + for (int specid : spectra) { auto ind = specs2index.find(specid); if (ind != specs2index.end()) { size_t wsid = ind->second; @@ -621,9 +619,8 @@ void GroupDetectors2::processGroupingWorkspace( det_ids.push_back(det->getID()); } - for (auto dit = det_ids.begin(); dit != det_ids.end(); ++dit) { + for (int det_id : det_ids) { // translate detectors to target det ws indexes - detid_t det_id = *dit; size_t targetWSIndex = detIdToWiMap[det_id]; targetWSIndexSet.insert(targetWSIndex); // mark as used @@ -638,10 +635,9 @@ void GroupDetectors2::processGroupingWorkspace( } // Build m_GroupSpecInds (group -> list of ws indices) - for (auto dit = group2WSIndexSetmap.begin(); dit != group2WSIndexSetmap.end(); - ++dit) { - size_t groupid = dit->first; - std::set<size_t> &targetWSIndexSet = dit->second; + for (auto &dit : group2WSIndexSetmap) { + size_t groupid = dit.first; + std::set<size_t> &targetWSIndexSet = dit.second; std::vector<size_t> tempv; tempv.assign(targetWSIndexSet.begin(), targetWSIndexSet.end()); m_GroupSpecInds.insert( @@ -690,9 +686,8 @@ void GroupDetectors2::processMatrixWorkspace( if (detGroup) { det_ids = detGroup->getDetectorIDs(); - for (auto dit = det_ids.begin(); dit != det_ids.end(); ++dit) { + for (int det_id : det_ids) { // translate detectors to target det ws indexes - detid_t det_id = *dit; size_t targetWSIndex = detIdToWiMap[det_id]; targetWSIndexSet.insert(targetWSIndex); // mark as used @@ -707,10 +702,9 @@ void GroupDetectors2::processMatrixWorkspace( } // Build m_GroupSpecInds (group -> list of ws indices) - for (auto dit = group2WSIndexSetmap.begin(); dit != group2WSIndexSetmap.end(); - ++dit) { - size_t groupid = dit->first; - std::set<size_t> &targetWSIndexSet = dit->second; + for (auto &dit : group2WSIndexSetmap) { + size_t groupid = dit.first; + std::set<size_t> &targetWSIndexSet = dit.second; if (!targetWSIndexSet.empty()) { std::vector<size_t> tempv; tempv.assign(targetWSIndexSet.begin(), targetWSIndexSet.end()); @@ -856,11 +850,11 @@ void GroupDetectors2::readSpectraIndexes(std::string line, std::string seperator) { // remove comments and white space Poco::StringTokenizer dataComment(line, seperator, IGNORE_SPACES); - for (auto itr = dataComment.begin(); itr != dataComment.end(); ++itr) { + for (const auto &itr : dataComment) { std::vector<size_t> specNums; specNums.reserve(output.capacity()); - RangeHelper::getList(*itr, specNums); + RangeHelper::getList(itr, specNums); std::vector<size_t>::const_iterator specN = specNums.begin(); for (; specN != specNums.end(); ++specN) { @@ -963,10 +957,7 @@ size_t GroupDetectors2::formGroups(API::MatrixWorkspace_const_sptr inputWS, size_t nonMaskedSpectra(0); beh->dataX(outIndex)[0] = 0.0; beh->dataE(outIndex)[0] = 0.0; - for (auto wsIter = it->second.cbegin(); wsIter != it->second.cend(); - ++wsIter) { - const size_t originalWI = *wsIter; - + for (unsigned long originalWI : it->second) { // detectors to add to firstSpecNum const ISpectrum *fromSpectrum = inputWS->getSpectrum(originalWI); @@ -1071,10 +1062,7 @@ GroupDetectors2::formGroupsEvent(DataObjects::EventWorkspace_const_sptr inputWS, size_t nonMaskedSpectra(0); beh->dataX(outIndex)[0] = 0.0; beh->dataE(outIndex)[0] = 0.0; - for (auto wsIter = it->second.cbegin(); wsIter != it->second.cend(); - ++wsIter) { - const size_t originalWI = *wsIter; - + for (unsigned long originalWI : it->second) { const EventList &fromEL = inputWS->getEventList(originalWI); // Add the event lists with the operator outEL += fromEL; @@ -1141,11 +1129,10 @@ void GroupDetectors2::moveOthers(const std::set<int64_t> &unGroupedSet, static_cast<double>(unGroupedSet.size()); // go thorugh all the spectra in the input workspace - for (auto copyFrIt = unGroupedSet.cbegin(); copyFrIt != unGroupedSet.cend(); - ++copyFrIt) { - if (*copyFrIt == USED) + for (value_type copyFrIt : unGroupedSet) { + if (copyFrIt == USED) continue; // Marked as not to be used - size_t sourceIndex = static_cast<size_t>(*copyFrIt); + size_t sourceIndex = static_cast<size_t>(copyFrIt); // The input spectrum we'll copy const ISpectrum *inputSpec = inputWS->getSpectrum(sourceIndex); @@ -1199,11 +1186,10 @@ void GroupDetectors2::moveOthersEvent( static_cast<double>(unGroupedSet.size()); // go thorugh all the spectra in the input workspace - for (auto copyFrIt = unGroupedSet.cbegin(); copyFrIt != unGroupedSet.cend(); - ++copyFrIt) { - if (*copyFrIt == USED) + for (value_type copyFrIt : unGroupedSet) { + if (copyFrIt == USED) continue; // Marked as not to be used - size_t sourceIndex = static_cast<size_t>(*copyFrIt); + size_t sourceIndex = static_cast<size_t>(copyFrIt); // The input spectrum we'll copy const EventList &inputSpec = inputWS->getEventList(sourceIndex); @@ -1324,8 +1310,7 @@ void translateAdd(const std::string &instructions, boost::split(spectra, instructions, boost::is_any_of("+")); std::vector<int> outSpectra; - for (auto sIt = spectra.begin(); sIt != spectra.end(); ++sIt) { - std::string spectrum = *sIt; + for (auto spectrum : spectra) { // remove leading/trailing whitespace boost::trim(spectrum); // add this spectrum to the group we're about to add @@ -1419,8 +1404,7 @@ void GroupDetectors2::translateInstructions(const std::string &instructions, std::vector<std::string> groups; boost::split(groups, instructions, boost::is_any_of(",")); - for (auto gIt = groups.begin(); gIt != groups.end(); ++gIt) { - std::string groupStr = *gIt; + for (auto groupStr : groups) { // remove leading/trailing whitespace boost::trim(groupStr); @@ -1445,9 +1429,9 @@ void GroupDetectors2::translateInstructions(const std::string &instructions, // We now have the groups as a vector of a vector of ints. Turn this into a // string, just like the contents of a map file. commands << outGroups.size() << "\n"; - for (size_t i = 0; i < outGroups.size(); ++i) { - const int groupId = outGroups[i][0] + 1; - const int groupSize = static_cast<int>(outGroups[i].size()); + for (auto &outGroup : outGroups) { + const int groupId = outGroup[0] + 1; + const int groupSize = static_cast<int>(outGroup.size()); // Comment the output for readability commands << "# Group " << groupId; @@ -1459,8 +1443,8 @@ void GroupDetectors2::translateInstructions(const std::string &instructions, // Group members // So far we've been using 0-indexed ids, but the mapfile syntax expects // 1-indexed ids, so we add 1 to the spectra ids here. - for (size_t j = 0; j < outGroups[i].size(); ++j) - commands << (j > 0 ? " " : "") << outGroups[i][j] + 1; + for (size_t j = 0; j < outGroup.size(); ++j) + commands << (j > 0 ? " " : "") << outGroup[j] + 1; commands << "\n"; } } diff --git a/Framework/DataHandling/src/ISISDataArchive.cpp b/Framework/DataHandling/src/ISISDataArchive.cpp index 7bea0f139c1..480ac90a3d9 100644 --- a/Framework/DataHandling/src/ISISDataArchive.cpp +++ b/Framework/DataHandling/src/ISISDataArchive.cpp @@ -42,16 +42,16 @@ const char *URL_PREFIX = "http://data.isis.rl.ac.uk/where.py/unixdir?name="; std::string ISISDataArchive::getArchivePath(const std::set<std::string> &filenames, const std::vector<std::string> &exts) const { - for (auto iter = filenames.cbegin(); iter != filenames.cend(); ++iter) { - g_log.debug() << *iter << ")\n"; + for (const auto &filename : filenames) { + g_log.debug() << filename << ")\n"; } - for (auto iter = exts.cbegin(); iter != exts.cend(); ++iter) { - g_log.debug() << *iter << ")\n"; + for (const auto &ext : exts) { + g_log.debug() << ext << ")\n"; } - for (auto ext = exts.cbegin(); ext != exts.cend(); ++ext) { - for (auto it = filenames.cbegin(); it != filenames.cend(); ++it) { - const std::string fullPath = getPath(*it + *ext); + for (const auto &ext : exts) { + for (const auto &filename : filenames) { + const std::string fullPath = getPath(filename + ext); if (!fullPath.empty()) return fullPath; } // it diff --git a/Framework/DataHandling/src/ISISRunLogs.cpp b/Framework/DataHandling/src/ISISRunLogs.cpp index 5502c31b438..5978bba9167 100644 --- a/Framework/DataHandling/src/ISISRunLogs.cpp +++ b/Framework/DataHandling/src/ISISRunLogs.cpp @@ -25,9 +25,9 @@ ISISRunLogs::ISISRunLogs(const API::Run &icpRun, const int totalNumPeriods) : m_logParser(), m_numOfPeriods(totalNumPeriods) { // ICP event either in form icp_event or icpevent static const char *icpLogNames[2] = {"icp_event", "icpevent"}; - for (int i = 0; i < 2; ++i) { + for (auto &icpLogName : icpLogNames) { try { - Kernel::Property *icpLog = icpRun.getLogData(icpLogNames[i]); + Kernel::Property *icpLog = icpRun.getLogData(icpLogName); m_logParser.reset(new LogParser(icpLog)); return; } catch (std::runtime_error &) { diff --git a/Framework/DataHandling/src/Load.cpp b/Framework/DataHandling/src/Load.cpp index dfac2364090..ba13d972f0e 100644 --- a/Framework/DataHandling/src/Load.cpp +++ b/Framework/DataHandling/src/Load.cpp @@ -53,11 +53,11 @@ bool isSingleFile(const std::vector<std::vector<std::string>> &fileNames) { std::string generateWsNameFromFileNames(std::vector<std::string> filenames) { std::string wsName(""); - for (size_t i = 0; i < filenames.size(); ++i) { + for (auto &filename : filenames) { if (!wsName.empty()) wsName += "_"; - Poco::Path path(filenames[i]); + Poco::Path path(filename); wsName += path.getBaseName(); } @@ -214,9 +214,9 @@ API::IAlgorithm_sptr Load::getFileLoader(const std::string &filePath) { void Load::findFilenameProperty(const API::IAlgorithm_sptr &loader) { // Use the first file property as the main Filename const auto &props = loader->getProperties(); - for (auto it = props.begin(); it != props.end(); ++it) { - auto *fp = dynamic_cast<API::MultipleFileProperty *>(*it); - auto *fp2 = dynamic_cast<API::FileProperty *>(*it); + for (auto prop : props) { + auto *fp = dynamic_cast<API::MultipleFileProperty *>(prop); + auto *fp2 = dynamic_cast<API::FileProperty *>(prop); if (fp) { m_filenamePropName = fp->name(); break; @@ -244,8 +244,8 @@ void Load::declareLoaderProperties(const API::IAlgorithm_sptr &loader) { // so take care of ensuring Load has the correct ones // THIS IS A COPY as the properties are mutated as we move through them const std::vector<Property *> existingProps = this->getProperties(); - for (size_t i = 0; i < existingProps.size(); ++i) { - const std::string name = existingProps[i]->name(); + for (auto existingProp : existingProps) { + const std::string name = existingProp->name(); // Wipe all properties except the Load native ones if (m_baseProps.find(name) == m_baseProps.end()) { this->removeProperty(name); @@ -438,10 +438,9 @@ void Load::loadMultipleFiles() { std::vector<std::string> childWsNames = group->getNames(); size_t count = 1; - for (auto childWsName = childWsNames.begin(); - childWsName != childWsNames.end(); ++childWsName) { - if (*childWsName == outputWsName) { - Mantid::API::Workspace_sptr child = group->getItem(*childWsName); + for (auto &childWsName : childWsNames) { + if (childWsName == outputWsName) { + Mantid::API::Workspace_sptr child = group->getItem(childWsName); // child->setName(child->getName() + "_" + // boost::lexical_cast<std::string>(count)); const std::string childName = @@ -453,14 +452,13 @@ void Load::loadMultipleFiles() { childWsNames = group->getNames(); count = 1; - for (auto childWsName = childWsNames.begin(); - childWsName != childWsNames.end(); ++childWsName) { - Workspace_sptr childWs = group->getItem(*childWsName); + for (auto &childWsName : childWsNames) { + Workspace_sptr childWs = group->getItem(childWsName); std::string outWsPropName = "OutputWorkspace_" + boost::lexical_cast<std::string>(count); ++count; declareProperty(new WorkspaceProperty<Workspace>( - outWsPropName, *childWsName, Direction::Output)); + outWsPropName, childWsName, Direction::Output)); setProperty(outWsPropName, childWs); } } @@ -515,13 +513,13 @@ void Load::setUpLoader(API::IAlgorithm_sptr &loader, const double startProgress, // If output workspaces are nameless, give them a temporary name to satisfy // validator const std::vector<Property *> &props = loader->getProperties(); - for (unsigned int i = 0; i < props.size(); ++i) { - auto wsProp = dynamic_cast<IWorkspaceProperty *>(props[i]); + for (auto prop : props) { + auto wsProp = dynamic_cast<IWorkspaceProperty *>(prop); if (wsProp && !wsProp->isOptional() && - props[i]->direction() == Direction::Output) { - if (props[i]->value().empty()) - props[i]->setValue("LoadChildWorkspace"); + prop->direction() == Direction::Output) { + if (prop->value().empty()) + prop->setValue("LoadChildWorkspace"); } } if (startProgress >= 0. && endProgress > startProgress && endProgress <= 1.) { @@ -646,8 +644,8 @@ API::Workspace_sptr Load::loadFileToWs(const std::string &fileName, const std::vector<Kernel::Property *> &props = getProperties(); // Loop through and set the properties on the Child Algorithm - for (auto prop = props.cbegin(); prop != props.cend(); ++prop) { - const std::string &propName = (*prop)->name(); + for (auto prop : props) { + const std::string &propName = prop->name(); if (this->existsProperty(propName)) { if (propName == "Filename") { @@ -730,9 +728,9 @@ API::WorkspaceGroup_sptr Load::groupWsList(const std::vector<API::Workspace_sptr> &wsList) { WorkspaceGroup_sptr group = WorkspaceGroup_sptr(new WorkspaceGroup); - for (auto ws = wsList.begin(); ws != wsList.end(); ++ws) { + for (const auto &ws : wsList) { WorkspaceGroup_sptr isGroup = - boost::dynamic_pointer_cast<WorkspaceGroup>(*ws); + boost::dynamic_pointer_cast<WorkspaceGroup>(ws); // If the ws to add is already a group, then add its children individually. if (isGroup) { std::vector<std::string> childrenNames = isGroup->getNames(); @@ -749,7 +747,7 @@ Load::groupWsList(const std::vector<API::Workspace_sptr> &wsList) { // Remove the old group from the ADS AnalysisDataService::Instance().remove(isGroup->getName()); } else { - group->addWorkspace(*ws); + group->addWorkspace(ws); } } diff --git a/Framework/DataHandling/src/LoadAscii.cpp b/Framework/DataHandling/src/LoadAscii.cpp index ee39464e0c9..8f3de67bd41 100644 --- a/Framework/DataHandling/src/LoadAscii.cpp +++ b/Framework/DataHandling/src/LoadAscii.cpp @@ -279,8 +279,7 @@ void LoadAscii::fillInputValues(std::vector<double> &values, const std::list<std::string> &columns) const { values.resize(columns.size()); int i = 0; - for (auto itr = columns.cbegin(); itr != columns.cend(); ++itr) { - std::string value = *itr; + for (auto value : columns) { boost::trim(value); boost::to_lower(value); if (value == "nan" || value == "1.#qnan") // ignores nans (not a number) and diff --git a/Framework/DataHandling/src/LoadAscii2.cpp b/Framework/DataHandling/src/LoadAscii2.cpp index 284ed879bc6..cf50263d52a 100644 --- a/Framework/DataHandling/src/LoadAscii2.cpp +++ b/Framework/DataHandling/src/LoadAscii2.cpp @@ -556,8 +556,7 @@ void LoadAscii2::fillInputValues(std::vector<double> &values, const std::list<std::string> &columns) const { values.resize(columns.size()); int i = 0; - for (auto itr = columns.cbegin(); itr != columns.cend(); ++itr) { - std::string value = *itr; + for (auto value : columns) { boost::trim(value); boost::to_lower(value); if (value == "nan" || value == "1.#qnan") // ignores nans (not a number) and @@ -597,10 +596,10 @@ void LoadAscii2::init() { {"UserDefined", "UserDefined"}}; // For the ListValidator std::vector<std::string> sepOptions; - for (size_t i = 0; i < 7; ++i) { - std::string option = spacers[i][0]; + for (auto &spacer : spacers) { + std::string option = spacer[0]; m_separatorIndex.insert( - std::pair<std::string, std::string>(option, spacers[i][1])); + std::pair<std::string, std::string>(option, spacer[1])); sepOptions.push_back(option); } declareProperty("Separator", "Automatic", diff --git a/Framework/DataHandling/src/LoadBBY.cpp b/Framework/DataHandling/src/LoadBBY.cpp index fb62c22096f..b8b01983884 100644 --- a/Framework/DataHandling/src/LoadBBY.cpp +++ b/Framework/DataHandling/src/LoadBBY.cpp @@ -93,12 +93,14 @@ int LoadBBY::confidence(Kernel::FileDescriptor &descriptor) const { size_t hdfFiles = 0; size_t binFiles = 0; const std::vector<std::string> &subFiles = file.files(); - for (auto itr = subFiles.begin(); itr != subFiles.end(); ++itr) { - auto len = itr->length(); - if ((len > 4) && (itr->find_first_of("\\/", 0, 2) == std::string::npos)) { - if ((itr->rfind(".hdf") == len - 4) && (itr->compare(0, 3, "BBY") == 0)) + for (const auto &subFile : subFiles) { + auto len = subFile.length(); + if ((len > 4) && + (subFile.find_first_of("\\/", 0, 2) == std::string::npos)) { + if ((subFile.rfind(".hdf") == len - 4) && + (subFile.compare(0, 3, "BBY") == 0)) hdfFiles++; - else if (itr->rfind(".bin") == len - 4) + else if (subFile.rfind(".bin") == len - 4) binFiles++; } } @@ -223,9 +225,9 @@ void LoadBBY::exec() { // set title const std::vector<std::string> &subFiles = tarFile.files(); - for (auto itr = subFiles.begin(); itr != subFiles.end(); ++itr) - if (itr->compare(0, 3, "BBY") == 0) { - std::string title = *itr; + for (const auto &subFile : subFiles) + if (subFile.compare(0, 3, "BBY") == 0) { + std::string title = subFile; if (title.rfind(".hdf") == title.length() - 4) title.resize(title.length() - 4); @@ -490,9 +492,9 @@ LoadBBY::createInstrument(ANSTO::Tar::File &tarFile, // extract hdf file int64_t fileSize = 0; const std::vector<std::string> &files = tarFile.files(); - for (auto itr = files.begin(); itr != files.end(); ++itr) - if (itr->rfind(".hdf") == itr->length() - 4) { - tarFile.select(itr->c_str()); + for (const auto &file : files) + if (file.rfind(".hdf") == file.length() - 4) { + tarFile.select(file.c_str()); fileSize = tarFile.selected_size(); break; } @@ -700,9 +702,9 @@ void LoadBBY::loadEvents(API::Progress &prog, const char *progMsg, // select bin file int64_t fileSize = 0; const std::vector<std::string> &files = tarFile.files(); - for (auto itr = files.begin(); itr != files.end(); ++itr) - if (itr->rfind(".bin") == itr->length() - 4) { - tarFile.select(itr->c_str()); + for (const auto &file : files) + if (file.rfind(".bin") == file.length() - 4) { + tarFile.select(file.c_str()); fileSize = tarFile.selected_size(); break; } diff --git a/Framework/DataHandling/src/LoadDetectorsGroupingFile.cpp b/Framework/DataHandling/src/LoadDetectorsGroupingFile.cpp index 083ce280b05..0fa97001061 100644 --- a/Framework/DataHandling/src/LoadDetectorsGroupingFile.cpp +++ b/Framework/DataHandling/src/LoadDetectorsGroupingFile.cpp @@ -144,10 +144,9 @@ void LoadDetectorsGroupingFile::exec() { // 6. Add group names, if user has specified any std::map<int, std::string> groupNamesMap = loader.getGroupNamesMap(); - for (auto it = groupNamesMap.begin(); it != groupNamesMap.end(); it++) { - std::string groupIdStr = boost::lexical_cast<std::string>(it->first); - m_groupWS->mutableRun().addProperty("GroupName_" + groupIdStr, - it->second); + for (auto &it : groupNamesMap) { + std::string groupIdStr = boost::lexical_cast<std::string>(it.first); + m_groupWS->mutableRun().addProperty("GroupName_" + groupIdStr, it.second); } } else if (ext == "map") { // Deal with file as map @@ -208,16 +207,15 @@ void LoadDetectorsGroupingFile::setByComponents() { m_groupWS->getDetectorIDToWorkspaceIndexMap(true); // 2. Set - for (auto it = m_groupComponentsMap.begin(); it != m_groupComponentsMap.end(); - ++it) { - g_log.debug() << "Group ID = " << it->first << " With " << it->second.size() + for (auto &it : m_groupComponentsMap) { + g_log.debug() << "Group ID = " << it.first << " With " << it.second.size() << " Components" << std::endl; - for (size_t i = 0; i < it->second.size(); i++) { + for (size_t i = 0; i < it.second.size(); i++) { // a) get component Geometry::IComponent_const_sptr component = - m_instrument->getComponentByName(it->second[i]); + m_instrument->getComponentByName(it.second[i]); // b) component -> component assembly --> children (more than detectors) boost::shared_ptr<const Geometry::ICompAssembly> asmb = @@ -225,13 +223,12 @@ void LoadDetectorsGroupingFile::setByComponents() { std::vector<Geometry::IComponent_const_sptr> children; asmb->getChildren(children, true); - g_log.debug() << "Component Name = " << it->second[i] + g_log.debug() << "Component Name = " << it.second[i] << " Component ID = " << component->getComponentID() << "Number of Children = " << children.size() << std::endl; - for (size_t ic = 0; ic < children.size(); ic++) { + for (auto child : children) { // c) convert component to detector - Geometry::IComponent_const_sptr child = children[ic]; Geometry::IDetector_const_sptr det = boost::dynamic_pointer_cast<const Geometry::IDetector>(child); @@ -241,7 +238,7 @@ void LoadDetectorsGroupingFile::setByComponents() { auto itx = indexmap.find(detid); if (itx != indexmap.end()) { size_t wsindex = itx->second; - m_groupWS->dataY(wsindex)[0] = it->first; + m_groupWS->dataY(wsindex)[0] = it.first; } else { g_log.error() << "Pixel w/ ID = " << detid << " Cannot Be Located" << std::endl; @@ -285,17 +282,16 @@ void LoadDetectorsGroupingFile::setByDetectors() { m_groupWS->getDetectorIDToWorkspaceIndexMap(true); // 2. Set GroupingWorkspace - for (auto it = m_groupDetectorsMap.begin(); it != m_groupDetectorsMap.end(); - ++it) { - g_log.debug() << "Group ID = " << it->first << std::endl; + for (auto &it : m_groupDetectorsMap) { + g_log.debug() << "Group ID = " << it.first << std::endl; - for (size_t i = 0; i < it->second.size(); i++) { - detid_t detid = it->second[i]; + for (size_t i = 0; i < it.second.size(); i++) { + detid_t detid = it.second[i]; auto itx = indexmap.find(detid); if (itx != indexmap.end()) { size_t wsindex = itx->second; - m_groupWS->dataY(wsindex)[0] = it->first; + m_groupWS->dataY(wsindex)[0] = it.first; } else { g_log.error() << "Pixel w/ ID = " << detid << " Cannot Be Located" << std::endl; @@ -320,8 +316,7 @@ void LoadDetectorsGroupingFile::setBySpectrumIDs() { for (gsiter = m_groupSpectraMap.begin(); gsiter != m_groupSpectraMap.end(); ++gsiter) { int groupid = gsiter->first; - for (size_t isp = 0; isp < gsiter->second.size(); isp++) { - int specid = gsiter->second[isp]; + for (int specid : gsiter->second) { s2iter = s2imap.find(specid); if (s2iter == s2imap.end()) { g_log.error() @@ -376,10 +371,9 @@ void LoadDetectorsGroupingFile::generateNoInstrumentGroupWorkspace() { for (groupspeciter = m_groupSpectraMap.begin(); groupspeciter != m_groupSpectraMap.end(); ++groupspeciter) { int groupid = groupspeciter->first; - for (size_t i = 0; i < groupspeciter->second.size(); i++) { - spectrumidgroupmap.insert( - std::pair<int, int>(groupspeciter->second[i], groupid)); - specids.push_back(groupspeciter->second[i]); + for (int &i : groupspeciter->second) { + spectrumidgroupmap.insert(std::pair<int, int>(i, groupid)); + specids.push_back(i); } } diff --git a/Framework/DataHandling/src/LoadDiffCal.cpp b/Framework/DataHandling/src/LoadDiffCal.cpp index e3c143ab8f6..81e21b82a1f 100644 --- a/Framework/DataHandling/src/LoadDiffCal.cpp +++ b/Framework/DataHandling/src/LoadDiffCal.cpp @@ -134,8 +134,8 @@ std::vector<NumT> readArrayCoerce(DataSet &dataset, } else if (PredType::NATIVE_FLOAT == dataType) { std::vector<float> temp(dataSpace.getSelectNpoints()); dataset.read(&temp[0], dataType, dataSpace); - for (auto it = temp.begin(); it != temp.end(); ++it) - result.push_back(static_cast<NumT>(*it)); + for (float &it : temp) + result.push_back(static_cast<NumT>(it)); } else { throw DataTypeIException(); } @@ -197,11 +197,11 @@ std::vector<double> LoadDiffCal::readDoubleArray(Group &group, << "\n"; } - for (size_t i = 0; i < result.size(); ++i) { - if (std::abs(result[i]) < 1.e-10) { - result[i] = 0.; - } else if (result[i] != result[i]) { // check for NaN - result[i] = 0.; + for (double &i : result) { + if (std::abs(i) < 1.e-10) { + i = 0.; + } else if (i != i) { // check for NaN + i = 0.; } } diff --git a/Framework/DataHandling/src/LoadDspacemap.cpp b/Framework/DataHandling/src/LoadDspacemap.cpp index 4aaf2df7c86..a3809d69baf 100644 --- a/Framework/DataHandling/src/LoadDspacemap.cpp +++ b/Framework/DataHandling/src/LoadDspacemap.cpp @@ -375,9 +375,9 @@ void LoadDspacemap::readVulcanBinaryFile(const std::string &fileName, BinaryFile<VulcanCorrectionFactor> file(fileName); std::vector<VulcanCorrectionFactor> *results = file.loadAll(); if (results) { - for (auto it = results->begin(); it != results->end(); ++it) { + for (auto &result : *results) { // std::cout << it->pixelID << " :! " << it->factor << std::endl; - vulcan[static_cast<detid_t>(it->pixelID)] = it->factor; + vulcan[static_cast<detid_t>(result.pixelID)] = result.factor; } } diff --git a/Framework/DataHandling/src/LoadEventNexus.cpp b/Framework/DataHandling/src/LoadEventNexus.cpp index f20accc92a9..7effaaea44d 100644 --- a/Framework/DataHandling/src/LoadEventNexus.cpp +++ b/Framework/DataHandling/src/LoadEventNexus.cpp @@ -57,9 +57,9 @@ void copyLogs(const Mantid::DataHandling::EventWorkspaceCollection_sptr &from, // from the logs, get all the properties that don't overwrite any // prop. already set in the sink workspace (like 'filename'). auto props = from->mutableRun().getLogData(); - for (size_t j = 0; j < props.size(); j++) { - if (!to->mutableRun().hasProperty(props[j]->name())) { - to->mutableRun().addLogData(props[j]->clone()); + for (auto &prop : props) { + if (!to->mutableRun().hasProperty(prop->name())) { + to->mutableRun().addLogData(prop->clone()); } } } @@ -516,9 +516,9 @@ public: // Now, we look through existing ones to see if it is already loaded // thisBankPulseTimes = NULL; - for (size_t i = 0; i < alg->m_bankPulseTimes.size(); i++) { - if (alg->m_bankPulseTimes[i]->equals(thisNumPulses, thisStartTime)) { - thisBankPulseTimes = alg->m_bankPulseTimes[i]; + for (auto &m_bankPulseTime : alg->m_bankPulseTimes) { + if (m_bankPulseTime->equals(thisNumPulses, thisStartTime)) { + thisBankPulseTimes = m_bankPulseTime; return; } } @@ -1802,27 +1802,24 @@ void LoadEventNexus::loadEvents(API::Progress *const prog, bool SingleBankPixelsOnly = getProperty("SingleBankPixelsOnly"); if ((!someBanks.empty()) && (!monitors)) { // check that all of the requested banks are in the file - for (auto someBank = someBanks.begin(); someBank != someBanks.end(); - ++someBank) { + for (auto &someBank : someBanks) { bool foundIt = false; - for (auto bankName = bankNames.begin(); bankName != bankNames.end(); - ++bankName) { - if ((*bankName) == (*someBank) + "_events") { + for (auto &bankName : bankNames) { + if (bankName == someBank + "_events") { foundIt = true; break; } } if (!foundIt) { - throw std::invalid_argument("No entry named '" + (*someBank) + + throw std::invalid_argument("No entry named '" + someBank + "' was found in the .NXS file.\n"); } } // change the number of banks to load bankNames.clear(); - for (auto someBank = someBanks.begin(); someBank != someBanks.end(); - ++someBank) - bankNames.push_back((*someBank) + "_events"); + for (auto &someBank : someBanks) + bankNames.push_back(someBank + "_events"); // how many events are in a bank bankNumEvents.clear(); @@ -2142,13 +2139,13 @@ void LoadEventNexus::deleteBanks(EventWorkspaceCollection_sptr workspace, } if (detList.size() == 0) return; - for (int i = 0; i < static_cast<int>(detList.size()); i++) { + for (auto &i : detList) { bool keep = false; - boost::shared_ptr<RectangularDetector> det = detList[i]; + boost::shared_ptr<RectangularDetector> det = i; std::string det_name = det->getName(); - for (int j = 0; j < static_cast<int>(bankNames.size()); j++) { - size_t pos = bankNames[j].find("_events"); - if (det_name.compare(bankNames[j].substr(0, pos)) == 0) + for (auto &bankName : bankNames) { + size_t pos = bankName.find("_events"); + if (det_name.compare(bankName.substr(0, pos)) == 0) keep = true; if (keep) break; @@ -2160,21 +2157,20 @@ void LoadEventNexus::deleteBanks(EventWorkspaceCollection_sptr workspace, boost::shared_ptr<const Geometry::ICompAssembly> asmb = boost::dynamic_pointer_cast<const Geometry::ICompAssembly>(parent); asmb->getChildren(children, false); - for (int col = 0; col < static_cast<int>(children.size()); col++) { + for (auto &col : children) { boost::shared_ptr<const Geometry::ICompAssembly> asmb2 = - boost::dynamic_pointer_cast<const Geometry::ICompAssembly>( - children[col]); + boost::dynamic_pointer_cast<const Geometry::ICompAssembly>(col); std::vector<Geometry::IComponent_const_sptr> grandchildren; asmb2->getChildren(grandchildren, false); - for (int row = 0; row < static_cast<int>(grandchildren.size()); row++) { - Detector *d = dynamic_cast<Detector *>( - const_cast<IComponent *>(grandchildren[row].get())); + for (auto &row : grandchildren) { + Detector *d = + dynamic_cast<Detector *>(const_cast<IComponent *>(row.get())); if (d) inst->removeDetector(d); } } - IComponent *comp = dynamic_cast<IComponent *>(detList[i].get()); + IComponent *comp = dynamic_cast<IComponent *>(i.get()); inst->remove(comp); } } @@ -2203,12 +2199,12 @@ void LoadEventNexus::createSpectraMapping( if (!monitorsOnly && !bankNames.empty()) { std::vector<IDetector_const_sptr> allDets; - for (auto name = bankNames.begin(); name != bankNames.end(); ++name) { + for (const auto &bankName : bankNames) { // Only build the map for the single bank std::vector<IDetector_const_sptr> dets; - m_ws->getInstrument()->getDetectorsInBank(dets, (*name)); + m_ws->getInstrument()->getDetectorsInBank(dets, bankName); if (dets.empty()) - throw std::runtime_error("Could not find the bank named '" + (*name) + + throw std::runtime_error("Could not find the bank named '" + bankName + "' as a component assembly in the instrument " "tree; or it did not contain any detectors." " Try unchecking SingleBankPixelsOnly."); @@ -2506,11 +2502,11 @@ bool LoadEventNexus::loadSpectraMapping(const std::string &filename, if (!m_specList.empty()) { int i = 0; std::vector<int32_t> spec_temp, udet_temp; - for (auto it = spec.begin(); it != spec.end(); it++) { - if (find(m_specList.begin(), m_specList.end(), *it) != + for (int &it : spec) { + if (find(m_specList.begin(), m_specList.end(), it) != m_specList.end()) // spec element *it is not in spec_list { - spec_temp.push_back(*it); + spec_temp.push_back(it); udet_temp.push_back(udet.at(i)); } i++; @@ -2741,9 +2737,8 @@ void LoadEventNexus::loadTimeOfFlightData(::NeXus::File &file, // spread the events uniformly inside the bin boost::uniform_real<> distribution(left, right); std::vector<double> random_numbers(m); - for (auto it = random_numbers.begin(); it != random_numbers.end(); - ++it) { - *it = distribution(rand_gen); + for (double &random_number : random_numbers) { + random_number = distribution(rand_gen); } std::sort(random_numbers.begin(), random_numbers.end()); auto it = random_numbers.begin(); diff --git a/Framework/DataHandling/src/LoadEventPreNexus.cpp b/Framework/DataHandling/src/LoadEventPreNexus.cpp index 7b70a3a3ab6..4dfe9010c46 100644 --- a/Framework/DataHandling/src/LoadEventPreNexus.cpp +++ b/Framework/DataHandling/src/LoadEventPreNexus.cpp @@ -237,14 +237,12 @@ static string generateMappingfileName(EventWorkspace_sptr &wksp) { // const string CAL("_CAL"); const size_t CAL_LEN = CAL.length(); // cache to make life easier vector<string> files; - for (size_t i = 0; i < dirs.size(); ++i) { - if ((dirs[i].length() > CAL_LEN) && - (dirs[i].compare(dirs[i].length() - CAL.length(), CAL.length(), CAL) == - 0)) { - if (Poco::File(base.path() + "/" + dirs[i] + "/calibrations/" + mapping) + for (auto &dir : dirs) { + if ((dir.length() > CAL_LEN) && + (dir.compare(dir.length() - CAL.length(), CAL.length(), CAL) == 0)) { + if (Poco::File(base.path() + "/" + dir + "/calibrations/" + mapping) .exists()) - files.push_back(base.path() + "/" + dirs[i] + "/calibrations/" + - mapping); + files.push_back(base.path() + "/" + dir + "/calibrations/" + mapping); } } @@ -479,8 +477,8 @@ void LoadEventPreNexus::procEvents( loadOnlySomeSpectra = (this->spectra_list.size() > 0); // Turn the spectra list into a map, for speed of access - for (auto it = spectra_list.begin(); it != spectra_list.end(); it++) - spectraLoadMap[*it] = true; + for (long long &it : spectra_list) + spectraLoadMap[it] = true; CPUTimer tim; diff --git a/Framework/DataHandling/src/LoadEventPreNexus2.cpp b/Framework/DataHandling/src/LoadEventPreNexus2.cpp index af47f471d31..7649ea8d856 100644 --- a/Framework/DataHandling/src/LoadEventPreNexus2.cpp +++ b/Framework/DataHandling/src/LoadEventPreNexus2.cpp @@ -170,14 +170,12 @@ static string generateMappingfileName(EventWorkspace_sptr &wksp) { const string CAL("_CAL"); const size_t CAL_LEN = CAL.length(); // cache to make life easier vector<string> files; - for (size_t i = 0; i < dirs.size(); ++i) { - if ((dirs[i].length() > CAL_LEN) && - (dirs[i].compare(dirs[i].length() - CAL.length(), CAL.length(), CAL) == - 0)) { - if (Poco::File(base.path() + "/" + dirs[i] + "/calibrations/" + mapping) + for (auto &dir : dirs) { + if ((dir.length() > CAL_LEN) && + (dir.compare(dir.length() - CAL.length(), CAL.length(), CAL) == 0)) { + if (Poco::File(base.path() + "/" + dir + "/calibrations/" + mapping) .exists()) - files.push_back(base.path() + "/" + dirs[i] + "/calibrations/" + - mapping); + files.push_back(base.path() + "/" + dir + "/calibrations/" + mapping); } } @@ -612,8 +610,8 @@ void LoadEventPreNexus2::runLoadInstrument( vector<string> eventExts(EVENT_EXTS, EVENT_EXTS + NUM_EXT); std::reverse(eventExts.begin(), eventExts.end()); - for (size_t i = 0; i < eventExts.size(); ++i) { - size_t pos = instrument.find(eventExts[i]); + for (auto &eventExt : eventExts) { + size_t pos = instrument.find(eventExt); if (pos != string::npos) { instrument = instrument.substr(0, pos); break; @@ -729,8 +727,8 @@ void LoadEventPreNexus2::procEvents( loadOnlySomeSpectra = (this->spectra_list.size() > 0); // Turn the spectra list into a map, for speed of access - for (auto it = spectra_list.begin(); it != spectra_list.end(); it++) - spectraLoadMap[*it] = true; + for (long long &it : spectra_list) + spectraLoadMap[it] = true; CPUTimer tim; diff --git a/Framework/DataHandling/src/LoadFITS.cpp b/Framework/DataHandling/src/LoadFITS.cpp index efed4c30a3f..2798dfba70f 100644 --- a/Framework/DataHandling/src/LoadFITS.cpp +++ b/Framework/DataHandling/src/LoadFITS.cpp @@ -754,11 +754,10 @@ void LoadFITS::addAxesInfoAndLogs(Workspace2D_sptr ws, bool loadAsRectImg, ws->setYUnitLabel("brightness"); // Add all header info to log. - for (auto it = fileInfo.headerKeys.begin(); it != fileInfo.headerKeys.end(); - ++it) { - ws->mutableRun().removeLogData(it->first, true); + for (const auto &headerKey : fileInfo.headerKeys) { + ws->mutableRun().removeLogData(headerKey.first, true); ws->mutableRun().addLogData( - new PropertyWithValue<std::string>(it->first, it->second)); + new PropertyWithValue<std::string>(headerKey.first, headerKey.second)); } // Add rotational data to log. Clear first from copied WS diff --git a/Framework/DataHandling/src/LoadFullprofResolution.cpp b/Framework/DataHandling/src/LoadFullprofResolution.cpp index 17036af19f5..31aa080eaca 100644 --- a/Framework/DataHandling/src/LoadFullprofResolution.cpp +++ b/Framework/DataHandling/src/LoadFullprofResolution.cpp @@ -125,8 +125,8 @@ void LoadFullprofResolution::exec() { if (useBankIDsInFile) sort(vec_bankinirf.begin(), vec_bankinirf.end()); - for (size_t i = 0; i < vec_bankinirf.size(); ++i) - g_log.debug() << "Irf containing bank " << vec_bankinirf[i] << ".\n"; + for (int i : vec_bankinirf) + g_log.debug() << "Irf containing bank " << i << ".\n"; // Bank-workspace correspondence map<int, size_t> workspaceOfBank; @@ -148,8 +148,7 @@ void LoadFullprofResolution::exec() { // Deal with banks sort(outputbankids.begin(), outputbankids.end()); - for (size_t i = 0; i < outputbankids.size(); ++i) { - int outputbankid = outputbankids[i]; + for (int outputbankid : outputbankids) { if (outputbankid < 0) { g_log.warning() << "Input bank ID (" << outputbankid << ") is negative. It is not allowed and is ignored. " @@ -359,10 +358,9 @@ void LoadFullprofResolution::scanBanks(const vector<string> &lines, g_log.debug() << "[DB1112] Number of bank IDs = " << banks.size() << ", " << "Number of ranges = " << bankstartindexmap.size() << endl; - for (size_t i = 0; i < banks.size(); ++i) { - g_log.debug() << "Bank " << banks[i] << " From line " - << bankstartindexmap[banks[i]] << " to " - << bankendindexmap[banks[i]] << endl; + for (int &bank : banks) { + g_log.debug() << "Bank " << bank << " From line " << bankstartindexmap[bank] + << " to " << bankendindexmap[bank] << endl; } return; diff --git a/Framework/DataHandling/src/LoadGSASInstrumentFile.cpp b/Framework/DataHandling/src/LoadGSASInstrumentFile.cpp index bb965c9f997..d2a4d30c45f 100644 --- a/Framework/DataHandling/src/LoadGSASInstrumentFile.cpp +++ b/Framework/DataHandling/src/LoadGSASInstrumentFile.cpp @@ -172,17 +172,17 @@ void LoadGSASInstrumentFile::exec() { if (bankIds.size()) { // If user provided a list of banks, check that they exist in the .prm // file - for (size_t i = 0; i < bankIds.size(); i++) { - if (!bankparammap.count(bankIds[i])) { + for (int bankId : bankIds) { + if (!bankparammap.count(bankId)) { std::stringstream errorString; - errorString << "Bank " << bankIds[i] << " not found in .prm file"; + errorString << "Bank " << bankId << " not found in .prm file"; throw runtime_error(errorString.str()); } } } else { // Else, use all available banks - for (auto it = bankparammap.begin(); it != bankparammap.end(); ++it) { - bankIds.push_back(static_cast<int>(it->first)); + for (auto &it : bankparammap) { + bankIds.push_back(static_cast<int>(it.first)); } } diff --git a/Framework/DataHandling/src/LoadIDFFromNexus.cpp b/Framework/DataHandling/src/LoadIDFFromNexus.cpp index 85ee0a0b0ce..9d18c0e0ebb 100644 --- a/Framework/DataHandling/src/LoadIDFFromNexus.cpp +++ b/Framework/DataHandling/src/LoadIDFFromNexus.cpp @@ -155,12 +155,11 @@ LoadIDFFromNexus::getParameterCorrectionFile(const std::string &instName) { std::vector<std::string> directoryNames = ConfigService::Instance().getInstrumentDirectories(); - for (auto instDirs_itr = directoryNames.begin(); - instDirs_itr != directoryNames.end(); ++instDirs_itr) { + for (auto &directoryName : directoryNames) { // This will iterate around the directories from user ->etc ->install, and // find the first appropriate file Poco::Path iPath( - *instDirs_itr, + directoryName, "embedded_instrument_corrections"); // Go to correction file subfolder // First see if the directory exists Poco::File ipDir(iPath); @@ -279,11 +278,9 @@ void LoadIDFFromNexus::LoadParameters( ConfigService::Instance().getInstrumentDirectories(); const std::string instrumentName = localWorkspace->getInstrument()->getName(); - for (auto instDirs_itr = directoryNames.begin(); - instDirs_itr != directoryNames.end(); ++instDirs_itr) { + for (auto directoryName : directoryNames) { // This will iterate around the directories from user ->etc ->install, and // find the first appropriate file - std::string directoryName = *instDirs_itr; const std::string paramFile = directoryName + instrumentName + "_Parameters.xml"; diff --git a/Framework/DataHandling/src/LoadILL.cpp b/Framework/DataHandling/src/LoadILL.cpp index 93fc3cba522..2c1af9f5667 100644 --- a/Framework/DataHandling/src/LoadILL.cpp +++ b/Framework/DataHandling/src/LoadILL.cpp @@ -516,15 +516,16 @@ void LoadILL::loadDataIntoTheWorkSpace( // The binning for monitors is considered the same as for detectors size_t spec = 0; - for (auto it = monitors.begin(); it != monitors.end(); ++it) { + for (const auto &monitor : monitors) { m_localWorkspace->dataX(spec) .assign(detectorTofBins.begin(), detectorTofBins.end()); // Assign Y - m_localWorkspace->dataY(spec).assign(it->begin(), it->end()); + m_localWorkspace->dataY(spec).assign(monitor.begin(), monitor.end()); // Assign Error MantidVec &E = m_localWorkspace->dataE(spec); - std::transform(it->begin(), it->end(), E.begin(), LoadILL::calculateError); + std::transform(monitor.begin(), monitor.end(), E.begin(), + LoadILL::calculateError); ++spec; } diff --git a/Framework/DataHandling/src/LoadISISNexus2.cpp b/Framework/DataHandling/src/LoadISISNexus2.cpp index c93baf6a8f6..6ba9044d7f2 100644 --- a/Framework/DataHandling/src/LoadISISNexus2.cpp +++ b/Framework/DataHandling/src/LoadISISNexus2.cpp @@ -722,8 +722,8 @@ size_t LoadISISNexus2::prepareSpectraBlocks( } // count the number of spectra size_t nSpec = 0; - for (auto it = m_spectraBlocks.begin(); it != m_spectraBlocks.end(); ++it) { - nSpec += it->last - it->first + 1; + for (auto &m_spectraBlock : m_spectraBlocks) { + nSpec += m_spectraBlock.last - m_spectraBlock.first + 1; } return nSpec; } @@ -745,10 +745,9 @@ void LoadISISNexus2::loadPeriodData( int64_t period_index(period - 1); // int64_t first_monitor_spectrum = 0; - for (auto block = m_spectraBlocks.begin(); block != m_spectraBlocks.end(); - ++block) { - if (block->isMonitor) { - NXData monitor = entry.openNXData(block->monName); + for (auto &m_spectraBlock : m_spectraBlocks) { + if (m_spectraBlock.isMonitor) { + NXData monitor = entry.openNXData(m_spectraBlock.monName); NXInt mondata = monitor.openIntData(); m_progress->report("Loading monitor"); mondata.load(1, static_cast<int>(period - 1)); // TODO this is just wrong @@ -782,9 +781,9 @@ void LoadISISNexus2::loadPeriodData( // divisible by the block-size // and if not have an extra read of the left overs const int64_t blocksize = 8; - const int64_t rangesize = block->last - block->first + 1; + const int64_t rangesize = m_spectraBlock.last - m_spectraBlock.first + 1; const int64_t fullblocks = rangesize / blocksize; - int64_t spectra_no = block->first; + int64_t spectra_no = m_spectraBlock.first; // For this to work correctly, we assume that the spectrum list increases // monotonically @@ -1176,8 +1175,8 @@ bool LoadISISNexus2::findSpectraDetRangeInFile( // number of groups. // identify monitor ID range. - for (auto it = monitors.begin(); it != monitors.end(); it++) { - int64_t mon_id = static_cast<int64_t>(it->first); + for (auto &monitor : monitors) { + int64_t mon_id = static_cast<int64_t>(monitor.first); if (m_monBlockInfo.spectraID_min > mon_id) m_monBlockInfo.spectraID_min = mon_id; if (m_monBlockInfo.spectraID_max < mon_id) @@ -1274,15 +1273,15 @@ bool LoadISISNexus2::findSpectraDetRangeInFile( std::map<int64_t, std::string> remaining_monitors; if (removeMonitors) { - for (auto it = monitors.begin(); it != monitors.end(); it++) { - if (it->first >= m_detBlockInfo.spectraID_min && - it->first <= m_detBlockInfo.spectraID_max) { // monitors ID-s are - // included with spectra - // ID-s -- let's try not - // to load it twice. - OvelapMonitors.insert(*it); + for (auto &monitor : monitors) { + if (monitor.first >= m_detBlockInfo.spectraID_min && + monitor.first <= m_detBlockInfo.spectraID_max) { // monitors ID-s are + // included with spectra + // ID-s -- let's try not + // to load it twice. + OvelapMonitors.insert(monitor); } else { - remaining_monitors.insert(*it); + remaining_monitors.insert(monitor); } } } diff --git a/Framework/DataHandling/src/LoadInstrument.cpp b/Framework/DataHandling/src/LoadInstrument.cpp index 431df970f99..87710eedef6 100644 --- a/Framework/DataHandling/src/LoadInstrument.cpp +++ b/Framework/DataHandling/src/LoadInstrument.cpp @@ -222,11 +222,9 @@ void LoadInstrument::runLoadParameterFile() { std::vector<std::string> directoryNames = configService.getInstrumentDirectories(); - for (auto instDirs_itr = directoryNames.begin(); - instDirs_itr != directoryNames.end(); ++instDirs_itr) { + for (auto directoryName : directoryNames) { // This will iterate around the directories from user ->etc ->install, and // find the first beat file - std::string directoryName = *instDirs_itr; fullPathParamIDF = getFullPathParamIDF(directoryName); // stop when you find the first one if (!fullPathParamIDF.empty()) diff --git a/Framework/DataHandling/src/LoadIsawDetCal.cpp b/Framework/DataHandling/src/LoadIsawDetCal.cpp index 6d1fe37a67a..d3b381b9f22 100644 --- a/Framework/DataHandling/src/LoadIsawDetCal.cpp +++ b/Framework/DataHandling/src/LoadIsawDetCal.cpp @@ -139,8 +139,8 @@ void LoadIsawDetCal::exec() { std::vector<IComponent_const_sptr> comps; inst->getChildren(comps, true); - for (size_t i = 0; i < comps.size(); i++) { - std::string bankName = comps[i]->getName(); + for (auto &comp : comps) { + std::string bankName = comp->getName(); boost::trim(bankName); boost::erase_all(bankName, bankPart); int bank = 0; diff --git a/Framework/DataHandling/src/LoadLog.cpp b/Framework/DataHandling/src/LoadLog.cpp index dceaa8cbe11..b6bab67985b 100644 --- a/Framework/DataHandling/src/LoadLog.cpp +++ b/Framework/DataHandling/src/LoadLog.cpp @@ -470,8 +470,8 @@ bool LoadLog::SNSTextFormatColumns(const std::string &str, boost::split(strs, str, boost::is_any_of("\t ")); double val; // Every column must evaluate to a double - for (size_t i = 0; i < strs.size(); i++) { - if (!Strings::convert<double>(strs[i], val)) + for (auto &str : strs) { + if (!Strings::convert<double>(str, val)) return false; else out.push_back(val); diff --git a/Framework/DataHandling/src/LoadLogsForSNSPulsedMagnet.cpp b/Framework/DataHandling/src/LoadLogsForSNSPulsedMagnet.cpp index 34df470e1b8..31c52df9b91 100644 --- a/Framework/DataHandling/src/LoadLogsForSNSPulsedMagnet.cpp +++ b/Framework/DataHandling/src/LoadLogsForSNSPulsedMagnet.cpp @@ -208,9 +208,9 @@ void LoadLogsForSNSPulsedMagnet::ParsePulseIDLogFile() { BinaryFile<Pulse> pulseFile(m_pulseidfilename); this->m_numpulses = pulseFile.getNumElements(); pulses = pulseFile.loadAll(); - for (auto it = pulses->begin(); it != pulses->end(); ++it) { - this->m_pulseidseconds.push_back(it->seconds); - this->m_pulseidnanoseconds.push_back(it->nanoseconds); + for (auto &pulse : *pulses) { + this->m_pulseidseconds.push_back(pulse.seconds); + this->m_pulseidnanoseconds.push_back(pulse.nanoseconds); } delete pulses; } diff --git a/Framework/DataHandling/src/LoadMLZ.cpp b/Framework/DataHandling/src/LoadMLZ.cpp index 437ca4d47ae..829ca85b293 100644 --- a/Framework/DataHandling/src/LoadMLZ.cpp +++ b/Framework/DataHandling/src/LoadMLZ.cpp @@ -138,9 +138,9 @@ void LoadMLZ::maskDetectors(NeXus::NXEntry &entry) { g_log.debug() << "Number of masked detectors: " << masked_detectors.size() << std::endl; - for (size_t i = 0; i < masked_detectors.size(); i++) { + for (int masked_detector : masked_detectors) { g_log.debug() << "List of masked detectors: "; - g_log.debug() << masked_detectors[i]; + g_log.debug() << masked_detector; g_log.debug() << ", "; } g_log.debug() << std::endl; diff --git a/Framework/DataHandling/src/LoadMask.cpp b/Framework/DataHandling/src/LoadMask.cpp index 60b3f96cbe0..a4733d81784 100644 --- a/Framework/DataHandling/src/LoadMask.cpp +++ b/Framework/DataHandling/src/LoadMask.cpp @@ -180,8 +180,7 @@ void LoadMask::processMaskOnDetectors(bool tomask, << " Final Single IDs Size = " << singledetids.size() << std::endl; - for (size_t i = 0; i < singledetids.size(); i++) { - detid_t detid = singledetids[i]; + for (int detid : singledetids) { detid2index_map::const_iterator it; it = indexmap.find(detid); if (it != indexmap.end()) { @@ -213,18 +212,18 @@ void LoadMask::componentToDetectors(std::vector<std::string> componentnames, std::vector<int32_t> &detectors) { Geometry::Instrument_const_sptr minstrument = m_maskWS->getInstrument(); - for (size_t i = 0; i < componentnames.size(); i++) { - g_log.debug() << "Component name = " << componentnames[i] << std::endl; + for (auto &componentname : componentnames) { + g_log.debug() << "Component name = " << componentname << std::endl; // a) get component Geometry::IComponent_const_sptr component = - minstrument->getComponentByName(componentnames[i]); + minstrument->getComponentByName(componentname); if (component) g_log.debug() << "Component ID = " << component->getComponentID() << std::endl; else { // A non-exiting component. Ignore - g_log.warning() << "Component " << componentnames[i] << " does not exist!" + g_log.warning() << "Component " << componentname << " does not exist!" << std::endl; continue; } @@ -241,9 +240,8 @@ void LoadMask::componentToDetectors(std::vector<std::string> componentnames, int32_t id_min = 1000000; int32_t id_max = 0; - for (size_t ic = 0; ic < children.size(); ic++) { + for (auto child : children) { // c) convert component to detector - Geometry::IComponent_const_sptr child = children[ic]; Geometry::IDetector_const_sptr det = boost::dynamic_pointer_cast<const Geometry::IDetector>(child); @@ -274,18 +272,18 @@ void LoadMask::bankToDetectors(std::vector<std::string> singlebanks, std::vector<int32_t> &detectorpairsup) { std::stringstream infoss; infoss << "Bank IDs to be converted to detectors: " << endl; - for (size_t i = 0; i < singlebanks.size(); i++) { - infoss << "Bank: " << singlebanks[i] << std::endl; + for (auto &singlebank : singlebanks) { + infoss << "Bank: " << singlebank << std::endl; } g_log.debug(infoss.str()); Geometry::Instrument_const_sptr minstrument = m_maskWS->getInstrument(); - for (size_t ib = 0; ib < singlebanks.size(); ib++) { + for (auto &singlebank : singlebanks) { std::vector<Geometry::IDetector_const_sptr> idetectors; - minstrument->getDetectorsInBank(idetectors, singlebanks[ib]); - g_log.debug() << "Bank: " << singlebanks[ib] << " has " << idetectors.size() + minstrument->getDetectorsInBank(idetectors, singlebank); + g_log.debug() << "Bank: " << singlebank << " has " << idetectors.size() << " detectors" << std::endl; // a) get information @@ -306,8 +304,7 @@ void LoadMask::bankToDetectors(std::vector<std::string> singlebanks, << "DetID: " << detid_first << ", " << detid_last << std::endl; - for (size_t i = 0; i < idetectors.size(); i++) { - Geometry::IDetector_const_sptr det = idetectors[i]; + for (auto det : idetectors) { int32_t detid = det->getID(); detectors.push_back(detid); } @@ -397,8 +394,8 @@ void LoadMask::detectorToDetectors(std::vector<int32_t> singles, << std::endl; } */ - for (size_t i = 0; i < singles.size(); i++) { - detectors.push_back(singles[i]); + for (int single : singles) { + detectors.push_back(single); } for (size_t i = 0; i < pairslow.size(); i++) { for (int32_t j = 0; j < pairsup[i] - pairslow[i] + 1; j++) { @@ -585,16 +582,16 @@ void LoadMask::parseSpectrumIDs(std::string inputstr, bool tomask) { // 2. Set to data storage if (tomask) { - for (size_t i = 0; i < singles.size(); i++) { - mask_specid_single.push_back(singles[i]); + for (int single : singles) { + mask_specid_single.push_back(single); } for (size_t i = 0; i < pairs.size() / 2; i++) { mask_specid_pair_low.push_back(pairs[2 * i]); mask_specid_pair_up.push_back(pairs[2 * i + 1]); } } else { - for (size_t i = 0; i < singles.size(); i++) { - unmask_specid_single.push_back(singles[i]); + for (int single : singles) { + unmask_specid_single.push_back(single); } for (size_t i = 0; i < pairs.size() / 2; i++) { unmask_specid_pair_low.push_back(pairs[2 * i]); @@ -618,16 +615,16 @@ void LoadMask::parseDetectorIDs(std::string inputstr, bool tomask) { // 2. Set to data storage if (tomask) { - for (size_t i = 0; i < singles.size(); i++) { - mask_detid_single.push_back(singles[i]); + for (int single : singles) { + mask_detid_single.push_back(single); } for (size_t i = 0; i < pairs.size() / 2; i++) { mask_detid_pair_low.push_back(pairs[2 * i]); mask_detid_pair_up.push_back(pairs[2 * i + 1]); } } else { - for (size_t i = 0; i < singles.size(); i++) { - unmask_detid_single.push_back(singles[i]); + for (int single : singles) { + unmask_detid_single.push_back(single); } for (size_t i = 0; i < pairs.size() / 2; i++) { unmask_detid_pair_low.push_back(pairs[2 * i]); @@ -652,35 +649,35 @@ void LoadMask::parseRangeText(std::string inputstr, // 2. Filter std::vector<std::string> strsingles; std::vector<std::string> strpairs; - for (size_t i = 0; i < rawstrings.size(); i++) { + for (auto &rawstring : rawstrings) { // a) Find '-': bool containto = false; - const char *tempchs = rawstrings[i].c_str(); - for (size_t j = 0; j < rawstrings[i].size(); j++) + const char *tempchs = rawstring.c_str(); + for (size_t j = 0; j < rawstring.size(); j++) if (tempchs[j] == '-') { containto = true; break; } // b) Rebin if (containto) - strpairs.push_back(rawstrings[i]); + strpairs.push_back(rawstring); else - strsingles.push_back(rawstrings[i]); + strsingles.push_back(rawstring); } // ENDFOR i // 3. Treat singles - for (size_t i = 0; i < strsingles.size(); i++) { - int32_t itemp = atoi(strsingles[i].c_str()); + for (auto &strsingle : strsingles) { + int32_t itemp = atoi(strsingle.c_str()); singles.push_back(itemp); } // 4. Treat pairs - for (size_t i = 0; i < strpairs.size(); i++) { + for (auto &strpair : strpairs) { // a) split and check std::vector<std::string> ptemp; - this->splitString(strpairs[i], ptemp, "-"); + this->splitString(strpair, ptemp, "-"); if (ptemp.size() != 2) { - g_log.error() << "Range string " << strpairs[i] << " has a wrong format!" + g_log.error() << "Range string " << strpair << " has a wrong format!" << std::endl; throw std::invalid_argument("Wrong format"); } @@ -689,7 +686,7 @@ void LoadMask::parseRangeText(std::string inputstr, int32_t intstart = atoi(ptemp[0].c_str()); int32_t intend = atoi(ptemp[1].c_str()); if (intstart >= intend) { - g_log.error() << "Range string " << strpairs[i] << " has a reversed order" + g_log.error() << "Range string " << strpair << " has a reversed order" << std::endl; throw std::invalid_argument("Wrong format"); } diff --git a/Framework/DataHandling/src/LoadMcStas.cpp b/Framework/DataHandling/src/LoadMcStas.cpp index 3b16dd7d066..1a02b83805e 100644 --- a/Framework/DataHandling/src/LoadMcStas.cpp +++ b/Framework/DataHandling/src/LoadMcStas.cpp @@ -97,9 +97,9 @@ void LoadMcStas::exec() { std::map<std::string, std::string> histogramEntries; // populate eventEntries and histogramEntries - for (auto eit = dataEntries.begin(); eit != dataEntries.end(); ++eit) { - std::string dataName = eit->first; - std::string dataType = eit->second; + for (auto &dataEntrie : dataEntries) { + std::string dataName = dataEntrie.first; + std::string dataType = dataEntrie.second; if (dataName == "content_nxs" || dataType != "NXdata") continue; // can be removed if sure no Nexus files contains // "content_nxs" @@ -116,19 +116,18 @@ void LoadMcStas::exec() { auto nxdataEntries = nxFile.getEntries(); - for (auto nit = nxdataEntries.begin(); nit != nxdataEntries.end(); - ++nit) { - if (nit->second == "NXparameters") + for (auto &nxdataEntrie : nxdataEntries) { + if (nxdataEntrie.second == "NXparameters") continue; - nxFile.openData(nit->first); + nxFile.openData(nxdataEntrie.first); if (nxFile.hasAttr("long_name")) { std::string nameAttrValue; nxFile.getAttr("long_name", nameAttrValue); if (nameAttrValue.find("Neutron_ID") != std::string::npos) { - eventEntries[eit->first] = eit->second; + eventEntries[dataEntrie.first] = dataEntrie.second; } else { - histogramEntries[eit->first] = eit->second; + histogramEntries[dataEntrie.first] = dataEntrie.second; } } nxFile.closeData(); @@ -247,9 +246,9 @@ void LoadMcStas::readEventData( const size_t numEventEntries = eventEntries.size(); Progress progEntries(this, progressFractionInitial, 1.0, numEventEntries * 2); - for (auto eit = eventEntries.begin(); eit != eventEntries.end(); ++eit) { - std::string dataName = eit->first; - std::string dataType = eit->second; + for (const auto &eventEntrie : eventEntries) { + std::string dataName = eventEntrie.first; + std::string dataType = eventEntrie.second; // open second level entry nxFile.openGroup(dataName, dataType); @@ -416,10 +415,9 @@ void LoadMcStas::readHistogramData( std::string nameAttrValueYLABEL; - for (auto eit = histogramEntries.begin(); eit != histogramEntries.end(); - ++eit) { - std::string dataName = eit->first; - std::string dataType = eit->second; + for (const auto &histogramEntrie : histogramEntries) { + std::string dataName = histogramEntrie.first; + std::string dataType = histogramEntrie.second; // open second level entry nxFile.openGroup(dataName, dataType); @@ -435,20 +433,20 @@ void LoadMcStas::readHistogramData( // Find the axis names auto nxdataEntries = nxFile.getEntries(); std::string axis1Name, axis2Name; - for (auto nit = nxdataEntries.begin(); nit != nxdataEntries.end(); ++nit) { - if (nit->second == "NXparameters") + for (auto &nxdataEntrie : nxdataEntries) { + if (nxdataEntrie.second == "NXparameters") continue; - if (nit->first == "ncount") + if (nxdataEntrie.first == "ncount") continue; - nxFile.openData(nit->first); + nxFile.openData(nxdataEntrie.first); if (nxFile.hasAttr("axis")) { int axisNo(0); nxFile.getAttr("axis", axisNo); if (axisNo == 1) - axis1Name = nit->first; + axis1Name = nxdataEntrie.first; else if (axisNo == 2) - axis2Name = nit->first; + axis2Name = nxdataEntrie.first; else throw std::invalid_argument("Unknown axis number"); } diff --git a/Framework/DataHandling/src/LoadMcStasNexus.cpp b/Framework/DataHandling/src/LoadMcStasNexus.cpp index fa4a798e93b..76224bfe41f 100644 --- a/Framework/DataHandling/src/LoadMcStasNexus.cpp +++ b/Framework/DataHandling/src/LoadMcStasNexus.cpp @@ -85,9 +85,9 @@ void LoadMcStasNexus::exec() { nxFile.openGroup(name, type); auto dataEntries = nxFile.getEntries(); - for (auto eit = dataEntries.begin(); eit != dataEntries.end(); ++eit) { - std::string dataName = eit->first; - std::string dataType = eit->second; + for (auto &dataEntrie : dataEntries) { + std::string dataName = dataEntrie.first; + std::string dataType = dataEntrie.second; if (dataName == "content_nxs" || dataType != "NXdata") continue; g_log.debug() << "Opening " << dataName << " " << dataType << std::endl; @@ -97,18 +97,17 @@ void LoadMcStasNexus::exec() { // Find the axis names auto nxdataEntries = nxFile.getEntries(); std::string axis1Name, axis2Name; - for (auto nit = nxdataEntries.begin(); nit != nxdataEntries.end(); - ++nit) { - if (nit->second == "NXparameters") + for (auto &nxdataEntrie : nxdataEntries) { + if (nxdataEntrie.second == "NXparameters") continue; - nxFile.openData(nit->first); + nxFile.openData(nxdataEntrie.first); if (nxFile.hasAttr("axis")) { int axisNo(0); nxFile.getAttr("axis", axisNo); if (axisNo == 1) - axis1Name = nit->first; + axis1Name = nxdataEntrie.first; else if (axisNo == 2) - axis2Name = nit->first; + axis2Name = nxdataEntrie.first; else throw std::invalid_argument("Unknown axis number"); } diff --git a/Framework/DataHandling/src/LoadMuonLog.cpp b/Framework/DataHandling/src/LoadMuonLog.cpp index 16a6232e1d3..f6a306cf500 100644 --- a/Framework/DataHandling/src/LoadMuonLog.cpp +++ b/Framework/DataHandling/src/LoadMuonLog.cpp @@ -110,8 +110,8 @@ void LoadMuonLog::exec() { * @returns The string but with all characters in lower case */ std::string LoadMuonLog::stringToLower(std::string strToConvert) { - for (unsigned int i = 0; i < strToConvert.length(); i++) { - strToConvert[i] = static_cast<char>(tolower(strToConvert[i])); + for (char &i : strToConvert) { + i = static_cast<char>(tolower(i)); } return strToConvert; // return the converted string } diff --git a/Framework/DataHandling/src/LoadMuonNexus1.cpp b/Framework/DataHandling/src/LoadMuonNexus1.cpp index d7a1621c0f9..21a55427a6c 100644 --- a/Framework/DataHandling/src/LoadMuonNexus1.cpp +++ b/Framework/DataHandling/src/LoadMuonNexus1.cpp @@ -260,10 +260,10 @@ void LoadMuonNexus1::exec() { } // Read in the spectra in the optional list parameter, if set if (m_list) { - for (size_t i = 0; i < m_spec_list.size(); ++i) { + for (int i : m_spec_list) { specid_t histToRead = - static_cast<specid_t>(m_spec_list[i] - 1 + period * nxload.t_nsp1); - specid_t specNo = static_cast<specid_t>(m_spec_list[i]); + static_cast<specid_t>(i - 1 + period * nxload.t_nsp1); + specid_t specNo = static_cast<specid_t>(i); loadData(counter, histToRead, specNo, nxload, lengthIn - 1, localWorkspace); counter++; @@ -349,8 +349,8 @@ void LoadMuonNexus1::loadDeadTimes(NXRoot &root) { for (int64_t i = m_spec_min; i < m_spec_max; i++) { specToLoad.push_back(static_cast<int>(i)); } - for (auto it = m_spec_list.begin(); it != m_spec_list.end(); ++it) { - specToLoad.push_back(*it); + for (int &it : m_spec_list) { + specToLoad.push_back(it); } } else { // Load all the spectra @@ -379,8 +379,8 @@ void LoadMuonNexus1::loadDeadTimes(NXRoot &root) { // Simpliest case - one dead time for one detector // Populate deadTimes - for (auto it = specToLoad.begin(); it != specToLoad.end(); ++it) { - deadTimes.push_back(deadTimesData[*it - 1]); + for (int &it : specToLoad) { + deadTimes.push_back(deadTimesData[it - 1]); } // Load into table TableWorkspace_sptr table = createDeadTimeTable(specToLoad, deadTimes); @@ -394,8 +394,8 @@ void LoadMuonNexus1::loadDeadTimes(NXRoot &root) { for (int64_t i = 0; i < m_numberOfPeriods; i++) { // Populate deadTimes - for (auto it = specToLoad.begin(); it != specToLoad.end(); ++it) { - int index = static_cast<int>(*it - 1 + i * m_numberOfSpectra); + for (int &it : specToLoad) { + int index = static_cast<int>(it - 1 + i * m_numberOfSpectra); deadTimes.push_back(deadTimesData[index]); } @@ -438,8 +438,8 @@ Workspace_sptr LoadMuonNexus1::loadDetectorGrouping(NXRoot &root) { for (int64_t i = m_spec_min; i < m_spec_max; i++) { specToLoad.push_back(static_cast<int>(i)); } - for (auto it = m_spec_list.begin(); it != m_spec_list.end(); ++it) { - specToLoad.push_back(*it); + for (int &it : m_spec_list) { + specToLoad.push_back(it); } } else { // Load all the spectra @@ -471,15 +471,15 @@ Workspace_sptr LoadMuonNexus1::loadDetectorGrouping(NXRoot &root) { // m_entrynumber = 0 && m_numberOfPeriods = 1 means that user did not // select // any periods but there is only one in the dataset - for (auto it = specToLoad.begin(); it != specToLoad.end(); ++it) { - int index = *it - 1; + for (int &it : specToLoad) { + int index = it - 1; grouping.push_back(groupingData[index]); } } else { // User selected an entry number - for (auto it = specToLoad.begin(); it != specToLoad.end(); ++it) { - int index = *it - 1 + static_cast<int>((m_entrynumber - 1) * - m_numberOfSpectra); + for (int &it : specToLoad) { + int index = it - 1 + static_cast<int>((m_entrynumber - 1) * + m_numberOfSpectra); grouping.push_back(groupingData[index]); } } @@ -499,8 +499,8 @@ Workspace_sptr LoadMuonNexus1::loadDetectorGrouping(NXRoot &root) { // Get the grouping grouping.clear(); - for (auto it = specToLoad.begin(); it != specToLoad.end(); ++it) { - int index = *it - 1 + i * static_cast<int>(m_numberOfSpectra); + for (int &it : specToLoad) { + int index = it - 1 + i * static_cast<int>(m_numberOfSpectra); grouping.push_back(groupingData[index]); } @@ -573,11 +573,11 @@ LoadMuonNexus1::createDetectorGroupingTable(std::vector<int> specToLoad, groupingMap[grouping[i]].push_back(specToLoad[i]); } - for (auto it = groupingMap.begin(); it != groupingMap.end(); ++it) { - if (it->first != 0) // Skip 0 group + for (auto &it : groupingMap) { + if (it.first != 0) // Skip 0 group { TableRow newRow = detectorGroupingTable->appendRow(); - newRow << it->second; + newRow << it.second; } } diff --git a/Framework/DataHandling/src/LoadMuonNexus2.cpp b/Framework/DataHandling/src/LoadMuonNexus2.cpp index abf0bd22c28..9b6056f7e7a 100644 --- a/Framework/DataHandling/src/LoadMuonNexus2.cpp +++ b/Framework/DataHandling/src/LoadMuonNexus2.cpp @@ -116,10 +116,10 @@ void LoadMuonNexus2::doExec() { std::string detectorName; // Only the first NXdata found - for (unsigned int i = 0; i < entry.groups().size(); i++) { - std::string className = entry.groups()[i].nxclass; + for (auto &i : entry.groups()) { + std::string className = i.nxclass; if (className == "NXdata") { - detectorName = entry.groups()[i].nxname; + detectorName = i.nxname; break; } } @@ -254,8 +254,7 @@ void LoadMuonNexus2::doExec() { // Read in the spectra in the optional list parameter, if set if (m_list) { - for (unsigned int i = 0; i < m_spec_list.size(); ++i) { - int spec = m_spec_list[i]; + for (int spec : m_spec_list) { int k = index_spectrum[spec]; // if spec not found k is 0 loadData(counts, timeBins, counter, period, k, localWorkspace); localWorkspace->getSpectrum(counter)->setSpectrumNo(spectrum_index[k]); diff --git a/Framework/DataHandling/src/LoadNexusLogs.cpp b/Framework/DataHandling/src/LoadNexusLogs.cpp index 6df5f9622fe..0afb6cd0719 100644 --- a/Framework/DataHandling/src/LoadNexusLogs.cpp +++ b/Framework/DataHandling/src/LoadNexusLogs.cpp @@ -229,9 +229,9 @@ void LoadNexusLogs::exec() { ptime.reserve(event_frame_number.size()); std::vector<Mantid::Kernel::DateAndTime> plogt = plog->timesAsVector(); std::vector<double> plogv = plog->valuesAsVector(); - for (size_t i = 0; i < event_frame_number.size(); ++i) { - ptime.push_back(plogt[event_frame_number[i]]); - pval.push_back(plogv[event_frame_number[i]]); + for (int i : event_frame_number) { + ptime.push_back(plogt[i]); + pval.push_back(plogv[i]); } pcharge->create(ptime, pval); pcharge->setUnits("uAh"); diff --git a/Framework/DataHandling/src/LoadNexusMonitors2.cpp b/Framework/DataHandling/src/LoadNexusMonitors2.cpp index 8b835b0ad98..015adbc522b 100644 --- a/Framework/DataHandling/src/LoadNexusMonitors2.cpp +++ b/Framework/DataHandling/src/LoadNexusMonitors2.cpp @@ -149,15 +149,14 @@ void LoadNexusMonitors2::exec() { int numEventThings = 0; // number of things that are eventish - should be 3 string_map_t inner_entries = file.getEntries(); // get list of entries - for (auto inner = inner_entries.begin(); inner != inner_entries.end(); - ++inner) { - if (inner->first == "event_index") { + for (auto &inner_entrie : inner_entries) { + if (inner_entrie.first == "event_index") { numEventThings += 1; continue; - } else if (inner->first == "event_time_offset") { + } else if (inner_entrie.first == "event_time_offset") { numEventThings += 1; continue; - } else if (inner->first == "event_time_zero") { + } else if (inner_entrie.first == "event_time_zero") { numEventThings += 1; continue; } @@ -234,9 +233,8 @@ void LoadNexusMonitors2::exec() { // number if (monitorNumber2Name.size() == monitorNames.size()) { monitorNames.clear(); - for (auto it = monitorNumber2Name.begin(); it != monitorNumber2Name.end(); - ++it) { - monitorNames.push_back(it->second); + for (auto &it : monitorNumber2Name) { + monitorNames.push_back(it.second); } } } else if (numEventMon == m_monitor_count) { diff --git a/Framework/DataHandling/src/LoadNexusProcessed.cpp b/Framework/DataHandling/src/LoadNexusProcessed.cpp index d468ab64ca8..108f1f8a7e2 100644 --- a/Framework/DataHandling/src/LoadNexusProcessed.cpp +++ b/Framework/DataHandling/src/LoadNexusProcessed.cpp @@ -1079,8 +1079,7 @@ API::Workspace_sptr LoadNexusProcessed::loadPeaksEntry(NXEntry &entry) { peakWS->addPeak(*p); } - for (size_t i = 0; i < columnNames.size(); i++) { - const std::string str = columnNames[i]; + for (auto str : columnNames) { if (!str.compare("column_1")) { NXInt nxInt = nx_tw.openNXInt(str.c_str()); nxInt.load(); diff --git a/Framework/DataHandling/src/LoadPreNexus.cpp b/Framework/DataHandling/src/LoadPreNexus.cpp index 4d076651853..7963962aebf 100644 --- a/Framework/DataHandling/src/LoadPreNexus.cpp +++ b/Framework/DataHandling/src/LoadPreNexus.cpp @@ -259,8 +259,8 @@ void LoadPreNexus::parseRuninfo(const string &runinfo, string &dataDir, g_log.debug() << "Found 1 event file: \"" << eventFilenames[0] << "\"\n"; } else { g_log.debug() << "Found " << eventFilenames.size() << " event files:"; - for (size_t i = 0; i < eventFilenames.size(); i++) { - g_log.debug() << "\"" << eventFilenames[i] << "\" "; + for (auto &eventFilename : eventFilenames) { + g_log.debug() << "\"" << eventFilename << "\" "; } g_log.debug() << "\n"; } @@ -296,20 +296,19 @@ void LoadPreNexus::runLoadNexusLogs(const string &runinfo, // run the algorithm bool loadedLogs = false; - for (size_t i = 0; i < possibilities.size(); i++) { - if (Poco::File(possibilities[i]).exists()) { - g_log.information() << "Loading logs from \"" << possibilities[i] - << "\"\n"; + for (auto &possibilitie : possibilities) { + if (Poco::File(possibilitie).exists()) { + g_log.information() << "Loading logs from \"" << possibilitie << "\"\n"; IAlgorithm_sptr alg = this->createChildAlgorithm("LoadNexusLogs", prog_start, prog_stop); alg->setProperty("Workspace", m_outputWorkspace); - alg->setProperty("Filename", possibilities[i]); + alg->setProperty("Filename", possibilitie); alg->setProperty("OverwriteLogs", false); alg->executeAsChildAlg(); loadedLogs = true; // Reload instrument so SNAP can use log values - std::string entry_name = LoadTOFRawNexus::getEntryName(possibilities[i]); - LoadEventNexus::runLoadInstrument(possibilities[i], m_outputWorkspace, + std::string entry_name = LoadTOFRawNexus::getEntryName(possibilitie); + LoadEventNexus::runLoadInstrument(possibilitie, m_outputWorkspace, entry_name, this); break; } diff --git a/Framework/DataHandling/src/LoadRKH.cpp b/Framework/DataHandling/src/LoadRKH.cpp index d737c518fdb..47e498f778a 100644 --- a/Framework/DataHandling/src/LoadRKH.cpp +++ b/Framework/DataHandling/src/LoadRKH.cpp @@ -97,8 +97,8 @@ int LoadRKH::confidence(Kernel::FileDescriptor &descriptor) const { "-SEP-", "-OCT-", "-NOV-", "-DEC-"}; bool foundMonth(false); - for (size_t i = 0; i < 12; ++i) { - if (!boost::ifind_first(fileline, MONTHS[i]).empty()) { + for (auto &i : MONTHS) { + if (!boost::ifind_first(fileline, i).empty()) { foundMonth = true; break; } @@ -342,8 +342,8 @@ const MatrixWorkspace_sptr LoadRKH::read2D(const std::string &firstLine) { // now read in the Y values MantidVec &YOut = outWrksp->dataY(i); - for (auto it = YOut.begin(), end = YOut.end(); it != end; ++it) { - m_fileIn >> *it; + for (double &it : YOut) { + m_fileIn >> it; } prog.report("Loading Y data"); } // loop on to the next spectrum @@ -351,8 +351,8 @@ const MatrixWorkspace_sptr LoadRKH::read2D(const std::string &firstLine) { // the error values form one big block after the Y-values for (size_t i = 0; i < nAxis1Values; ++i) { MantidVec &EOut = outWrksp->dataE(i); - for (auto it = EOut.begin(), end = EOut.end(); it != end; ++it) { - m_fileIn >> *it; + for (double &it : EOut) { + m_fileIn >> it; } prog.report("Loading error estimates"); } // loop on to the next spectrum diff --git a/Framework/DataHandling/src/LoadRaw/isisraw.cpp b/Framework/DataHandling/src/LoadRaw/isisraw.cpp index b46931a5449..cddc2aec89b 100644 --- a/Framework/DataHandling/src/LoadRaw/isisraw.cpp +++ b/Framework/DataHandling/src/LoadRaw/isisraw.cpp @@ -142,8 +142,8 @@ ISISRAW::ISISRAW(ISISCRPT_STRUCT *crpt) ddes(0), dat1(0) { memset(r_title, ' ', sizeof(r_title)); memset(i_inst, ' ', sizeof(i_inst)); - for (int i = 0; i < 256; i++) { - t_pmap[i] = 1; // period number for each basic period + for (int &i : t_pmap) { + i = 1; // period number for each basic period } memset(t_tcm1, 0, sizeof(t_tcm1)); // time channel mode memset(t_tcp1, 0, sizeof(t_tcp1)); // time channel parameters @@ -167,8 +167,8 @@ ISISRAW::ISISRAW(ISISCRPT_STRUCT *crpt, bool doUpdateFromCRPT) ddes(0), dat1(0) { memset(r_title, ' ', sizeof(r_title)); memset(i_inst, ' ', sizeof(i_inst)); - for (int i = 0; i < 256; i++) { - t_pmap[i] = 1; // period number for each basic period + for (int &i : t_pmap) { + i = 1; // period number for each basic period } memset(t_tcm1, 0, sizeof(t_tcm1)); // time channel mode memset(t_tcp1, 0, sizeof(t_tcp1)); // time channel parameters diff --git a/Framework/DataHandling/src/LoadRawHelper.cpp b/Framework/DataHandling/src/LoadRawHelper.cpp index 398eee8c2c7..45e1ccf8ab4 100644 --- a/Framework/DataHandling/src/LoadRawHelper.cpp +++ b/Framework/DataHandling/src/LoadRawHelper.cpp @@ -424,15 +424,15 @@ LoadRawHelper::getmonitorSpectrumList(const SpectrumDetectorMapping &mapping) { if (!m_monitordetectorList.empty()) { const auto &map = mapping.getMapping(); - for (auto it = map.begin(); it != map.end(); ++it) { - auto detIDs = it->second; + for (const auto &it : map) { + auto detIDs = it.second; // Both m_monitordetectorList & detIDs should be (very) short so the // nested loop shouldn't be too evil - for (auto detIt = detIDs.begin(); detIt != detIDs.end(); ++detIt) { + for (value_type detID : detIDs) { if (std::find(m_monitordetectorList.begin(), m_monitordetectorList.end(), - *detIt) != m_monitordetectorList.end()) { - spectrumIndices.push_back(it->first); + detID) != m_monitordetectorList.end()) { + spectrumIndices.push_back(it.first); } } } diff --git a/Framework/DataHandling/src/LoadSpice2D.cpp b/Framework/DataHandling/src/LoadSpice2D.cpp index 4312bfd53be..559ce24c718 100644 --- a/Framework/DataHandling/src/LoadSpice2D.cpp +++ b/Framework/DataHandling/src/LoadSpice2D.cpp @@ -206,10 +206,10 @@ void LoadSpice2D::parseDetectorDimensions(const std::string &dims_str) { void LoadSpice2D::addMetadataAsRunProperties( const std::map<std::string, std::string> &metadata) { - for (auto it = metadata.begin(); it != metadata.end(); it++) { - std::string key = it->first; + for (const auto &it : metadata) { + std::string key = it.first; std::replace(key.begin(), key.end(), '/', '_'); - m_workspace->mutableRun().addProperty(key, it->second, true); + m_workspace->mutableRun().addProperty(key, it.second, true); } } @@ -317,8 +317,8 @@ void LoadSpice2D::createWorkspace(const std::vector<int> &data, m_dwavelength); // Store detector pixels - for (auto it = data.begin(); it != data.end(); ++it) { - double count = static_cast<double>(*it); + for (int it : data) { + double count = static_cast<double>(it); // Data uncertainties, computed according to the HFIR/IGOR reduction code // The following is what I would suggest instead... // error = count > 0 ? sqrt((double)count) : 0.0; diff --git a/Framework/DataHandling/src/LoadTOFRawNexus.cpp b/Framework/DataHandling/src/LoadTOFRawNexus.cpp index c26abaf5921..fc3e545b6b8 100644 --- a/Framework/DataHandling/src/LoadTOFRawNexus.cpp +++ b/Framework/DataHandling/src/LoadTOFRawNexus.cpp @@ -199,8 +199,8 @@ void LoadTOFRawNexus::countPixels(const std::string &nexusfilename, if (!dims.empty()) { size_t newPixels = 1; - for (size_t i = 0; i < dims.size(); i++) - newPixels *= dims[i]; + for (long long dim : dims) + newPixels *= dim; m_numPixels += newPixels; } } else { @@ -547,9 +547,8 @@ void LoadTOFRawNexus::exec() { // Load each bank sequentially // PARALLEL_FOR1(WS) - for (int i = 0; i < int(bankNames.size()); i++) { + for (auto bankName : bankNames) { // PARALLEL_START_INTERUPT_REGION - std::string bankName = bankNames[i]; prog->report("Loading bank " + bankName); g_log.debug() << "Loading bank " << bankName << std::endl; loadBank(filename, entry_name, bankName, WS, id_to_wi); diff --git a/Framework/DataHandling/src/LoadVulcanCalFile.cpp b/Framework/DataHandling/src/LoadVulcanCalFile.cpp index 1db822e8ec8..7f38f3e1835 100644 --- a/Framework/DataHandling/src/LoadVulcanCalFile.cpp +++ b/Framework/DataHandling/src/LoadVulcanCalFile.cpp @@ -393,9 +393,8 @@ void LoadVulcanCalFile::processOffsets( std::set<int> set_bankID; map<detid_t, pair<bool, int>> map_verify; // key: detector ID, value: flag to have a match, bank ID - for (auto miter = map_detoffset.begin(); miter != map_detoffset.end(); - ++miter) { - detid_t pid = miter->first; + for (auto &miter : map_detoffset) { + detid_t pid = miter.first; auto fiter = map_det2index.find(pid); if (fiter == map_det2index.end()) { map_verify.insert(make_pair(pid, make_pair(false, -1))); @@ -421,8 +420,7 @@ void LoadVulcanCalFile::processOffsets( static const size_t arr[] = {21, 22, 23, 26, 27, 28}; vector<size_t> vec_banks(arr, arr + sizeof(arr) / sizeof(arr[0])); - for (size_t i = 0; i < vec_banks.size(); ++i) { - size_t bankindex = vec_banks[i]; + for (unsigned long bankindex : vec_banks) { for (size_t j = 0; j < NUMBERDETECTORPERMODULE; ++j) { detid_t detindex = static_cast<detid_t>(bankindex * NUMBERRESERVEDPERMODULE + j); diff --git a/Framework/DataHandling/src/ProcessDasNexusLog.cpp b/Framework/DataHandling/src/ProcessDasNexusLog.cpp index bf766508f08..1737749c8c8 100644 --- a/Framework/DataHandling/src/ProcessDasNexusLog.cpp +++ b/Framework/DataHandling/src/ProcessDasNexusLog.cpp @@ -177,8 +177,8 @@ void ProcessDasNexusLog::addLog(API::MatrixWorkspace_sptr ws, // 2. Add log auto newlog = new Kernel::TimeSeriesProperty<double>(logname); - for (size_t i = 0; i < timevec.size(); i++) { - newlog->addValue(timevec[i], unifylogvalue); + for (auto &i : timevec) { + newlog->addValue(i, unifylogvalue); } ws->mutableRun().addProperty(newlog, true); @@ -402,11 +402,11 @@ void ProcessDasNexusLog::convertToAbsoluteTime( if (tnow > prevtime) { // (a) Process previous logs std::sort(tofs.begin(), tofs.end()); - for (size_t j = 0; j < tofs.size(); j++) { + for (double tof : tofs) { Kernel::DateAndTime temptime = - prevtime + static_cast<int64_t>(tofs[j] * 100); + prevtime + static_cast<int64_t>(tof * 100); abstimevec.push_back(temptime); - orderedtofs.push_back(tofs[j]); + orderedtofs.push_back(tof); } // (b) Clear tofs.clear(); @@ -422,11 +422,10 @@ void ProcessDasNexusLog::convertToAbsoluteTime( if (!tofs.empty()) { // (a) Process previous logs: note value is in unit of 100 nano-second std::sort(tofs.begin(), tofs.end()); - for (size_t j = 0; j < tofs.size(); j++) { - Kernel::DateAndTime temptime = - prevtime + static_cast<int64_t>(tofs[j] * 100); + for (double tof : tofs) { + Kernel::DateAndTime temptime = prevtime + static_cast<int64_t>(tof * 100); abstimevec.push_back(temptime); - orderedtofs.push_back(tofs[j]); + orderedtofs.push_back(tof); } } else { throw std::runtime_error("Impossible for this to happen!"); @@ -467,11 +466,11 @@ void ProcessDasNexusLog::writeLogtoFile(API::MatrixWorkspace_sptr ws, if (tnow > prevtime) { // (a) Process previous logs std::sort(tofs.begin(), tofs.end()); - for (size_t j = 0; j < tofs.size(); j++) { + for (double tof : tofs) { Kernel::DateAndTime temptime = - prevtime + static_cast<int64_t>(tofs[j] * 100); + prevtime + static_cast<int64_t>(tof * 100); ofs << temptime.totalNanoseconds() << "\t" << tnow.totalNanoseconds() - << "\t" << tofs[j] * 0.1 << std::endl; + << "\t" << tof * 0.1 << std::endl; } // (b) Clear tofs.clear(); @@ -486,11 +485,10 @@ void ProcessDasNexusLog::writeLogtoFile(API::MatrixWorkspace_sptr ws, if (!tofs.empty()) { // (a) Process previous logs: note value is in unit of 100 nano-second std::sort(tofs.begin(), tofs.end()); - for (size_t j = 0; j < tofs.size(); j++) { - Kernel::DateAndTime temptime = - prevtime + static_cast<int64_t>(tofs[j] * 100); + for (double tof : tofs) { + Kernel::DateAndTime temptime = prevtime + static_cast<int64_t>(tof * 100); ofs << temptime.totalNanoseconds() << "\t" << prevtime.totalNanoseconds() - << "\t" << tofs[j] * 0.1 << std::endl; + << "\t" << tof * 0.1 << std::endl; } } else { throw std::runtime_error("Impossible for this to happen!"); diff --git a/Framework/DataHandling/src/SNSDataArchive.cpp b/Framework/DataHandling/src/SNSDataArchive.cpp index 1048c22c38a..cb903d523b0 100644 --- a/Framework/DataHandling/src/SNSDataArchive.cpp +++ b/Framework/DataHandling/src/SNSDataArchive.cpp @@ -45,8 +45,8 @@ SNSDataArchive::getArchivePath(const std::set<std::string> &filenames, // ICAT4 web service take upper case filename such as HYSA_2662 std::transform(filename.begin(), filename.end(), filename.begin(), toupper); - for (auto iter2 = exts.cbegin(); iter2 != exts.cend(); ++iter2) { - g_log.debug() << *iter2 << ";"; + for (const auto &ext : exts) { + g_log.debug() << ext << ";"; } g_log.debug() << "\n"; @@ -79,8 +79,8 @@ SNSDataArchive::getArchivePath(const std::set<std::string> &filenames, } } - for (auto ext = exts.begin(); ext != exts.cend(); ++ext) { - std::string datafile = filename + *ext; + for (const auto &ext : exts) { + std::string datafile = filename + ext; std::vector<std::string>::const_iterator iter = locations.begin(); for (; iter != locations.end(); ++iter) { if (boost::algorithm::ends_with((*iter), datafile)) { diff --git a/Framework/DataHandling/src/SaveAscii.cpp b/Framework/DataHandling/src/SaveAscii.cpp index 569ea6ee768..8212073efb4 100644 --- a/Framework/DataHandling/src/SaveAscii.cpp +++ b/Framework/DataHandling/src/SaveAscii.cpp @@ -59,10 +59,10 @@ void SaveAscii::init() { {"SemiColon", ";"}, {"UserDefined", "UserDefined"}}; std::vector<std::string> sepOptions; - for (size_t i = 0; i < 6; ++i) { - std::string option = spacers[i][0]; + for (auto &spacer : spacers) { + std::string option = spacer[0]; m_separatorIndex.insert( - std::pair<std::string, std::string>(option, spacers[i][1])); + std::pair<std::string, std::string>(option, spacer[1])); sepOptions.push_back(option); } @@ -150,11 +150,11 @@ void SaveAscii::exec() { // Add spectra list into the index list if (!spec_list.empty()) { - for (size_t i = 0; i < spec_list.size(); i++) { - if (spec_list[i] >= nSpectra) + for (int &i : spec_list) { + if (i >= nSpectra) throw std::invalid_argument("Inconsistent spectra list"); else - idx.insert(spec_list[i]); + idx.insert(i); } } if (!idx.empty()) @@ -181,10 +181,10 @@ void SaveAscii::exec() { file << " , DX" << spec; } else - for (auto spec = idx.cbegin(); spec != idx.cend(); ++spec) { - file << comstr << "Y" << *spec << comstr << errstr << *spec << errstr2; + for (value_type spec : idx) { + file << comstr << "Y" << spec << comstr << errstr << spec << errstr2; if (write_dx) - file << " , DX" << *spec; + file << " , DX" << spec; } file << std::endl; } @@ -214,11 +214,11 @@ void SaveAscii::exec() { file << ws->readE(spec)[bin]; } else - for (auto spec = idx.cbegin(); spec != idx.cend(); ++spec) { + for (value_type spec : idx) { file << sep; - file << ws->readY(*spec)[bin]; + file << ws->readY(spec)[bin]; file << sep; - file << ws->readE(*spec)[bin]; + file << ws->readE(spec)[bin]; } if (write_dx) { diff --git a/Framework/DataHandling/src/SaveAscii2.cpp b/Framework/DataHandling/src/SaveAscii2.cpp index 2f31a286492..d36b383826d 100644 --- a/Framework/DataHandling/src/SaveAscii2.cpp +++ b/Framework/DataHandling/src/SaveAscii2.cpp @@ -71,10 +71,10 @@ void SaveAscii2::init() { {"SemiColon", ";"}, {"UserDefined", "UserDefined"}}; std::vector<std::string> sepOptions; - for (size_t i = 0; i < 6; ++i) { - std::string option = spacers[i][0]; + for (auto &spacer : spacers) { + std::string option = spacer[0]; m_separatorIndex.insert( - std::pair<std::string, std::string>(option, spacers[i][1])); + std::pair<std::string, std::string>(option, spacer[1])); sepOptions.push_back(option); } @@ -181,11 +181,11 @@ void SaveAscii2::exec() { // Add spectra list into the index list if (!spec_list.empty()) { - for (size_t i = 0; i < spec_list.size(); i++) { - if (spec_list[i] >= nSpectra) { + for (int &i : spec_list) { + if (i >= nSpectra) { throw std::invalid_argument("Inconsistent spectra list"); } else { - idx.insert(spec_list[i]); + idx.insert(i); } } } diff --git a/Framework/DataHandling/src/SaveCSV.cpp b/Framework/DataHandling/src/SaveCSV.cpp index d73643c8301..fb4265b3ac3 100644 --- a/Framework/DataHandling/src/SaveCSV.cpp +++ b/Framework/DataHandling/src/SaveCSV.cpp @@ -129,8 +129,8 @@ void SaveCSV::exec() { outCSV_File << "A"; - for (int j = 0; j < (int)xValue.size(); j++) { - outCSV_File << std::setw(15) << xValue[j] << m_separator; + for (double j : xValue) { + outCSV_File << std::setw(15) << j << m_separator; } outCSV_File << m_lineSeparator; @@ -147,8 +147,8 @@ void SaveCSV::exec() { if (xValue != xValuePrevious) { outCSV_File << "A"; - for (int j = 0; j < (int)xValue.size(); j++) { - outCSV_File << std::setw(15) << xValue[j] << m_separator; + for (double j : xValue) { + outCSV_File << std::setw(15) << j << m_separator; } outCSV_File << m_lineSeparator; @@ -161,8 +161,8 @@ void SaveCSV::exec() { outCSV_File << i; - for (int j = 0; j < (int)yValue.size(); j++) { - outCSV_File << std::setw(15) << yValue[j] << m_separator; + for (double j : yValue) { + outCSV_File << std::setw(15) << j << m_separator; } outCSV_File << m_lineSeparator; @@ -177,8 +177,8 @@ void SaveCSV::exec() { outCSV_File << i; - for (int j = 0; j < (int)eValue.size(); j++) { - outCSV_File << std::setw(15) << eValue[j] << m_separator; + for (double j : eValue) { + outCSV_File << std::setw(15) << j << m_separator; } outCSV_File << m_lineSeparator; p.report(); @@ -213,8 +213,8 @@ void SaveCSV::saveXerrors(std::ofstream &stream, stream << i; - for (int j = 0; j < (int)dXvalue.size(); j++) { - stream << std::setw(15) << dXvalue[j] << m_separator; + for (double j : dXvalue) { + stream << std::setw(15) << j << m_separator; } stream << m_lineSeparator; p.report("Saving x errors..."); diff --git a/Framework/DataHandling/src/SaveCanSAS1D.cpp b/Framework/DataHandling/src/SaveCanSAS1D.cpp index 33224957650..3adb13d3030 100644 --- a/Framework/DataHandling/src/SaveCanSAS1D.cpp +++ b/Framework/DataHandling/src/SaveCanSAS1D.cpp @@ -308,9 +308,9 @@ void SaveCanSAS1D::searchandreplaceSpecialChars(std::string &input) { std::string specialchars = "&<>'\""; std::string::size_type searchIndex = 0; std::string::size_type findIndex; - for (std::string::size_type i = 0; i < specialchars.size(); ++i) { + for (char specialchar : specialchars) { while (searchIndex < input.length()) { - findIndex = input.find(specialchars[i], searchIndex); + findIndex = input.find(specialchar, searchIndex); if (findIndex != std::string::npos) { searchIndex = findIndex + 1; // replace with xml entity refrence diff --git a/Framework/DataHandling/src/SaveDetectorsGrouping.cpp b/Framework/DataHandling/src/SaveDetectorsGrouping.cpp index 78cb9fc24eb..a5d0a77437c 100644 --- a/Framework/DataHandling/src/SaveDetectorsGrouping.cpp +++ b/Framework/DataHandling/src/SaveDetectorsGrouping.cpp @@ -119,8 +119,8 @@ void SaveDetectorsGrouping::createGroupDetectorIDMap( throw; } detid_t detid = 0; - for (auto it = detids.begin(); it != detids.end(); ++it) { - detid = *it; + for (value_type it : detids) { + detid = it; } it->second.push_back(detid); } @@ -135,21 +135,21 @@ void SaveDetectorsGrouping::convertToDetectorsRanges( std::map<int, std::vector<detid_t>> groupdetidsmap, std::map<int, std::vector<detid_t>> &groupdetidrangemap) { - for (auto it = groupdetidsmap.begin(); it != groupdetidsmap.end(); ++it) { + for (auto &it : groupdetidsmap) { // a) Get handler of group ID and detector Id vector - int groupid = it->first; - sort(it->second.begin(), it->second.end()); + int groupid = it.first; + sort(it.second.begin(), it.second.end()); - g_log.debug() << "Group " << groupid << " has " << it->second.size() + g_log.debug() << "Group " << groupid << " has " << it.second.size() << " detectors. " << std::endl; // b) Group to ranges std::vector<detid_t> detranges; - detid_t st = it->second[0]; + detid_t st = it.second[0]; detid_t ed = st; - for (size_t i = 1; i < it->second.size(); i++) { - detid_t detid = it->second[i]; + for (size_t i = 1; i < it.second.size(); i++) { + detid_t detid = it.second[i]; if (detid == ed + 1) { // consecutive ed = detid; @@ -197,11 +197,10 @@ void SaveDetectorsGrouping::printToXML( } // 3. Append Groups - for (auto it = groupdetidrangemap.begin(); it != groupdetidrangemap.end(); - ++it) { + for (auto &it : groupdetidrangemap) { // a) Group Node - int groupid = it->first; + int groupid = it.first; std::stringstream sid; sid << groupid; @@ -222,12 +221,12 @@ void SaveDetectorsGrouping::printToXML( // b) Detector ID Child Nodes std::stringstream ss; - for (size_t i = 0; i < it->second.size() / 2; i++) { + for (size_t i = 0; i < it.second.size() / 2; i++) { // i. Generate text value bool writedata = true; - detid_t ist = it->second[i * 2]; - detid_t ied = it->second[i * 2 + 1]; + detid_t ist = it.second[i * 2]; + detid_t ied = it.second[i * 2 + 1]; // "a-b" or "a" if (ist < ied) { ss << ist << "-" << ied; @@ -239,12 +238,12 @@ void SaveDetectorsGrouping::printToXML( throw std::invalid_argument("Impossible to have this sitaution!"); } // add "," - if (writedata && i < it->second.size() / 2 - 1) { + if (writedata && i < it.second.size() / 2 - 1) { ss << ","; } - g_log.debug() << "Detectors: " << it->second[i * 2] << ", " - << it->second[i * 2 + 1] << std::endl; + g_log.debug() << "Detectors: " << it.second[i * 2] << ", " + << it.second[i * 2 + 1] << std::endl; } // FOREACH Detectors Range Set std::string textvalue = ss.str(); diff --git a/Framework/DataHandling/src/SaveDiffCal.cpp b/Framework/DataHandling/src/SaveDiffCal.cpp index 9d17f2e8a92..3b6c105fb75 100644 --- a/Framework/DataHandling/src/SaveDiffCal.cpp +++ b/Framework/DataHandling/src/SaveDiffCal.cpp @@ -238,8 +238,8 @@ void SaveDiffCal::generateDetidToIndex() { bool SaveDiffCal::tableHasColumn(const std::string name) const { const std::vector<std::string> names = m_calibrationWS->getColumnNames(); - for (auto it = names.begin(); it != names.end(); ++it) { - if (name == (*it)) + for (const auto &it : names) { + if (name == it) return true; } diff --git a/Framework/DataHandling/src/SaveFullprofResolution.cpp b/Framework/DataHandling/src/SaveFullprofResolution.cpp index 5ef18d5b0db..f5dafd1fd0e 100644 --- a/Framework/DataHandling/src/SaveFullprofResolution.cpp +++ b/Framework/DataHandling/src/SaveFullprofResolution.cpp @@ -166,8 +166,8 @@ void SaveFullprofResolution::parseTableWorkspace() { size_t numcols = colnames.size(); stringstream dbmsgss("Input table's column names: "); - for (size_t i = 0; i < colnames.size(); ++i) { - dbmsgss << setw(20) << colnames[i]; + for (auto &colname : colnames) { + dbmsgss << setw(20) << colname; } g_log.debug(dbmsgss.str()); diff --git a/Framework/DataHandling/src/SaveGSASInstrumentFile.cpp b/Framework/DataHandling/src/SaveGSASInstrumentFile.cpp index cee57a816a7..9f403cf0176 100644 --- a/Framework/DataHandling/src/SaveGSASInstrumentFile.cpp +++ b/Framework/DataHandling/src/SaveGSASInstrumentFile.cpp @@ -231,9 +231,9 @@ ChopperConfiguration::parseStringDbl(const string &instring) const { boost::split(strs, instring, boost::is_any_of(", ")); vector<double> vecdouble; - for (size_t i = 0; i < strs.size(); i++) { - if (strs[i].size() > 0) { - double item = atof(strs[i].c_str()); + for (auto &str : strs) { + if (str.size() > 0) { + double item = atof(str.c_str()); vecdouble.push_back(item); // cout << "[C] |" << strs[i] << "|" << item << "\n"; } @@ -254,9 +254,9 @@ ChopperConfiguration::parseStringUnsignedInt(const string &instring) const { boost::split(strs, instring, boost::is_any_of(", ")); vector<unsigned int> vecinteger; - for (size_t i = 0; i < strs.size(); i++) { - if (strs[i].size() > 0) { - int item = atoi(strs[i].c_str()); + for (auto &str : strs) { + if (str.size() > 0) { + int item = atoi(str.c_str()); if (item < 0) { throw runtime_error( "Found negative number in a string for unsigned integers."); @@ -365,9 +365,8 @@ void SaveGSASInstrumentFile::exec() { // Deal with a default if (m_vecBankID2File.empty()) { // Default is to export all banks - for (auto miter = bankprofileparammap.begin(); - miter != bankprofileparammap.end(); ++miter) { - unsigned int bankid = miter->first; + for (auto &miter : bankprofileparammap) { + unsigned int bankid = miter.first; m_vecBankID2File.push_back(bankid); } sort(m_vecBankID2File.begin(), m_vecBankID2File.end()); @@ -552,8 +551,8 @@ void SaveGSASInstrumentFile::parseProfileTableWorkspace( stringstream db1ss; db1ss << "[DBx912] Number of banks in profile table = " << vecbankindex.size() << " containing bank "; - for (size_t i = 0; i < vecbankindex.size(); ++i) - db1ss << vecbankindex[i] << ", "; + for (unsigned int i : vecbankindex) + db1ss << i << ", "; g_log.information(db1ss.str()); // Construct output @@ -704,8 +703,7 @@ void SaveGSASInstrumentFile::convertToGSAS( throw runtime_error("Not set up yet!"); // Set up min-dsp, max-tof - for (size_t i = 0; i < outputbankids.size(); ++i) { - unsigned int bankid = outputbankids[i]; + for (unsigned int bankid : outputbankids) { if (!m_configuration->hasBank(bankid)) throw runtime_error( "Chopper configuration does not have some certain bank."); @@ -724,8 +722,7 @@ void SaveGSASInstrumentFile::convertToGSAS( // Convert and write vector<unsigned int> banks = outputbankids; sort(banks.begin(), banks.end()); - for (size_t ib = 0; ib < banks.size(); ++ib) { - unsigned int bankid = banks[ib]; + for (unsigned int bankid : banks) { if (m_configuration->hasBank(bankid)) { buildGSASTabulatedProfile(bankprofilemap, bankid); writePRMSingleBank(bankprofilemap, bankid, gsasinstrfilename); @@ -1077,9 +1074,8 @@ double SaveGSASInstrumentFile::getProfileParameterValue( stringstream errss; errss << "Profile map does not contain parameter " << paramname << ". Available parameters are "; - for (auto piter = profilemap.cbegin(); piter != profilemap.cend(); - ++piter) { - errss << piter->first << ", "; + for (const auto &piter : profilemap) { + errss << piter.first << ", "; } g_log.error(errss.str()); throw runtime_error(errss.str()); diff --git a/Framework/DataHandling/src/SaveGSS.cpp b/Framework/DataHandling/src/SaveGSS.cpp index 28b217eb934..aa8dab8310a 100644 --- a/Framework/DataHandling/src/SaveGSS.cpp +++ b/Framework/DataHandling/src/SaveGSS.cpp @@ -472,10 +472,10 @@ void SaveGSS::writeHeaders(const std::string &format, std::stringstream &os, bool norm_by_monitor = false; const Mantid::API::AlgorithmHistories &algohist = inputWS->getHistory().getAlgorithmHistories(); - for (auto it = algohist.cbegin(); it != algohist.cend(); ++it) { - if ((*it)->name().compare("NormaliseByCurrent") == 0) + for (const auto &it : algohist) { + if (it->name().compare("NormaliseByCurrent") == 0) norm_by_current = true; - if ((*it)->name().compare("NormaliseToMonitor") == 0) + if (it->name().compare("NormaliseToMonitor") == 0) norm_by_monitor = true; } os << "#"; diff --git a/Framework/DataHandling/src/SaveILLCosmosAscii.cpp b/Framework/DataHandling/src/SaveILLCosmosAscii.cpp index 11c2a9ba4b6..e05dc58e5b9 100644 --- a/Framework/DataHandling/src/SaveILLCosmosAscii.cpp +++ b/Framework/DataHandling/src/SaveILLCosmosAscii.cpp @@ -66,9 +66,9 @@ void SaveILLCosmosAscii::extraHeaders(std::ofstream &file) { const std::vector<std::string> logList = getProperty("LogList"); /// logs - for (auto log = logList.begin(); log != logList.end(); ++log) { - file << boost::lexical_cast<std::string>(*log) << ": " - << boost::lexical_cast<std::string>(samp.getLogData(*log)->value()) + for (const auto &log : logList) { + file << boost::lexical_cast<std::string>(log) << ": " + << boost::lexical_cast<std::string>(samp.getLogData(log)->value()) << std::endl; } diff --git a/Framework/DataHandling/src/SaveISISNexus.cpp b/Framework/DataHandling/src/SaveISISNexus.cpp index 727565fad93..b3eed9fec06 100644 --- a/Framework/DataHandling/src/SaveISISNexus.cpp +++ b/Framework/DataHandling/src/SaveISISNexus.cpp @@ -322,8 +322,8 @@ int SaveISISNexus::saveStringVectorOpen(const char *name, } int buff_size = max_str_size; if (buff_size <= 0) - for (std::size_t i = 0; i < str_vec.size(); ++i) { - buff_size = std::max(buff_size, int(str_vec[i].size())); + for (const auto &i : str_vec) { + buff_size = std::max(buff_size, int(i.size())); } if (buff_size <= 0) buff_size = 1; @@ -968,8 +968,8 @@ void SaveISISNexus::selog() { // create a log for each of the found log files std::size_t nBase = base_name.size() + 1; - for (std::size_t i = 0; i < potentialLogFiles.size(); ++i) { - std::string logName = Poco::Path(potentialLogFiles[i]).getFileName(); + for (auto &potentialLogFile : potentialLogFiles) { + std::string logName = Poco::Path(potentialLogFile).getFileName(); logName.erase(0, nBase); logName.erase(logName.size() - 4); if (logName.size() > 3) { @@ -979,9 +979,9 @@ void SaveISISNexus::selog() { continue; } - std::ifstream fil(potentialLogFiles[i].c_str()); + std::ifstream fil(potentialLogFile.c_str()); if (!fil) { - g_log.warning("Cannot open log file " + potentialLogFiles[i]); + g_log.warning("Cannot open log file " + potentialLogFile); continue; } diff --git a/Framework/DataHandling/src/SaveIsawDetCal.cpp b/Framework/DataHandling/src/SaveIsawDetCal.cpp index 1403f5f74b4..392eeef81cd 100644 --- a/Framework/DataHandling/src/SaveIsawDetCal.cpp +++ b/Framework/DataHandling/src/SaveIsawDetCal.cpp @@ -91,8 +91,8 @@ void SaveIsawDetCal::exec() { std::vector<IComponent_const_sptr> comps; inst->getChildren(comps, true); - for (size_t i = 0; i < comps.size(); i++) { - std::string bankName = comps[i]->getName(); + for (auto &comp : comps) { + std::string bankName = comp->getName(); boost::trim(bankName); boost::erase_all(bankName, bankPart); int bank = 0; @@ -103,8 +103,7 @@ void SaveIsawDetCal::exec() { uniqueBanks.insert(bank); } } else { - for (size_t i = 0; i < bankNames.size(); i++) { - std::string bankName = bankNames[i]; + for (auto bankName : bankNames) { boost::trim(bankName); boost::erase_all(bankName, bankPart); int bank = 0; diff --git a/Framework/DataHandling/src/SaveNXTomo.cpp b/Framework/DataHandling/src/SaveNXTomo.cpp index 02e49ef74d7..b79348ede49 100644 --- a/Framework/DataHandling/src/SaveNXTomo.cpp +++ b/Framework/DataHandling/src/SaveNXTomo.cpp @@ -110,8 +110,8 @@ void SaveNXTomo::processAll() { m_includeError = getProperty("IncludeError"); m_overwriteFile = getProperty("OverwriteFile"); - for (auto it = m_workspaces.begin(); it != m_workspaces.end(); ++it) { - const std::string workspaceID = (*it)->id(); + for (auto &m_workspace : m_workspaces) { + const std::string workspaceID = m_workspace->id(); if ((workspaceID.find("Workspace2D") == std::string::npos) && (workspaceID.find("RebinnedOutput") == std::string::npos)) @@ -119,7 +119,7 @@ void SaveNXTomo::processAll() { "SaveNXTomo passed invalid workspaces. Must be Workspace2D"); // Do the full check for common binning - if (!WorkspaceHelpers::commonBoundaries(*it)) { + if (!WorkspaceHelpers::commonBoundaries(m_workspace)) { g_log.error("The input workspace must have common bins"); throw std::invalid_argument("The input workspace must have common bins"); } @@ -156,8 +156,8 @@ void SaveNXTomo::processAll() { // Create a progress reporting object Progress progress(this, 0, 1, m_workspaces.size()); - for (auto it = m_workspaces.begin(); it != m_workspaces.end(); ++it) { - writeSingleWorkspace(*it, nxFile); + for (auto &m_workspace : m_workspaces) { + writeSingleWorkspace(m_workspace, nxFile); progress.report(); } @@ -405,8 +405,7 @@ void SaveNXTomo::writeLogValues(const DataObjects::Workspace2D_sptr workspace, // value std::vector<Property *> logVals = workspace->run().getLogData(); - for (auto it = logVals.begin(); it != logVals.end(); ++it) { - auto prop = *it; + for (auto prop : logVals) { if (prop->name() != "ImageKey" && prop->name() != "Rotation" && prop->name() != "Intensity" && prop->name() != "Axis1" && prop->name() != "Axis2") { diff --git a/Framework/DataHandling/src/SaveNexusProcessed.cpp b/Framework/DataHandling/src/SaveNexusProcessed.cpp index b1cce74d4f6..60a83f0fe30 100644 --- a/Framework/DataHandling/src/SaveNexusProcessed.cpp +++ b/Framework/DataHandling/src/SaveNexusProcessed.cpp @@ -113,8 +113,7 @@ void SaveNexusProcessed::getSpectrumList( for (int i = spec_min; i <= spec_max; i++) spec.push_back(i); if (list) { - for (size_t i = 0; i < spec_list.size(); i++) { - int s = spec_list[i]; + for (int s : spec_list) { if (s < 0) continue; if (s < spec_min || s > spec_max) @@ -124,8 +123,7 @@ void SaveNexusProcessed::getSpectrumList( } else if (list) { spec_max = 0; spec_min = numberOfHist - 1; - for (size_t i = 0; i < spec_list.size(); i++) { - int s = spec_list[i]; + for (int s : spec_list) { if (s < 0) continue; spec.push_back(s); diff --git a/Framework/DataHandling/src/SaveOpenGenieAscii.cpp b/Framework/DataHandling/src/SaveOpenGenieAscii.cpp index 002073671c1..4fc7fc51d41 100644 --- a/Framework/DataHandling/src/SaveOpenGenieAscii.cpp +++ b/Framework/DataHandling/src/SaveOpenGenieAscii.cpp @@ -103,8 +103,8 @@ void SaveOpenGenieAscii::exec() { // writes out x, y, e to vector std::string alpha; - for (int Num = 0; Num < 3; Num++) { - alpha = Alpha[Num]; + for (const auto &Num : Alpha) { + alpha = Num; axisToFile(alpha, singleSpc, fourspc, nBins, isHistogram); } @@ -236,10 +236,10 @@ std::string SaveOpenGenieAscii::getAxisValues(std::string alpha, int bin, void SaveOpenGenieAscii::getSampleLogs(std::string fourspc) { const std::vector<Property *> &logData = ws->run().getLogData(); - for (auto log = logData.begin(); log != logData.end(); ++log) { - std::string name = (*log)->name(); - std::string type = (*log)->type(); - std::string value = (*log)->value(); + for (auto log : logData) { + std::string name = log->name(); + std::string type = log->type(); + std::string value = log->value(); if (type.std::string::find("vector") && type.std::string::find("double") != std::string::npos) { diff --git a/Framework/DataHandling/src/SaveParameterFile.cpp b/Framework/DataHandling/src/SaveParameterFile.cpp index 1644aee9015..f497d863dae 100644 --- a/Framework/DataHandling/src/SaveParameterFile.cpp +++ b/Framework/DataHandling/src/SaveParameterFile.cpp @@ -90,14 +90,14 @@ void SaveParameterFile::exec() { Progress prog(this, 0.0, 0.3, params->size()); // Build a list of parameters to save; - for (auto paramsIt = params->begin(); paramsIt != params->end(); ++paramsIt) { + for (auto ¶msIt : *params) { if (prog.hasCancellationBeenRequested()) break; prog.report("Generating parameters"); - const ComponentID cID = (*paramsIt).first; - const std::string pName = (*paramsIt).second->name(); - const std::string pType = (*paramsIt).second->type(); - const std::string pValue = (*paramsIt).second->asString(); + const ComponentID cID = paramsIt.first; + const std::string pName = paramsIt.second->name(); + const std::string pType = paramsIt.second->type(); + const std::string pValue = paramsIt.second->asString(); if (pName == "x" || pName == "y" || pName == "z" || pName == "r-position" || pName == "t-position" || pName == "p-position" || pName == "rotx" || @@ -140,7 +140,7 @@ void SaveParameterFile::exec() { // With fitting parameters we do something special (i.e. silly) // We create an entire XML element to be inserted into the output, // instead of just giving a single fixed value - const FitParameter &fitParam = paramsIt->second->value<FitParameter>(); + const FitParameter &fitParam = paramsIt.second->value<FitParameter>(); const std::string fpName = fitParam.getFunction() + ":" + fitParam.getName(); std::stringstream fpValue; @@ -166,12 +166,12 @@ void SaveParameterFile::exec() { prog.resetNumSteps((int64_t)toSave.size(), 0.6, 1.0); // Iterate through all the parameters we want to save and build an XML // document out of them. - for (auto compIt = toSave.begin(); compIt != toSave.end(); ++compIt) { + for (auto &compIt : toSave) { if (prog.hasCancellationBeenRequested()) break; prog.report("Saving parameters"); // Component data - const ComponentID cID = compIt->first; + const ComponentID cID = compIt.first; const std::string cFullName = cID->getFullName(); const IDetector *cDet = dynamic_cast<IDetector *>(cID); const detid_t cDetID = (cDet) ? cDet->getID() : 0; @@ -180,7 +180,7 @@ void SaveParameterFile::exec() { if (cDetID != 0) file << " id=\"" << cDetID << "\""; file << " name=\"" << cFullName << "\">\n"; - for (auto paramIt = compIt->second.begin(); paramIt != compIt->second.end(); + for (auto paramIt = compIt.second.begin(); paramIt != compIt.second.end(); ++paramIt) { const std::string pName = paramIt->get<0>(); const std::string pType = paramIt->get<1>(); diff --git a/Framework/DataHandling/src/SaveReflCustomAscii.cpp b/Framework/DataHandling/src/SaveReflCustomAscii.cpp index e907662a21e..0f93aa57d76 100644 --- a/Framework/DataHandling/src/SaveReflCustomAscii.cpp +++ b/Framework/DataHandling/src/SaveReflCustomAscii.cpp @@ -50,9 +50,9 @@ void SaveReflCustomAscii::extraHeaders(std::ofstream &file) { const std::vector<std::string> logList = getProperty("LogList"); /// logs - for (auto log = logList.begin(); log != logList.end(); ++log) { - file << boost::lexical_cast<std::string>(*log) << ": " - << boost::lexical_cast<std::string>(samp.getLogData(*log)->value()) + for (const auto &log : logList) { + file << boost::lexical_cast<std::string>(log) << ": " + << boost::lexical_cast<std::string>(samp.getLogData(log)->value()) << std::endl; } } diff --git a/Framework/DataHandling/src/SaveReflTBL.cpp b/Framework/DataHandling/src/SaveReflTBL.cpp index 080823d4ea0..2ef30a414af 100644 --- a/Framework/DataHandling/src/SaveReflTBL.cpp +++ b/Framework/DataHandling/src/SaveReflTBL.cpp @@ -73,9 +73,8 @@ void SaveReflTBL::exec() { throw Exception::FileError("Unable to create file: ", filename); } - for (auto iterator = m_stichgroups.begin(); iterator != m_stichgroups.end(); - ++iterator) { - std::vector<size_t> &rowNos = iterator->second; + for (auto &m_stichgroup : m_stichgroups) { + std::vector<size_t> &rowNos = m_stichgroup.second; size_t i = 0; for (; i < rowNos.size(); ++i) { // for each row in the group print the first 5 columns to file @@ -101,9 +100,8 @@ void SaveReflTBL::exec() { // now do the same for the ungrouped - for (auto iterator = m_nogroup.begin(); iterator != m_nogroup.end(); - ++iterator) { - TableRow row = ws->getRow(*iterator); + for (unsigned long &iterator : m_nogroup) { + TableRow row = ws->getRow(iterator); for (int j = 0; j < 5; ++j) { writeVal(row.cell<std::string>(j), file); } diff --git a/Framework/DataHandling/src/SaveReflThreeColumnAscii.cpp b/Framework/DataHandling/src/SaveReflThreeColumnAscii.cpp index 4c1fa580d52..de935f0ca38 100644 --- a/Framework/DataHandling/src/SaveReflThreeColumnAscii.cpp +++ b/Framework/DataHandling/src/SaveReflThreeColumnAscii.cpp @@ -34,9 +34,9 @@ void SaveReflThreeColumnAscii::extraHeaders(std::ofstream &file) { const std::vector<std::string> logList = getProperty("LogList"); /// logs - for (auto log = logList.begin(); log != logList.end(); ++log) { - file << boost::lexical_cast<std::string>(*log) << ": " - << boost::lexical_cast<std::string>(samp.getLogData(*log)->value()) + for (const auto &log : logList) { + file << boost::lexical_cast<std::string>(log) << ": " + << boost::lexical_cast<std::string>(samp.getLogData(log)->value()) << std::endl; } } diff --git a/Framework/DataHandling/src/SaveSavuTomoConfig.cpp b/Framework/DataHandling/src/SaveSavuTomoConfig.cpp index a329ed0bf50..1e21343377b 100644 --- a/Framework/DataHandling/src/SaveSavuTomoConfig.cpp +++ b/Framework/DataHandling/src/SaveSavuTomoConfig.cpp @@ -92,15 +92,16 @@ bool SaveSavuTomoConfig::tableLooksGenuine(const ITableWorkspace_sptr &tws) { std::vector<ITableWorkspace_sptr> SaveSavuTomoConfig::checkTables(const std::vector<std::string> &workspaces) { std::vector<ITableWorkspace_sptr> wss; - for (auto it = workspaces.begin(); it != workspaces.end(); ++it) { - if (AnalysisDataService::Instance().doesExist(*it)) { + for (const auto &workspace : workspaces) { + if (AnalysisDataService::Instance().doesExist(workspace)) { ITableWorkspace_sptr table = - AnalysisDataService::Instance().retrieveWS<ITableWorkspace>(*it); + AnalysisDataService::Instance().retrieveWS<ITableWorkspace>( + workspace); // Check it's valid. Very permissive check for the time being if (table && tableLooksGenuine(table)) { wss.push_back(table); } else { - throw std::runtime_error("Invalid workspace provided: " + *it + + throw std::runtime_error("Invalid workspace provided: " + workspace + ". This algorithm requires a table " "workspace with correct savu plugin/ " "pipeline process information."); @@ -109,7 +110,7 @@ SaveSavuTomoConfig::checkTables(const std::vector<std::string> &workspaces) { throw std::runtime_error( "One or more specified table workspaces don't exist. I could not " "find this one: " + - *it); + workspace); } } return wss; @@ -164,11 +165,10 @@ void SaveSavuTomoConfig::saveFile( // Iterate through all plugin entries (number sub groups 0....n-1) size_t procCount = 0; - for (size_t i = 0; i < wss.size(); ++i) { + for (auto w : wss) { // Concatenate table contents, putting pipeline processing steps in the same // sequence // as they come in the seq of table workspaces - ITableWorkspace_sptr w = wss[i]; for (size_t ti = 0; ti < w->rowCount(); ++ti) { // Column info order is [ID / Params {as json string} / name {description} // / diff --git a/Framework/DataHandling/src/SetScalingPSD.cpp b/Framework/DataHandling/src/SetScalingPSD.cpp index bc5384007eb..c1bbd1d2e7c 100644 --- a/Framework/DataHandling/src/SetScalingPSD.cpp +++ b/Framework/DataHandling/src/SetScalingPSD.cpp @@ -265,8 +265,8 @@ void SetScalingPSD::movePos(API::MatrixWorkspace_sptr &WS, // double prog=0.5; Progress prog(this, 0.5, 1.0, static_cast<int>(m_vectDet.size())); // loop over detector (IComps) - for (size_t id = 0; id < m_vectDet.size(); id++) { - comp = m_vectDet[id]; + for (auto &id : m_vectDet) { + comp = id; boost::shared_ptr<const IDetector> det = boost::dynamic_pointer_cast<const IDetector>(comp); int idet = 0; -- GitLab