Mantid
Loading...
Searching...
No Matches
MaskBinsFromWorkspace.cpp
Go to the documentation of this file.
1// Mantid Repository : https://github.com/mantidproject/mantid
2//
3// Copyright © 2019 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 +
8#include "MantidAPI/Algorithm.tcc"
10
11namespace Mantid::Algorithms {
12
13// Register the algorithm into the AlgorithmFactory
14DECLARE_ALGORITHM(MaskBinsFromWorkspace)
15
16using namespace Kernel;
17using namespace API;
18
20 declareWorkspaceInputProperties<MatrixWorkspace>("InputWorkspace",
21 "The name of the input workspace. Must contain histogram data.",
22 std::make_shared<HistogramValidator>());
23 declareWorkspaceInputProperties<MatrixWorkspace>(
24 "MaskedWorkspace",
25 "The name of the workspaces containing masked bins to copy over. Must "
26 "contain histogram data.",
27 std::make_shared<HistogramValidator>());
28
29 declareProperty(std::make_unique<WorkspaceProperty<>>("OutputWorkspace", "", Direction::Output),
30 "The name of the Workspace containing the masked bins.");
31}
32
37 std::tie(inputWS, m_indexSet) = getWorkspaceAndIndices<MatrixWorkspace>("InputWorkspace");
38 MatrixWorkspace_sptr maskedWS = getProperty("MaskedWorkspace");
39
40 // Only create the output workspace if it's different to the input one
41 MatrixWorkspace_sptr outputWS = getProperty("OutputWorkspace");
42 if (outputWS != inputWS) {
43 outputWS = inputWS->clone();
44 setProperty("OutputWorkspace", outputWS);
45 }
46
47 // We assume that MaskedWorkspace contains a masked 0th spectra.
48 // The masks flags attached to this spectrum are copied over to every spectrum
49 // in the input workspace
50 if (maskedWS->hasMaskedBins(0)) {
51 const auto maskedBins = maskedWS->maskedBins(0);
52 for (const auto wi : m_indexSet) {
53 for (const auto &maskedBin : maskedBins) {
54 outputWS->flagMasked(wi, maskedBin.first, maskedBin.second);
55 }
56 }
57 }
58}
59
60} // namespace Mantid::Algorithms
#define DECLARE_ALGORITHM(classname)
Definition: Algorithm.h:576
void declareProperty(std::unique_ptr< Kernel::Property > p, const std::string &doc="") override
Add a property to the list of managed properties.
Definition: Algorithm.cpp:1913
TypedValue getProperty(const std::string &name) const override
Get the value of a property.
Definition: Algorithm.cpp:2076
A property class for workspaces.
void init() override
Initialisation code.
Indexing::SpectrumIndexSet m_indexSet
the list of Spectra (workspace index) to load
IPropertyManager * setProperty(const std::string &name, const T &value)
Templated method to set the value of a PropertyWithValue.
std::shared_ptr< MatrixWorkspace > MatrixWorkspace_sptr
shared pointer to the matrix workspace base class
@ Output
An output workspace.
Definition: Property.h:54