Mantid
Loading...
Searching...
No Matches
WorkspaceUnitValidator.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
9#include "MantidAPI/Axis.h"
12#include "MantidKernel/Unit.h"
13
14namespace Mantid::API {
15
23 : MatrixWorkspaceValidator(), m_unitID(std::move(unitID)) {}
24
29 return std::make_shared<WorkspaceUnitValidator>(*this);
30}
31
39 // This effectively checks for single-valued workspaces
40 if (value->axes() == 0)
41 return "A single valued workspace has no unit, which is required for "
42 "this algorithm";
43
44 Kernel::Unit_const_sptr unit = value->getAxis(0)->unit();
45 // If m_unitID is empty it means that the workspace must have units, which
46 // can be anything
47 if (m_unitID.empty()) {
48 return (unit && (!std::dynamic_pointer_cast<const Kernel::Units::Empty>(unit)) ? ""
49 : "The workspace must have units");
50 }
51 // now check if the units of the workspace is correct
52 else {
53 if ((!unit) || (unit->unitID().compare(m_unitID))) {
54 return "The workspace must have units of " + m_unitID; //+ "; its unit is: " + unit->caption();
55 } else
56 return "";
57 }
58}
59
60} // namespace Mantid::API
double value
The value of the point.
Definition: FitMW.cpp:51
An interface for those validators that require the MatrixWorkspace interface.
const std::string m_unitID
The name of the required unit.
std::string checkValidity(const MatrixWorkspace_sptr &value) const override
Check for validity.
WorkspaceUnitValidator(std::string unitID="")
Constructor.
Kernel::IValidator_sptr clone() const override
Clone the current state.
std::shared_ptr< MatrixWorkspace > MatrixWorkspace_sptr
shared pointer to the matrix workspace base class
std::shared_ptr< const Unit > Unit_const_sptr
Shared pointer to the Unit base class (const version)
Definition: Unit.h:231
std::shared_ptr< IValidator > IValidator_sptr
A shared_ptr to an IValidator.
Definition: IValidator.h:26
STL namespace.