forked from mantidproject/mantid
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCropWorkspace.cpp
84 lines (67 loc) · 3 KB
/
CropWorkspace.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
//----------------------------------------------------------------------
// Includes
//----------------------------------------------------------------------
#include "MantidAPI/MatrixWorkspace.h"
#include "MantidAlgorithms/CropWorkspace.h"
#include "MantidKernel/BoundedValidator.h"
namespace Mantid {
namespace Algorithms {
using std::size_t;
// Register the algorithm into the AlgorithmFactory
DECLARE_ALGORITHM(CropWorkspace)
using namespace Kernel;
using namespace API;
void CropWorkspace::init() {
declareProperty(
make_unique<WorkspaceProperty<>>("InputWorkspace", "", Direction::Input),
"The input workspace");
declareProperty(make_unique<WorkspaceProperty<>>("OutputWorkspace", "",
Direction::Output),
"Name of the output workspace");
declareProperty("XMin", EMPTY_DBL(), "An X value that is within the first "
"(lowest X value) bin that will be "
"retained\n"
"(default: workspace min)");
declareProperty("XMax", EMPTY_DBL(), "An X value that is in the highest X "
"value bin to be retained (default: max "
"X)");
auto mustBePositive = boost::make_shared<BoundedValidator<int>>();
mustBePositive->setLower(0);
declareProperty("StartWorkspaceIndex", 0, mustBePositive,
"The index number of the first entry in the Workspace that "
"will be loaded\n"
"(default: first entry in the Workspace)");
// As the property takes ownership of the validator pointer, have to take care
// to pass in a unique
// pointer to each property.
declareProperty(
"EndWorkspaceIndex", EMPTY_INT(), mustBePositive,
"The index number of the last entry in the Workspace to be loaded\n"
"(default: last entry in the Workspace)");
}
/** Executes the algorithm
* @throw std::out_of_range If a property is set to an invalid value for the
* input workspace
*/
void CropWorkspace::exec() {
auto extract = createChildAlgorithm("ExtractSpectra", 0, 1);
extract->initialize();
extract->setRethrows(true);
MatrixWorkspace_sptr inputWorkspace = getProperty("InputWorkspace");
extract->setProperty("InputWorkspace", inputWorkspace);
MatrixWorkspace_sptr outputWorkspace = getProperty("OutputWorkspace");
extract->setProperty("OutputWorkspace", outputWorkspace);
double xmin = getProperty("XMin");
extract->setProperty("XMin", xmin);
double xmax = getProperty("XMax");
extract->setProperty("XMax", xmax);
int start = getProperty("StartWorkspaceIndex");
extract->setProperty("StartWorkspaceIndex", start);
int end = getProperty("EndWorkspaceIndex");
extract->setProperty("EndWorkspaceIndex", end);
extract->execute();
outputWorkspace = extract->getProperty("OutputWorkspace");
setProperty("OutputWorkspace", outputWorkspace);
}
} // namespace Algorithms
} // namespace Mantid