@@ -41,7 +41,7 @@ class CreateDetectorTableTest : public CxxTest::TestSuite {
41
41
TS_ASSERT (alg.isInitialized ());
42
42
43
43
const auto &props = alg.getProperties ();
44
- TS_ASSERT_EQUALS (props.size (), 4 );
44
+ TS_ASSERT_EQUALS (props.size (), 5 );
45
45
46
46
TS_ASSERT_EQUALS (props[0 ]->name (), " InputWorkspace" );
47
47
TS_ASSERT (props[0 ]->isDefault ());
@@ -52,17 +52,20 @@ class CreateDetectorTableTest : public CxxTest::TestSuite {
52
52
TS_ASSERT_EQUALS (props[2 ]->name (), " IncludeData" );
53
53
TS_ASSERT (props[2 ]->isDefault ());
54
54
55
- TS_ASSERT_EQUALS (props[3 ]->name (), " DetectorTableWorkspace " );
55
+ TS_ASSERT_EQUALS (props[3 ]->name (), " IncludeDetectorPosition " );
56
56
TS_ASSERT (props[3 ]->isDefault ());
57
- TS_ASSERT (dynamic_cast <WorkspaceProperty<TableWorkspace> *>(props[3 ]));
57
+
58
+ TS_ASSERT_EQUALS (props[4 ]->name (), " DetectorTableWorkspace" );
59
+ TS_ASSERT (props[4 ]->isDefault ());
60
+ TS_ASSERT (dynamic_cast <WorkspaceProperty<TableWorkspace> *>(props[4 ]));
58
61
}
59
62
60
63
void test_Exec_Matrix_Workspace () {
61
64
Workspace2D_sptr inputWS = WorkspaceCreationHelper::create2DWorkspaceWithFullInstrument (2 , 10 );
62
65
63
66
CreateDetectorTable alg;
64
- TS_ASSERT_THROWS_NOTHING (alg.initialize ())
65
- TS_ASSERT (alg.isInitialized ())
67
+ TS_ASSERT_THROWS_NOTHING (alg.initialize ());
68
+ TS_ASSERT (alg.isInitialized ());
66
69
TS_ASSERT_THROWS_NOTHING (alg.setProperty (" InputWorkspace" , std::dynamic_pointer_cast<MatrixWorkspace>(inputWS)));
67
70
TS_ASSERT_THROWS_NOTHING (alg.execute ();)
68
71
TS_ASSERT (alg.isExecuted ());
@@ -81,6 +84,39 @@ class CreateDetectorTableTest : public CxxTest::TestSuite {
81
84
// Check the results
82
85
TS_ASSERT_EQUALS (ws->columnCount (), 11 );
83
86
TS_ASSERT_EQUALS (ws->rowCount (), 2 );
87
+ TS_ASSERT_EQUALS (ws->cell <int >(0 , 1 ), 1 ); // Spectrum No should be 1, if not in the exception
88
+
89
+ // Remove workspace from the data service.
90
+ AnalysisDataService::Instance ().remove (ws->getName ());
91
+ }
92
+
93
+ void test_Exec_Matrix_Workspace_with_no_valid_spectra () {
94
+ Workspace2D_sptr inputWS = WorkspaceCreationHelper::create2DWorkspaceWithFullInstrument (1 , 10 );
95
+ auto &spec = inputWS->getSpectrum (0 );
96
+ spec.clearDetectorIDs (); // clear the detectors to test the exception catching
97
+
98
+ CreateDetectorTable alg;
99
+ TS_ASSERT_THROWS_NOTHING (alg.initialize ());
100
+ TS_ASSERT (alg.isInitialized ());
101
+ TS_ASSERT_THROWS_NOTHING (alg.setProperty (" InputWorkspace" , std::dynamic_pointer_cast<MatrixWorkspace>(inputWS)));
102
+ TS_ASSERT_THROWS_NOTHING (alg.execute ();)
103
+ TS_ASSERT (alg.isExecuted ());
104
+
105
+ // Not setting an output workspace name should give the name:
106
+ // [input workspace name] + "-Detectors"
107
+ TableWorkspace_sptr ws;
108
+ TS_ASSERT_THROWS_NOTHING (
109
+ ws = AnalysisDataService::Instance ().retrieveWS <TableWorkspace>(inputWS->getName () + " -Detectors" ));
110
+ TS_ASSERT (ws);
111
+
112
+ if (!ws) {
113
+ return ;
114
+ }
115
+
116
+ // Check the results
117
+ TS_ASSERT_EQUALS (ws->columnCount (), 11 );
118
+ TS_ASSERT_EQUALS (ws->rowCount (), 1 );
119
+ TS_ASSERT_EQUALS (ws->cell <int >(0 , 1 ), -1 ); // Spectrum No should be -1
84
120
85
121
// Remove workspace from the data service.
86
122
AnalysisDataService::Instance ().remove (ws->getName ());
@@ -91,8 +127,8 @@ class CreateDetectorTableTest : public CxxTest::TestSuite {
91
127
std::string outWSName{" Detector Table Test" };
92
128
93
129
CreateDetectorTable alg;
94
- TS_ASSERT_THROWS_NOTHING (alg.initialize ())
95
- TS_ASSERT (alg.isInitialized ())
130
+ TS_ASSERT_THROWS_NOTHING (alg.initialize ());
131
+ TS_ASSERT (alg.isInitialized ());
96
132
TS_ASSERT_THROWS_NOTHING (alg.setProperty (" InputWorkspace" , std::dynamic_pointer_cast<MatrixWorkspace>(inputWS)));
97
133
TS_ASSERT_THROWS_NOTHING (alg.setProperty (" WorkspaceIndices" , " 1" ));
98
134
TS_ASSERT_THROWS_NOTHING (alg.setProperty (" IncludeData" , true ));
@@ -122,6 +158,7 @@ class CreateDetectorTableTest : public CxxTest::TestSuite {
122
158
// Check the results
123
159
TS_ASSERT_EQUALS (ws->columnCount (), 13 );
124
160
TS_ASSERT_EQUALS (ws->rowCount (), 1 );
161
+ TS_ASSERT_EQUALS (ws->cell <int >(0 , 1 ), 2 ); // Spectrum No should be 2 due to the WorkspaceIndex
125
162
126
163
// Remove workspace from the data service.
127
164
AnalysisDataService::Instance ().remove (outWSName);
@@ -131,11 +168,11 @@ class CreateDetectorTableTest : public CxxTest::TestSuite {
131
168
PeaksWorkspace_sptr inputWS = WorkspaceCreationHelper::createPeaksWorkspace (5 , false );
132
169
133
170
CreateDetectorTable alg;
134
- TS_ASSERT_THROWS_NOTHING (alg.initialize ())
135
- TS_ASSERT (alg.isInitialized ())
136
- TS_ASSERT_THROWS_NOTHING (alg.setProperty (" InputWorkspace" , inputWS))
137
- TS_ASSERT_THROWS_NOTHING (alg.execute ())
138
- TS_ASSERT (alg.isExecuted ())
171
+ TS_ASSERT_THROWS_NOTHING (alg.initialize ());
172
+ TS_ASSERT (alg.isInitialized ());
173
+ TS_ASSERT_THROWS_NOTHING (alg.setProperty (" InputWorkspace" , inputWS));
174
+ TS_ASSERT_THROWS_NOTHING (alg.execute ());
175
+ TS_ASSERT (alg.isExecuted ());
139
176
140
177
TableWorkspace_sptr ws;
141
178
TS_ASSERT_THROWS_NOTHING (
@@ -147,8 +184,9 @@ class CreateDetectorTableTest : public CxxTest::TestSuite {
147
184
}
148
185
149
186
// Check the results
150
- TS_ASSERT_EQUALS (ws->columnCount (), 2 )
151
- TS_ASSERT_EQUALS (ws->rowCount (), 5 )
187
+ TS_ASSERT_EQUALS (ws->columnCount (), 2 );
188
+ TS_ASSERT_EQUALS (ws->rowCount (), 5 );
189
+ TS_ASSERT_EQUALS (ws->cell <int >(0 , 1 ), 0 ); // First column is Index when exec on PeaksWorkspace, so expect 0
152
190
153
191
// Remove workspace from the data service.
154
192
AnalysisDataService::Instance ().remove (ws->getName ());
@@ -158,12 +196,79 @@ class CreateDetectorTableTest : public CxxTest::TestSuite {
158
196
ITableWorkspace_sptr inputWS = std::make_shared<TableWorkspace>();
159
197
160
198
CreateDetectorTable alg;
161
- TS_ASSERT_THROWS_NOTHING (alg.initialize ())
162
- TS_ASSERT (alg.isInitialized ())
163
- TS_ASSERT_THROWS_NOTHING (alg.setProperty (" InputWorkspace" , inputWS))
199
+ TS_ASSERT_THROWS_NOTHING (alg.initialize ());
200
+ TS_ASSERT (alg.isInitialized ());
201
+ TS_ASSERT_THROWS_NOTHING (alg.setProperty (" InputWorkspace" , inputWS));
164
202
165
203
TS_ASSERT_THROWS (alg.executeAsChildAlg (), const std::runtime_error &);
166
204
}
205
+
206
+ void test_Exec_Matrix_Workspace_with_Include_DetPos () {
207
+ Workspace2D_sptr inputWS = WorkspaceCreationHelper::create2DWorkspaceWithFullInstrument (3 , 10 , true );
208
+
209
+ CreateDetectorTable alg;
210
+ TS_ASSERT_THROWS_NOTHING (alg.initialize ());
211
+ TS_ASSERT (alg.isInitialized ());
212
+ TS_ASSERT_THROWS_NOTHING (alg.setProperty (" InputWorkspace" , std::dynamic_pointer_cast<MatrixWorkspace>(inputWS)));
213
+ TS_ASSERT_THROWS_NOTHING (alg.setProperty (" IncludeDetectorPosition" , true ));
214
+ TS_ASSERT_THROWS_NOTHING (alg.execute ());
215
+ TS_ASSERT (alg.isExecuted ());
216
+
217
+ // Not setting an output workspace name should give the name:
218
+ // [input workspace name] + "-Detectors"
219
+ TableWorkspace_sptr ws;
220
+ TS_ASSERT_THROWS_NOTHING (
221
+ ws = AnalysisDataService::Instance ().retrieveWS <TableWorkspace>(inputWS->getName () + " -Detectors" ));
222
+ TS_ASSERT (ws);
223
+
224
+ if (!ws) {
225
+ return ;
226
+ }
227
+
228
+ // Check the results
229
+ TS_ASSERT_EQUALS (ws->columnCount (), 12 ); // extra column compared to test_Exec_Matrix_Workspace
230
+ TS_ASSERT_EQUALS (ws->rowCount (), 3 );
231
+ TS_ASSERT_EQUALS (ws->cell <int >(0 , 1 ), 1 ); // Spectrum No should be 1, if not in the exception
232
+ TS_ASSERT_EQUALS (ws->cell <V3D>(1 , 11 ),
233
+ V3D (0.0 , 0.0 , -9.0 )); // Last two are monitors, first position should be (0.0, 0.0, -9.0)
234
+
235
+ // Remove workspace from the data service.
236
+ AnalysisDataService::Instance ().remove (ws->getName ());
237
+ }
238
+
239
+ void test_Exec_Matrix_Workspace_with_no_valid_spectra_include_DetPos () {
240
+ Workspace2D_sptr inputWS = WorkspaceCreationHelper::create2DWorkspaceWithFullInstrument (1 , 10 );
241
+ auto &spec = inputWS->getSpectrum (0 );
242
+ spec.clearDetectorIDs (); // clear the detectors to test the exception catching
243
+
244
+ CreateDetectorTable alg;
245
+ TS_ASSERT_THROWS_NOTHING (alg.initialize ());
246
+ TS_ASSERT (alg.isInitialized ());
247
+ TS_ASSERT_THROWS_NOTHING (alg.setProperty (" InputWorkspace" , std::dynamic_pointer_cast<MatrixWorkspace>(inputWS)));
248
+ TS_ASSERT_THROWS_NOTHING (alg.setProperty (" IncludeDetectorPosition" , true ));
249
+ TS_ASSERT_THROWS_NOTHING (alg.execute ());
250
+ TS_ASSERT (alg.isExecuted ());
251
+
252
+ // Not setting an output workspace name should give the name:
253
+ // [input workspace name] + "-Detectors"
254
+ TableWorkspace_sptr ws;
255
+ TS_ASSERT_THROWS_NOTHING (
256
+ ws = AnalysisDataService::Instance ().retrieveWS <TableWorkspace>(inputWS->getName () + " -Detectors" ));
257
+ TS_ASSERT (ws);
258
+
259
+ if (!ws) {
260
+ return ;
261
+ }
262
+
263
+ // Check the results
264
+ TS_ASSERT_EQUALS (ws->columnCount (), 12 );
265
+ TS_ASSERT_EQUALS (ws->rowCount (), 1 );
266
+ TS_ASSERT_EQUALS (ws->cell <int >(0 , 1 ), -1 ); // Spectrum No should be -1
267
+ TS_ASSERT_EQUALS (ws->cell <V3D>(0 , 11 ), V3D (0.0 , 0.0 , 0.0 )); // Detector Position should be (0.0, 0.0, 0.0)
268
+
269
+ // Remove workspace from the data service.
270
+ AnalysisDataService::Instance ().remove (ws->getName ());
271
+ }
167
272
};
168
273
169
274
class CreateDetectorTablePerformance : public CxxTest ::TestSuite {
0 commit comments