Skip to content
Snippets Groups Projects
Commit 390052c2 authored by Brandon Hewer's avatar Brandon Hewer
Browse files

Ensure the grouping string is constructed correctly

Refs #22988
parent 36a60ddf
No related branches found
No related tags found
No related merge requests found
#include "ISISEnergyTransfer.h" #include "ISISEnergyTransfer.h"
#include "../General/UserInputValidator.h"
#include "MantidAPI/MatrixWorkspace.h" #include "MantidAPI/MatrixWorkspace.h"
#include "MantidAPI/WorkspaceGroup.h" #include "MantidAPI/WorkspaceGroup.h"
#include "../General/UserInputValidator.h"
#include <QFileInfo> #include <QFileInfo>
using namespace Mantid::API; using namespace Mantid::API;
using MantidQt::API::BatchAlgorithmRunner; using MantidQt::API::BatchAlgorithmRunner;
namespace {
std::string createRangeString(std::size_t from, std::size_t to) {
return std::to_string(from) + "-" + std::to_string(to);
}
std::string createGroupString(std::size_t start, std::size_t size) {
return createRangeString(start, start + size - 1);
}
std::string createGroupingString(std::size_t groupSize,
std::size_t numberOfGroups) {
auto groupingString = createRangeString(0, groupSize - 1);
for (auto i = groupSize; i < groupSize * numberOfGroups; i += groupSize)
groupingString += "," + createGroupString(i, groupSize);
return groupingString;
}
std::string createDetectorGroupingString(std::size_t groupSize,
std::size_t numberOfGroups,
std::size_t numberOfDetectors) {
const auto groupingString = createGroupingString(groupSize, numberOfGroups);
const auto remainder = numberOfDetectors % numberOfGroups;
if (remainder == 0)
return groupingString;
return groupingString + "," +
createRangeString(numberOfDetectors - remainder,
numberOfDetectors - 1);
}
std::string createDetectorGroupingString(std::size_t numberOfDetectors,
std::size_t numberOfGroups) {
const auto groupSize = numberOfDetectors / numberOfGroups;
if (groupSize == 0)
return createRangeString(0, numberOfDetectors);
return createDetectorGroupingString(groupSize, numberOfGroups,
numberOfDetectors);
}
} // namespace
namespace MantidQt { namespace MantidQt {
namespace CustomInterfaces { namespace CustomInterfaces {
//---------------------------------------------------------------------------------------------- //----------------------------------------------------------------------------------------------
...@@ -457,7 +498,7 @@ ISISEnergyTransfer::createMapFile(const std::string &groupType) { ...@@ -457,7 +498,7 @@ ISISEnergyTransfer::createMapFile(const std::string &groupType) {
return std::make_pair("File", groupFile.toStdString()); return std::make_pair("File", groupFile.toStdString());
} else if (groupType == "Groups") } else if (groupType == "Groups")
return std::make_pair("Custom", createDetectorGroupingString()); return std::make_pair("Custom", getDetectorGroupingString());
else if (groupType == "Default") else if (groupType == "Default")
return std::make_pair("IPF", ""); return std::make_pair("IPF", "");
else if (groupType == "Custom") else if (groupType == "Custom")
...@@ -469,25 +510,12 @@ ISISEnergyTransfer::createMapFile(const std::string &groupType) { ...@@ -469,25 +510,12 @@ ISISEnergyTransfer::createMapFile(const std::string &groupType) {
} }
} }
const std::string ISISEnergyTransfer::createDetectorGroupingString() { std::string ISISEnergyTransfer::getDetectorGroupingString() const {
const unsigned int nGroups = m_uiForm.spNumberGroups->value(); const unsigned int nGroups = m_uiForm.spNumberGroups->value();
const unsigned int nSpectra = const unsigned int nSpectra =
m_uiForm.spSpectraMax->value() - m_uiForm.spSpectraMin->value(); 1 + m_uiForm.spSpectraMax->value() - m_uiForm.spSpectraMin->value();
const unsigned int groupSize = nSpectra / nGroups; return createDetectorGroupingString(static_cast<std::size_t>(nSpectra),
auto n = groupSize; static_cast<std::size_t>(nGroups));
std::stringstream groupingString;
groupingString << "0-" << std::to_string(n);
for (auto i = 1u; i < nGroups; ++i) {
groupingString << ", " << std::to_string(n + 1) << "-";
n += groupSize;
groupingString << std::to_string(n);
}
if (n != nSpectra) // add remainder as extra group
groupingString << ", " << std::to_string(n + 1) << "-"
<< std::to_string(nSpectra);
return groupingString.str();
} }
/** /**
...@@ -575,6 +603,7 @@ void ISISEnergyTransfer::plotRaw() { ...@@ -575,6 +603,7 @@ void ISISEnergyTransfer::plotRaw() {
if (m_uiForm.ckBackgroundRemoval->isChecked()) { if (m_uiForm.ckBackgroundRemoval->isChecked()) {
MatrixWorkspace_sptr tempWs = MatrixWorkspace_sptr tempWs =
AnalysisDataService::Instance().retrieveWS<MatrixWorkspace>(name); AnalysisDataService::Instance().retrieveWS<MatrixWorkspace>(name);
const double minBack = tempWs->x(0)[0]; const double minBack = tempWs->x(0)[0];
const double maxBack = tempWs->x(0)[tempWs->blocksize()]; const double maxBack = tempWs->x(0)[tempWs->blocksize()];
...@@ -744,4 +773,4 @@ void ISISEnergyTransfer::saveClicked() { ...@@ -744,4 +773,4 @@ void ISISEnergyTransfer::saveClicked() {
} }
} // namespace CustomInterfaces } // namespace CustomInterfaces
} // namespace Mantid } // namespace MantidQt
...@@ -76,7 +76,7 @@ private: ...@@ -76,7 +76,7 @@ private:
std::vector<std::string> std::vector<std::string>
m_outputWorkspaces; ///< get a vector of workspaces to plot m_outputWorkspaces; ///< get a vector of workspaces to plot
QString validateDetectorGrouping(); QString validateDetectorGrouping();
const std::string createDetectorGroupingString(); std::string getDetectorGroupingString() const;
}; };
} // namespace CustomInterfaces } // namespace CustomInterfaces
} // namespace Mantid } // namespace Mantid
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment