Mantid
Loading...
Searching...
No Matches
ExtractMask.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 +
14
15namespace Mantid::Algorithms {
16
17// Register the algorithm into the AlgorithmFactory
18DECLARE_ALGORITHM(ExtractMask)
19
21using Kernel::Direction;
22using namespace API;
23using namespace Kernel;
24
29 declareProperty(std::make_unique<WorkspaceProperty<MatrixWorkspace>>("InputWorkspace", "", Direction::Input),
30 "A workspace whose masking is to be extracted");
31 declareProperty(std::make_unique<WorkspaceProperty<MatrixWorkspace>>("OutputWorkspace", "", Direction::Output),
32 "A workspace containing the masked spectra as zeroes and ones.");
33
35 std::make_unique<ArrayProperty<detid_t>>("DetectorList", std::make_shared<NullValidator>(), Direction::Output),
36 "A comma separated list or array containing a list of masked "
37 "detector ID's");
38}
39
44 MatrixWorkspace_const_sptr inputWS = getProperty("InputWorkspace");
45
46 // convert input to a mask workspace
47 auto inputMaskWS = std::dynamic_pointer_cast<const DataObjects::MaskWorkspace>(inputWS);
48 auto inputWSIsSpecial = bool(inputMaskWS);
49 if (inputWSIsSpecial) {
50 g_log.notice() << "Input workspace is a MaskWorkspace.\n";
51 }
52
53 // List masked of detector IDs
54 std::vector<detid_t> detectorList;
55 const auto &detInfo = inputWS->detectorInfo();
56 const auto &detIds = detInfo.detectorIDs();
57 for (size_t i = 0; i < detInfo.size(); ++i) {
58 if ((inputWSIsSpecial && inputMaskWS->isMasked(detIds[i])) || detInfo.isMasked(i)) {
59 detectorList.emplace_back(detIds[i]);
60 }
61 }
62
63 // Create a new workspace for the results, copy from the input to ensure
64 // that we copy over the instrument and current masking
65 auto maskWS = std::make_shared<DataObjects::MaskWorkspace>(inputWS);
66 maskWS->setTitle(inputWS->getTitle());
67
68 const auto &spectrumInfo = inputWS->spectrumInfo();
69 const auto nHist = static_cast<int64_t>(inputWS->getNumberHistograms());
70 Progress prog(this, 0.0, 1.0, nHist);
71
72 PARALLEL_FOR_IF(Kernel::threadSafe(*inputWS, *maskWS))
73 for (int64_t i = 0; i < nHist; ++i) {
75 bool inputIsMasked(false);
76 if (spectrumInfo.hasDetectors(i)) {
77 // special workspaces can mysteriously have the mask bit set
78 inputIsMasked = (inputWSIsSpecial && inputMaskWS->isMaskedIndex(i)) || spectrumInfo.isMasked(i);
79 }
80 maskWS->setMaskedIndex(i, inputIsMasked);
81 prog.report();
83 }
85
86 g_log.information() << maskWS->getNumberMasked() << " spectra are masked\n";
87 g_log.information() << detectorList.size() << " detectors are masked\n";
88 setProperty("OutputWorkspace", maskWS);
89 setProperty("DetectorList", detectorList);
90}
91} // namespace Mantid::Algorithms
#define DECLARE_ALGORITHM(classname)
Definition: Algorithm.h:576
IntArray detectorList
#define PARALLEL_START_INTERRUPT_REGION
Begins a block to skip processing is the algorithm has been interupted Note the end of the block if n...
Definition: MultiThreaded.h:94
#define PARALLEL_END_INTERRUPT_REGION
Ends a block to skip processing is the algorithm has been interupted Note the start of the block if n...
#define PARALLEL_FOR_IF(condition)
Empty definitions - to enable set your complier to enable openMP.
#define PARALLEL_CHECK_INTERRUPT_REGION
Adds a check after a Parallel region to see if it was interupted.
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
Kernel::Logger & g_log
Definition: Algorithm.h:451
Helper class for reporting progress from algorithms.
Definition: Progress.h:25
A property class for workspaces.
void exec() override
Execution code.
Definition: ExtractMask.cpp:43
void init() override
Initialisation code.
Definition: ExtractMask.cpp:28
Support for a property that holds an array of values.
Definition: ArrayProperty.h:28
IPropertyManager * setProperty(const std::string &name, const T &value)
Templated method to set the value of a PropertyWithValue.
void notice(const std::string &msg)
Logs at notice level.
Definition: Logger.cpp:95
void information(const std::string &msg)
Logs at information level.
Definition: Logger.cpp:105
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< const MatrixWorkspace > MatrixWorkspace_const_sptr
shared pointer to the matrix workspace base class (const version)
std::shared_ptr< const Mantid::Geometry::IDetector > IDetector_const_sptr
Shared pointer to IDetector (const version)
Definition: IDetector.h:102
std::enable_if< std::is_pointer< Arg >::value, bool >::type threadSafe(Arg workspace)
Thread-safety check Checks the workspace to ensure it is suitable for multithreaded access.
Definition: MultiThreaded.h:22
@ Input
An input workspace.
Definition: Property.h:53
@ Output
An output workspace.
Definition: Property.h:54