-
Notifications
You must be signed in to change notification settings - Fork 122
/
LoadLiveDataTest.h
470 lines (420 loc) · 21.2 KB
/
LoadLiveDataTest.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
#ifndef MANTID_LIVEDATA_LOADLIVEDATATEST_H_
#define MANTID_LIVEDATA_LOADLIVEDATATEST_H_
#include "MantidLiveData/LoadLiveData.h"
#include "MantidDataObjects/EventWorkspace.h"
#include "MantidAPI/FrameworkManager.h"
#include "MantidKernel/System.h"
#include "MantidKernel/Timer.h"
#include <cxxtest/TestSuite.h>
#include <iomanip>
#include <iostream>
#include <numeric>
#include "MantidDataObjects/Workspace2D.h"
#include "MantidKernel/ConfigService.h"
#include "MantidAPI/LiveListenerFactory.h"
#include "MantidTestHelpers/FacilityHelper.h"
#include "TestGroupDataListener.h"
using namespace Mantid;
using namespace Mantid::LiveData;
using namespace Mantid::DataObjects;
using namespace Mantid::API;
using namespace Mantid::Kernel;
class LoadLiveDataTest : 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 LoadLiveDataTest *createSuite() { return new LoadLiveDataTest(); }
static void destroySuite( LoadLiveDataTest *suite ) { delete suite; }
void setUp()
{
FrameworkManager::Instance();
AnalysisDataService::Instance().clear();
ConfigService::Instance().setString("testdatalistener.reset_after", "0");
}
void test_Init()
{
LoadLiveData alg;
TS_ASSERT_THROWS_NOTHING( alg.initialize() )
TS_ASSERT( alg.isInitialized() )
}
//--------------------------------------------------------------------------------------------
/** Run a test with a fake output, no processing
*
* @param AccumulationMethod :: parameter string
* @return the created processed WS
*/
template <typename TYPE>
boost::shared_ptr<TYPE> doExec(std::string AccumulationMethod,
std::string ProcessingAlgorithm = "",
std::string ProcessingProperties = "",
std::string PostProcessingAlgorithm = "",
std::string PostProcessingProperties = "",
bool PreserveEvents = true,
ILiveListener_sptr listener = ILiveListener_sptr(),
bool makeThrow = false
)
{
FacilityHelper::ScopedFacilities loadTESTFacility("IDFs_for_UNIT_TESTING/UnitTestFacilities.xml", "TEST");
LoadLiveData alg;
TS_ASSERT_THROWS_NOTHING( alg.initialize() )
TS_ASSERT( alg.isInitialized() )
TS_ASSERT_THROWS_NOTHING( alg.setPropertyValue("Instrument", "TestDataListener") );
TS_ASSERT_THROWS_NOTHING( alg.setPropertyValue("AccumulationMethod", AccumulationMethod) );
TS_ASSERT_THROWS_NOTHING( alg.setPropertyValue("ProcessingAlgorithm", ProcessingAlgorithm) );
TS_ASSERT_THROWS_NOTHING( alg.setPropertyValue("ProcessingProperties", ProcessingProperties) );
TS_ASSERT_THROWS_NOTHING( alg.setPropertyValue("PostProcessingAlgorithm", PostProcessingAlgorithm) );
TS_ASSERT_THROWS_NOTHING( alg.setPropertyValue("PostProcessingProperties", PostProcessingProperties) );
TS_ASSERT_THROWS_NOTHING( alg.setProperty("PreserveEvents", PreserveEvents) );
if (!PostProcessingAlgorithm.empty())
TS_ASSERT_THROWS_NOTHING( alg.setPropertyValue("AccumulationWorkspace", "fake_accum") );
TS_ASSERT_THROWS_NOTHING( alg.setPropertyValue("OutputWorkspace", "fake") );
if (listener)
alg.setLiveListener(listener);
if (!makeThrow)
{ TS_ASSERT_THROWS_NOTHING( alg.execute(); ); }
else
alg.exec();
TS_ASSERT( alg.isExecuted() );
// Retrieve the workspace from data service.
boost::shared_ptr<TYPE> ws;
TS_ASSERT_THROWS_NOTHING( ws = AnalysisDataService::Instance().retrieveWS<TYPE>("fake") );
TS_ASSERT(ws);
if ( dynamic_cast<MatrixWorkspace*>(ws.get()) )
{
TSM_ASSERT_LESS_THAN( "Run number should be non-zero", 0, alg.runNumber() );
}
return ws;
}
//--------------------------------------------------------------------------------------------
void test_replace()
{
EventWorkspace_sptr ws1, ws2;
ws1 = doExec<EventWorkspace>("Replace");
TS_ASSERT_EQUALS(ws1->getNumberHistograms(), 2);
TS_ASSERT_EQUALS(ws1->getNumberEvents(), 200);
ws2 = doExec<EventWorkspace>("Replace");
TS_ASSERT_EQUALS(ws2->getNumberHistograms(), 2);
TS_ASSERT_EQUALS(ws2->getNumberEvents(), 200);
TSM_ASSERT( "Workspace changed when replaced", ws1 != ws2 );
TS_ASSERT_EQUALS(AnalysisDataService::Instance().size(), 1);
TSM_ASSERT( "Events are sorted", ws2->getEventList(0).isSortedByTof());
}
//--------------------------------------------------------------------------------------------
void test_append()
{
EventWorkspace_sptr ws1, ws2;
// First go creates the fake ws
ws1 = doExec<EventWorkspace>("Append");
TS_ASSERT_EQUALS(ws1->getNumberHistograms(), 2);
// Next one actually conjoins
ws2 = doExec<EventWorkspace>("Append");
TS_ASSERT_EQUALS(ws2->getNumberHistograms(), 4);
TS_ASSERT_EQUALS(AnalysisDataService::Instance().size(), 1);
TSM_ASSERT( "Events are sorted", ws2->getEventList(0).isSortedByTof());
}
//--------------------------------------------------------------------------------------------
void test_add()
{
EventWorkspace_sptr ws1, ws2;
// First go creates the fake ws
ws1 = doExec<EventWorkspace>("Add");
TS_ASSERT_EQUALS(ws1->getNumberHistograms(), 2);
TS_ASSERT_EQUALS(ws1->getNumberEvents(), 200);
// Next one adds events, keeps # of histos the same
ws2 = doExec<EventWorkspace>("Add", "","","","",true, ILiveListener_sptr());
TS_ASSERT_EQUALS(ws2->getNumberHistograms(), 2);
TS_ASSERT_EQUALS(ws2->getNumberEvents(), 400);
TSM_ASSERT( "Workspace being added stayed the same pointer", ws1 == ws2 );
TSM_ASSERT( "Events are sorted", ws2->getEventList(0).isSortedByTof());
TS_ASSERT_EQUALS(AnalysisDataService::Instance().size(), 1);
// Test monitor workspace is present
TS_ASSERT( ws2->monitorWorkspace() );
}
//--------------------------------------------------------------------------------------------
/** Make the test listener send out a "reset" signal. */
void test_dataReset()
{
// Will reset after the 2nd call to extract data
ConfigService::Instance().setString("testdatalistener.reset_after", "2");
EventWorkspace_sptr ws1, ws2, ws3;
// Manually make the listener so I can pass the same one to the algo
ILiveListener_sptr listener = LiveListenerFactory::Instance().create("TestDataListener",true);
listener->start();
// First go creates the fake ws
ws1 = doExec<EventWorkspace>("Add", "","","","",true, listener);
TS_ASSERT_EQUALS(ws1->getNumberEvents(), 200);
ws2 = doExec<EventWorkspace>("Add", "","","","",true, listener);
TS_ASSERT_EQUALS(ws2->getNumberEvents(), 400);
TSM_ASSERT( "Workspace being added stayed the same pointer", ws1 == ws2 );
// This next time, it should reset
ws3 = doExec<EventWorkspace>("Add", "","","","",true, listener);
TS_ASSERT_EQUALS(ws3->getNumberEvents(), 200);
TSM_ASSERT( "Accumulation workspace changed!", ws3 != ws1 );
TS_ASSERT_EQUALS(AnalysisDataService::Instance().size(), 1);
}
//--------------------------------------------------------------------------------------------
void test_add_DontPreserveEvents()
{
Workspace2D_sptr ws1, ws2;
// First go creates the fake ws
ws1 = doExec<Workspace2D>("Add", "Rebin", "Params=40e3, 1e3, 60e3", "", "", false);
TS_ASSERT_EQUALS(ws1->getNumberHistograms(), 2);
double total;
total = 0;
for (auto it = ws1->readY(0).begin(); it != ws1->readY(0).end(); it++)
total += *it;
TS_ASSERT_DELTA( total, 100.0, 1e-4);
// Next one adds the histograms together
ws2 = doExec<Workspace2D>("Add", "Rebin", "Params=40e3, 1e3, 60e3", "", "", false);
TS_ASSERT_EQUALS(ws2->getNumberHistograms(), 2);
// The new total signal is 200.0
total = 0;
for (auto it = ws1->readY(0).begin(); it != ws1->readY(0).end(); it++)
total += *it;
TS_ASSERT_DELTA( total, 200.0, 1e-4);
TSM_ASSERT( "Workspace being added stayed the same pointer", ws1 == ws2 );
TS_ASSERT_EQUALS(AnalysisDataService::Instance().size(), 1);
TS_ASSERT( ws1->monitorWorkspace() );
TS_ASSERT_EQUALS( ws1->monitorWorkspace(), ws2->monitorWorkspace() );
}
//--------------------------------------------------------------------------------------------
/** Simple processing of a chunk */
void test_ProcessChunk_DoPreserveEvents()
{
EventWorkspace_sptr ws;
ws = doExec<EventWorkspace>("Replace", "Rebin", "Params=40e3, 1e3, 60e3", "", "", true);
TS_ASSERT_EQUALS(ws->getNumberHistograms(), 2);
TS_ASSERT_EQUALS(ws->getNumberEvents(), 200);
// Check that rebin was called
TS_ASSERT_EQUALS(ws->blocksize(), 20);
TS_ASSERT_DELTA(ws->dataX(0)[0], 40e3, 1e-4);
TS_ASSERT_EQUALS(AnalysisDataService::Instance().size(), 1);
TS_ASSERT( ws->monitorWorkspace() );
}
//--------------------------------------------------------------------------------------------
/** DONT convert to workspace 2D when processing */
void test_ProcessChunk_DontPreserveEvents()
{
Workspace2D_sptr ws;
ws = doExec<Workspace2D>("Replace", "Rebin", "Params=40e3, 1e3, 60e3", "", "", false);
TS_ASSERT_EQUALS(ws->getNumberHistograms(), 2);
// Check that rebin was called
TS_ASSERT_EQUALS(ws->blocksize(), 20);
TS_ASSERT_DELTA(ws->dataX(0)[0], 40e3, 1e-4);
TS_ASSERT_EQUALS(AnalysisDataService::Instance().size(), 1);
TS_ASSERT( ws->monitorWorkspace() );
}
//--------------------------------------------------------------------------------------------
/** Do PostProcessing */
void test_PostProcessing()
{
// No chunk processing, but PostProcessing
EventWorkspace_sptr ws = doExec<EventWorkspace>("Replace", "", "", "Rebin", "Params=40e3, 1e3, 60e3");
EventWorkspace_sptr ws_accum = AnalysisDataService::Instance().retrieveWS<EventWorkspace>("fake_accum");
TS_ASSERT( ws )
TS_ASSERT( ws_accum )
// The accumulated workspace: it was NOT rebinned.
TS_ASSERT_EQUALS(ws_accum->getNumberHistograms(), 2);
TS_ASSERT_EQUALS(ws_accum->getNumberEvents(), 200);
TS_ASSERT_EQUALS(ws_accum->blocksize(), 1);
// The post-processed workspace: Check that rebin was called
TS_ASSERT_EQUALS(ws->getNumberHistograms(), 2);
TS_ASSERT_EQUALS(ws->getNumberEvents(), 200);
TS_ASSERT_EQUALS(ws->blocksize(), 20);
TS_ASSERT_DELTA(ws->dataX(0)[0], 40e3, 1e-4);
TS_ASSERT_EQUALS(AnalysisDataService::Instance().size(), 2);
TSM_ASSERT( "Events are sorted", ws_accum->getEventList(0).isSortedByTof());
TSM_ASSERT( "Events are sorted", ws->getEventList(0).isSortedByTof());
}
//--------------------------------------------------------------------------------------------
/** Perform both chunk and post-processing*/
void test_Chunk_and_PostProcessing()
{
// Process both times
EventWorkspace_sptr ws = doExec<EventWorkspace>("Replace", "Rebin", "Params=20e3, 1e3, 60e3", "Rebin", "Params=40e3, 1e3, 60e3");
EventWorkspace_sptr ws_accum = AnalysisDataService::Instance().retrieveWS<EventWorkspace>("fake_accum");
TS_ASSERT( ws )
TS_ASSERT( ws_accum )
// The accumulated workspace: it was rebinned starting at 20e3
TS_ASSERT_EQUALS(ws_accum->getNumberHistograms(), 2);
TS_ASSERT_EQUALS(ws_accum->getNumberEvents(), 200);
TS_ASSERT_EQUALS(ws_accum->blocksize(), 40);
TS_ASSERT_DELTA(ws_accum->dataX(0)[0], 20e3, 1e-4);
// The post-processed workspace was rebinned starting at 40e3
TS_ASSERT_EQUALS(ws->getNumberHistograms(), 2);
TS_ASSERT_EQUALS(ws->getNumberEvents(), 200);
TS_ASSERT_EQUALS(ws->blocksize(), 20);
TS_ASSERT_DELTA(ws->dataX(0)[0], 40e3, 1e-4);
TS_ASSERT_EQUALS(AnalysisDataService::Instance().size(), 2);
TSM_ASSERT( "Events are sorted", ws_accum->getEventList(0).isSortedByTof());
TSM_ASSERT( "Events are sorted", ws->getEventList(0).isSortedByTof());
}
//--------------------------------------------------------------------------------------------
/** Do some processing that converts to a different type of workspace */
void test_ProcessToMDWorkspace_and_Add()
{
IMDWorkspace_sptr ws;
ws = doExec<IMDWorkspace>("Add", "ConvertToDiffractionMDWorkspace", "");
if (!ws) return;
TS_ASSERT_EQUALS(ws->getNumDims(), 3);
TS_ASSERT_EQUALS(ws->getNPoints(), 200);
// Does the adding work?
ws = doExec<IMDWorkspace>("Add", "ConvertToDiffractionMDWorkspace", "");
TS_ASSERT_EQUALS(ws->getNPoints(), 400);
}
//--------------------------------------------------------------------------------------------
/** Handle WorkspaceGroups returned by the listener */
void test_WorkspaceGroup_Replace_None_None()
{
WorkspaceGroup_sptr ws = doExec<WorkspaceGroup>("Replace", "", "", "", "", false, ILiveListener_sptr(new TestGroupDataListener) );
TS_ASSERT(ws);
TS_ASSERT_EQUALS(ws->getNumberOfEntries(),3);
TS_ASSERT_EQUALS(ws->name(),"fake");
MatrixWorkspace_sptr mws = AnalysisDataService::Instance().retrieveWS<MatrixWorkspace>("fake_2");
TS_ASSERT(mws);
TS_ASSERT_EQUALS( mws->getNumberHistograms(), 2 );
TS_ASSERT_EQUALS( mws->blocksize(), 10 );
TS_ASSERT_EQUALS( mws->readX(1)[10], 10.0 );
TS_ASSERT_EQUALS( mws->readY(1)[5], 2.0 );
TS_ASSERT_EQUALS( std::accumulate( mws->readY(1).begin(), mws->readY(1).end(), 0.0, std::plus<double>() ), 20.0 );
AnalysisDataService::Instance().clear();
}
//--------------------------------------------------------------------------------------------
void test_WorkspaceGroup_Replace_Rebin_None()
{
WorkspaceGroup_sptr ws = doExec<WorkspaceGroup>("Replace", "Rebin", "Params=0,2,8", "", "", false, ILiveListener_sptr(new TestGroupDataListener) );
TS_ASSERT(ws);
TS_ASSERT_EQUALS(ws->getNumberOfEntries(),3);
TS_ASSERT_EQUALS(ws->name(),"fake");
MatrixWorkspace_sptr mws = AnalysisDataService::Instance().retrieveWS<MatrixWorkspace>("fake_2");
TS_ASSERT(mws);
TS_ASSERT_EQUALS( mws->getNumberHistograms(), 2 );
TS_ASSERT_EQUALS( mws->blocksize(), 4 );
TS_ASSERT_EQUALS( mws->readX(1)[4], 8.0 );
TS_ASSERT_EQUALS( mws->readY(1)[3], 4.0 );
TS_ASSERT_EQUALS( std::accumulate( mws->readY(1).begin(), mws->readY(1).end(), 0.0, std::plus<double>() ), 16.0 );
AnalysisDataService::Instance().clear();
}
//--------------------------------------------------------------------------------------------
void test_WorkspaceGroup_Replace_None_Rebin()
{
WorkspaceGroup_sptr ws = doExec<WorkspaceGroup>("Replace", "", "", "Rebin", "Params=0,2,8", false, ILiveListener_sptr(new TestGroupDataListener) );
TS_ASSERT(ws);
TS_ASSERT_EQUALS(ws->getNumberOfEntries(),3);
TS_ASSERT_EQUALS(ws->name(),"fake");
MatrixWorkspace_sptr mws = AnalysisDataService::Instance().retrieveWS<MatrixWorkspace>("fake_2");
TS_ASSERT(mws);
TS_ASSERT_EQUALS( mws->getNumberHistograms(), 2 );
TS_ASSERT_EQUALS( mws->blocksize(), 4 );
TS_ASSERT_EQUALS( mws->readX(1)[4], 8.0 );
TS_ASSERT_EQUALS( mws->readY(1)[3], 4.0 );
TS_ASSERT_EQUALS( std::accumulate( mws->readY(1).begin(), mws->readY(1).end(), 0.0, std::plus<double>() ), 16.0 );
AnalysisDataService::Instance().clear();
}
//--------------------------------------------------------------------------------------------
/** Handle WorkspaceGroups returned by the listener */
void test_WorkspaceGroup_Add_None_None()
{
doExec<WorkspaceGroup>("Add", "", "", "", "", false, ILiveListener_sptr(new TestGroupDataListener) );
WorkspaceGroup_sptr ws = doExec<WorkspaceGroup>("Add", "", "", "", "", false, ILiveListener_sptr(new TestGroupDataListener) );
TS_ASSERT(ws);
TS_ASSERT_EQUALS(ws->getNumberOfEntries(),3);
TS_ASSERT_EQUALS(ws->name(),"fake");
MatrixWorkspace_sptr mws = AnalysisDataService::Instance().retrieveWS<MatrixWorkspace>("fake_2");
TS_ASSERT(mws);
TS_ASSERT_EQUALS( mws->getNumberHistograms(), 2 );
TS_ASSERT_EQUALS( mws->blocksize(), 10 );
TS_ASSERT_EQUALS( mws->readX(1)[10], 10.0 );
TS_ASSERT_EQUALS( mws->readY(1)[5], 4.0 );
TS_ASSERT_EQUALS( std::accumulate( mws->readY(1).begin(), mws->readY(1).end(), 0.0, std::plus<double>() ), 40.0 );
AnalysisDataService::Instance().clear();
}
//--------------------------------------------------------------------------------------------
void test_WorkspaceGroup_Add_Rebin_None()
{
doExec<WorkspaceGroup>("Add", "Rebin", "Params=0,2,8", "", "", false, ILiveListener_sptr(new TestGroupDataListener) );
WorkspaceGroup_sptr ws = doExec<WorkspaceGroup>("Add", "Rebin", "Params=0,2,8", "", "", false, ILiveListener_sptr(new TestGroupDataListener) );
TS_ASSERT(ws);
TS_ASSERT_EQUALS(ws->getNumberOfEntries(),3);
TS_ASSERT_EQUALS(ws->name(),"fake");
MatrixWorkspace_sptr mws = AnalysisDataService::Instance().retrieveWS<MatrixWorkspace>("fake_2");
TS_ASSERT(mws);
TS_ASSERT_EQUALS( mws->getNumberHistograms(), 2 );
TS_ASSERT_EQUALS( mws->blocksize(), 4 );
TS_ASSERT_EQUALS( mws->readX(1)[4], 8.0 );
TS_ASSERT_EQUALS( mws->readY(1)[3], 8.0 );
TS_ASSERT_EQUALS( std::accumulate( mws->readY(1).begin(), mws->readY(1).end(), 0.0, std::plus<double>() ), 32.0 );
AnalysisDataService::Instance().clear();
}
//--------------------------------------------------------------------------------------------
void test_WorkspaceGroup_Add_None_Rebin()
{
doExec<WorkspaceGroup>("Add", "", "", "Rebin", "Params=0,2,8", false, ILiveListener_sptr(new TestGroupDataListener) );
WorkspaceGroup_sptr ws = doExec<WorkspaceGroup>("Add", "", "", "Rebin", "Params=0,2,8", false, ILiveListener_sptr(new TestGroupDataListener) );
TS_ASSERT(ws);
TS_ASSERT_EQUALS(ws->getNumberOfEntries(),3);
TS_ASSERT_EQUALS(ws->name(),"fake");
MatrixWorkspace_sptr mws = AnalysisDataService::Instance().retrieveWS<MatrixWorkspace>("fake_2");
TS_ASSERT(mws);
TS_ASSERT_EQUALS( mws->getNumberHistograms(), 2 );
TS_ASSERT_EQUALS( mws->blocksize(), 4 );
TS_ASSERT_EQUALS( mws->readX(1)[4], 8.0 );
TS_ASSERT_EQUALS( mws->readY(1)[3], 8.0 );
TS_ASSERT_EQUALS( std::accumulate( mws->readY(1).begin(), mws->readY(1).end(), 0.0, std::plus<double>() ), 32.0 );
AnalysisDataService::Instance().clear();
}
//--------------------------------------------------------------------------------------------
/** Handle WorkspaceGroups returned by the listener */
void test_WorkspaceGroup_Append_None_None()
{
doExec<WorkspaceGroup>("Append", "", "", "", "", false, ILiveListener_sptr(new TestGroupDataListener) );
WorkspaceGroup_sptr ws = doExec<WorkspaceGroup>("Append", "", "", "", "", false, ILiveListener_sptr(new TestGroupDataListener) );
TS_ASSERT(ws);
TS_ASSERT_EQUALS(ws->getNumberOfEntries(),3);
TS_ASSERT_EQUALS(ws->name(),"fake");
MatrixWorkspace_sptr mws = AnalysisDataService::Instance().retrieveWS<MatrixWorkspace>("fake_2");
TS_ASSERT(mws);
TS_ASSERT_EQUALS( mws->getNumberHistograms(), 4 );
TS_ASSERT_EQUALS( mws->blocksize(), 10 );
TS_ASSERT_EQUALS( mws->readX(1)[10], 10.0 );
TS_ASSERT_EQUALS( mws->readY(1)[5], 2.0 );
TS_ASSERT_EQUALS( std::accumulate( mws->readY(1).begin(), mws->readY(1).end(), 0.0, std::plus<double>() ), 20.0 );
AnalysisDataService::Instance().clear();
}
//--------------------------------------------------------------------------------------------
void test_WorkspaceGroup_Append_Rebin_None()
{
doExec<WorkspaceGroup>("Append", "Rebin", "Params=0,2,8", "", "", false, ILiveListener_sptr(new TestGroupDataListener) );
WorkspaceGroup_sptr ws = doExec<WorkspaceGroup>("Append", "Rebin", "Params=0,2,8", "", "", false, ILiveListener_sptr(new TestGroupDataListener) );
TS_ASSERT(ws);
TS_ASSERT_EQUALS(ws->getNumberOfEntries(),3);
TS_ASSERT_EQUALS(ws->name(),"fake");
MatrixWorkspace_sptr mws = AnalysisDataService::Instance().retrieveWS<MatrixWorkspace>("fake_2");
TS_ASSERT(mws);
TS_ASSERT_EQUALS( mws->getNumberHistograms(), 4 );
TS_ASSERT_EQUALS( mws->blocksize(), 4 );
TS_ASSERT_EQUALS( mws->readX(1)[4], 8.0 );
TS_ASSERT_EQUALS( mws->readY(1)[3], 4.0 );
TS_ASSERT_EQUALS( std::accumulate( mws->readY(1).begin(), mws->readY(1).end(), 0.0, std::plus<double>() ), 16.0 );
AnalysisDataService::Instance().clear();
}
//--------------------------------------------------------------------------------------------
void test_WorkspaceGroup_Append_None_Rebin()
{
doExec<WorkspaceGroup>("Append", "", "", "Rebin", "Params=0,2,8", false, ILiveListener_sptr(new TestGroupDataListener) );
WorkspaceGroup_sptr ws = doExec<WorkspaceGroup>("Append", "", "", "Rebin", "Params=0,2,8", false, ILiveListener_sptr(new TestGroupDataListener) );
TS_ASSERT(ws);
TS_ASSERT_EQUALS(ws->getNumberOfEntries(),3);
TS_ASSERT_EQUALS(ws->name(),"fake");
MatrixWorkspace_sptr mws = AnalysisDataService::Instance().retrieveWS<MatrixWorkspace>("fake_2");
TS_ASSERT(mws);
TS_ASSERT_EQUALS( mws->getNumberHistograms(), 4 );
TS_ASSERT_EQUALS( mws->blocksize(), 4 );
TS_ASSERT_EQUALS( mws->readX(1)[4], 8.0 );
TS_ASSERT_EQUALS( mws->readY(1)[3], 4.0 );
TS_ASSERT_EQUALS( std::accumulate( mws->readY(1).begin(), mws->readY(1).end(), 0.0, std::plus<double>() ), 16.0 );
AnalysisDataService::Instance().clear();
}
};
#endif /* MANTID_LIVEDATA_LOADLIVEDATATEST_H_ */