Mantid
Loading...
Searching...
No Matches
JSONGeometryParserTestHelper.cpp
Go to the documentation of this file.
1// Mantid Repository : https://github.com/mantidproject/mantid
2//
3// Copyright © 2018 ISIS Rutherford Appleton Laboratory UKRI,
4// NScD Oak Ridge National Laboratory, European Spallation Source,
5// Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
6// SPDX - License - Identifier: GPL - 3.0 +
8#include "json/json.h"
9#include <iostream>
10#include <numeric>
11
12namespace {
13template <class T> std::string getType() {
14 if (std::is_same<T, std::int64_t>::value)
15 return "int64";
16 if (std::is_same<T, std::int32_t>::value)
17 return "int32";
18 if (std::is_same<T, double>::value)
19 return "double";
20 if (std::is_same<T, float>::value)
21 return "float";
22
23 return "unknown";
24}
25
26template <class T> Json::Value convertToJsonValue(const T value) {
27 if (std::is_same<T, int64_t>::value)
28 return Json::Value(static_cast<Json::Int64>(value));
29 else if (std::is_same<T, int32_t>::value)
30 return Json::Value(static_cast<Json::Int>(value));
31 else if (std::is_same<T, double>::value || std::is_same<T, float>::value)
32 return Json::Value(static_cast<double>(value));
33}
34
35Json::Value createNXAttributes(const std::string &NXClass) {
36 Json::Value attributes;
37 attributes[0]["name"] = "NX_class";
38 attributes[0]["values"] = NXClass;
39 return attributes;
40}
41
42Json::Value createAttribute(const std::string &name, const std::string &values) {
43 Json::Value attribute;
44 attribute["name"] = name;
45 attribute["values"] = values;
46 return attribute;
47}
48
49template <class T> Json::Value createAttribute(const std::string &name, const std::vector<T> &values) {
50 Json::Value attribute;
51 attribute["name"] = name;
52 attribute["type"] = getType<T>();
53 for (size_t i = 0; i < values.size(); ++i)
54 attribute["values"][static_cast<int>(i)] = values[i];
55
56 return attribute;
57}
58
59Json::Value createEmptyDataset(const std::string &name, const std::string &type) {
60 Json::Value dataset;
61 dataset["type"] = "dataset";
62 dataset["name"] = name;
63
64 Json::Value datasetType;
65 datasetType["type"] = type;
66
67 dataset["dataset"] = datasetType;
68
69 return dataset;
70}
71
72Json::Value createNX(const std::string &name, const std::string &NXClass) {
73 Json::Value nx;
74 nx["type"] = "group";
75 nx["name"] = name;
76 nx["children"].resize(0);
77 nx["attributes"] = createNXAttributes(NXClass);
78
79 return nx;
80}
81
82void appendToChildren(Json::Value &parent, const Json::Value &child) {
83 Json::Value &children = parent["children"];
84 children[children.size()] = child;
85}
86
87void resizeValues(Json::Value &values, size_t size) {
88 if (values.empty()) {
89 values.resize(static_cast<Json::ArrayIndex>(size));
90 for (Json::ArrayIndex i = 0; i < values.size(); ++i)
91 values[i].resize(0);
92 } else {
93 for (auto &val : values) {
94 if (val.size() > 0) {
95 for (auto &child : val)
96 resizeValues(child, size);
97 } else
98 resizeValues(val, size);
99 }
100 }
101}
102
103template <class T> void fillValues(Json::Value &values, const std::vector<T> &fillArray, size_t &start, size_t size) {
104 if (!values.isNull() && !values.empty()) {
105 for (auto &val : values)
106 fillValues<T>(val, fillArray, start, size);
107 } else {
108 for (size_t i = 0; i < size; ++i) {
109 values[static_cast<int>(i)] = convertToJsonValue<T>(fillArray[start + i]);
110 }
111 start += size;
112 }
113}
114
115template <class T>
116void addDataset(Json::Value &parent, const std::string &name, const std::vector<int> &arrayShape,
117 const std::vector<T> &data, const std::string &attributesName = "",
118 const std::string &attributesValues = "") {
119 auto dataset = createEmptyDataset(name, getType<T>());
120 int i = 0;
121 for (; i < static_cast<int>(arrayShape.size() - 1); ++i) {
122 auto s = arrayShape[i];
123 dataset["dataset"]["size"][i] = s;
124 resizeValues(dataset["values"], s);
125 }
126
127 auto leafSize = static_cast<size_t>(arrayShape[arrayShape.size() - 1]);
128 dataset["dataset"]["size"][i] = convertToJsonValue<int64_t>(leafSize);
129 size_t start = 0;
130 fillValues<T>(dataset["values"], data, start, leafSize);
131
132 if (!attributesName.empty())
133 dataset["attributes"][0] = createAttribute(attributesName, attributesValues);
134
135 appendToChildren(parent, dataset);
136}
137
138void addTransformationChild(Json::Value &transformation, const std::string &name, const std::string &transformationType,
139 const std::string &dependency, const std::string &units, const std::vector<int> &arrayShape,
140 const std::vector<double> &values, const std::vector<double> &vec) {
141 addDataset<double>(transformation, name, arrayShape, values, "units", units);
142 auto index = transformation["children"].size() - 1;
143 Json::Value &child = transformation["children"][index];
144 child["attributes"][1] = createAttribute("vector", vec);
145 child["attributes"][2] = createAttribute("depends_on", dependency);
146 child["attributes"][3] = createAttribute("transformation_type", transformationType);
147}
148
149Json::Value &addNX(Json::Value &parent, const std::string &name, const std::string &NXClass) {
150 auto &children = parent["children"];
151 auto &child = children[children.size()];
152 child = createNX(name, NXClass);
153 return child;
154}
155
156void addStream(Json::Value &parent, const std::string &name, const std::string &topic, const std::string &source,
157 const std::string &writerModule) {
158 Json::Value streamGroup;
159 streamGroup["type"] = "group";
160 streamGroup["name"] = name;
161 Json::Value stream;
162 stream["type"] = "stream";
163 stream["stream"]["topic"] = topic;
164 stream["stream"]["source"] = source;
165 stream["stream"]["writer_module"] = writerModule;
166 appendToChildren(streamGroup, stream);
167 appendToChildren(parent, streamGroup);
168}
169} // namespace
170
172namespace JSONTestInstrumentBuilder {
173
174void initialiseRoot(const Json::Value &root, const std::string &name) { root[name]; }
175
176Json::Value &addNXEntry(Json::Value &root, const std::string &name) {
177 return addNX(root["nexus_structure"], name, "NXentry");
178}
179
180Json::Value &addNXSample(Json::Value &entry, const std::string &name) { return addNX(entry, name, "NXsample"); }
181
182Json::Value &addNXInstrument(Json::Value &entry, const std::string &name) { return addNX(entry, name, "NXinstrument"); }
183
184void addNXInstrumentName(Json::Value &instrument, const std::string &name) {
185 auto instrumentName = createEmptyDataset("name", "string");
186 instrumentName["values"] = name;
187 appendToChildren(instrument, instrumentName);
188}
189
190Json::Value &addNXSource(Json::Value &instrument, const std::string &name) {
191 return addNX(instrument, name, "NXsource");
192}
193
194Json::Value &addNXMonitor(Json::Value &entry, const std::string &name) { return addNX(entry, name, "NXmonitor"); }
195void addNXMonitorName(Json::Value &monitor, const std::string &name) {
196 auto monitorName = createEmptyDataset("name", "string");
197 monitorName["values"] = name;
198 appendToChildren(monitor, monitorName);
199}
200
201void addNXMonitorDetectorID(Json::Value &monitor, const int32_t detectorID) {
202 auto monitorDetID = createEmptyDataset("detector_id", "int32");
203 monitorDetID["values"] = convertToJsonValue<int32_t>(detectorID);
204 appendToChildren(monitor, monitorDetID);
205}
206
207void addNXMonitorEventStreamInfo(Json::Value &monitor, const std::string &topic, const std::string &source,
208 const std::string &writerModule) {
209 addStream(monitor, "events", topic, source, writerModule);
210}
211
212void addNXMonitorWaveformStreamInfo(Json::Value &monitor, const std::string &topic, const std::string &source,
213 const std::string &writerModule) {
214 addStream(monitor, "waveforms", topic, source, writerModule);
215}
216
217Json::Value &addNXChopper(Json::Value &instrument, const std::string &name) {
218 return addNX(instrument, name, "NXdisk_chopper");
219}
220
221void addNXChopperName(Json::Value &chopper, const std::string &chopperName) {
222 auto chopperFullName = createEmptyDataset("name", "string");
223 chopperFullName["values"] = chopperName;
224 appendToChildren(chopper, chopperFullName);
225}
226
227void addNXChopperRadius(Json::Value &chopper, const double radius) {
228 auto chopperRadius = createEmptyDataset("radius", "double");
229 chopperRadius["values"] = radius;
230 chopperRadius["attributes"][0] = createAttribute("units", "mm");
231 appendToChildren(chopper, chopperRadius);
232}
233
234void addNXChopperSlitEdges(Json::Value &chopper, const std::vector<double> &edges) {
235 addDataset<double>(chopper, "slit_edges", {2}, edges, "units", "mm");
236}
237
238void addNXChopperSlitHeight(Json::Value &chopper, const double slitHeight) {
239 auto chopperSlitHeight = createEmptyDataset("slit_height", "double");
240 chopperSlitHeight["values"] = slitHeight;
241 chopperSlitHeight["attributes"][0] = createAttribute("units", "mm");
242 appendToChildren(chopper, chopperSlitHeight);
243}
244
245void addNXChopperSlits(Json::Value &chopper, const int32_t value) {
246 auto chopperSlits = createEmptyDataset("slits", "int32");
247 chopperSlits["values"] = convertToJsonValue<int32_t>(value);
248 appendToChildren(chopper, chopperSlits);
249}
250
251void addNXChopperTopDeadCenter(Json::Value &chopper, const std::string &topic, const std::string &source,
252 const std::string &writerModule) {
253 addStream(chopper, "top_dead_center", topic, source, writerModule);
254}
255
256Json::Value &addNXDetector(Json::Value &instrument, const std::string &name) {
257 return addNX(instrument, name, "NXdetector");
258}
259
260void addNXTransformationDependency(Json::Value &nxDetector, const std::string &dependencyPath) {
261 auto transDep = createEmptyDataset("depends_on", "string");
262 transDep["values"] = dependencyPath;
263 appendToChildren(nxDetector, transDep);
264}
265
266Json::Value &addNXTransformation(Json::Value &nxDetector, const std::string &name) {
267 return addNX(nxDetector, name, "NXtransformations");
268}
269
270void addNXTransformationBeamDirectionOffset(Json::Value &nxTransformation, const std::vector<int> &arrayShape,
271 const std::vector<double> &values, const std::vector<double> &vec) {
272 addTransformationChild(nxTransformation, "beam_direction_offset", "translation",
273 "/entry/instrument/detector_1/transformations/orientation", "m", arrayShape, values, vec);
274}
275
276void addNXTransformationLocation(Json::Value &nxTransformation, const std::vector<int> &arrayShape,
277 const std::vector<double> &values, const std::vector<double> &vec) {
278 addTransformationChild(nxTransformation, "location", "translation",
279 "/entry/instrument/detector_1/transformations/beam_direction_offset", "m", arrayShape, values,
280 vec);
281}
282
283void addNXTransformationOrientation(Json::Value &nxTransformation, const std::vector<int> &arrayShape,
284 const std::vector<double> &values, const std::vector<double> &vec) {
285 addTransformationChild(nxTransformation, "orientation", "translation", ".", "degrees", arrayShape, values, vec);
286}
287
288void addDetectorNumbers(Json::Value &nxDetector, const std::vector<int32_t> &arrayShape,
289 const std::vector<int32_t> &values) {
290 addDataset<int32_t>(nxDetector, "detector_number", arrayShape, values);
291}
292
293void addXPixelOffset(Json::Value &nxDetector, const std::vector<int32_t> &arrayShape,
294 const std::vector<double> &values) {
295 addDataset<double>(nxDetector, "x_pixel_offset", arrayShape, values, "units", "m");
296}
297
298void addYPixelOffset(Json::Value &nxDetector, const std::vector<int32_t> &arrayShape,
299 const std::vector<double> &values) {
300 addDataset<double>(nxDetector, "y_pixel_offset", arrayShape, values, "units", "m");
301}
302
303void addZPixelOffset(Json::Value &nxDetector, const std::vector<int32_t> &arrayShape,
304 const std::vector<double> &values) {
305 addDataset<double>(nxDetector, "z_pixel_offset", arrayShape, values, "units", "m");
306}
307
308Json::Value &addOffShape(Json::Value &nxDetector, const std::string &name) {
309 return addNX(nxDetector, name, "NXoff_geometry");
310}
311
312void addOffShapeFaces(Json::Value &shape, const std::vector<int> &arrayShape, const std::vector<int> &indices) {
313 addDataset<int>(shape, "faces", arrayShape, indices, "", "");
314}
315
316void addOffShapeVertices(Json::Value &shape, const std::vector<int> &arrayShape, const std::vector<double> &vertices) {
317 addDataset<double>(shape, "vertices", arrayShape, vertices, "units", "m");
318}
319
320void addOffShapeWindingOrder(Json::Value &shape, const std::vector<int> &arrayShape,
321 const std::vector<int> &windingOrder) {
322 addDataset<int>(shape, "winding_order", arrayShape, windingOrder, "", "");
323}
324
325Json::Value &addCylindricalShape(Json::Value &nxDetector, const std::string &name) {
326 return addNX(nxDetector, name, "NXcylindrical_geometry");
327}
328
329void addCylindricalShapeCylinders(Json::Value &shape, const std::vector<int> &arrayShape,
330 const std::vector<int> &indices) {
331 addDataset<int>(shape, "cylinders", arrayShape, indices);
332}
333
334void addCylindricalShapeVertices(Json::Value &shape, const std::vector<int> &arrayShape,
335 const std::vector<double> &vertices) {
336 addDataset<double>(shape, "vertices", arrayShape, vertices, "units", "m");
337}
338
339const std::string convertToString(const Json::Value &value) { return value.toStyledString(); }
340
341} // namespace JSONTestInstrumentBuilder
342
344 Json::Value root;
345 JSONTestInstrumentBuilder::initialiseRoot(root, "nexus_structure");
348}
349
351 Json::Value root;
352 JSONTestInstrumentBuilder::initialiseRoot(root, "nexus_structure");
353 auto &entry = JSONTestInstrumentBuilder::addNXEntry(root, "entry");
355
357}
358
360 Json::Value root;
361 JSONTestInstrumentBuilder::initialiseRoot(root, "nexus_structure");
362 auto &entry = JSONTestInstrumentBuilder::addNXEntry(root, "entry");
365
367}
368
370 Json::Value root;
371 JSONTestInstrumentBuilder::initialiseRoot(root, "nexus_structure");
372 auto &entry = JSONTestInstrumentBuilder::addNXEntry(root, "entry");
374 auto &instrument = JSONTestInstrumentBuilder::addNXInstrument(entry, "instrument");
375 JSONTestInstrumentBuilder::addNXDetector(instrument, "detector_1");
376
378}
379
381 Json::Value root;
382 JSONTestInstrumentBuilder::initialiseRoot(root, "nexus_structure");
383 auto &entry = JSONTestInstrumentBuilder::addNXEntry(root, "entry");
385 auto &instrument = JSONTestInstrumentBuilder::addNXInstrument(entry, "instrument");
386 auto &detectorBank = JSONTestInstrumentBuilder::addNXDetector(instrument, "detector_1");
387
388 JSONTestInstrumentBuilder::addDetectorNumbers(detectorBank, {2, 2}, std::vector<int32_t>{1, 2, 3, 4});
389
391}
392
394 Json::Value root;
395 JSONTestInstrumentBuilder::initialiseRoot(root, "nexus_structure");
396 auto &entry = JSONTestInstrumentBuilder::addNXEntry(root, "entry");
398 auto &instrument = JSONTestInstrumentBuilder::addNXInstrument(entry, "instrument");
399 auto &detectorBank = JSONTestInstrumentBuilder::addNXDetector(instrument, "detector_1");
400
401 JSONTestInstrumentBuilder::addDetectorNumbers(detectorBank, {2, 2}, std::vector<int32_t>{1, 2, 3, 4});
402 JSONTestInstrumentBuilder::addXPixelOffset(detectorBank, {2, 2}, {-0.299, -0.297, -0.299, -0.297});
403
405}
406
408 Json::Value root;
409 JSONTestInstrumentBuilder::initialiseRoot(root, "nexus_structure");
410 auto &entry = JSONTestInstrumentBuilder::addNXEntry(root, "entry");
412 auto &instrument = JSONTestInstrumentBuilder::addNXInstrument(entry, "instrument");
413 auto &detectorBank = JSONTestInstrumentBuilder::addNXDetector(instrument, "detector_1");
414
415 JSONTestInstrumentBuilder::addDetectorNumbers(detectorBank, {2, 2}, std::vector<int32_t>{1, 2, 3, 4});
416 JSONTestInstrumentBuilder::addXPixelOffset(detectorBank, {2, 2}, {-0.299, -0.297, -0.299, -0.297});
417 JSONTestInstrumentBuilder::addYPixelOffset(detectorBank, {2, 2}, {-0.299, -0.299, -0.297, -0.297});
419}
420
422 Json::Value root;
423 JSONTestInstrumentBuilder::initialiseRoot(root, "nexus_structure");
424 auto &entry = JSONTestInstrumentBuilder::addNXEntry(root, "entry");
426 auto &instrument = JSONTestInstrumentBuilder::addNXInstrument(entry, "instrument");
427 auto &detectorBank = JSONTestInstrumentBuilder::addNXDetector(instrument, "detector_1");
428
429 JSONTestInstrumentBuilder::addDetectorNumbers(detectorBank, {2, 2}, std::vector<int32_t>{1, 2, 3, 4});
430 JSONTestInstrumentBuilder::addXPixelOffset(detectorBank, {2, 2}, {-0.299, -0.297, -0.299, -0.297});
431 JSONTestInstrumentBuilder::addYPixelOffset(detectorBank, {2, 2}, {-0.299, -0.299, -0.297, -0.297});
434}
435
437 Json::Value root;
438 JSONTestInstrumentBuilder::initialiseRoot(root, "nexus_structure");
439 auto &entry = JSONTestInstrumentBuilder::addNXEntry(root, "entry");
441 auto &instrument = JSONTestInstrumentBuilder::addNXInstrument(entry, "instrument");
442 auto &detectorBank = JSONTestInstrumentBuilder::addNXDetector(instrument, "detector_1");
443
444 JSONTestInstrumentBuilder::addDetectorNumbers(detectorBank, {2, 2}, std::vector<int32_t>{1, 2, 3, 4});
445 JSONTestInstrumentBuilder::addXPixelOffset(detectorBank, {2, 2}, {-0.299, -0.297, -0.299, -0.297});
446 JSONTestInstrumentBuilder::addYPixelOffset(detectorBank, {2, 2}, {-0.299, -0.299, -0.297, -0.297});
447 auto &pixelShape = JSONTestInstrumentBuilder::addOffShape(detectorBank);
450 JSONTestInstrumentBuilder::addOffShapeWindingOrder(pixelShape, {3}, {0, 1, 2}); // invalid
451
453}
454
456 Json::Value root;
457 JSONTestInstrumentBuilder::initialiseRoot(root, "nexus_structure");
458 auto &entry = JSONTestInstrumentBuilder::addNXEntry(root, "entry");
460 auto &instrument = JSONTestInstrumentBuilder::addNXInstrument(entry, "instrument");
461 auto &detectorBank = JSONTestInstrumentBuilder::addNXDetector(instrument, "detector_1");
462
463 JSONTestInstrumentBuilder::addDetectorNumbers(detectorBank, {2, 2}, std::vector<int32_t>{1, 2, 3, 4});
464 JSONTestInstrumentBuilder::addXPixelOffset(detectorBank, {2, 2}, {-0.299, -0.297, -0.299, -0.297});
465 JSONTestInstrumentBuilder::addYPixelOffset(detectorBank, {2, 2}, {-0.299, -0.299, -0.297, -0.297});
468}
469
471 Json::Value root;
472 JSONTestInstrumentBuilder::initialiseRoot(root, "nexus_structure");
473 auto &entry = JSONTestInstrumentBuilder::addNXEntry(root, "entry");
475 auto &instrument = JSONTestInstrumentBuilder::addNXInstrument(entry, "instrument");
476 auto &detectorBank = JSONTestInstrumentBuilder::addNXDetector(instrument, "detector_1");
477
478 JSONTestInstrumentBuilder::addDetectorNumbers(detectorBank, {2, 2}, std::vector<int32_t>{1, 2, 3, 4});
479 JSONTestInstrumentBuilder::addXPixelOffset(detectorBank, {2, 2}, {-0.299, -0.297, -0.299, -0.297});
480 JSONTestInstrumentBuilder::addYPixelOffset(detectorBank, {2, 2}, {-0.299, -0.299, -0.297, -0.297});
481 auto &pixelShape = JSONTestInstrumentBuilder::addCylindricalShape(detectorBank);
483 // invalid
484 JSONTestInstrumentBuilder::addCylindricalShapeVertices(pixelShape, {3, 2}, {-0.001, 0, -0.001, 0.0045, 0.001, 0});
485
487}
488
490 Json::Value root;
491 JSONTestInstrumentBuilder::initialiseRoot(root, "nexus_structure");
492 auto &entry = JSONTestInstrumentBuilder::addNXEntry(root, "entry");
494 auto &instrument = JSONTestInstrumentBuilder::addNXInstrument(entry, "instrument");
495 auto &detectorBank = JSONTestInstrumentBuilder::addNXDetector(instrument, "detector_1");
496
497 JSONTestInstrumentBuilder::addDetectorNumbers(detectorBank, {2, 2}, std::vector<int32_t>{1, 2, 3, 4});
498 JSONTestInstrumentBuilder::addXPixelOffset(detectorBank, {2, 2}, {-0.299, -0.297, -0.299, -0.297});
499 JSONTestInstrumentBuilder::addYPixelOffset(detectorBank, {2, 2}, {-0.299, -0.299, -0.297, -0.297});
500 auto &pixelShape = JSONTestInstrumentBuilder::addOffShape(detectorBank);
504
505 // Add dependency but no transformations
507 "/entry/instrument/detector_1/transformations/location");
508
510}
511
513 Json::Value root;
514 JSONTestInstrumentBuilder::initialiseRoot(root, "nexus_structure");
515 auto &entry = JSONTestInstrumentBuilder::addNXEntry(root, "entry");
517 auto &instrument = JSONTestInstrumentBuilder::addNXInstrument(entry, "instrument");
518 auto &detectorBank = JSONTestInstrumentBuilder::addNXDetector(instrument, "detector_1");
519
520 JSONTestInstrumentBuilder::addDetectorNumbers(detectorBank, {2, 2}, std::vector<int32_t>{1, 2, 3, 4});
521 JSONTestInstrumentBuilder::addXPixelOffset(detectorBank, {2, 2}, {-0.299, -0.297, -0.299, -0.297});
522 JSONTestInstrumentBuilder::addYPixelOffset(detectorBank, {2, 2}, {-0.299, -0.299, -0.297, -0.297});
523 auto &pixelShape = JSONTestInstrumentBuilder::addOffShape(detectorBank);
527
528 // Add dependency but no transformations
530 "/entry/instrument/detector_1/transformations/location");
531
532 auto &transformation = JSONTestInstrumentBuilder::addNXTransformation(detectorBank, "transformations");
535}
536
538 Json::Value root;
539 JSONTestInstrumentBuilder::initialiseRoot(root, "nexus_structure");
540 auto &entry = JSONTestInstrumentBuilder::addNXEntry(root, "entry");
542 auto &instrument = JSONTestInstrumentBuilder::addNXInstrument(entry, "instrument");
543 auto &detectorBank = JSONTestInstrumentBuilder::addNXDetector(instrument, "detector_1");
544
545 JSONTestInstrumentBuilder::addDetectorNumbers(detectorBank, {2, 2}, std::vector<int32_t>{1, 2, 3, 4});
546 JSONTestInstrumentBuilder::addXPixelOffset(detectorBank, {2, 2}, {-0.299, -0.297, -0.299, -0.297});
547 JSONTestInstrumentBuilder::addYPixelOffset(detectorBank, {2, 2}, {-0.299, -0.299, -0.297, -0.297});
548 auto &pixelShape = JSONTestInstrumentBuilder::addOffShape(detectorBank);
552
553 // Add dependency but no transformations
555 "/entry/instrument/detector_1/transformations/location");
556
557 auto &transformation = JSONTestInstrumentBuilder::addNXTransformation(detectorBank, "transformations");
561}
562
564 Json::Value root;
565 JSONTestInstrumentBuilder::initialiseRoot(root, "nexus_structure");
566 auto &entry = JSONTestInstrumentBuilder::addNXEntry(root, "entry");
568 auto &instrument = JSONTestInstrumentBuilder::addNXInstrument(entry, "instrument");
569 auto &detectorBank = JSONTestInstrumentBuilder::addNXDetector(instrument, "detector_1");
570
571 JSONTestInstrumentBuilder::addNXMonitor(instrument, "monitor_1");
572 JSONTestInstrumentBuilder::addDetectorNumbers(detectorBank, {2, 2}, std::vector<int32_t>{1, 2, 3, 4});
573 JSONTestInstrumentBuilder::addXPixelOffset(detectorBank, {2, 2}, {-0.299, -0.297, -0.299, -0.297});
574 JSONTestInstrumentBuilder::addYPixelOffset(detectorBank, {2, 2}, {-0.299, -0.299, -0.297, -0.297});
575 auto &pixelShape = JSONTestInstrumentBuilder::addOffShape(detectorBank);
579
580 // Add dependency but no transformations
582 "/entry/instrument/detector_1/transformations/location");
583
584 auto &transformation = JSONTestInstrumentBuilder::addNXTransformation(detectorBank, "transformations");
589}
590
592 Json::Value root;
593 JSONTestInstrumentBuilder::initialiseRoot(root, "nexus_structure");
594 auto &entry = JSONTestInstrumentBuilder::addNXEntry(root, "entry");
596 auto &instrument = JSONTestInstrumentBuilder::addNXInstrument(entry, "instrument");
597 auto &detectorBank = JSONTestInstrumentBuilder::addNXDetector(instrument, "detector_1");
598
599 JSONTestInstrumentBuilder::addNXChopper(instrument, "chopper_1");
600 JSONTestInstrumentBuilder::addDetectorNumbers(detectorBank, {2, 2}, std::vector<int32_t>{1, 2, 3, 4});
601 JSONTestInstrumentBuilder::addXPixelOffset(detectorBank, {2, 2}, {-0.299, -0.297, -0.299, -0.297});
602 JSONTestInstrumentBuilder::addYPixelOffset(detectorBank, {2, 2}, {-0.299, -0.299, -0.297, -0.297});
603 auto &pixelShape = JSONTestInstrumentBuilder::addOffShape(detectorBank);
607
608 // Add dependency but no transformations
610 "/entry/instrument/detector_1/transformations/location");
611
612 auto &transformation = JSONTestInstrumentBuilder::addNXTransformation(detectorBank, "transformations");
617}
618
620 Json::Value root;
621 JSONTestInstrumentBuilder::initialiseRoot(root, "nexus_structure");
622 auto &entry = JSONTestInstrumentBuilder::addNXEntry(root, "entry");
624 auto &instrument = JSONTestInstrumentBuilder::addNXInstrument(entry, "instrument");
625 JSONTestInstrumentBuilder::addNXInstrumentName(instrument, "SimpleInstrument");
626 auto &detectorBank = JSONTestInstrumentBuilder::addNXDetector(instrument, "detector_1");
627
628 JSONTestInstrumentBuilder::addDetectorNumbers(detectorBank, {2, 2}, std::vector<int32_t>{1, 2, 3, 4});
629 JSONTestInstrumentBuilder::addXPixelOffset(detectorBank, {2, 2}, {-0.299, -0.297, -0.299, -0.297});
630 JSONTestInstrumentBuilder::addYPixelOffset(detectorBank, {2, 2}, {-0.299, -0.299, -0.297, -0.297});
631 auto &pixelShape = JSONTestInstrumentBuilder::addOffShape(detectorBank);
635
636 // Add dependency but no transformations
638 "/entry/instrument/detector_1/transformations/location");
639
640 auto &transformation = JSONTestInstrumentBuilder::addNXTransformation(detectorBank, "transformations");
645}
646
648 Json::Value root;
649 JSONTestInstrumentBuilder::initialiseRoot(root, "nexus_structure");
650 auto &entry = JSONTestInstrumentBuilder::addNXEntry(root, "entry");
652 auto &instrument = JSONTestInstrumentBuilder::addNXInstrument(entry, "instrument");
653 JSONTestInstrumentBuilder::addNXInstrumentName(instrument, "SimpleInstrument");
654
655 // add source to NXInstrument
656 auto &source = JSONTestInstrumentBuilder::addNXSource(instrument, "moderator");
657 auto &sourceTransformation = JSONTestInstrumentBuilder::addNXTransformation(source, "transformations");
658 JSONTestInstrumentBuilder::addNXTransformationLocation(sourceTransformation, {1}, {28.900002}, {0.0, 0.0, -1.0});
659
660 auto &detectorBank = JSONTestInstrumentBuilder::addNXDetector(instrument, "detector_1");
661
662 JSONTestInstrumentBuilder::addDetectorNumbers(detectorBank, {2, 2}, std::vector<int32_t>{1, 2, 3, 4});
663 JSONTestInstrumentBuilder::addXPixelOffset(detectorBank, {2, 2}, {-0.299, -0.297, -0.299, -0.297});
664 JSONTestInstrumentBuilder::addYPixelOffset(detectorBank, {2, 2}, {-0.299, -0.299, -0.297, -0.297});
665 auto &pixelShape = JSONTestInstrumentBuilder::addOffShape(detectorBank);
669
670 // Add dependency but no transformations
672 "/entry/instrument/detector_1/transformations/location");
673
674 auto &transformation = JSONTestInstrumentBuilder::addNXTransformation(detectorBank, "transformations");
679}
680
682 Json::Value root;
683 JSONTestInstrumentBuilder::initialiseRoot(root, "nexus_structure");
684 auto &entry = JSONTestInstrumentBuilder::addNXEntry(root, "entry");
686 auto &instrument = JSONTestInstrumentBuilder::addNXInstrument(entry, "instrument");
687 JSONTestInstrumentBuilder::addNXInstrumentName(instrument, "SimpleInstrument");
688 auto &detectorBank = JSONTestInstrumentBuilder::addNXDetector(instrument, "detector_1");
689
690 JSONTestInstrumentBuilder::addDetectorNumbers(detectorBank, {2, 2}, std::vector<int32_t>{1, 2, 3, 4});
691 JSONTestInstrumentBuilder::addXPixelOffset(detectorBank, {2, 2}, {-0.299, -0.297, -0.299, -0.297});
692 JSONTestInstrumentBuilder::addYPixelOffset(detectorBank, {2, 2}, {-0.299, -0.299, -0.297, -0.297});
693 auto &pixelShape = JSONTestInstrumentBuilder::addCylindricalShape(detectorBank);
696
697 // Add dependency but no transformations
699 "/entry/instrument/detector_1/transformations/location");
700
701 auto &transformation = JSONTestInstrumentBuilder::addNXTransformation(detectorBank, "transformations");
706}
707
709 Json::Value root;
710 JSONTestInstrumentBuilder::initialiseRoot(root, "nexus_structure");
711 auto &entry = JSONTestInstrumentBuilder::addNXEntry(root, "entry");
713 auto &instrument = JSONTestInstrumentBuilder::addNXInstrument(entry, "instrument");
714 JSONTestInstrumentBuilder::addNXInstrumentName(instrument, "SimpleInstrument");
715
716 auto &chopper = JSONTestInstrumentBuilder::addNXChopper(instrument, "chopper_1");
717 JSONTestInstrumentBuilder::addNXChopperName(chopper, "Airbus, Source Chopper, ESS Pulse, Disc 1");
722 JSONTestInstrumentBuilder::addNXChopperTopDeadCenter(chopper, "V20_choppers", "HZB-V20:Chop-Drv-0401:TDC_array",
723 "senv");
724
725 auto &detectorBank = JSONTestInstrumentBuilder::addNXDetector(instrument, "detector_1");
726
727 JSONTestInstrumentBuilder::addDetectorNumbers(detectorBank, {2, 2}, std::vector<int32_t>{1, 2, 3, 4});
728 JSONTestInstrumentBuilder::addXPixelOffset(detectorBank, {2, 2}, {-0.299, -0.297, -0.299, -0.297});
729 JSONTestInstrumentBuilder::addYPixelOffset(detectorBank, {2, 2}, {-0.299, -0.299, -0.297, -0.297});
730 auto &pixelShape = JSONTestInstrumentBuilder::addCylindricalShape(detectorBank);
733
734 // Add dependency but no transformations
736 "/entry/instrument/detector_1/transformations/location");
737
738 auto &transformation = JSONTestInstrumentBuilder::addNXTransformation(detectorBank, "transformations");
743}
744
746 Json::Value root;
747 JSONTestInstrumentBuilder::initialiseRoot(root, "nexus_structure");
748 auto &entry = JSONTestInstrumentBuilder::addNXEntry(root, "entry");
750 auto &instrument = JSONTestInstrumentBuilder::addNXInstrument(entry, "instrument");
751 JSONTestInstrumentBuilder::addNXInstrumentName(instrument, "SimpleInstrument");
752
753 auto &monitor = JSONTestInstrumentBuilder::addNXMonitor(instrument, "monitor_1");
754 JSONTestInstrumentBuilder::addNXMonitorName(monitor, "Helium-3 monitor");
756 JSONTestInstrumentBuilder::addNXMonitorEventStreamInfo(monitor, "monitor", "Monitor_Adc0_Ch1", "ev42");
757 JSONTestInstrumentBuilder::addNXMonitorWaveformStreamInfo(monitor, "monitor", "Monitor_Adc0_Ch1", "senv");
758
759 auto &monitorTransformation = JSONTestInstrumentBuilder::addNXTransformation(monitor, "transformations");
760 JSONTestInstrumentBuilder::addNXTransformationLocation(monitorTransformation, {1}, {-3.298}, {0, 0, 1});
761 JSONTestInstrumentBuilder::addNXTransformationOrientation(monitorTransformation, {1}, {45}, {0, 1, 0});
762 JSONTestInstrumentBuilder::addNXTransformationDependency(monitor, "/entry/monitor_1/transformations/location");
763
764 auto &detectorBank = JSONTestInstrumentBuilder::addNXDetector(instrument, "detector_1");
765
766 JSONTestInstrumentBuilder::addDetectorNumbers(detectorBank, {2, 2}, std::vector<int32_t>{1, 2, 3, 4});
767 JSONTestInstrumentBuilder::addXPixelOffset(detectorBank, {2, 2}, {-0.299, -0.297, -0.299, -0.297});
768 JSONTestInstrumentBuilder::addYPixelOffset(detectorBank, {2, 2}, {-0.299, -0.299, -0.297, -0.297});
769 auto &pixelShape = JSONTestInstrumentBuilder::addCylindricalShape(detectorBank);
772
773 // Add dependency but no transformations
775 "/entry/instrument/detector_1/transformations/location");
776
777 auto &transformation = JSONTestInstrumentBuilder::addNXTransformation(detectorBank, "transformations");
782}
783
785 Json::Value root;
786 JSONTestInstrumentBuilder::initialiseRoot(root, "nexus_structure");
787 auto &entry = JSONTestInstrumentBuilder::addNXEntry(root, "entry");
789 auto &instrument = JSONTestInstrumentBuilder::addNXInstrument(entry, "instrument");
790 JSONTestInstrumentBuilder::addNXInstrumentName(instrument, "SimpleInstrument");
791
792 auto &monitor = JSONTestInstrumentBuilder::addNXMonitor(instrument, "monitor_1");
793 JSONTestInstrumentBuilder::addNXMonitorName(monitor, "Helium-3 monitor");
795 JSONTestInstrumentBuilder::addNXMonitorEventStreamInfo(monitor, "monitor", "Monitor_Adc0_Ch1", "ev42");
796 JSONTestInstrumentBuilder::addNXMonitorWaveformStreamInfo(monitor, "monitor", "Monitor_Adc0_Ch1", "senv");
797
798 auto &monitorTransformation = JSONTestInstrumentBuilder::addNXTransformation(monitor, "transformations");
799 JSONTestInstrumentBuilder::addNXTransformationLocation(monitorTransformation, {1}, {-3.298}, {0, 0, 1});
800 JSONTestInstrumentBuilder::addNXTransformationOrientation(monitorTransformation, {1}, {45}, {0, 1, 0});
801 JSONTestInstrumentBuilder::addNXTransformationDependency(monitor, "/entry/monitor_1/transformations/location");
802
803 auto &monitorShape = JSONTestInstrumentBuilder::addCylindricalShape(monitor, "shape");
806
807 auto &detectorBank = JSONTestInstrumentBuilder::addNXDetector(instrument, "detector_1");
808
809 JSONTestInstrumentBuilder::addDetectorNumbers(detectorBank, {2, 2}, std::vector<int32_t>{1, 2, 3, 4});
810 JSONTestInstrumentBuilder::addXPixelOffset(detectorBank, {2, 2}, {-0.299, -0.297, -0.299, -0.297});
811 JSONTestInstrumentBuilder::addYPixelOffset(detectorBank, {2, 2}, {-0.299, -0.299, -0.297, -0.297});
812 auto &pixelShape = JSONTestInstrumentBuilder::addCylindricalShape(detectorBank);
815
816 // Add dependency but no transformations
818 "/entry/instrument/detector_1/transformations/location");
819
820 auto &transformation = JSONTestInstrumentBuilder::addNXTransformation(detectorBank, "transformations");
825}
826
828 Json::Value root;
829 JSONTestInstrumentBuilder::initialiseRoot(root, "nexus_structure");
830 auto &entry = JSONTestInstrumentBuilder::addNXEntry(root, "entry");
832 auto &instrument = JSONTestInstrumentBuilder::addNXInstrument(entry, "instrument");
833 JSONTestInstrumentBuilder::addNXInstrumentName(instrument, "SimpleInstrument");
834 auto &detectorBank = JSONTestInstrumentBuilder::addNXDetector(instrument, "detector_1");
835
836 JSONTestInstrumentBuilder::addDetectorNumbers(detectorBank, {2, 2}, std::vector<int32_t>{1, 2, 3, 4});
837 JSONTestInstrumentBuilder::addXPixelOffset(detectorBank, {2, 2}, {-0.299, -0.297, -0.299, -0.297});
838 JSONTestInstrumentBuilder::addYPixelOffset(detectorBank, {2, 2}, {-0.299, -0.299, -0.297, -0.297});
839 JSONTestInstrumentBuilder::addZPixelOffset(detectorBank, {2, 2}, {-0.0405, -0.0405, -0.0405, -0.0405});
840 auto &pixelShape = JSONTestInstrumentBuilder::addOffShape(detectorBank);
844
845 // Add dependency but no transformations
847 "/entry/instrument/detector_1/transformations/location");
848
849 auto &transformation = JSONTestInstrumentBuilder::addNXTransformation(detectorBank, "transformations");
854}
855
856} // namespace Mantid::FrameworkTestHelpers
double value
The value of the point.
Definition: FitMW.cpp:51
std::map< DeltaEMode::Type, std::string > index
Definition: DeltaEMode.cpp:19
double radius
Definition: Rasterize.cpp:31
H5::DataType getType()
Convert a primitive type to the appropriate H5::DataType.
Definition: H5Util.cpp:32
void addYPixelOffset(Json::Value &nxDetector, const std::vector< int > &arrayShape, const std::vector< double > &values)
void addNXMonitorName(Json::Value &monitor, const std::string &name)
void addNXInstrumentName(Json::Value &instrument, const std::string &name)
Json::Value & addNXSource(Json::Value &instrument, const std::string &name)
void addNXTransformationDependency(Json::Value &nxDetector, const std::string &dependencyPath)
void addNXMonitorWaveformStreamInfo(Json::Value &monitor, const std::string &topic, const std::string &source, const std::string &writerModule)
Json::Value & addNXTransformation(Json::Value &nxDetector, const std::string &name)
void addOffShapeWindingOrder(Json::Value &shape, const std::vector< int > &arrayShape={4}, const std::vector< int > &windingOrder={0, 1, 2, 3})
void addOffShapeFaces(Json::Value &shape, const std::vector< int > &arrayShape={1}, const std::vector< int > &faces={0})
void addNXChopperSlitEdges(Json::Value &chopper, const std::vector< double > &edges={0.0, 23.0})
void addNXTransformationBeamDirectionOffset(Json::Value &nxTransformation, const std::vector< int > &arrayShape={1}, const std::vector< double > &values={0.049}, const std::vector< double > &vec={0, 0, -1})
Json::Value & addNXDetector(Json::Value &instrument, const std::string &name)
Json::Value & addOffShape(Json::Value &nxDetector, const std::string &name="pixel_shape")
Json::Value & addCylindricalShape(Json::Value &nxDetector, const std::string &name="pixel_shape")
void addOffShapeVertices(Json::Value &shape, const std::vector< int > &arrayShape={4, 3}, const std::vector< double > &vertices={-0.001, -0.001, 0, 0.001, -0.001, 0, 0.001, 0.001, 0, -0.001, 0.001, 0})
void addNXMonitorEventStreamInfo(Json::Value &monitor, const std::string &topic, const std::string &source, const std::string &writerModule)
void addXPixelOffset(Json::Value &nxDetector, const std::vector< int > &arrayShape, const std::vector< double > &values)
Json::Value & addNXInstrument(Json::Value &entry, const std::string &name)
void addNXChopperSlitHeight(Json::Value &chopper, const double slitHeight=150)
void addNXChopperSlits(Json::Value &chopper, const int32_t value)
Json::Value & addNXSample(Json::Value &entry, const std::string &name)
void addDetectorNumbers(Json::Value &nxDetector, const std::vector< int > &arrayShape, const std::vector< int32_t > &values)
void addCylindricalShapeCylinders(Json::Value &shape, const std::vector< int > &arrayShape={3}, const std::vector< int > &indices={0, 1, 2})
Json::Value & addNXMonitor(Json::Value &entry, const std::string &name)
void initialiseRoot(const Json::Value &root, const std::string &name)
void addNXMonitorDetectorID(Json::Value &monitor, const int32_t detectorID)
void addNXTransformationLocation(Json::Value &nxTransformation, const std::vector< int > &arrayShape={1}, const std::vector< double > &values={0.971}, const std::vector< double > &vec={1, 0, 0})
void addNXChopperName(Json::Value &chopper, const std::string &chopperName)
Json::Value & addNXChopper(Json::Value &instrument, const std::string &name)
void addZPixelOffset(Json::Value &nxDetector, const std::vector< int > &arrayShape, const std::vector< double > &values)
void addNXChopperRadius(Json::Value &chopper, const double radius=350)
void addCylindricalShapeVertices(Json::Value &shape, const std::vector< int > &arrayShape={3, 3}, const std::vector< double > &vertices={-0.001, 0, 0, 0.001, 0.00405, 0, 0.001, 0, 0})
Json::Value & addNXEntry(Json::Value &root, const std::string &name)
void addNXChopperTopDeadCenter(Json::Value &chopper, const std::string &topic, const std::string &source, const std::string &writerModule)
void addNXTransformationOrientation(Json::Value &nxTransformation, const std::vector< int > &arrayShape={1}, const std::vector< double > &values={90}, const std::vector< double > &vec={0, 1, 0})