Mantid
Loading...
Searching...
No Matches
PolSANSWorkspaceValidator.cpp
Go to the documentation of this file.
1// Mantid Repository : https://github.com/mantidproject/mantid
2//
3// Copyright © 2025 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
9#include "MantidAPI/Axis.h"
10#include "MantidAPI/Run.h"
12
13namespace Mantid {
14namespace API {
15
16PolSANSWorkspaceValidator::PolSANSWorkspaceValidator(bool expectHistogramData, bool allowMultiPeriodData,
17 const std::unordered_set<int> &allowedNumberOfPeriods)
18 : m_expectHistogramData(expectHistogramData), m_allowMultiPeriodData(allowMultiPeriodData),
19 m_allowedNumberOfPeriods(allowedNumberOfPeriods) {};
20
22 return std::make_shared<PolSANSWorkspaceValidator>(*this);
23}
24
26 std::vector<std::string> workspaceIssues;
27 if (!workspace) {
28 return "All workspaces must be of type MatrixWorkspace.";
29 }
30
31 Kernel::Unit_const_sptr unit = workspace->getAxis(0)->unit();
32 if (unit->unitID() != "Wavelength") {
33 workspaceIssues.push_back("All workspaces must be in units of Wavelength.");
34 }
35
36 if (!m_allowMultiPeriodData && workspace->getNumberHistograms() != 1) {
37 workspaceIssues.push_back("All workspaces must contain a single histogram.");
38 }
39
40 if (workspace->isHistogramData() != m_expectHistogramData) {
42 workspaceIssues.push_back("All workspaces must be histogram data.");
43 } else {
44 workspaceIssues.push_back("All workspaces must not be histogram data.");
45 }
46 }
47
48 if (!workspaceIssues.empty()) {
49 return Kernel::Strings::join(workspaceIssues.cbegin(), workspaceIssues.cend(), " ");
50 }
51
52 return "";
53}
54
56
57 const int numberOfEntries = workspace->getNumberOfEntries();
58 if (m_allowedNumberOfPeriods.find(numberOfEntries) == m_allowedNumberOfPeriods.cend()) {
59 return "The number of periods within the input workspace is not an allowed value.";
60 }
61
62 for (const API::Workspace_sptr &ws : workspace->getAllItems()) {
63 const auto groupItem = std::dynamic_pointer_cast<API::MatrixWorkspace>(ws);
64 const std::string errors = validateGroupItem(groupItem);
65 if (errors != "") {
66 return errors;
67 }
68 }
69
70 return "";
71}
72
73} // namespace API
74} // namespace Mantid
IPeaksWorkspace_sptr workspace
Kernel::IValidator_sptr clone() const override
Clone the current state.
PolSANSWorkspaceValidator(bool expectHistogramData=true, bool allowMultiPeriodData=false, const std::unordered_set< int > &allowedNumberOfPeriods={4})
const std::unordered_set< int > m_allowedNumberOfPeriods
std::string checkValidity(const WorkspaceGroup_sptr &workspace) const override
Check for validity.
std::string validateGroupItem(API::MatrixWorkspace_sptr const &workspace) const
std::shared_ptr< WorkspaceGroup > WorkspaceGroup_sptr
shared pointer to Mantid::API::WorkspaceGroup
std::shared_ptr< Workspace > Workspace_sptr
shared pointer to Mantid::API::Workspace
std::shared_ptr< MatrixWorkspace > MatrixWorkspace_sptr
shared pointer to the matrix workspace base class
DLLExport std::string join(ITERATOR_TYPE begin, ITERATOR_TYPE end, const std::string &separator, typename std::enable_if<!(std::is_same< typename std::iterator_traits< ITERATOR_TYPE >::iterator_category, std::random_access_iterator_tag >::value)>::type *=nullptr)
Join a set or vector of (something that turns into a string) together into one string,...
Definition Strings.h:84
std::shared_ptr< const Unit > Unit_const_sptr
Shared pointer to the Unit base class (const version)
Definition Unit.h:196
std::shared_ptr< IValidator > IValidator_sptr
A shared_ptr to an IValidator.
Definition IValidator.h:26
Helper class which provides the Collimation Length for SANS instruments.