-
Notifications
You must be signed in to change notification settings - Fork 122
/
InvertMask.cpp
61 lines (49 loc) · 1.8 KB
/
InvertMask.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#include "MantidAlgorithms/InvertMask.h"
#include "MantidKernel/System.h"
#include "MantidAPI/WorkspaceProperty.h"
#include "MantidDataObjects/MaskWorkspace.h"
using namespace Mantid::Kernel;
using namespace Mantid::API;
namespace Mantid {
namespace Algorithms {
DECLARE_ALGORITHM(InvertMask)
void InvertMask::init() {
this->declareProperty(
make_unique<API::WorkspaceProperty<DataObjects::MaskWorkspace>>(
"InputWorkspace", "Anonymous", Direction::Input),
"MaskWorkspace to be inverted. ");
this->declareProperty(
make_unique<API::WorkspaceProperty<DataObjects::MaskWorkspace>>(
"OutputWorkspace", "AnonynmousOutput", Direction::Output),
"MaskWorkspace has inverted bits from input MaskWorkspace.");
}
void InvertMask::exec() {
// 1. Get input
DataObjects::MaskWorkspace_const_sptr inWS =
this->getProperty("InputWorkspace");
if (!inWS) {
throw std::invalid_argument("InputWorkspace is not a MaskWorkspace.");
}
// 2. Do Invert by calling Child Algorithm
API::IAlgorithm_sptr invert =
createChildAlgorithm("BinaryOperateMasks", 0.0, 1.0, true);
invert->setPropertyValue("InputWorkspace1", inWS->getName());
invert->setProperty("OperationType", "NOT");
invert->setProperty("OutputWorkspace", "tempws");
invert->execute();
if (!invert->isExecuted()) {
g_log.error()
<< "ChildAlgorithm BinaryOperateMask() cannot be executed. \n";
throw std::runtime_error(
"ChildAlgorithm BinaryOperateMask() cannot be executed. ");
}
DataObjects::MaskWorkspace_sptr outputws =
invert->getProperty("OutputWorkspace");
if (!outputws) {
throw std::runtime_error("Output Workspace is not a MaskWorkspace. ");
}
// 3. Set
this->setProperty("OutputWorkspace", outputws);
}
} // namespace Mantid
} // namespace Algorithms