LoadILLSANSTest.h 5.23 KB
Newer Older
1
2
3
4
5
#ifndef MANTID_DATAHANDLING_LOADILLSANSTEST_H_
#define MANTID_DATAHANDLING_LOADILLSANSTEST_H_

#include <cxxtest/TestSuite.h>

6
#include "MantidAPI/AnalysisDataService.h"
7
#include "MantidAPI/MatrixWorkspace.h"
8
#include "MantidDataHandling/LoadILLSANS.h"
9
10
11
12
#include "MantidGeometry/IComponent.h"
#include "MantidGeometry/Instrument.h"
#include "MantidGeometry/Instrument/DetectorInfo.h"
#include "MantidKernel/ConfigService.h"
13
14

using Mantid::DataHandling::LoadILLSANS;
15
16
17
18
19
20
using Mantid::API::MatrixWorkspace_const_sptr;
using Mantid::API::AnalysisDataService;
using Mantid::Kernel::ConfigService;
using Mantid::Kernel::V3D;
using Mantid::Geometry::IComponent_const_sptr;
using Mantid::Geometry::Instrument;
21

22
class LoadILLSANSTest : public CxxTest::TestSuite {
23
public:
24
25
26
27
28
  // This pair of boilerplate methods prevent the suite being created statically
  // This means the constructor isn't called when running other tests
  static LoadILLSANSTest *createSuite() { return new LoadILLSANSTest(); }
  static void destroySuite(LoadILLSANSTest *suite) { delete suite; }

29
30
31
32
33
34
35
36
37
38
39
  void setUp() override {
    ConfigService::Instance().appendDataSearchSubDir("ILL/D11/");
    ConfigService::Instance().appendDataSearchSubDir("ILL/D22/");
    ConfigService::Instance().appendDataSearchSubDir("ILL/D33/");
    ConfigService::Instance().setFacility("ILL");
  }

  void tearDown() override {
      AnalysisDataService::Instance().clear();
  }

40
41
42
43
44
45
46
47
48
49
  void testName() {
    LoadILLSANS alg;
    TS_ASSERT_EQUALS(alg.name(), "LoadILLSANS");
  }

  void testVersion() {
    LoadILLSANS alg;
    TS_ASSERT_EQUALS(alg.version(), 1);
  }

50
  void test_init() {
51
52
53
54
55
    LoadILLSANS alg;
    TS_ASSERT_THROWS_NOTHING(alg.initialize())
    TS_ASSERT(alg.isInitialized())
  }

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
void test_D11() {
    LoadILLSANS alg;
    alg.setChild(true);
    alg.initialize();
    TS_ASSERT_THROWS_NOTHING(alg.setPropertyValue("Filename", "010560.nxs"))
    TS_ASSERT_THROWS_NOTHING(
        alg.setPropertyValue("OutputWorkspace", "__unused_for_child"))
    TS_ASSERT_THROWS_NOTHING(alg.execute())
    TS_ASSERT(alg.isExecuted())
    MatrixWorkspace_const_sptr outputWS = alg.getProperty("OutputWorkspace");
    TS_ASSERT(outputWS)
    TS_ASSERT_EQUALS(outputWS->getNumberHistograms(),128*128+2)
    TS_ASSERT_EQUALS(outputWS->blocksize(), 1)
    TS_ASSERT(outputWS->detectorInfo().isMonitor(128*128))
    TS_ASSERT(outputWS->detectorInfo().isMonitor(128*128+1))
    TS_ASSERT(outputWS->isHistogramData())
    TS_ASSERT(!outputWS->isDistribution())
    const auto &instrument = outputWS->getInstrument();
    IComponent_const_sptr component = instrument->getComponentByName("detector");
    V3D pos = component->getPos();
    TS_ASSERT_DELTA(pos.Z(), 20.007, 1E-3)
    const auto& xAxis = outputWS->x(0).rawData();
    const auto& spec6 = outputWS->y(6).rawData();
    TS_ASSERT_EQUALS(xAxis.size(), 2)
    TS_ASSERT_DELTA(xAxis[0], 5.72778, 1E-5)
    TS_ASSERT_DELTA(xAxis[1], 6.26757, 1E-5)
    TS_ASSERT_EQUALS(spec6[0], 20)
}

void test_D22() {
    LoadILLSANS alg;
    alg.setChild(true);
    alg.initialize();
    TS_ASSERT_THROWS_NOTHING(alg.setPropertyValue("Filename", "192068.nxs"))
    TS_ASSERT_THROWS_NOTHING(
        alg.setPropertyValue("OutputWorkspace", "__unused_for_child"))
    TS_ASSERT_THROWS_NOTHING(alg.execute())
    TS_ASSERT(alg.isExecuted())
    MatrixWorkspace_const_sptr outputWS = alg.getProperty("OutputWorkspace");
    TS_ASSERT(outputWS)
    TS_ASSERT_EQUALS(outputWS->getNumberHistograms(),128*256+2)
    TS_ASSERT_EQUALS(outputWS->blocksize(), 1)
    TS_ASSERT(outputWS->detectorInfo().isMonitor(128*256))
    TS_ASSERT(outputWS->detectorInfo().isMonitor(128*256+1))
    TS_ASSERT(outputWS->isHistogramData())
    TS_ASSERT(!outputWS->isDistribution())
    const auto &instrument = outputWS->getInstrument();
    IComponent_const_sptr component = instrument->getComponentByName("detector");
    V3D pos = component->getPos();
    TS_ASSERT_DELTA(pos.Z(), 8, 0.01)
    TS_ASSERT_DELTA(pos.X(), 0.35, 0.01)
    const auto& xAxis = outputWS->x(0).rawData();
    const auto& spec6 = outputWS->y(6).rawData();
    TS_ASSERT_EQUALS(xAxis.size(), 2)
    TS_ASSERT_DELTA(xAxis[0], 4.75015, 1E-5)
    TS_ASSERT_DELTA(xAxis[1], 5.25016, 1E-5)
    TS_ASSERT_EQUALS(spec6[0], 45)
}
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
class LoadILLSANSTestPerformance : public CxxTest::TestSuite {
public:
  void setUp() override {
    for (int i = 0; i < numberOfIterations; ++i) {
      loadAlgPtrs.emplace_back(setupAlg());
    }
  }

  void testLoadILLSANSPerformance() {
    for (auto alg : loadAlgPtrs) {
      TS_ASSERT_THROWS_NOTHING(alg->execute());
    }
  }

  void tearDown() override {
    for (int i = 0; i < numberOfIterations; i++) {
      delete loadAlgPtrs[i];
      loadAlgPtrs[i] = nullptr;
    }
    Mantid::API::AnalysisDataService::Instance().remove(outWSName);
  }

private:
  std::vector<LoadILLSANS *> loadAlgPtrs;

  const int numberOfIterations = 2;

  const std::string inFileName = "ILLD33_041714_NonTof.nxs";
  const std::string outWSName = "LoadILLSANSWsOut";

  LoadILLSANS *setupAlg() {
    LoadILLSANS *loader = new LoadILLSANS;
    loader->initialize();
    loader->isInitialized();
    loader->setPropertyValue("Filename", inFileName);
    loader->setPropertyValue("OutputWorkspace", outWSName);

    loader->setRethrows(true);
    return loader;
  }
};

159
#endif /* MANTID_DATAHANDLING_LOADILLSANSTEST_H_ */