Mantid
Loading...
Searching...
No Matches
BinaryOperateMasks.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(BinaryOperateMasks)
17
18// enum BinaryOperator{AND, OR, XOR, NOT};
19
20//----------------------------------------------------------------------------------------------
24 // TODO Auto-generated constructor stub
25}
26
27//----------------------------------------------------------------------------------------------
31 // TODO Auto-generated destructor stub
32}
33
35
36 std::vector<std::string> operators{"AND", "OR", "XOR", "NOT"};
37
39 std::make_unique<WorkspaceProperty<DataObjects::MaskWorkspace>>("InputWorkspace1", "", Direction::Input),
40 "MaskWorkspace 1 for binary operation");
42 "InputWorkspace2", "", Direction::Input, PropertyMode::Optional),
43 "Optional MaskWorkspace 2 for binary operation");
44 declareProperty("OperationType", "AND", std::make_shared<StringListValidator>(operators),
45 "Operator for Workspace1 and Workspace2");
47 std::make_unique<WorkspaceProperty<DataObjects::MaskWorkspace>>("OutputWorkspace", "", Direction::Output),
48 "Output MaskWorkspace as result of binary operation");
49}
50
51//----------------------------------------------------------------------------------------------
55
56 // 1. Read input
57 DataObjects::MaskWorkspace_const_sptr inputws1 = getProperty("InputWorkspace1");
58 std::string op = getProperty("OperationType");
59
60 // 2. Output
61 DataObjects::MaskWorkspace_sptr outputws = getProperty("OutputWorkspace");
62
63 if (outputws != inputws1) {
64 // if the input and output are not the same, then create a new workspace for
65 // the output.
66 outputws = std::make_shared<DataObjects::MaskWorkspace>(inputws1->getInstrument());
67 outputws->copyFrom(inputws1);
68 }
69
70 // 3. Call Child Algorithm
71 if (op == "NOT") {
72 // Unary operation
73 outputws->binaryOperation(Mantid::DataObjects::BinaryOperator::NOT);
74 } else {
75 // Binary operation
76 // a. 2nd Input
77 DataObjects::MaskWorkspace_const_sptr inputws2 = getProperty("InputWorkspace2");
78 DataObjects::SpecialWorkspace2D_const_sptr inputws2_special(inputws2);
79
80 unsigned int binop;
81 if (op == "AND") {
82 binop = static_cast<unsigned int>(Mantid::DataObjects::BinaryOperator::AND);
83 } else if (op == "OR") {
84 binop = static_cast<unsigned int>(Mantid::DataObjects::BinaryOperator::OR);
85 } else if (op == "XOR") {
86 binop = static_cast<unsigned int>(Mantid::DataObjects::BinaryOperator::XOR);
87 } else {
88 binop = 1000;
89 }
90 outputws->binaryOperation(inputws2_special, binop);
91 }
92
93 // 4. Output
94 this->setProperty("OutputWorkspace", outputws);
95}
96
97} // 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.
BinaryOperateMasks : TODO: DESCRIPTION.
void init() override
Initialisation code.
void exec() override
Execution code.
IPropertyManager * setProperty(const std::string &name, const T &value)
Templated method to set the value of a PropertyWithValue.
std::shared_ptr< const SpecialWorkspace2D > SpecialWorkspace2D_const_sptr
shared pointer to a const SpecialWorkspace2D
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