Mantid
Loading...
Searching...
No Matches
Max.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 +
7//----------------------------------------------------------------------
8// Includes
9//----------------------------------------------------------------------
13
14namespace Mantid::Algorithms {
15
16// Register the class into the algorithm factory
18
19using namespace Kernel;
20using namespace API;
21
25void Max::init() {
26 declareProperty(std::make_unique<WorkspaceProperty<>>("InputWorkspace", "", Direction::Input,
27 std::make_shared<HistogramValidator>()),
28 "The name of the Workspace2D to take as input");
29 declareProperty(std::make_unique<WorkspaceProperty<>>("OutputWorkspace", "", Direction::Output),
30 "The name of the workspace in which to store the result");
31
32 declareProperty("RangeLower", EMPTY_DBL(), "The X value to search from (default min)");
33 declareProperty("RangeUpper", EMPTY_DBL(), "The X value to search to (default max)");
34 auto mustBePositive = std::make_shared<BoundedValidator<int>>();
35 mustBePositive->setLower(0);
36 declareProperty("StartWorkspaceIndex", 0, mustBePositive, "Start spectrum number (default 0)");
37 declareProperty("EndWorkspaceIndex", EMPTY_INT(), mustBePositive, "End spectrum number (default max)");
38}
39
44void Max::exec() {
45 // Try and retrieve the optional properties
46 double m_MinRange = getProperty("RangeLower");
47 double m_MaxRange = getProperty("RangeUpper");
48 int m_MinSpec = getProperty("StartWorkspaceIndex");
49 int m_MaxSpec = getProperty("EndWorkspaceIndex");
50
51 // Get the input workspace
52 MatrixWorkspace_sptr inworkspace = getProperty("InputWorkspace");
53
54 // Child Algorithme does all of the actual work - do not set the output
55 // workspace
56 auto maxAlgo = createChildAlgorithm("MaxMin", 0., 1.);
57 maxAlgo->setProperty("InputWorkspace", inworkspace);
58 maxAlgo->setProperty("RangeLower", m_MinRange);
59 maxAlgo->setProperty("RangeUpper", m_MaxRange);
60 maxAlgo->setProperty("StartWorkspaceIndex", m_MinSpec);
61 maxAlgo->setProperty("EndWorkspaceIndex", m_MaxSpec);
62 maxAlgo->setProperty("ShowMin", false);
63 maxAlgo->execute();
64 // just grab the child's output workspace
65 MatrixWorkspace_sptr outputWS = maxAlgo->getProperty("OutputWorkspace");
66
67 this->setProperty("OutputWorkspace", outputWS);
68}
69
70} // 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 exec() override
Executes the algorithm.
Definition: Max.cpp:44
void init() override
Initialisation method.
Definition: Max.cpp:25
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