Mantid
Loading...
Searching...
No Matches
InvertMask.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 +
10
11using namespace Mantid::Kernel;
12using namespace Mantid::API;
13
14namespace Mantid::Algorithms {
15
16DECLARE_ALGORITHM(InvertMask)
17
18void InvertMask::init() {
19 this->declareProperty(std::make_unique<API::WorkspaceProperty<DataObjects::MaskWorkspace>>(
20 "InputWorkspace", "Anonymous", Direction::Input),
21 "MaskWorkspace to be inverted. ");
22
23 this->declareProperty(std::make_unique<API::WorkspaceProperty<DataObjects::MaskWorkspace>>(
24 "OutputWorkspace", "AnonynmousOutput", Direction::Output),
25 "MaskWorkspace has inverted bits from input MaskWorkspace.");
26}
27
29 // 1. Get input
30 DataObjects::MaskWorkspace_const_sptr inWS = this->getProperty("InputWorkspace");
31 if (!inWS) {
32 throw std::invalid_argument("InputWorkspace is not a MaskWorkspace.");
33 }
34
35 // 2. Do Invert by calling Child Algorithm
36 auto invert = createChildAlgorithm("BinaryOperateMasks", 0.0, 1.0, true);
37 invert->setPropertyValue("InputWorkspace1", inWS->getName());
38 invert->setProperty("OperationType", "NOT");
39 invert->setProperty("OutputWorkspace", "tempws");
40
41 invert->execute();
42
43 if (!invert->isExecuted()) {
44 g_log.error() << "ChildAlgorithm BinaryOperateMask() cannot be executed. \n";
45 throw std::runtime_error("ChildAlgorithm BinaryOperateMask() cannot be executed. ");
46 }
47
48 DataObjects::MaskWorkspace_sptr outputws = invert->getProperty("OutputWorkspace");
49 if (!outputws) {
50 throw std::runtime_error("Output Workspace is not a MaskWorkspace. ");
51 }
52
53 // 3. Set
54 this->setProperty("OutputWorkspace", outputws);
55}
56
57} // namespace Mantid::Algorithms
#define DECLARE_ALGORITHM(classname)
Definition: Algorithm.h:576
TypedValue getProperty(const std::string &name) const override
Get the value of a property.
Definition: Algorithm.cpp:2076
virtual std::shared_ptr< Algorithm > createChildAlgorithm(const std::string &name, const double startProgress=-1., const double endProgress=-1., const bool enableLogging=true, const int &version=-1)
Create a Child Algorithm.
Definition: Algorithm.cpp:842
Kernel::Logger & g_log
Definition: Algorithm.h:451
A property class for workspaces.
InvertMask : TODO: DESCRIPTION.
Definition: InvertMask.h:19
void exec() override
Virtual method - must be overridden by concrete algorithm.
Definition: InvertMask.cpp:28
IPropertyManager * setProperty(const std::string &name, const T &value)
Templated method to set the value of a PropertyWithValue.
void error(const std::string &msg)
Logs at error level.
Definition: Logger.cpp:77
std::shared_ptr< const MaskWorkspace > MaskWorkspace_const_sptr
shared pointer to a const MaskWorkspace
Definition: MaskWorkspace.h:67
std::shared_ptr< MaskWorkspace > MaskWorkspace_sptr
shared pointer to the MaskWorkspace class
Definition: MaskWorkspace.h:64
@ Input
An input workspace.
Definition: Property.h:53
@ Output
An output workspace.
Definition: Property.h:54