Mantid
Loading...
Searching...
No Matches
CropWorkspace.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
11namespace Mantid::Algorithms {
12
13using std::size_t;
14
15// Register the algorithm into the AlgorithmFactory
16DECLARE_ALGORITHM(CropWorkspace)
17
18using namespace Kernel;
19using namespace API;
20
22 declareProperty(std::make_unique<WorkspaceProperty<>>("InputWorkspace", "", Direction::Input), "The input workspace");
23 declareProperty(std::make_unique<WorkspaceProperty<>>("OutputWorkspace", "", Direction::Output),
24 "Name of the output workspace");
25
26 declareProperty("XMin", EMPTY_DBL(),
27 "An X value that is within the first "
28 "(lowest X value) bin that will be "
29 "retained\n"
30 "(default: workspace min)");
31 declareProperty("XMax", EMPTY_DBL(),
32 "An X value that is in the highest X "
33 "value bin to be retained (default: max "
34 "X)");
35 auto mustBePositive = std::make_shared<BoundedValidator<int>>();
36 mustBePositive->setLower(0);
37 declareProperty("StartWorkspaceIndex", 0, mustBePositive,
38 "The index number of the first entry in the Workspace that "
39 "will be loaded\n"
40 "(default: first entry in the Workspace)");
41 // As the property takes ownership of the validator pointer, have to take care
42 // to pass in a unique
43 // pointer to each property.
44 declareProperty("EndWorkspaceIndex", EMPTY_INT(), mustBePositive,
45 "The index number of the last entry in the Workspace to be loaded\n"
46 "(default: last entry in the Workspace)");
47}
48
54
55 auto extract = createChildAlgorithm("ExtractSpectra", 0, 1);
56 extract->initialize();
57 extract->setRethrows(true);
58
59 MatrixWorkspace_sptr inputWorkspace = getProperty("InputWorkspace");
60 extract->setProperty("InputWorkspace", inputWorkspace);
61
62 MatrixWorkspace_sptr outputWorkspace = getProperty("OutputWorkspace");
63 extract->setProperty("OutputWorkspace", outputWorkspace);
64
65 double xmin = getProperty("XMin");
66 extract->setProperty("XMin", xmin);
67
68 double xmax = getProperty("XMax");
69 extract->setProperty("XMax", xmax);
70
71 int start = getProperty("StartWorkspaceIndex");
72 extract->setProperty("StartWorkspaceIndex", start);
73
74 int end = getProperty("EndWorkspaceIndex");
75 extract->setProperty("EndWorkspaceIndex", end);
76
77 extract->execute();
78
79 outputWorkspace = extract->getProperty("OutputWorkspace");
80 setProperty("OutputWorkspace", outputWorkspace);
81}
82
83} // 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
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
A property class for workspaces.
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< MatrixWorkspace > MatrixWorkspace_sptr
shared pointer to the matrix workspace base class
constexpr int EMPTY_INT() noexcept
Returns what we consider an "empty" integer within a property.
Definition: EmptyValues.h:25
constexpr double EMPTY_DBL() noexcept
Returns what we consider an "empty" double within a property.
Definition: EmptyValues.h:43
@ Input
An input workspace.
Definition: Property.h:53
@ Output
An output workspace.
Definition: Property.h:54