Mantid
Loading...
Searching...
No Matches
MDFramesToSpecialCoordinateSystem.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 +
11
12namespace Mantid::DataObjects {
13
19boost::optional<Mantid::Kernel::SpecialCoordinateSystem>
21 // Make sure that the workspaces are either an MDHisto or MDEvent workspaces
22 if (!dynamic_cast<const Mantid::API::IMDEventWorkspace *>(workspace) &&
23 !dynamic_cast<const Mantid::API::IMDHistoWorkspace *>(workspace)) {
24 throw std::invalid_argument("Error in MDFrameFromWorkspace: Can only "
25 "extract MDFrame from MDEvent and MDHisto "
26 "workspaces");
27 }
28
29 // Requirements for the special coordinate are: If there are more than one
30 // Q-compatible (QSample, QLab, HKL) dimension, then they have to be identical
31 // This dimension will define the special coordinate system. Otherwise, we
32 // don't have a special coordinate system
33
34 boost::optional<Mantid::Kernel::SpecialCoordinateSystem> qFrameType =
35 Mantid::Kernel::SpecialCoordinateSystem::None; // Set to none just to have
36 // it initialized
37 auto hasQFrame = false;
38 auto isUnknown = false;
39 for (size_t dimIndex = 0; dimIndex < workspace->getNumDims(); ++dimIndex) {
40 auto dimension = workspace->getDimension(dimIndex);
41 auto &frame = dimension->getMDFrame();
42 // Check for QCompatibility. This has gotten a bit more complicated than
43 // necessary since the boost optional
44 // caused a GCC error, when it was not initialized. Using -Wuninitialized
45 // didn't make the compiler happy.
46 if (frame.getMDUnit().isQUnit()) {
47 auto specialCoordinteSystem = frame.equivalientSpecialCoordinateSystem();
48 if (hasQFrame) {
49 checkQCompatibility(specialCoordinteSystem, qFrameType);
50 }
51 qFrameType = specialCoordinteSystem;
52 hasQFrame = true;
53 }
54
55 isUnknown = isUnknownFrame(dimension);
56 }
57
58 boost::optional<Mantid::Kernel::SpecialCoordinateSystem> output;
59 if (hasQFrame) {
60 output = qFrameType;
61 } else {
62 // If the frame is unknown then keep the optional empty
63 if (!isUnknown) {
65 }
66 }
67
68 return output;
69}
70
77 Mantid::Kernel::SpecialCoordinateSystem specialCoordinateSystem,
78 boost::optional<Mantid::Kernel::SpecialCoordinateSystem> qFrameType) const {
79 if (qFrameType) {
80 if (specialCoordinateSystem != qFrameType.get()) {
81 throw std::invalid_argument("Error in MDFrameFromWorkspace: Coordinate "
82 "system in the different dimensions don't "
83 "match.");
84 }
85 }
86}
87
88/* Checks if an MDFrame is an UnknownFrame
89 * @param dimension: a dimension
90 * @returns true if the MDFrame is of UnknownFrame type.
91 */
93 const Mantid::Geometry::IMDDimension_const_sptr &dimension) const {
94 Mantid::Geometry::MDFrame_uptr replica(dimension->getMDFrame().clone());
95 auto isUnknown = false;
96 if (dynamic_cast<Mantid::Geometry::UnknownFrame *>(replica.get())) {
97 isUnknown = true;
98 }
99 return isUnknown;
100}
101} // namespace Mantid::DataObjects
IPeaksWorkspace_sptr workspace
Definition: IndexPeaks.cpp:114
Abstract base class for multi-dimension event workspaces (MDEventWorkspace).
Abstract interface to MDHistoWorkspace, for use in exposing to Python.
Basic MD Workspace Abstract Class.
Definition: IMDWorkspace.h:40
bool isUnknownFrame(const Mantid::Geometry::IMDDimension_const_sptr &dimension) const
boost::optional< Mantid::Kernel::SpecialCoordinateSystem > operator()(const Mantid::API::IMDWorkspace *workspace) const
Get the Special Coordinate System based on the MDFrame information.
void checkQCompatibility(Mantid::Kernel::SpecialCoordinateSystem specialCoordinateSystem, boost::optional< Mantid::Kernel::SpecialCoordinateSystem > qFrameType) const
Make sure that the QFrame types are the same.
UnknownFrame : Unknown MDFrame.
Definition: UnknownFrame.h:21
std::unique_ptr< MDFrame > MDFrame_uptr
Definition: MDFrame.h:36
std::shared_ptr< const IMDDimension > IMDDimension_const_sptr
Shared Pointer to const IMDDimension.
Definition: IMDDimension.h:101
SpecialCoordinateSystem
Special coordinate systems for Q3D.