Commit ed83c290 authored by Matthew D Jones's avatar Matthew D Jones
Browse files

Re #15287 Remove explicit use of std::set by using auto

parent e24e9368
......@@ -761,7 +761,7 @@ MatrixWorkspace::getDetector(const size_t workspaceIndex) const {
"workspace index.",
"");
const std::set<detid_t> &dets = spec->getDetectorIDs();
const auto &dets = spec->getDetectorIDs();
Instrument_const_sptr localInstrument = getInstrument();
if (!localInstrument) {
g_log.debug() << "No instrument defined.\n";
......@@ -1012,7 +1012,7 @@ void MatrixWorkspace::maskWorkspaceIndex(const std::size_t index) {
// Virtual method clears the spectrum as appropriate
spec->clearData();
const std::set<detid_t> dets = spec->getDetectorIDs();
const auto dets = spec->getDetectorIDs();
for (auto detId : dets) {
try {
if (const Geometry::Detector *det =
......@@ -1661,7 +1661,7 @@ void MatrixWorkspace::saveSpectraMapNexus(
spectra[i] = int32_t(spectrum->getSpectrumNo());
// The detectors in this spectrum
const std::set<detid_t> &detectorgroup = spectrum->getDetectorIDs();
const auto &detectorgroup = spectrum->getDetectorIDs();
const int ndet1 = static_cast<int>(detectorgroup.size());
detector_index[i + 1] = int32_t(
......
......@@ -104,7 +104,7 @@ std::set<specid_t> SpectrumDetectorMapping::getSpectrumNumbers() const {
const std::set<detid_t> &SpectrumDetectorMapping::getDetectorIDsForSpectrumNo(
const specid_t spectrumNo) const {
if (!m_indexIsSpecNo)
throw std::runtime_error("Indicies are in spectrum index, not number.");
throw std::runtime_error("Indices are in spectrum index, not number.");
return m_mapping.at(spectrumNo);
}
......@@ -112,7 +112,7 @@ const std::set<detid_t> &
SpectrumDetectorMapping::getDetectorIDsForSpectrumIndex(
const size_t spectrumIndex) const {
if (m_indexIsSpecNo)
throw std::runtime_error("Indicies are in spectrum number, not index.");
throw std::runtime_error("Indices are in spectrum number, not index.");
return m_mapping.at(static_cast<int>(spectrumIndex));
}
......
......@@ -123,10 +123,9 @@ void ConjoinWorkspaces::checkForOverlap(API::MatrixWorkspace_const_sptr ws1,
const ISpectrum *spec = ws1->getSpectrum(i);
const specid_t spectrum = spec->getSpectrumNo();
spectra.insert(spectrum);
const std::set<detid_t> &dets = spec->getDetectorIDs();
std::set<detid_t>::const_iterator it;
for (it = dets.begin(); it != dets.end(); ++it) {
detectors.insert(*it);
const auto &dets = spec->getDetectorIDs();
for (auto const &det : dets) {
detectors.insert(det);
}
}
......@@ -145,11 +144,10 @@ void ConjoinWorkspaces::checkForOverlap(API::MatrixWorkspace_const_sptr ws1,
"The input workspaces have overlapping spectrum numbers");
}
}
const std::set<detid_t> &dets = spec->getDetectorIDs();
std::set<detid_t>::const_iterator it;
for (it = dets.begin(); it != dets.end(); ++it) {
if (detectors.find(*it) != detectors.end()) {
g_log.error() << "The input workspaces have common detectors: " << (*it)
const auto &dets = spec->getDetectorIDs();
for (const auto &det : dets) {
if (detectors.find(det) != detectors.end()) {
g_log.error() << "The input workspaces have common detectors: " << (det)
<< "\n";
throw std::invalid_argument(
"The input workspaces have common detectors");
......
......@@ -776,8 +776,7 @@ void FilterEvents::setupCustomizedTOFCorrection() {
// If there are more than 1 spectrum, it is very likely to have problem
// with correction factor
const DataObjects::EventList events = m_eventWS->getEventList(i);
std::set<detid_t> detids = events.getDetectorIDs();
std::set<detid_t>::iterator detit;
auto detids = events.getDetectorIDs();
if (detids.size() != 1) {
// Check whether there are more than 1 detector per spectra.
stringstream errss;
......@@ -788,7 +787,7 @@ void FilterEvents::setupCustomizedTOFCorrection() {
throw runtime_error(errss.str());
}
detid_t detid = 0;
for (detit = detids.begin(); detit != detids.end(); ++detit)
for (auto detit = detids.begin(); detit != detids.end(); ++detit)
detid = *detit;
vecDetIDs[i] = detid;
}
......
......@@ -101,14 +101,13 @@ void FindDeadDetectors::exec() {
// Write the spectrum number to file
file << i << " " << specNo;
// Get the list of detectors for this spectrum and iterate over
const std::set<detid_t> &dets = spec->getDetectorIDs();
std::set<detid_t>::const_iterator it;
for (it = dets.begin(); it != dets.end(); ++it) {
const auto &dets = spec->getDetectorIDs();
for (const auto &det : dets) {
// Write the detector ID to file, log & the FoundDead output property
file << " " << *it;
file << " " << det;
// we could write dead detectors to the log but if they are viewing the
// log in the MantidPlot viewer it will crash MantidPlot
deadDets.push_back(*it);
deadDets.push_back(det);
++countDets;
}
file << std::endl;
......
......@@ -131,16 +131,15 @@ void GetDetectorOffsets::exec() {
}
// Get the list of detectors in this pixel
const std::set<detid_t> &dets = inputW->getSpectrum(wi)->getDetectorIDs();
const auto &dets = inputW->getSpectrum(wi)->getDetectorIDs();
// Most of the exec time is in FitSpectra, so this critical block should not
// be a problem.
PARALLEL_CRITICAL(GetDetectorOffsets_setValue) {
// Use the same offset for all detectors from this pixel
std::set<detid_t>::iterator it;
for (it = dets.begin(); it != dets.end(); ++it) {
outputW->setValue(*it, offset);
const auto mapEntry = pixel_to_wi.find(*it);
for (const auto &det : dets) {
outputW->setValue(det, offset);
const auto mapEntry = pixel_to_wi.find(det);
if (mapEntry == pixel_to_wi.end())
continue;
const size_t workspaceIndex = mapEntry->second;
......
......@@ -165,7 +165,7 @@ void GetEi::getGeometry(API::MatrixWorkspace_const_sptr WS, specid_t mon0Spec,
g_log.error() << "Error retrieving data for the first monitor" << std::endl;
throw std::bad_cast();
}
const std::set<detid_t> &dets = WS->getSpectrum(monWI)->getDetectorIDs();
const auto &dets = WS->getSpectrum(monWI)->getDetectorIDs();
if (dets.size() != 1) {
g_log.error() << "The detector for spectrum number " << mon0Spec
......@@ -187,7 +187,7 @@ void GetEi::getGeometry(API::MatrixWorkspace_const_sptr WS, specid_t mon0Spec,
g_log.error() << "Error retrieving data for the second monitor\n";
throw std::bad_cast();
}
const std::set<detid_t> &dets2 = WS->getSpectrum(monWI)->getDetectorIDs();
const auto &dets2 = WS->getSpectrum(monWI)->getDetectorIDs();
if (dets2.size() != 1) {
g_log.error() << "The detector for spectrum number " << mon1Spec
<< " was either not found or is a group, grouped monitors "
......
......@@ -72,7 +72,7 @@ void MaskDetectorsIf::exec() {
for (size_t i = 0; i < nspec; ++i) {
// Get the list of udets contributing to this spectra
const std::set<detid_t> &dets = inputW->getSpectrum(i)->getDetectorIDs();
const auto &dets = inputW->getSpectrum(i)->getDetectorIDs();
if (dets.empty())
continue;
......
......@@ -168,7 +168,7 @@ void MergeRuns::buildAdditionTables() {
table->reserve(nhist);
for (int inWI = 0; inWI < static_cast<int>(nhist); inWI++) {
// Get the set of detectors in the output
std::set<detid_t> &inDets = ews->getEventList(inWI).getDetectorIDs();
auto &inDets = ews->getEventList(inWI).getDetectorIDs();
bool done = false;
......@@ -177,7 +177,7 @@ void MergeRuns::buildAdditionTables() {
int outWI = inWI;
if (outWI < lhs_nhist) // don't go out of bounds
{
std::set<detid_t> &outDets = lhs->getEventList(outWI).getDetectorIDs();
auto &outDets = lhs->getEventList(outWI).getDetectorIDs();
// Checks that inDets is a subset of outDets
if (std::includes(outDets.begin(), outDets.end(), inDets.begin(),
......
......@@ -112,7 +112,7 @@ void ReadGroupsFromFile::exec() {
for (int64_t i = 0; i < nHist; i++) {
ISpectrum *spec = localWorkspace->getSpectrum(i);
const std::set<detid_t> &dets = spec->getDetectorIDs();
const auto &dets = spec->getDetectorIDs();
if (dets.empty()) // Nothing
{
spec->dataY()[0] = 0.0;
......
......@@ -355,7 +355,7 @@ void SmoothNeighbours::findNeighboursUbiqutious() {
// We want to skip monitors
try {
// Get the list of detectors in this pixel
const std::set<detid_t> &dets = inWS->getSpectrum(wi)->getDetectorIDs();
const auto &dets = inWS->getSpectrum(wi)->getDetectorIDs();
det = inst->getDetector(*dets.begin());
if (det->isMonitor())
continue; // skip monitor
......@@ -713,7 +713,7 @@ void SmoothNeighbours::setupNewInstrument(MatrixWorkspace_sptr outws) {
const ISpectrum *inSpec = inWS->getSpectrum(inWI);
std::set<detid_t> thesedetids = inSpec->getDetectorIDs();
auto thesedetids = inSpec->getDetectorIDs();
outSpec->addDetectorIDs(thesedetids);
} //(each neighbour)
......@@ -748,7 +748,7 @@ void SmoothNeighbours::spreadPixels(MatrixWorkspace_sptr outws) {
ISpectrum *inSpec = inWS->getSpectrum(outWIi);
MantidVec &inX = inSpec->dataX();
std::set<detid_t> thesedetids = inSpec->getDetectorIDs();
auto thesedetids = inSpec->getDetectorIDs();
ISpectrum *outSpec2 = outws2->getSpectrum(outWIi);
MantidVec &outX = outSpec2->dataX();
outX = inX;
......
......@@ -52,7 +52,7 @@ public:
TS_ASSERT_THROWS_NOTHING(
result = boost::dynamic_pointer_cast<MatrixWorkspace>(
AnalysisDataService::Instance().retrieve("to_remap")));
std::set<detid_t> resultDetIDs = result->getSpectrum(0)->getDetectorIDs();
auto resultDetIDs = result->getSpectrum(0)->getDetectorIDs();
TS_ASSERT(detIDs == resultDetIDs);
// Clean up workspace
......
......@@ -203,7 +203,7 @@ public:
// Now let's test the grouping of detector UDETS to groups
for (size_t wi = 0; wi < output->getNumberHistograms(); wi++) {
// This is the list of the detectors (grouped)
std::set<detid_t> mylist = output->getSpectrum(wi)->getDetectorIDs();
auto mylist = output->getSpectrum(wi)->getDetectorIDs();
// 1024 pixels in a bank
TS_ASSERT_EQUALS(mylist.size(), bankWidthInPixels * bankWidthInPixels);
}
......
......@@ -61,11 +61,10 @@ public:
API::ISpectrum *spectrum1 = workspace->getSpectrum(0);
Geometry::Instrument_const_sptr instrument = workspace->getInstrument();
std::set<detid_t> detids = spectrum1->getDetectorIDs();
auto detids = spectrum1->getDetectorIDs();
TS_ASSERT_EQUALS(detids.size(), 1);
detid_t detid = 0;
std::set<detid_t>::iterator it;
for (it = detids.begin(); it != detids.end(); ++it) {
for (auto it = detids.begin(); it != detids.end(); ++it) {
detid = *it;
}
Geometry::IDetector_const_sptr detector = instrument->getDetector(detid);
......@@ -172,11 +171,10 @@ public:
API::ISpectrum *spectrum1 = workspace->getSpectrum(wsindex);
Geometry::Instrument_const_sptr instrument = workspace->getInstrument();
std::set<detid_t> detids = spectrum1->getDetectorIDs();
auto detids = spectrum1->getDetectorIDs();
TS_ASSERT_EQUALS(detids.size(), 1);
detid_t detid = 0;
std::set<detid_t>::iterator it;
for (it = detids.begin(); it != detids.end(); ++it) {
for (auto it = detids.begin(); it != detids.end(); ++it) {
detid = *it;
}
Geometry::IDetector_const_sptr detector = instrument->getDetector(detid);
......@@ -195,11 +193,10 @@ public:
API::ISpectrum *spectrum1 = workspace->getSpectrum(wsindex);
Geometry::Instrument_const_sptr instrument = workspace->getInstrument();
std::set<detid_t> detids = spectrum1->getDetectorIDs();
auto detids = spectrum1->getDetectorIDs();
TS_ASSERT_EQUALS(detids.size(), 1);
detid_t thisdetid = 0;
std::set<detid_t>::iterator it;
for (it = detids.begin(); it != detids.end(); ++it) {
for (auto it = detids.begin(); it != detids.end(); ++it) {
thisdetid = *it;
}
......
......@@ -113,7 +113,7 @@ private:
TS_ASSERT_THROWS_NOTHING(spectrum = outputWS->getSpectrum(0));
if (spectrum) {
TS_ASSERT_EQUALS(spectrum->getSpectrumNo(), specID);
std::set<detid_t> detids = spectrum->getDetectorIDs();
auto detids = spectrum->getDetectorIDs();
TS_ASSERT_EQUALS(detids.size(), 1);
const detid_t id = *(detids.begin());
TS_ASSERT_EQUALS(id, detID);
......
......@@ -67,7 +67,7 @@ public:
// 4. Check output
for (size_t ih = 0; ih < ws4->getNumberHistograms(); ih++) {
std::set<detid_t> tempdetids = ws4->getDetectorIDs(ih);
auto tempdetids = ws4->getDetectorIDs(ih);
detid_t tempdetid = *(tempdetids.begin());
TS_ASSERT_EQUALS(tempdetids.size(), 1);
TS_ASSERT_DELTA(ws4->getValue(tempdetid), ws1->getValue(tempdetid), 1);
......
......@@ -279,9 +279,8 @@ public:
<< ".\n";
return;
} else {
std::set<detid_t> detidset = spec->getDetectorIDs();
set<detid_t>::iterator setiter;
for (setiter = detidset.begin(); setiter != detidset.end(); ++setiter)
auto detidset = spec->getDetectorIDs();
for (auto setiter = detidset.begin(); setiter != detidset.end(); ++setiter)
cout << "WorkspaceIndex = " << i << ": Detector ID = " << *setiter
<< ".\n";
}
......
......@@ -583,7 +583,7 @@ public:
//But two detector IDs in each one
for (int i=0; i<3; i++)
{
std::set<detid_t>::const_iterator detIT = work_out->getSpectrum(i)->getDetectorIDs().begin();
auto detIT = work_out->getSpectrum(i)->getDetectorIDs().begin();
TS_ASSERT_EQUALS( *detIT, 0+i );
if (DO_PLUS)
{
......
......@@ -354,10 +354,9 @@ void AnvredCorrection::execEvent() {
}
correctionFactors->getOrAddEventList(i) += events;
std::set<detid_t> &dets = eventW->getEventList(i).getDetectorIDs();
std::set<detid_t>::iterator j;
for (j = dets.begin(); j != dets.end(); ++j)
correctionFactors->getOrAddEventList(i).addDetectorID(*j);
auto &dets = eventW->getEventList(i).getDetectorIDs();
for (auto const &det : dets)
correctionFactors->getOrAddEventList(i).addDetectorID(det);
// When focussing in place, you can clear out old memory from the input one!
if (inPlace) {
eventW->getEventList(i).clear();
......
......@@ -109,7 +109,7 @@ void SaveDetectorsGrouping::createGroupDetectorIDMap(
<< " has no spectrum. Impossible!" << std::endl;
throw;
}
std::set<detid_t> detids = mspec->getDetectorIDs();
auto detids = mspec->getDetectorIDs();
if (detids.size() != 1) {
g_log.error() << "Spectrum " << mspec->getSpectrumNo() << " has "
<< detids.size() << " detectors. Not allowed situation!"
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment