Mantid
Loading...
Searching...
No Matches
MDAxisValidator.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#include <utility>
8
10
11namespace Mantid::Kernel {
12
13//----------------------------------------------------------------------------------------------
19MDAxisValidator::MDAxisValidator(std::vector<int> axes, const size_t nDimensions, const bool checkIfEmpty)
20 : m_axes(std::move(axes)), m_wsDimensions(nDimensions), m_emptyCheck(checkIfEmpty) {}
21
29std::map<std::string, std::string> MDAxisValidator::validate() const {
30 std::map<std::string, std::string> invalidProperties;
31
32 // Empty check if required
33 // (Some algorithms have special handling for an empty axes vector, e.g.
34 // TransposeMD, so don't need an error here).
35 if (m_emptyCheck) {
36 if (m_axes.empty()) {
37 invalidProperties.insert(std::make_pair("Axes", "No index was specified."));
38 }
39 }
40
41 // Make sure that there are fewer axes specified than exist on the workspace
42 if (m_axes.size() > m_wsDimensions) {
43 invalidProperties.emplace("Axes", "More axes specified than dimensions available in the input");
44 }
45
46 // Ensure that the axes selection is within the number of dimensions of the
47 // workspace
48 if (!m_axes.empty()) {
49 auto it = std::max_element(m_axes.begin(), m_axes.end());
50 auto largest = static_cast<size_t>(*it);
51 if (largest >= m_wsDimensions) {
52 invalidProperties.insert(std::make_pair("Axes", "One of the axis indexes specified indexes a "
53 "dimension outside the real dimension range"));
54 }
55 }
56
57 return invalidProperties;
58}
59
60} // namespace Mantid::Kernel
MDAxisValidator(std::vector< int > axes, const size_t nDimensions, const bool checkIfEmpty)
Constructor.
virtual std::map< std::string, std::string > validate() const
Checks the MD axes given against the given number of dimensions of the input workspace.
STL namespace.