Mantid
Loading...
Searching...
No Matches
InstrumentValidator.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 +
11#include <list>
12#include <memory>
13
14namespace Mantid::API {
16
21InstrumentValidator::InstrumentValidator(const unsigned int flags) : m_requires(flags) {}
22
26std::string InstrumentValidator::getType() const { return "Instrument"; }
27
31Kernel::IValidator_sptr InstrumentValidator::clone() const { return std::make_shared<InstrumentValidator>(*this); }
32
37std::string InstrumentValidator::checkValidity(const std::shared_ptr<ExperimentInfo> &value) const {
38 const auto inst = value->getInstrument();
39 if (!inst)
40 return "The workspace must have an instrument defined";
41
42 std::list<std::string> missing;
43 if ((m_requires & SourcePosition) && !inst->hasSource()) {
44 missing.emplace_back("source");
45 }
46 if ((m_requires & SamplePosition) && !inst->hasSample()) {
47 missing.emplace_back("sample holder");
48 }
49
50 if (missing.empty())
51 return "";
52 else {
53 return "The instrument is missing the following "
54 "components: " +
55 join(missing.begin(), missing.end(), ",");
56 }
57}
58
59} // namespace Mantid::API
double value
The value of the point.
Definition: FitMW.cpp:51
std::string checkValidity(const std::shared_ptr< ExperimentInfo > &value) const override
Checks that the workspace has an instrument defined.
InstrumentValidator(const unsigned int flags=SamplePosition)
Construct a validator with requirements (default = SamplePosition)
Kernel::IValidator_sptr clone() const override
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< IValidator > IValidator_sptr
A shared_ptr to an IValidator.
Definition: IValidator.h:26