23#include <boost/pointer_cast.hpp>
47 return "MDAlgorithms";
53 return "Sets a new MDFrame type for a selection of axes for legacy MDHisto "
64 "The workspace for which the MDFrames are to be changed. "
65 "Note that only MDHisto and MDEvent workspaces can be "
66 "altered by this algorithm.");
69 std::vector<std::string> mdFrames;
80 std::make_shared<Mantid::Kernel::StringListValidator>(mdFrames),
"MDFrame type selection.\n");
82 auto axisValidator = std::make_shared<Mantid::Kernel::ArrayBoundedValidator<int>>();
83 axisValidator->setLower(0);
86 "Selects the axes which are going to be set to the new MDFrame type.");
94 std::vector<int> axesInts = this->
getProperty(
"Axes");
95 std::vector<size_t> axes(axesInts.begin(), axesInts.end());
102 for (
auto &axe : axes) {
104 auto dimension = inputWorkspace->getDimension(axe);
108 const auto &mdFrame = dimension->getMDFrame();
114 auto mdHistoDimension = std::const_pointer_cast<Mantid::Geometry::MDHistoDimension>(
115 std::dynamic_pointer_cast<const Mantid::Geometry::MDHistoDimension>(dimension));
116 if (!mdHistoDimension) {
117 throw std::runtime_error(
"SetMDFrame: Cannot convert to MDHistDimension");
119 mdHistoDimension->setMDFrame(*newMDFrame);
128 std::map<std::string, std::string> invalidProperties;
131 if (!std::dynamic_pointer_cast<Mantid::API::IMDEventWorkspace>(ws) &&
132 !std::dynamic_pointer_cast<Mantid::API::IMDHistoWorkspace>(ws)) {
133 invalidProperties.insert(std::make_pair(
"InputWorkspace",
"The input workspace has to be either "
134 "an MDEvent or MDHisto Workspace."));
135 return invalidProperties;
138 std::vector<int> axesInts = this->
getProperty(
"Axes");
140 auto axisErrors = axisChecker.
validate();
141 for (
auto &axisError : axisErrors) {
142 invalidProperties.insert(axisError);
145 return invalidProperties;
160 return mdFrameFactory->create(argument);
163 return mdFrameFactory->create(argument);
166 return mdFrameFactory->create(argument);
172 auto canInterpret = hklFrameFactory.
canInterpret(argument);
174 throw std::invalid_argument(
"SetMDFrame: " + frameSelection +
175 " does not have units which are compatible "
176 "with an HKL frame. Please contact the "
177 "Mantid team if you believe that the units "
178 "should be compatible.");
181 return mdFrameFactory->create(argument);
185 return mdFrameFactory->create(argument);
187 throw std::invalid_argument(
"SetMDFrame: The selected MDFrame does not seem to be supported");
#define DECLARE_ALGORITHM(classname)
void declareProperty(std::unique_ptr< Kernel::Property > p, const std::string &doc="") override
Add a property to the list of managed properties.
TypedValue getProperty(const std::string &name) const override
Get the value of a property.
A property class for workspaces.
static const std::string GeneralFrameName
HKLFrame derived MDFrameFactory type.
bool canInterpret(const MDFrameArgument &argument) const override
Indicate an ability to intepret the string.
static const std::string HKLName
Input argument type for MDFrameFactory chainable factory.
MDFrame : The coordinate frame for a dimension, or set of dimensions in a multidimensional workspace.
virtual Mantid::Kernel::UnitLabel getUnitLabel() const =0
static const std::string QLabName
static const std::string QSampleName
static const std::string UnknownFrameName
Support for a property that holds an array of values.
MDAxisValidator is a class that checks the number of MD axes match the number of workspace dimensions...
virtual std::map< std::string, std::string > validate() const
Checks the MD axes given against the given number of dimensions of the input workspace.
const std::string category() const override
Algorithm's category for identification.
Mantid::Geometry::MDFrame_uptr createMDFrame(const std::string &frameSelection, const Mantid::Geometry::MDFrame &oldFrame) const
Creates an MDFrame based on the users selection.
static const std::string mdFrameSpecifier
std::map< std::string, std::string > validateInputs() override
Check the inputs for invalid values.
const std::string name() const override
Algorithms name for identification.
void exec() override
Execute the algorithm.
int version() const override
Algorithm's version for identification.
void init() override
Initialize the algorithm's properties.
const std::string summary() const override
Algorithm's summary for use in the GUI and help.
std::shared_ptr< IMDWorkspace > IMDWorkspace_sptr
Shared pointer to the IMDWorkspace base class.
std::unique_ptr< MDFrame > MDFrame_uptr
MDFrameFactory_uptr MANTID_GEOMETRY_DLL makeMDFrameFactoryChain()
Make a complete factory chain.
Describes the direction (within an algorithm) of a Property.
@ InOut
Both an input & output workspace.
@ Input
An input workspace.