Mantid
Loading...
Searching...
No Matches
MDAlgorithmsTestHelper.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 +
7/*********************************************************************************
8 * PLEASE READ THIS!!!!!!!
9 *
10 * This collection of functions MAY ONLY be used in packages above MDAlgorithms
11 *********************************************************************************/
13
18
19namespace Mantid {
20using namespace API;
21using namespace DataObjects;
22
23namespace MDAlgorithms::MDAlgorithmsTestHelper {
24
25std::string makeUniqueId() { return Kernel::Strings::randomString(12); }
26
39DataObjects::MDEventWorkspace3Lean::sptr makeFileBackedMDEW(const std::string &wsName, bool fileBacked, long numEvents,
41 // ---------- Make a file-backed MDEventWorkspace -----------------------
42 std::string snEvents = std::to_string(numEvents);
43 MDEventWorkspace3Lean::sptr ws1 = MDEventsTestHelper::makeMDEW<3>(10, 0.0, 10.0, 0);
44 ws1->getBoxController()->setSplitThreshold(100);
45 ws1->setCoordinateSystem(coord);
46 Mantid::API::AnalysisDataService::Instance().addOrReplace(
47 wsName, std::dynamic_pointer_cast<Mantid::API::IMDEventWorkspace>(ws1));
48 FrameworkManager::Instance().exec("FakeMDEventData", 6, "InputWorkspace", wsName.c_str(), "UniformParams",
49 snEvents.c_str(), "RandomizeSignal", "1");
50 if (fileBacked) {
51 std::string filename = wsName + ".nxs";
52 auto saver =
53 FrameworkManager::Instance().exec("SaveMD", 4, "InputWorkspace", wsName.c_str(), "Filename", filename.c_str());
54 FrameworkManager::Instance().exec("LoadMD", 8, "OutputWorkspace", wsName.c_str(), "Filename",
55 saver->getPropertyValue("Filename").c_str(), "FileBackEnd", "1", "Memory", "0");
56 }
57 return std::dynamic_pointer_cast<MDEventWorkspace3Lean>(
58 Mantid::API::AnalysisDataService::Instance().retrieve(wsName));
59}
60
75 const Mantid::Geometry::MDFrame &frame,
76 long numEvents,
78 // ---------- Make a file-backed MDEventWorkspace -----------------------
79 std::string snEvents = std::to_string(numEvents);
81 MDEventsTestHelper::makeAnyMDEWWithFrames<MDLeanEvent<3>, 3>(10, 0.0, 10.0, frame, 0);
82 ws1->getBoxController()->setSplitThreshold(100);
83 ws1->setCoordinateSystem(coord);
84 Mantid::API::AnalysisDataService::Instance().addOrReplace(
85 wsName, std::dynamic_pointer_cast<Mantid::API::IMDEventWorkspace>(ws1));
86 FrameworkManager::Instance().exec("FakeMDEventData", 6, "InputWorkspace", wsName.c_str(), "UniformParams",
87 snEvents.c_str(), "RandomizeSignal", "1");
88 if (fileBacked) {
89 std::string filename = wsName + ".nxs";
90 auto saver =
91 FrameworkManager::Instance().exec("SaveMD", 4, "InputWorkspace", wsName.c_str(), "Filename", filename.c_str());
92 FrameworkManager::Instance().exec("LoadMD", 8, "OutputWorkspace", wsName.c_str(), "Filename",
93 saver->getPropertyValue("Filename").c_str(), "FileBackEnd", "1", "Memory", "0");
94 }
95 return std::dynamic_pointer_cast<MDEventWorkspace3Lean>(
96 Mantid::API::AnalysisDataService::Instance().retrieve(wsName));
97}
98
99} // namespace MDAlgorithms::MDAlgorithmsTestHelper
100} // namespace Mantid
std::shared_ptr< MDEventWorkspace< MDE, nd > > sptr
Typedef for a shared pointer of this kind of event workspace.
MDFrame : The coordinate frame for a dimension, or set of dimensions in a multidimensional workspace.
Definition MDFrame.h:22
std::size_t numEvents(Nexus::File &file, bool &hasTotalCounts, bool &oldNeXusFileNames, const std::string &prefix)
Get the number of events in the currently opened group.
MANTID_KERNEL_DLL std::string randomString(const size_t len)
Generates random alpha-numeric string.
Definition Strings.cpp:1186
SpecialCoordinateSystem
Special coordinate systems for Q3D.
DataObjects::MDEventWorkspace3Lean::sptr makeFileBackedMDEW(const std::string &wsName, bool fileBacked, long numEvents=10000, Kernel::SpecialCoordinateSystem coord=Kernel::None)
Make a (optionally) file backed MDEventWorkspace with nEvents fake data points the points are randoml...
std::string makeUniqueId()
Returns an ID suitable for filenames shared between concurrent test processes.
DataObjects::MDEventWorkspace3Lean::sptr makeFileBackedMDEWwithMDFrame(const std::string &wsName, bool fileBacked, const Mantid::Geometry::MDFrame &frame, long numEvents=10000, Kernel::SpecialCoordinateSystem coord=Kernel::None)
Make a (optionally) file backed MDEventWorkspace with nEvents fake data points the points are randoml...
Helper class which provides the Collimation Length for SANS instruments.
std::string to_string(const wide_integer< Bits, Signed > &n)