Mantid
Loading...
Searching...
No Matches
MaskSpectra.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 +
8#include "MantidAPI/Algorithm.tcc"
11
12namespace Mantid::DataHandling {
13
14using namespace API;
15using namespace Kernel;
16
17// Register the algorithm into the AlgorithmFactory
18DECLARE_ALGORITHM(MaskSpectra)
19
20
21const std::string MaskSpectra::name() const { return "MaskSpectra"; }
22
24int MaskSpectra::version() const { return 1; }
25
27const std::string MaskSpectra::category() const { return "Transforms\\Masking"; }
28
30const std::string MaskSpectra::summary() const {
31 return "Mask (zero) spectra and the underlying detectors in a workspace.";
32}
33
35 declareWorkspaceInputProperties<MatrixWorkspace, static_cast<int>(IndexType::SpectrumNum) |
36 static_cast<int>(IndexType::WorkspaceIndex)>(
37 "InputWorkspace", "The input workspace");
38 declareProperty(std::make_unique<WorkspaceProperty<>>("OutputWorkspace", "", Direction::Output),
39 "Name of the output workspace");
40}
41
43 std::shared_ptr<MatrixWorkspace> inputWS;
44 Indexing::SpectrumIndexSet indexSet;
45 std::tie(inputWS, indexSet) = getWorkspaceAndIndices<MatrixWorkspace>("InputWorkspace");
46 MatrixWorkspace_sptr outputWS = getProperty("OutputWorkspace");
47 if (outputWS != inputWS) {
48 outputWS = inputWS->clone();
49 setProperty("OutputWorkspace", outputWS);
50 }
51
52 auto &spectrumInfo = outputWS->mutableSpectrumInfo();
53 Progress prog(this, 0.0, 1.0, indexSet.size());
54 for (const auto i : indexSet) {
55 outputWS->getSpectrum(i).clearData();
56 if (spectrumInfo.hasDetectors(i))
57 spectrumInfo.setMasked(i, true);
58 prog.report();
59 }
60}
61
62} // namespace Mantid::DataHandling
#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
Helper class for reporting progress from algorithms.
Definition: Progress.h:25
A property class for workspaces.
Mask specified spectra and the underlying detectors in a workspace.
Definition: MaskSpectra.h:22
const std::string category() const override
Algorithm's category for identification.
Definition: MaskSpectra.cpp:27
int version() const override
Algorithm's version for identification.
Definition: MaskSpectra.cpp:24
const std::string summary() const override
Algorithm's summary for use in the GUI and help.
Definition: MaskSpectra.cpp:30
void init() override
Virtual method - must be overridden by concrete algorithm.
Definition: MaskSpectra.cpp:34
void exec() override
Virtual method - must be overridden by concrete algorithm.
Definition: MaskSpectra.cpp:42
IPropertyManager * setProperty(const std::string &name, const T &value)
Templated method to set the value of a PropertyWithValue.
void report()
Increments the loop counter by 1, then sends the progress notification on behalf of its algorithm.
Definition: ProgressBase.h:51
std::shared_ptr< MatrixWorkspace > MatrixWorkspace_sptr
shared pointer to the matrix workspace base class
STL namespace.
@ Output
An output workspace.
Definition: Property.h:54