Newer
Older
// Mantid Repository : https://github.com/mantidproject/mantid
//
// Copyright © 2018 ISIS Rutherford Appleton Laboratory UKRI,
// NScD Oak Ridge National Laboratory, European Spallation Source,
// Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
// SPDX - License - Identifier: GPL - 3.0 +
#include "MantidAPI/InstrumentValidator.h"
#include "MantidAPI/ExperimentInfo.h"
Federico Montesino Pouzols
committed
#include "MantidGeometry/Instrument.h"
#include "MantidKernel/Strings.h"
#include <boost/make_shared.hpp>
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
namespace Mantid {
namespace API {
using Kernel::Strings::join;
/**
* Construct a validator with requirements (default = SamplePosition)
* @param flags A combination of flags to specify requirements
*/
InstrumentValidator::InstrumentValidator(const unsigned int flags)
: m_requires(flags) {}
/**
* @return A string type identifier for the object
*/
std::string InstrumentValidator::getType() const { return "Instrument"; }
/**
* @return A copy of the current state of the object
*/
Kernel::IValidator_sptr InstrumentValidator::clone() const {
return boost::make_shared<InstrumentValidator>(*this);
}
/** Checks that the workspace has an instrument defined
* @param value :: The workspace to test
* @return A user-level description if a problem exists or ""
*/
std::string InstrumentValidator::checkValidity(
const boost::shared_ptr<ExperimentInfo> &value) const {
const auto inst = value->getInstrument();
if (!inst)
return "The workspace must have an instrument defined";
std::list<std::string> missing;
if ((m_requires & SourcePosition) && !inst->getSource()) {
missing.emplace_back("source");
}
if ((m_requires & SamplePosition) && !inst->getSample()) {
missing.emplace_back("sample holder");
}
if (missing.empty())
return "";
else {
return "The instrument is missing the following "
"components: " +
join(missing.begin(), missing.end(), ",");
}
}
} // namespace API
} // namespace Mantid