forked from npshub/mantid
-
Notifications
You must be signed in to change notification settings - Fork 0
/
WorkspaceCreationTest.h
500 lines (442 loc) · 21.3 KB
/
WorkspaceCreationTest.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
// Mantid Repository : https://github.com/mantidproject/mantid
//
// Copyright © 2018 ISIS Rutherford Appleton Laboratory UKRI,
// NScD Oak Ridge National Laboratory, European Spallation Source,
// Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
// SPDX - License - Identifier: GPL - 3.0 +
#pragma once
#include <cxxtest/TestSuite.h>
#include "MantidAPI/BinEdgeAxis.h"
#include "MantidAPI/Run.h"
#include "MantidDataObjects/EventWorkspace.h"
#include "MantidDataObjects/SpecialWorkspace2D.h"
#include "MantidDataObjects/Workspace2D.h"
#include "MantidDataObjects/WorkspaceCreation.h"
#include "MantidIndexing/IndexInfo.h"
#include "MantidParallel/Communicator.h"
#include "MantidParallel/StorageMode.h"
#include "MantidTypes/SpectrumDefinition.h"
#include "MantidFrameworkTestHelpers/ComponentCreationHelper.h"
#include "MantidFrameworkTestHelpers/ParallelRunner.h"
using namespace Mantid;
using namespace API;
using namespace DataObjects;
using namespace HistogramData;
using namespace Indexing;
using namespace ParallelTestHelpers;
namespace {
void run_create_partitioned(const Parallel::Communicator &comm) {
IndexInfo indices(47, Parallel::StorageMode::Distributed, comm);
indices.setSpectrumDefinitions(std::vector<SpectrumDefinition>(indices.size()));
const auto ws = create<Workspace2D>(indices, Histogram(BinEdges{1, 2, 4}));
const auto &i = ws->indexInfo();
TS_ASSERT_EQUALS(i.globalSize(), 47);
size_t expectedSize = 0;
for (size_t globalIndex = 0; globalIndex < i.globalSize(); ++globalIndex) {
// Current default is RoundRobinPartitioner
if (static_cast<int>(globalIndex) % comm.size() == comm.rank()) {
TS_ASSERT_EQUALS(i.spectrumNumber(expectedSize), static_cast<int>(globalIndex) + 1);
++expectedSize;
}
}
TS_ASSERT_EQUALS(i.size(), expectedSize);
TS_ASSERT_EQUALS(ws->storageMode(), Parallel::StorageMode::Distributed);
}
void run_create_partitioned_parent(const Parallel::Communicator &comm) {
IndexInfo indices(47, Parallel::StorageMode::Distributed, comm);
indices.setSpectrumDefinitions(std::vector<SpectrumDefinition>(indices.size()));
const auto parent = create<Workspace2D>(indices, Histogram(BinEdges{1, 2, 4}));
const auto ws = create<MatrixWorkspace>(*parent);
const auto &i = ws->indexInfo();
TS_ASSERT_EQUALS(i.globalSize(), 47);
size_t expectedSize = 0;
for (size_t globalIndex = 0; globalIndex < i.globalSize(); ++globalIndex) {
// Current default is RoundRobinPartitioner
if (static_cast<int>(globalIndex) % comm.size() == comm.rank()) {
TS_ASSERT_EQUALS(i.spectrumNumber(expectedSize), static_cast<int>(globalIndex) + 1);
++expectedSize;
}
}
TS_ASSERT_EQUALS(parent->indexInfo().globalSize(), ws->indexInfo().globalSize());
TS_ASSERT_EQUALS(parent->indexInfo().size(), ws->indexInfo().size());
TS_ASSERT_EQUALS(parent->getNumberHistograms(), ws->getNumberHistograms());
TS_ASSERT_EQUALS(i.size(), expectedSize);
TS_ASSERT_EQUALS(ws->storageMode(), Parallel::StorageMode::Distributed);
}
void run_create_partitioned_with_instrument(const Parallel::Communicator &comm,
const std::shared_ptr<Geometry::Instrument> &instrument) {
IndexInfo indices(4, Parallel::StorageMode::Distributed, comm);
// should a nullptr spectrum definitions vector indicate building default
// defs?
// - same length -> build
// - different length -> fail (cannot create default mapping)
// same for setIndexInfo?
const auto ws = create<Workspace2D>(instrument, indices, Histogram(BinEdges{1, 2, 4}));
const auto &i = ws->indexInfo();
TS_ASSERT_EQUALS(i.globalSize(), 4);
size_t expectedSize = 0;
for (size_t globalIndex = 0; globalIndex < i.globalSize(); ++globalIndex) {
// Current default is RoundRobinPartitioner
if (static_cast<int>(globalIndex) % comm.size() == comm.rank()) {
TS_ASSERT_EQUALS(i.spectrumNumber(expectedSize), static_cast<int>(globalIndex) + 1);
++expectedSize;
}
}
TS_ASSERT_EQUALS(i.size(), expectedSize);
}
void run_indexInfo_legacy_compatibility_partitioned_workspace_failure(const Parallel::Communicator &comm) {
IndexInfo indices(3, Parallel::StorageMode::Distributed, comm);
indices.setSpectrumDefinitions(std::vector<SpectrumDefinition>(indices.size()));
const auto ws = create<Workspace2D>(indices, Histogram(BinEdges{1, 2}));
if (comm.size() > 1) {
TS_ASSERT_THROWS_EQUALS(ws->getSpectrum(0).setSpectrumNo(7), const std::logic_error &e, std::string(e.what()),
"Setting spectrum numbers in MatrixWorkspace via "
"ISpectrum::setSpectrumNo is not possible in MPI "
"runs for distributed workspaces. Use IndexInfo.");
} else {
TS_ASSERT_THROWS_NOTHING(ws->getSpectrum(0).setSpectrumNo(7));
}
}
} // namespace
class WorkspaceCreationTest : public CxxTest::TestSuite {
public:
// This pair of boilerplate methods prevent the suite being created statically
// This means the constructor isn't called when running other tests
static WorkspaceCreationTest *createSuite() { return new WorkspaceCreationTest(); }
static void destroySuite(WorkspaceCreationTest *suite) { delete suite; }
WorkspaceCreationTest() {
// 1 bank, 2x2 pixels, IDs 4,5,6,7
m_instrument = ComponentCreationHelper::createTestInstrumentRectangular(1, 2);
}
IndexInfo make_indices() {
IndexInfo indices(2);
indices.setSpectrumNumbers({2, 4});
std::vector<SpectrumDefinition> specDefs(2);
specDefs[0].add(0);
specDefs[1].add(2);
specDefs[1].add(3);
indices.setSpectrumDefinitions(specDefs);
return indices;
}
IndexInfo make_indices_no_detectors() {
IndexInfo indices(2);
indices.setSpectrumNumbers({2, 4});
indices.setSpectrumDefinitions(std::vector<SpectrumDefinition>(2));
return indices;
}
Histogram make_data() {
BinEdges edges{1, 2, 4};
Counts counts{3.0, 5.0};
CountStandardDeviations deviations{2.0, 4.0};
return Histogram{edges, counts, deviations};
}
void check_size(const MatrixWorkspace &ws) { TS_ASSERT_EQUALS(ws.getNumberHistograms(), 2); }
void check_default_indices(const MatrixWorkspace &ws) {
check_size(ws);
TS_ASSERT_EQUALS(ws.getSpectrum(0).getSpectrumNo(), 1);
TS_ASSERT_EQUALS(ws.getSpectrum(1).getSpectrumNo(), 2);
TS_ASSERT_EQUALS(ws.getSpectrum(0).getDetectorIDs(), (std::set<detid_t>{}));
TS_ASSERT_EQUALS(ws.getSpectrum(1).getDetectorIDs(), (std::set<detid_t>{}));
}
void check_indices(const MatrixWorkspace &ws) {
check_size(ws);
TS_ASSERT_EQUALS(ws.getSpectrum(0).getSpectrumNo(), 2);
TS_ASSERT_EQUALS(ws.getSpectrum(1).getSpectrumNo(), 4);
TS_ASSERT_EQUALS(ws.getSpectrum(0).getDetectorIDs(), (std::set<detid_t>{4}));
TS_ASSERT_EQUALS(ws.getSpectrum(1).getDetectorIDs(), (std::set<detid_t>{6, 7}));
}
void check_indices_no_detectors(const MatrixWorkspace &ws) {
check_size(ws);
TS_ASSERT_EQUALS(ws.getSpectrum(0).getSpectrumNo(), 2);
TS_ASSERT_EQUALS(ws.getSpectrum(1).getSpectrumNo(), 4);
TS_ASSERT_EQUALS(ws.getSpectrum(0).getDetectorIDs(), (std::set<detid_t>{}));
TS_ASSERT_EQUALS(ws.getSpectrum(1).getDetectorIDs(), (std::set<detid_t>{}));
}
void check_zeroed_data(const MatrixWorkspace &ws) {
TS_ASSERT_EQUALS(ws.x(0).rawData(), std::vector<double>({1, 2, 4}));
TS_ASSERT_EQUALS(ws.x(1).rawData(), std::vector<double>({1, 2, 4}));
TS_ASSERT_EQUALS(ws.y(0).rawData(), std::vector<double>({0, 0}));
TS_ASSERT_EQUALS(ws.y(1).rawData(), std::vector<double>({0, 0}));
TS_ASSERT_EQUALS(ws.e(0).rawData(), std::vector<double>({0, 0}));
TS_ASSERT_EQUALS(ws.e(1).rawData(), std::vector<double>({0, 0}));
}
void check_instrument(const MatrixWorkspace &ws) {
TS_ASSERT_EQUALS(ws.getInstrument()->baseInstrument(), m_instrument);
}
void check_data(const MatrixWorkspace &ws) {
TS_ASSERT_EQUALS(ws.x(0).rawData(), std::vector<double>({1, 2, 4}));
TS_ASSERT_EQUALS(ws.x(1).rawData(), std::vector<double>({1, 2, 4}));
TS_ASSERT_EQUALS(ws.y(0).rawData(), std::vector<double>({3, 5}));
TS_ASSERT_EQUALS(ws.y(1).rawData(), std::vector<double>({3, 5}));
TS_ASSERT_EQUALS(ws.e(0).rawData(), std::vector<double>({2, 4}));
TS_ASSERT_EQUALS(ws.e(1).rawData(), std::vector<double>({2, 4}));
}
void test_create_size_Histogram() {
const auto ws = create<Workspace2D>(2, Histogram(BinEdges{1, 2, 4}));
check_default_indices(*ws);
check_zeroed_data(*ws);
}
void test_create_size_fully_specified_Histogram() {
std::unique_ptr<Workspace2D> ws;
TS_ASSERT_THROWS_NOTHING(ws = create<Workspace2D>(2, make_data()))
check_data(*ws);
}
void test_create_parent_size_fully_specified_Histogram() {
const auto parent = create<Workspace2D>(make_indices_no_detectors(), Histogram(BinEdges{-1, 0, 2}));
std::unique_ptr<Workspace2D> ws;
TS_ASSERT_THROWS_NOTHING(ws = create<Workspace2D>(*parent, 2, make_data()))
check_indices_no_detectors(*ws);
check_data(*ws);
}
void test_create_IndexInfo_Histogram() {
const auto ws = create<Workspace2D>(make_indices_no_detectors(), Histogram(BinEdges{1, 2, 4}));
check_indices_no_detectors(*ws);
check_zeroed_data(*ws);
}
void test_create_bad_IndexInfo_Histogram_no_instrument() {
// No instrument, so spectrum definitions created by make_indices are bad.
TS_ASSERT_THROWS(create<Workspace2D>(make_indices(), Histogram(BinEdges{1, 2, 4})), const std::invalid_argument &);
}
void test_create_Instrument_size_Histogram() {
const auto ws = create<Workspace2D>(m_instrument, 2, Histogram(BinEdges{1, 2, 4}));
check_default_indices(*ws);
check_zeroed_data(*ws);
check_instrument(*ws);
}
void test_create_Instrument_IndexInfo_Histogram() {
const auto ws = create<Workspace2D>(m_instrument, make_indices(), Histogram(BinEdges{1, 2, 4}));
check_indices(*ws);
check_zeroed_data(*ws);
check_instrument(*ws);
}
void test_create_parent() {
const auto parent = create<Workspace2D>(m_instrument, make_indices(), Histogram(BinEdges{1, 2, 4}));
const auto ws = create<Workspace2D>(*parent);
check_indices(*ws);
check_zeroed_data(*ws);
check_instrument(*ws);
}
void test_create_parent_distribution_flag() {
Histogram hist(BinEdges{1, 2}, Counts{1});
Histogram dist(BinEdges{1, 2}, Frequencies{1});
const auto wsHist = create<Workspace2D>(m_instrument, make_indices(), hist);
const auto wsDist = create<Workspace2D>(m_instrument, make_indices(), dist);
// Distribution flag inherited from parent if not explicitly specified
TS_ASSERT(!create<Workspace2D>(*wsHist)->isDistribution());
TS_ASSERT(create<Workspace2D>(*wsDist)->isDistribution());
TS_ASSERT(!create<Workspace2D>(*wsHist, BinEdges{1, 2})->isDistribution());
TS_ASSERT(create<Workspace2D>(*wsDist, BinEdges{1, 2})->isDistribution());
// Passing a full Histogram explicitly specifies the YMode, i.e.,
// distribution flag.
TS_ASSERT(!create<Workspace2D>(*wsHist, hist)->isDistribution());
TS_ASSERT(!create<Workspace2D>(*wsDist, hist)->isDistribution());
TS_ASSERT(create<Workspace2D>(*wsHist, dist)->isDistribution());
TS_ASSERT(create<Workspace2D>(*wsDist, dist)->isDistribution());
}
void test_create_parent_without_logs() {
const auto parent = create<Workspace2D>(m_instrument, make_indices(), Histogram(BinEdges{1, 2, 4}));
const std::string &name0 = "Log2";
parent->mutableRun().addProperty(name0, 3.2);
const std::string &name1 = "Log4";
const std::string &value1 = "6.4a";
parent->mutableRun().addProperty(name1, value1);
const auto ws = create<Workspace2D>(*parent);
TS_ASSERT_EQUALS(&parent->run(), &ws->run());
ws->setSharedRun(Kernel::make_cow<Run>());
check_indices(*ws);
check_zeroed_data(*ws);
check_instrument(*ws);
TS_ASSERT_EQUALS(ws->run().getProperties().size(), 0);
}
void test_create_parent_varying_bins() {
auto parent = create<Workspace2D>(make_indices_no_detectors(), make_data());
const double binShift = -0.54;
parent->mutableX(1) += binShift;
const auto ws = create<Workspace2D>(*parent);
check_indices_no_detectors(*ws);
TS_ASSERT_EQUALS(ws->x(0).rawData(), std::vector<double>({1, 2, 4}));
TS_ASSERT_EQUALS(ws->x(1).rawData(), std::vector<double>({1 + binShift, 2 + binShift, 4 + binShift}));
TS_ASSERT_EQUALS(ws->y(0).rawData(), std::vector<double>({0, 0}));
TS_ASSERT_EQUALS(ws->y(1).rawData(), std::vector<double>({0, 0}));
TS_ASSERT_EQUALS(ws->e(0).rawData(), std::vector<double>({0, 0}));
TS_ASSERT_EQUALS(ws->e(1).rawData(), std::vector<double>({0, 0}));
}
void test_create_parent_varying_bins_from_event() {
auto parent = create<EventWorkspace>(make_indices_no_detectors(), BinEdges{1, 2, 4});
const double binShift = -0.54;
parent->mutableX(1) += binShift;
const auto ws = create<EventWorkspace>(*parent);
check_indices_no_detectors(*ws);
TS_ASSERT_EQUALS(ws->x(0).rawData(), std::vector<double>({1, 2, 4}));
TS_ASSERT_EQUALS(ws->x(1).rawData(), std::vector<double>({1 + binShift, 2 + binShift, 4 + binShift}));
TS_ASSERT_EQUALS(ws->y(0).rawData(), std::vector<double>({0, 0}));
TS_ASSERT_EQUALS(ws->y(1).rawData(), std::vector<double>({0, 0}));
TS_ASSERT_EQUALS(ws->e(0).rawData(), std::vector<double>({0, 0}));
TS_ASSERT_EQUALS(ws->e(1).rawData(), std::vector<double>({0, 0}));
}
void test_create_parent_Histogram() {
const auto parent = create<Workspace2D>(m_instrument, make_indices(), Histogram(BinEdges{0, 1}));
const auto ws = create<Workspace2D>(*parent, Histogram(BinEdges{1, 2, 4}));
check_indices(*ws);
check_zeroed_data(*ws);
check_instrument(*ws);
}
void test_create_parent_same_size() {
const auto parent = create<Workspace2D>(m_instrument, make_indices(), Histogram(BinEdges{1, 2, 4}));
const auto ws = create<Workspace2D>(*parent, 2, parent->histogram(0));
// Same size -> Indices copied from parent
check_indices(*ws);
check_zeroed_data(*ws);
check_instrument(*ws);
}
void test_create_parent_size() {
const auto parent = create<Workspace2D>(3, Histogram(BinEdges{1, 2, 4}));
parent->getSpectrum(0).setSpectrumNo(7);
const auto ws = create<Workspace2D>(*parent, 2, parent->histogram(0));
check_default_indices(*ws);
check_zeroed_data(*ws);
}
void test_create_parent_same_size_does_not_ignore_IndexInfo_no_instrument() {
const auto parent = create<Workspace2D>(2, Histogram(BinEdges{1, 2, 4}));
const auto ws = create<Workspace2D>(*parent, make_indices_no_detectors(), parent->histogram(0));
// Even if parent has same size data in IndexInfo should not be ignored
// since it is given explicitly.
check_indices_no_detectors(*ws);
check_zeroed_data(*ws);
}
void test_create_parent_same_size_does_not_ignore_IndexInfo() {
auto parentIndices = make_indices();
parentIndices.setSpectrumNumbers({666, 1});
const auto parent = create<Workspace2D>(m_instrument, parentIndices, Histogram(BinEdges{1, 2, 4}));
const auto ws = create<Workspace2D>(*parent, make_indices(), parent->histogram(0));
// Even if parent has same size data in IndexInfo should not be ignored
// since it is given explicitly.
check_indices(*ws);
check_zeroed_data(*ws);
}
void test_create_parent_bad_IndexInfo_no_instrument() {
const auto parent = create<Workspace2D>(3, Histogram(BinEdges{1, 2, 4}));
// parent has no instrument set, so spectrum definitions created by
// make_indices are bad.
TS_ASSERT_THROWS(create<Workspace2D>(*parent, make_indices(), (BinEdges{1, 2, 4})), const std::invalid_argument &);
}
void test_create_parent_IndexInfo() {
const auto parent = create<Workspace2D>(m_instrument, 3, Histogram(BinEdges{1, 2, 4}));
const auto ws = create<Workspace2D>(*parent, make_indices(), parent->histogram(0));
check_indices(*ws);
check_zeroed_data(*ws);
}
void test_create_parent_size_edges_from_event() {
const auto parent = create<EventWorkspace>(make_indices_no_detectors(), Histogram(BinEdges{1, 2, 4}));
std::unique_ptr<EventWorkspace> ws;
TS_ASSERT_THROWS_NOTHING(ws = create<EventWorkspace>(*parent, 2, parent->binEdges(0)))
TS_ASSERT_EQUALS(ws->id(), "EventWorkspace");
check_indices_no_detectors(*ws);
check_zeroed_data(*ws);
}
void test_create_parent_numeric_vertical_axis() {
constexpr size_t parentNhist{3};
const auto parent = create<Workspace2D>(parentNhist, Histogram(Points{1}));
std::vector<double> vec{-1.5, -0.5, 2.3};
auto parentAxis = std::make_unique<NumericAxis>(vec);
parent->replaceAxis(1, std::move(parentAxis));
constexpr size_t nhist{2};
const auto ws = create<Workspace2D>(*parent, nhist, parent->histogram(0));
auto axis = ws->getAxis(1);
TS_ASSERT_DIFFERS(dynamic_cast<NumericAxis *>(axis), nullptr)
TS_ASSERT_EQUALS(axis->length(), nhist);
}
void test_create_parent_bin_edge_vertical_axis() {
constexpr size_t parentNhist{3};
const auto parent = create<Workspace2D>(parentNhist, Histogram(Points{1}));
std::vector<double> vec{-1.5, -0.5, 2.3, 3.4};
auto parentAxis = std::make_unique<BinEdgeAxis>(vec);
parent->replaceAxis(1, std::move(parentAxis));
constexpr size_t nhist{2};
const auto ws = create<Workspace2D>(*parent, nhist, parent->histogram(0));
auto axis = ws->getAxis(1);
TS_ASSERT_DIFFERS(dynamic_cast<BinEdgeAxis *>(axis), nullptr)
TS_ASSERT_EQUALS(axis->length(), nhist + 1);
}
void test_create_drop_events() {
auto eventWS = create<EventWorkspace>(1, Histogram(BinEdges(3)));
auto ws = create<HistoWorkspace>(*eventWS);
TS_ASSERT_EQUALS(ws->id(), "Workspace2D");
}
void test_EventWorkspace_MRU_is_empty() {
const auto ws1 = create<EventWorkspace>(1, Histogram(BinEdges(3)));
const auto ws2 = create<EventWorkspace>(*ws1, 1, Histogram(BinEdges(3)));
TS_ASSERT_EQUALS(ws2->MRUSize(), 0);
}
void test_create_from_more_derived() {
const auto parent = create<SpecialWorkspace2D>(2, Histogram(Points(1)));
const auto ws = create<Workspace2D>(*parent);
TS_ASSERT_EQUALS(ws->id(), "SpecialWorkspace2D");
}
void test_create_from_less_derived() {
const auto parent = create<Workspace2D>(2, Histogram(Points(1)));
const auto ws = create<SpecialWorkspace2D>(*parent);
TS_ASSERT_EQUALS(ws->id(), "SpecialWorkspace2D");
}
void test_create_event_from_histo() {
const auto parent = create<Workspace2D>(2, Histogram(BinEdges(2)));
const auto ws = create<EventWorkspace>(*parent);
TS_ASSERT_EQUALS(ws->id(), "EventWorkspace");
}
void test_create_event_from_event() {
const auto parent = create<Workspace2D>(2, Histogram(BinEdges{1, 2, 4}));
const auto ws = create<EventWorkspace>(*parent);
TS_ASSERT_EQUALS(ws->id(), "EventWorkspace");
check_zeroed_data(*ws);
}
void test_create_event_from_edges() {
std::unique_ptr<EventWorkspace> ws;
TS_ASSERT_THROWS_NOTHING(ws = create<EventWorkspace>(2, BinEdges{1, 2, 4}))
TS_ASSERT_EQUALS(ws->id(), "EventWorkspace");
check_zeroed_data(*ws);
}
void test_default_StorageMode_is_Cloned() {
IndexInfo indices(2);
indices.setSpectrumDefinitions(std::vector<SpectrumDefinition>(2));
TS_ASSERT_EQUALS(create<Workspace2D>(indices, BinEdges{1, 2, 4})->storageMode(), Parallel::StorageMode::Cloned);
}
void test_create_with_StorageMode() {
IndexInfo indices(2, Parallel::StorageMode::Distributed);
indices.setSpectrumDefinitions(std::vector<SpectrumDefinition>(2));
std::unique_ptr<Workspace2D> ws;
TS_ASSERT_THROWS_NOTHING(ws = create<Workspace2D>(indices, BinEdges{1, 2, 4}));
TS_ASSERT_EQUALS(ws->storageMode(), Parallel::StorageMode::Distributed);
}
void test_storageMode_propagated() {
IndexInfo indices(2, Parallel::StorageMode::Distributed);
indices.setSpectrumDefinitions(std::vector<SpectrumDefinition>(2));
const auto parent = create<Workspace2D>(indices, BinEdges{1, 2, 4});
const auto ws = create<Workspace2D>(*parent);
TS_ASSERT_EQUALS(ws->storageMode(), Parallel::StorageMode::Distributed);
}
void test_create_partitioned() { runParallel(run_create_partitioned); }
void test_create_partitioned_parent() { runParallel(run_create_partitioned_parent); }
void test_create_partitioned_with_instrument() {
run_create_partitioned_with_instrument(Parallel::Communicator{}, m_instrument);
// Currently having 0 spectra on a rank is not supported by MatrixWorkspace
// so we must make sure to use fewer threads than detectors here:
int n_thread = 3;
ParallelRunner runner(n_thread);
runner.runSerial(run_create_partitioned_with_instrument, m_instrument);
runner.runParallel(run_create_partitioned_with_instrument, m_instrument);
}
void test_indexInfo_legacy_compatibility_partitioned_workspace_failure() {
// Sibling of MatrixWorkspace::test_indexInfo_legacy_compatibility().
// Setting spectrum numbers via legacy interface should fail for partitioned
// workspace.
run_indexInfo_legacy_compatibility_partitioned_workspace_failure(Parallel::Communicator{});
// Currently having 0 spectra on a rank is not supported by MatrixWorkspace
// so we must make sure to use fewer threads than detectors here:
int n_thread = 3;
ParallelRunner runner(n_thread);
runner.runSerial(run_indexInfo_legacy_compatibility_partitioned_workspace_failure);
runner.runParallel(run_indexInfo_legacy_compatibility_partitioned_workspace_failure);
}
private:
std::shared_ptr<Geometry::Instrument> m_instrument;
};