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#include "MantidKernel/Unit.h"
13
14namespace Mantid {
15namespace API {
16
17PolSANSWorkspaceValidator::PolSANSWorkspaceValidator(bool expectHistogramData, bool allowMultiPeriodData,
18 const std::unordered_set<int> &allowedNumberOfPeriods)
19 : m_expectHistogramData(expectHistogramData), m_allowMultiPeriodData(allowMultiPeriodData),
20 m_allowedNumberOfPeriods(allowedNumberOfPeriods) {};
21
23 return std::make_shared<PolSANSWorkspaceValidator>(*this);
24}
25
27 std::vector<std::string> workspaceIssues;
28 if (!workspace) {
29 return "All workspaces must be of type MatrixWorkspace.";
30 }
31
32 Kernel::Unit_const_sptr unit = workspace->getAxis(0)->unit();
33 if (unit->unitID() != "Wavelength") {
34 workspaceIssues.push_back("All workspaces must be in units of Wavelength.");
35 }
36
37 if (!m_allowMultiPeriodData && workspace->getNumberHistograms() != 1) {
38 workspaceIssues.push_back("All workspaces must contain a single histogram.");
39 }
40
41 if (workspace->isHistogramData() != m_expectHistogramData) {
43 workspaceIssues.push_back("All workspaces must be histogram data.");
44 } else {
45 workspaceIssues.push_back("All workspaces must not be histogram data.");
46 }
47 }
48
49 if (!workspaceIssues.empty()) {
50 return Kernel::Strings::join(workspaceIssues.cbegin(), workspaceIssues.cend(), " ");
51 }
52
53 return "";
54}
55
57
58 const int numberOfEntries = workspace->getNumberOfEntries();
59 if (m_allowedNumberOfPeriods.find(numberOfEntries) == m_allowedNumberOfPeriods.cend()) {
60 return "The number of periods within the input workspace is not an allowed value.";
61 }
62
63 for (const API::Workspace_sptr &ws : workspace->getAllItems()) {
64 const auto groupItem = std::dynamic_pointer_cast<API::MatrixWorkspace>(ws);
65 const std::string errors = validateGroupItem(groupItem);
66 if (errors != "") {
67 return errors;
68 }
69 }
70
71 return "";
72}
73
74} // namespace API
75} // 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
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_fwd.h:19
std::shared_ptr< IValidator > IValidator_sptr
A shared_ptr to an IValidator.
Helper class which provides the Collimation Length for SANS instruments.