Mantid
Loading...
Searching...
No Matches
WorkspaceValidators.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 +
18#include <boost/python/class.hpp>
19#include <boost/python/list.hpp>
20#include <boost/python/make_constructor.hpp>
21
24using Mantid::Kernel::TypedValidator;
26using namespace boost::python;
27
28std::shared_ptr<Mantid::API::PolSANSWorkspaceValidator>
29polSANSValidatorConstructor(bool expectHistogramData = true, bool allowMultiPeriodData = false,
30 list allowedNumberOfPeriods = list()) {
31 // setup default value
32 if (len(allowedNumberOfPeriods) == 0) {
33 allowedNumberOfPeriods.append(4);
34 }
35
36 std::unordered_set<int> allowedPeriodsSet;
37 for (int i = 0; i < len(allowedNumberOfPeriods); i++) {
38 int periodN = extract<int>(allowedNumberOfPeriods[i]);
39 allowedPeriodsSet.insert(periodN);
40 }
41
42 return std::make_shared<Mantid::API::PolSANSWorkspaceValidator>(expectHistogramData, allowMultiPeriodData,
43 allowedPeriodsSet);
44}
45
53
54 class_<MatrixWorkspaceValidator, bases<TypedValidator<MatrixWorkspace_sptr>>, boost::noncopyable>(
55 "MatrixWorkspaceValidator", no_init);
56
57 class_<TypedValidator<IMDWorkspace_sptr>, boost::noncopyable>("IMDWorkspaceValidator", no_init);
58 class_<TypedValidator<WorkspaceGroup_sptr>, boost::noncopyable>("WorkspaceGroupValidator", no_init);
59}
62#define EXPORT_WKSP_VALIDATOR_NO_ARG(ValidatorType, DocString) \
63 class_<ValidatorType, bases<MatrixWorkspaceValidator>, boost::noncopyable>(#ValidatorType, init<>(DocString));
66#define EXPORT_WKSP_VALIDATOR_ARG(ValidatorType, ArgType, ArgName, DocString) \
67 class_<ValidatorType, bases<MatrixWorkspaceValidator>, boost::noncopyable>(#ValidatorType, \
68 init<ArgType>(arg(ArgName), DocString));
72#define EXPORT_WKSP_VALIDATOR_DEFAULT_ARG(ValidatorType, ArgType, ArgName, DefaultValue, DocString) \
73 class_<ValidatorType, bases<MatrixWorkspaceValidator>, boost::noncopyable>( \
74 #ValidatorType, init<ArgType>(arg(ArgName) = DefaultValue, DocString));
75
77 using namespace Mantid::API;
78
80 "Checks the workspace has the given unit along the X-axis");
81 EXPORT_WKSP_VALIDATOR_DEFAULT_ARG(HistogramValidator, bool, "mustBeHistogram", true,
82 "If mustBeHistogram=True then the "
83 "workspace must be a histogram "
84 "otherwise it must be point data.");
85 EXPORT_WKSP_VALIDATOR_DEFAULT_ARG(RawCountValidator, bool, "mustNotBeDistribution", true,
86 "If mustNotBeDistribution=True then the workspace must not have been "
87 "divided by the bin-width");
88 EXPORT_WKSP_VALIDATOR_NO_ARG(CommonBinsValidator, "A tentative check that the bins are common across the workspace");
90 "Checks whether the axis specified by axisNumber is a SpectraAxis");
92 "Checks whether the axis specified by axisNumber is a NumericAxis");
93
94 class_<MDFrameValidator, bases<TypedValidator<IMDWorkspace_sptr>>, boost::noncopyable>(
95 "MDFrameValidator", init<std::string>(arg("frameName"), "Checks the MD workspace has the given frame along all "
96 "dimensions. Accepted values for the `frameName` are "
97 "currently: `HKL`, `QLab`, `QSample`, `Time of "
98 "Flight`, `Distance`, `General frame`, `Unknown "
99 "frame` "));
100
101 class_<PolSANSWorkspaceValidator, bases<TypedValidator<WorkspaceGroup_sptr>>,
102 std::shared_ptr<PolSANSWorkspaceValidator>, boost::noncopyable>("PolSANSWorkspaceValidator", no_init)
103 .def("__init__",
104 make_constructor(&polSANSValidatorConstructor, default_call_policies(),
105 (arg("expectHistogramData") = true, arg("allowMultiPeriodData") = false,
106 arg("allowedNumberOfPeriods") = list())),
107 "Checks that the workspace group is a valid Polarised SANS transmission run. It should have 4 (by default, "
108 "use allowedNumberOfPeriods with a list ints to change) "
109 "group entries which are of type MatrixWorkspace, "
110 "have X axis unit Wavelength, have a single spectrum per workspace (depending on the value of "
111 "allowMultiPeriodData), and are histogram data "
112 "(depending on expectHistogramData).");
113}
std::shared_ptr< Mantid::API::PolSANSWorkspaceValidator > polSANSValidatorConstructor(bool expectHistogramData=true, bool allowMultiPeriodData=false, list allowedNumberOfPeriods=list())
#define EXPORT_WKSP_VALIDATOR_NO_ARG(ValidatorType, DocString)
Export a validator derived from a MatrixWorkspaceValidator that has a no-arg constructor.
#define EXPORT_WKSP_VALIDATOR_ARG(ValidatorType, ArgType, ArgName, DocString)
Export a validator derived from a MatrixWorkspaceValidator that has a single-arg constructor.
void export_WorkspaceValidators()
#define EXPORT_WKSP_VALIDATOR_DEFAULT_ARG(ValidatorType, ArgType, ArgName, DefaultValue, DocString)
Export a validator derived from a MatrixWorkspaceValidator that has a single-arg constructor with a d...
void export_MatrixWorkspaceValidator()
This is the base TypedValidator for most of the WorkspaceValidators.
A validator which provides a TENTATIVE check that a workspace contains common bins in each spectrum.
A validator which checks that a workspace contains histogram data (the default) or point data as requ...
An interface for those validators that require the MatrixWorkspace interface.
A validator which checks whether the input workspace has the Numeric data in the axis.
A validator which checks that a workspace contains raw counts in its bins.
A validator which checks whether the input workspace has the Spectra number in the axis.
A validator which checks that the unit of the workspace referred to by a WorkspaceProperty is the exp...
std::shared_ptr< WorkspaceGroup > WorkspaceGroup_sptr
shared pointer to Mantid::API::WorkspaceGroup
std::shared_ptr< IMDWorkspace > IMDWorkspace_sptr
Shared pointer to the IMDWorkspace base class.
std::shared_ptr< MatrixWorkspace > MatrixWorkspace_sptr
shared pointer to the matrix workspace base class
Declares a simple static struct to export a TypedValidator to Python.
static void define(const char *pythonClassName)