Skip to content

Commit e088bb1

Browse files
Fix crash in PolarizationEfficiencyCor algorithm for wrong input (#39921)
### Description of work Details in issue #39832 <!-- Please provide an outline and reasoning for the work. If there is no linked issue provide context. --> Closes #39832. <!-- One line per closed issue. --> <!-- If issue raised by user. Do not leak email addresses. **Report to:** [user name] --> ### To test: Build the branch and check that this script throws an error but doesn't crash Mantid ( while in the nightly does): ``` from mantid.simpleapi import * names = [] for i in range(4): names.append(f'group_{i}') CreateWorkspace(DataX=np.linspace(0,5,6), DataY=[1]*5, OutputWorkspace=names[-1],Distribution=False, UnitX='Wavelength') group = GroupWorkspaces(names) ws=names[-1] efficiencies= JoinISISPolarizationEfficiencies(F1=ws,F2=ws,P1=ws,P2=ws) PolarizationEfficiencyCor(InputWorkspaces='group', OutputWorkspace='corr', Efficiencies=efficiencies) ``` _Added release notes_
1 parent ebdbcc9 commit e088bb1

File tree

3 files changed

+17
-0
lines changed

3 files changed

+17
-0
lines changed

Framework/Algorithms/src/PolarizationEfficiencyCor.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,13 @@ std::vector<std::string> PolarizationEfficiencyCor::getWorkspaceNameList() const
269269
std::vector<std::string> wsNames;
270270
if (!isDefault(Prop::INPUT_WORKSPACES)) {
271271
wsNames = getProperty(Prop::INPUT_WORKSPACES);
272+
if (std::any_of(wsNames.cbegin(), wsNames.cend(), [](const auto &wsName) {
273+
return AnalysisDataService::Instance().retrieveWS<MatrixWorkspace>(wsName) == nullptr;
274+
})) {
275+
throw std::invalid_argument(
276+
"Only Matrix Workspaces can be added in InputWorkspace property list. If the input is a group, "
277+
"use the InputWorkspaceGroup property");
278+
}
272279
} else {
273280
WorkspaceGroup_sptr group = getProperty(Prop::INPUT_WORKSPACE_GROUP);
274281
auto const n = group->size();

Framework/Algorithms/test/PolarizationEfficiencyCorTest.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,15 @@ class PolarizationEfficiencyCorTest : public CxxTest::TestSuite {
9595
alg->execute();
9696
checkOutputWorkspaceGroupSize(4);
9797
}
98+
99+
void test_input_ws_wildes_list_with_group_throws_error() {
100+
auto alg = createAlgorithm(WILDES_METHOD, WILDES_METHOD);
101+
(void)createWorkspaceGroup(4);
102+
alg->setProperty("InputWorkspaces", "WS_GROUP_1");
103+
// Error: InputWorkspaces property does not accept groups
104+
TS_ASSERT_THROWS(alg->execute(), const std::invalid_argument &);
105+
}
106+
98107
void test_input_ws_frederikze_needs_group() {
99108
auto alg = createAlgorithm(FREDRIKZE_METHOD, FREDRIKZE_METHOD);
100109
alg->setProperty("InputWorkspaces", createWorkspacesInADS(4));
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
- Algorithm :ref:`algm-PolarizationEfficiencyCor` no longer crashes Mantid when using workspace groups in the ``InputWorkspaces`` property list.

0 commit comments

Comments
 (0)