Mantid
Loading...
Searching...
No Matches
ExtractMonitorWorkspace.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 +
9
10namespace Mantid::DataHandling {
11// Register the algorithm into the AlgorithmFactory
12DECLARE_ALGORITHM(ExtractMonitorWorkspace)
13
14using namespace Mantid::Kernel;
15using namespace Mantid::API;
16
18const std::string ExtractMonitorWorkspace::name() const { return "ExtractMonitorWorkspace"; }
19
21int ExtractMonitorWorkspace::version() const { return 1; }
22
24const std::string ExtractMonitorWorkspace::category() const { return "Utility\\Workspaces"; }
25
27const std::string ExtractMonitorWorkspace::summary() const {
28 return "Retrieves a workspace of monitor data held within the input "
29 "workspace, if present.";
30}
31
35 declareProperty(std::make_unique<WorkspaceProperty<>>("InputWorkspace", "", Direction::Input),
36 "A data workspace that holds a monitor workspace within.");
37 declareProperty(std::make_unique<WorkspaceProperty<>>("MonitorWorkspace", "", Direction::Output),
38 "The workspace containing only monitor data relating to the main data in "
39 "the InputWorkspace.");
40 declareProperty("ClearFromInputWorkspace", true,
41 "Whether to hold onto the monitor workspace within "
42 "the input workspace. The default is not to, but if you are running this "
43 "algorithm in the post-processing "
44 "step of a live data run then you will need this to be false.");
45}
46
50 MatrixWorkspace_sptr inputWS = getProperty("InputWorkspace");
51 auto monitorWS = inputWS->monitorWorkspace();
52
53 if (!monitorWS) {
54 throw std::invalid_argument("The input workspace does not hold a monitor workspace");
55 }
56
57 setProperty("MonitorWorkspace", monitorWS);
58 // Now clear off the pointer on the input workspace, if desired
59 const bool clearPointer = getProperty("ClearFromInputWorkspace");
60 if (clearPointer)
61 inputWS->setMonitorWorkspace(MatrixWorkspace_sptr());
62}
63
64} // namespace Mantid::DataHandling
#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.
const std::string category() const override
Algorithm's category for identification.
int version() const override
Algorithm's version for identification.
void init() override
Initialize the algorithm's properties.
const std::string name() const override
Algorithm's name for identification.
const std::string summary() const override
Algorithm's summary for use in the GUI and help.
void exec() override
Execute the algorithm.
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
@ Input
An input workspace.
Definition: Property.h:53
@ Output
An output workspace.
Definition: Property.h:54