-
Notifications
You must be signed in to change notification settings - Fork 122
/
CreateMDWorkspaceTest.h
194 lines (165 loc) · 6.01 KB
/
CreateMDWorkspaceTest.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
#ifndef MANTID_MDEVENTS_CREATEMDEVENTWORKSPACETEST_H_
#define MANTID_MDEVENTS_CREATEMDEVENTWORKSPACETEST_H_
#include "MantidAPI/AnalysisDataService.h"
#include "MantidAPI/IMDEventWorkspace.h"
#include "MantidKernel/System.h"
#include "MantidKernel/Timer.h"
#include "MantidMDEvents/MDEventFactory.h"
#include "MantidMDAlgorithms/CreateMDWorkspace.h"
#include "MantidAPI/FrameworkManager.h"
#include <cxxtest/TestSuite.h>
#include <iomanip>
#include <iostream>
#include <Poco/File.h>
using namespace Mantid::API;
using namespace Mantid::Geometry;
using namespace Mantid::MDEvents;
using namespace Mantid::MDAlgorithms;
class CreateMDWorkspaceTest : public CxxTest::TestSuite
{
public:
void test_Init()
{
CreateMDWorkspace alg;
TS_ASSERT_THROWS_NOTHING( alg.initialize() )
TS_ASSERT( alg.isInitialized() )
}
void test_default_properties()
{
TS_ASSERT( FrameworkManager::Instance().exec("CreateMDWorkspace", 10,
"OutputWorkspace","simple_md",
"Dimensions", "3",
"Extents", "-1,1,-2,2,3,3",
"Names", "One,Two,Three",
"Units", "One,Two,Three"
)->isExecuted() );
}
/** Validate bad inputs. */
void test_validation()
{
TS_ASSERT( !FrameworkManager::Instance().exec("CreateMDWorkspace", 4,
"OutputWorkspace","failed_output",
"Dimensions", "0")->isExecuted() );
TS_ASSERT( !FrameworkManager::Instance().exec("CreateMDWorkspace", 6,
"OutputWorkspace","failed_output",
"Dimensions", "3",
"Extents", "-1,1,-2,2")->isExecuted() );
TS_ASSERT( !FrameworkManager::Instance().exec("CreateMDWorkspace", 6,
"OutputWorkspace","failed_output",
"Dimensions", "3",
"Extents", "-1,1,-2,2,3,3,4,4")->isExecuted() );
TS_ASSERT( !FrameworkManager::Instance().exec("CreateMDWorkspace", 8,
"OutputWorkspace","failed_output",
"Dimensions", "3", "Extents", "-1,1,-2,2,3,3",
"Names", "One,Two")->isExecuted() );
TS_ASSERT( !FrameworkManager::Instance().exec("CreateMDWorkspace", 12,
"OutputWorkspace","failed_output",
"Dimensions", "3", "Extents", "-1,1,-2,2,3,3",
"Names", "One,Two,Three",
"MinRecursionDepth", "5",
"MaxRecursionDepth", "4")->isExecuted() );
// Uses too much memory
TS_ASSERT( !FrameworkManager::Instance().exec("CreateMDWorkspace", 14,
"OutputWorkspace","failed_output",
"Dimensions", "3", "Extents", "-1,1,-2,2,3,3",
"Names", "One,Two,Three",
"Units", "One,Two,Three",
"SplitInto", "10",
"MinRecursionDepth", "5",
"MaxRecursionDepth", "5")->isExecuted() );
}
void do_test_exec(std::string Filename, bool lean, int MinRecursionDepth=0, int expectedNumMDBoxes=216)
{
if (Filename != "")
{
if (Poco::File(Filename).exists()) Poco::File(Filename).remove();
}
std::string wsName = "CreateMDWorkspaceTest_out";
CreateMDWorkspace alg;
TS_ASSERT_THROWS_NOTHING( alg.initialize() )
TS_ASSERT( alg.isInitialized() )
alg.setPropertyValue("Dimensions", "3");
alg.setPropertyValue("EventType", lean ? "MDLeanEvent" : "MDEvent");
alg.setPropertyValue("Extents", "-1,1,-2,2,-3,3");
alg.setPropertyValue("Names", "x,y,z");
alg.setPropertyValue("Units", "m,mm,um");
alg.setPropertyValue("SplitInto", "6");
alg.setPropertyValue("SplitThreshold", "500");
alg.setProperty("MinRecursionDepth", MinRecursionDepth);
alg.setProperty("MaxRecursionDepth", 7);
alg.setPropertyValue("OutputWorkspace",wsName);
alg.setPropertyValue("Filename", Filename);
alg.setPropertyValue("Memory", "1");
TS_ASSERT_THROWS_NOTHING( alg.execute(); );
TS_ASSERT( alg.isExecuted() );
// Get it from data service
IMDEventWorkspace_sptr ws;
TS_ASSERT_THROWS_NOTHING(ws = boost::dynamic_pointer_cast<IMDEventWorkspace>( AnalysisDataService::Instance().retrieve(wsName) ));
TS_ASSERT( ws );
// Correct info?
TS_ASSERT_EQUALS( ws->getNumDims(), 3);
TS_ASSERT_EQUALS( ws->getNPoints(), 0);
IMDDimension_const_sptr dim;
dim = ws->getDimension(0);
TS_ASSERT_DELTA( dim->getMaximum(), 1.0, 1e-6);
TS_ASSERT_EQUALS( dim->getName(), "x");
TS_ASSERT_EQUALS( dim->getUnits(), "m");
dim = ws->getDimension(1);
TS_ASSERT_DELTA( dim->getMaximum(), 2.0, 1e-6);
TS_ASSERT_EQUALS( dim->getName(), "y");
TS_ASSERT_EQUALS( dim->getUnits(), "mm");
dim = ws->getDimension(2);
TS_ASSERT_DELTA( dim->getMaximum(), 3.0, 1e-6);
TS_ASSERT_EQUALS( dim->getName(), "z");
TS_ASSERT_EQUALS( dim->getUnits(), "um");
// What about the box controller
BoxController_sptr bc;
if (lean)
{
MDEventWorkspace3Lean::sptr ews = boost::dynamic_pointer_cast<MDEventWorkspace3Lean>(ws);
TS_ASSERT( ews ); if (!ews) return;
bc = ews->getBoxController();
}
else
{
MDEventWorkspace3::sptr ews = boost::dynamic_pointer_cast<MDEventWorkspace3>(ws);
TS_ASSERT( ews ); if (!ews) return;
bc = ews->getBoxController();
}
TS_ASSERT( bc );
if (!bc) return;
TS_ASSERT_EQUALS(bc->getSplitInto(0), 6 );
TS_ASSERT_EQUALS(bc->getSplitThreshold(), 500 );
TS_ASSERT_EQUALS(bc->getMaxDepth(), 7 );
TS_ASSERT_EQUALS(bc->getTotalNumMDBoxes(), expectedNumMDBoxes);
if (Filename != "")
{
std::string s = alg.getPropertyValue("Filename");
TSM_ASSERT( "File for the back-end was created.", Poco::File(s).exists() );
std::cout << "Closing the file." << std::endl;
bc->closeFile();
if (Poco::File(s).exists()) Poco::File(s).remove();
}
}
void test_exec_MDEvent()
{
do_test_exec("", false);
}
void test_exec_MDEvent_fileBacked()
{
do_test_exec("CreateMDWorkspaceTest.nxs", false);
}
void test_exec_MDLeanEvent()
{
do_test_exec("", true);
}
void test_exec_MDLeanEvent_fileBacked()
{
do_test_exec("CreateMDWorkspaceTest.nxs", true);
}
void test_exec_MinRecursionDepth()
{
do_test_exec("", true, 2, 216*216);
}
};
#endif /* MANTID_MDEVENTS_CREATEMDEVENTWORKSPACETEST_H_ */