@@ -128,69 +128,88 @@ void PolarizationEfficienciesWildes::init() {
128
128
}
129
129
130
130
namespace {
131
-
132
- void validateMatchingBins (const Mantid::API::MatrixWorkspace_sptr &workspace,
133
- const Mantid::API::MatrixWorkspace_sptr &refWs, const std::string &propertyName,
134
- std::map<std::string, std::string> &problems) {
131
+ bool hasMatchingBins (const Mantid::API::MatrixWorkspace_sptr &workspace, const Mantid::API::MatrixWorkspace_sptr &refWs,
132
+ const std::string &propertyName, std::map<std::string, std::string> &problems) {
135
133
if (!WorkspaceHelpers::matchingBins (*workspace, *refWs, true )) {
136
134
problems[propertyName] = " All input workspaces must have the same X values." ;
137
- return ;
135
+ return false ;
138
136
}
137
+
138
+ return true ;
139
139
}
140
140
141
- void validateInputWorkspace (const Mantid::API::MatrixWorkspace_sptr &workspace,
142
- const Mantid::API::MatrixWorkspace_sptr &refWs, const std::string &propertyName,
143
- std::map<std::string, std::string> &problems) {
141
+ bool isValidInputWorkspace (const Mantid::API::MatrixWorkspace_sptr &workspace,
142
+ const Mantid::API::MatrixWorkspace_sptr &refWs, const std::string &propertyName,
143
+ std::map<std::string, std::string> &problems) {
144
144
if (workspace == nullptr ) {
145
145
problems[propertyName] = " All input workspaces must be matrix workspaces." ;
146
- return ;
146
+ return false ;
147
147
}
148
148
149
149
Kernel::Unit_const_sptr unit = workspace->getAxis (0 )->unit ();
150
150
if (unit->unitID () != " Wavelength" ) {
151
151
problems[propertyName] = " All input workspaces must be in units of Wavelength." ;
152
- return ;
152
+ return false ;
153
153
}
154
154
155
155
if (workspace->getNumberHistograms () != 1 ) {
156
156
problems[propertyName] = " All input workspaces must contain only a single spectrum." ;
157
- return ;
157
+ return false ;
158
158
}
159
159
160
- validateMatchingBins (workspace, refWs, propertyName, problems);
160
+ return hasMatchingBins (workspace, refWs, propertyName, problems);
161
161
}
162
162
163
- void validateInputWSGroup (const Mantid::API::WorkspaceGroup_sptr &groupWs, const std::string &propertyName,
164
- std::map<std::string, std::string> &problems) {
163
+ bool isValidInputWSGroup (const Mantid::API::WorkspaceGroup_sptr &groupWs, const std::string &propertyName,
164
+ std::map<std::string, std::string> &problems) {
165
165
if (groupWs == nullptr ) {
166
166
problems[propertyName] = " The input workspace must be a group workspace." ;
167
- return ;
167
+ return false ;
168
168
}
169
169
170
170
if (groupWs->size () != 4 ) {
171
171
problems[propertyName] = " The input group must contain a workspace for all four flipper configurations." ;
172
- return ;
172
+ return false ;
173
173
}
174
174
175
175
const MatrixWorkspace_sptr refWs = std::dynamic_pointer_cast<MatrixWorkspace>(groupWs->getItem (0 ));
176
176
for (size_t i = 0 ; i < groupWs->size (); ++i) {
177
177
const MatrixWorkspace_sptr childWs = std::dynamic_pointer_cast<MatrixWorkspace>(groupWs->getItem (i));
178
- validateInputWorkspace (childWs, refWs, propertyName, problems);
178
+ if (!isValidInputWorkspace (childWs, refWs, propertyName, problems)) {
179
+ return false ;
180
+ }
179
181
}
182
+
183
+ return true ;
180
184
}
181
185
} // namespace
182
186
183
187
std::map<std::string, std::string> PolarizationEfficienciesWildes::validateInputs () {
184
188
std::map<std::string, std::string> problems;
185
189
186
- const WorkspaceGroup_sptr nonMagWsGrp = getProperty (PropNames::INPUT_NON_MAG_WS);
187
- validateInputWSGroup (nonMagWsGrp, PropNames::INPUT_NON_MAG_WS, problems);
188
- const MatrixWorkspace_sptr nonMagRefWs = std::dynamic_pointer_cast<MatrixWorkspace>(nonMagWsGrp->getItem (0 ));
189
-
190
190
const bool hasMagWsGrp = !isDefault (PropNames::INPUT_MAG_WS);
191
191
const bool hasInputPWs = !isDefault (PropNames::INPUT_P_EFF_WS);
192
192
const bool hasInputAWs = !isDefault (PropNames::INPUT_A_EFF_WS);
193
193
194
+ if (!isDefault (PropNames::OUTPUT_P_EFF_WS) && !hasMagWsGrp && !hasInputPWs && !hasInputAWs) {
195
+ problems[PropNames::OUTPUT_P_EFF_WS] = " If output polarizer efficiency is requested then either the magnetic "
196
+ " workspace or the known analyser efficiency should be provided." ;
197
+ }
198
+
199
+ if (!isDefault (PropNames::OUTPUT_A_EFF_WS) && !hasMagWsGrp && !hasInputPWs && !hasInputAWs) {
200
+ problems[PropNames::OUTPUT_A_EFF_WS] = " If output analyser efficiency is requested then either the magnetic "
201
+ " workspace or the known polarizer efficiency should be provided." ;
202
+ }
203
+
204
+ const WorkspaceGroup_sptr nonMagWsGrp = getProperty (PropNames::INPUT_NON_MAG_WS);
205
+ if (!isValidInputWSGroup (nonMagWsGrp, PropNames::INPUT_NON_MAG_WS, problems)) {
206
+ // We need to use a child workspace from the nonMag group as a reference for later checks, so stop here if there are
207
+ // any issues with this input
208
+ return problems;
209
+ }
210
+
211
+ const MatrixWorkspace_sptr nonMagRefWs = std::dynamic_pointer_cast<MatrixWorkspace>(nonMagWsGrp->getItem (0 ));
212
+
194
213
// If a magnetic workspace has been provided then we will use that to calculate the polarizer and analyser
195
214
// efficiencies, so individual efficiency workspaces should not be provided as well
196
215
if (hasMagWsGrp) {
@@ -203,34 +222,23 @@ std::map<std::string, std::string> PolarizationEfficienciesWildes::validateInput
203
222
}
204
223
205
224
const WorkspaceGroup_sptr magWsGrp = getProperty (PropNames::INPUT_MAG_WS);
206
- validateInputWSGroup (magWsGrp, PropNames::INPUT_MAG_WS, problems);
207
-
208
- if (problems.find (PropNames::INPUT_MAG_WS) == problems.end ()) {
225
+ if (isValidInputWSGroup (magWsGrp, PropNames::INPUT_MAG_WS, problems)) {
226
+ // Check that bins match between the input mag and nonMag workspace groups
209
227
const MatrixWorkspace_sptr magWs = std::dynamic_pointer_cast<MatrixWorkspace>(magWsGrp->getItem (0 ));
210
- validateMatchingBins (magWs, nonMagRefWs, PropNames::INPUT_MAG_WS, problems);
228
+ hasMatchingBins (magWs, nonMagRefWs, PropNames::INPUT_MAG_WS, problems);
211
229
}
212
230
} else {
213
231
if (hasInputPWs) {
214
232
const MatrixWorkspace_sptr inputPolEffWs = getProperty (PropNames::INPUT_P_EFF_WS);
215
- validateInputWorkspace (inputPolEffWs, nonMagRefWs, PropNames::INPUT_P_EFF_WS, problems);
233
+ isValidInputWorkspace (inputPolEffWs, nonMagRefWs, PropNames::INPUT_P_EFF_WS, problems);
216
234
}
217
235
218
236
if (hasInputAWs) {
219
237
const MatrixWorkspace_sptr inputAnaEffWs = getProperty (PropNames::INPUT_A_EFF_WS);
220
- validateInputWorkspace (inputAnaEffWs, nonMagRefWs, PropNames::INPUT_A_EFF_WS, problems);
238
+ isValidInputWorkspace (inputAnaEffWs, nonMagRefWs, PropNames::INPUT_A_EFF_WS, problems);
221
239
}
222
240
}
223
241
224
- if (!isDefault (PropNames::OUTPUT_P_EFF_WS) && !hasMagWsGrp && !hasInputPWs && !hasInputAWs) {
225
- problems[PropNames::OUTPUT_P_EFF_WS] = " If output polarizer efficiency is requested then either the magnetic "
226
- " workspace or the known analyser efficiency should be provided." ;
227
- }
228
-
229
- if (!isDefault (PropNames::OUTPUT_A_EFF_WS) && !hasMagWsGrp && !hasInputPWs && !hasInputAWs) {
230
- problems[PropNames::OUTPUT_A_EFF_WS] = " If output analyser efficiency is requested then either the magnetic "
231
- " workspace or the known polarizer efficiency should be provided." ;
232
- }
233
-
234
242
return problems;
235
243
}
236
244
0 commit comments