Newer
Older
#include "MantidKernel/MDAxisValidator.h"
namespace Mantid {
namespace Kernel {
//----------------------------------------------------------------------------------------------
/** Constructor
* @param axes Vector containing MD axes to validate
* @param nDimensions Number of dimensions of input workspace for algorithm
* @param checkIfEmpty Whether validator will check if the axes vector is empty
*/
MDAxisValidator::MDAxisValidator(const std::vector<int> &axes,
const size_t nDimensions,
const bool checkIfEmpty)
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
: m_wsDimensions(nDimensions), m_emptyCheck(checkIfEmpty) {
for (auto iter = axes.begin(); iter != axes.end(); iter++) {
m_axes.push_back(*iter);
}
}
//----------------------------------------------------------------------------------------------
/** Destructor
*/
MDAxisValidator::~MDAxisValidator() {}
/**
* @brief Checks the MD axes given against the given number of dimensions of the
* input workspace.
*
* @returns A map with validation warnings, to be used in an algorithm's
* validateInputs()
*/
std::map<std::string, std::string> MDAxisValidator::validate() const {
std::map<std::string, std::string> invalidProperties;
// Empty check if required
// (Some algorithms have special handling for an empty axes vector, e.g.
// TransposeMD, so don't need an error here).
if (m_emptyCheck) {
if (m_axes.empty()) {
invalidProperties.insert(
std::make_pair("Axes", "No index was specified."));
}
}
// Make sure that there are fewer axes specified than exist on the workspace
if (m_axes.size() > m_wsDimensions) {
invalidProperties.insert(std::make_pair(
"Axes", "More axes specified than dimensions available in the input"));
}
// Ensure that the axes selection is within the number of dimensions of the
// workspace
if (!m_axes.empty()) {
auto it = std::max_element(m_axes.begin(), m_axes.end());
size_t largest = static_cast<size_t>(*it);
if (largest >= m_wsDimensions) {
invalidProperties.insert(
std::make_pair("Axes", "One of the axis indexes specified indexes a "
"dimension outside the real dimension range"));
}
}
return invalidProperties;
}
} // namespace Kernel
} // namespace Mantid