Skip to content

Commit

Permalink
Merge pull request #37226 from jclarkeSTFC/37217_helium_analyser_cove…
Browse files Browse the repository at this point in the history
…rity

Fix Coverity issues in HeliumAnalyserEfficiency
  • Loading branch information
SilkeSchomann committed Apr 26, 2024
2 parents 08c54b8 + b66ebd9 commit 4d60af2
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 13 deletions.
Expand Up @@ -16,8 +16,7 @@ namespace PolarizationCorrectionsHelpers {
MANTID_ALGORITHMS_DLL API::MatrixWorkspace_sptr workspaceForSpinState(API::WorkspaceGroup_sptr group,
const std::string &spinStateOrder,
const std::string &targetSpinState);
MANTID_ALGORITHMS_DLL size_t indexOfWorkspaceForSpinState(API::WorkspaceGroup_sptr group,
const std::string &spinStateOrder,
MANTID_ALGORITHMS_DLL size_t indexOfWorkspaceForSpinState(const std::string &spinStateOrder,
const std::string &targetSpinState);
MANTID_ALGORITHMS_DLL std::vector<std::string> splitSpinStateString(const std::string &spinStates);
} // namespace PolarizationCorrectionsHelpers
Expand Down
Expand Up @@ -54,8 +54,7 @@ void HeliumAnalyserEfficiency::init() {
"Helium analyzer efficiency as a function of wavelength");

auto spinValidator = std::make_shared<SpinStateValidator>(std::unordered_set<int>{4});
std::string initialSpinConfig = "11,10,01,00";
declareProperty(PropertyNames::SPIN_STATES, initialSpinConfig, spinValidator,
declareProperty(PropertyNames::SPIN_STATES, "11,10,01,00", spinValidator,
"Order of individual spin states in the input group workspace, e.g. \"01,11,00,10\"");

auto mustBePositive = std::make_shared<BoundedValidator<double>>();
Expand Down Expand Up @@ -112,8 +111,9 @@ std::map<std::string, std::string> HeliumAnalyserEfficiency::validateInputs() {
*/
void HeliumAnalyserEfficiency::validateGroupInput() {
const auto results = validateInputs();
for (const auto &result : results) {
throw std::runtime_error("Issue in " + result.first + " property: " + result.second);
if (results.size() > 0) {
const auto result = results.cbegin();
throw std::runtime_error("Issue in " + result->first + " property: " + result->second);
}
}

Expand Down Expand Up @@ -150,8 +150,8 @@ void HeliumAnalyserEfficiency::calculateAnalyserEfficiency() {
// We're going to calculate e from the data, e = T_NSF / (T_NSF + T_SF),
// then fit (1 + tanh(mu * phe))/2 to it in order to calculate phe, the
// helium atom polarization in the analyser.
MatrixWorkspace_sptr denom = addTwoWorkspaces(tnsfWs, tsfWs);
MatrixWorkspace_sptr e = divideWorkspace(tnsfWs, denom);
MatrixWorkspace_sptr denom = addTwoWorkspaces(tnsfWs, std::move(tsfWs));
MatrixWorkspace_sptr e = divideWorkspace(std::move(tnsfWs), std::move(denom));

// Now we fit (1 + tanh(mu*pHe*x))/2 to P to give us pHe

Expand All @@ -161,7 +161,7 @@ void HeliumAnalyserEfficiency::calculateAnalyserEfficiency() {
const MantidVec wavelengthValues = e->dataX(0);
double pHe, pHeError;
MantidVec eCalc;
fitAnalyserEfficiency(mu, e, wavelengthValues, pHe, pHeError, eCalc);
fitAnalyserEfficiency(mu, std::move(e), wavelengthValues, pHe, pHeError, eCalc);
auto efficiency = calculateEfficiencyWorkspace(wavelengthValues, eCalc, pHe, pHeError, mu);
setProperty(PropertyNames::OUTPUT_WORKSPACE, efficiency);
}
Expand Down
Expand Up @@ -19,17 +19,16 @@ state in the spin state order as the index of the workspace in the group.
*/
API::MatrixWorkspace_sptr workspaceForSpinState(API::WorkspaceGroup_sptr group, const std::string &spinStateOrder,
const std::string &targetSpinState) {
const auto wsIndex = indexOfWorkspaceForSpinState(group, spinStateOrder, targetSpinState);
const auto wsIndex = indexOfWorkspaceForSpinState(spinStateOrder, targetSpinState);
return std::dynamic_pointer_cast<API::MatrixWorkspace>(group->getItem(wsIndex));
}

/*
For a given workspace group, spin state order, and desired spin state, this method will
return the index of the specified workspace from the group, using the position of the desired spin
return the index of the specified workspace in the group, using the position of the desired spin
state in the spin state order.
*/
size_t indexOfWorkspaceForSpinState(API::WorkspaceGroup_sptr group, const std::string &spinStateOrder,
const std::string &targetSpinState) {
size_t indexOfWorkspaceForSpinState(const std::string &spinStateOrder, const std::string &targetSpinState) {
std::vector<std::string> spinStateVector = splitSpinStateString(spinStateOrder);
auto trimmedTargetSpinState = targetSpinState;
boost::trim(trimmedTargetSpinState);
Expand Down

0 comments on commit 4d60af2

Please sign in to comment.