-
Notifications
You must be signed in to change notification settings - Fork 122
/
ExtractMonitorWorkspace.cpp
66 lines (55 loc) · 2.71 KB
/
ExtractMonitorWorkspace.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
// Mantid Repository : https://github.com/mantidproject/mantid
//
// Copyright © 2018 ISIS Rutherford Appleton Laboratory UKRI,
// NScD Oak Ridge National Laboratory, European Spallation Source,
// Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
// SPDX - License - Identifier: GPL - 3.0 +
#include "MantidDataHandling/ExtractMonitorWorkspace.h"
#include "MantidAPI/MatrixWorkspace.h"
namespace Mantid {
namespace DataHandling {
// Register the algorithm into the AlgorithmFactory
DECLARE_ALGORITHM(ExtractMonitorWorkspace)
using namespace Mantid::Kernel;
using namespace Mantid::API;
/// Algorithm's name for identification. @see Algorithm::name
const std::string ExtractMonitorWorkspace::name() const { return "ExtractMonitorWorkspace"; }
/// Algorithm's version for identification. @see Algorithm::version
int ExtractMonitorWorkspace::version() const { return 1; }
/// Algorithm's category for identification. @see Algorithm::category
const std::string ExtractMonitorWorkspace::category() const { return "Utility\\Workspaces"; }
/// Algorithm's summary for use in the GUI and help. @see Algorithm::summary
const std::string ExtractMonitorWorkspace::summary() const {
return "Retrieves a workspace of monitor data held within the input "
"workspace, if present.";
}
/** Initialize the algorithm's properties.
*/
void ExtractMonitorWorkspace::init() {
declareProperty(std::make_unique<WorkspaceProperty<>>("InputWorkspace", "", Direction::Input),
"A data workspace that holds a monitor workspace within.");
declareProperty(std::make_unique<WorkspaceProperty<>>("MonitorWorkspace", "", Direction::Output),
"The workspace containing only monitor data relating to the main data in "
"the InputWorkspace.");
declareProperty("ClearFromInputWorkspace", true,
"Whether to hold onto the monitor workspace within "
"the input workspace. The default is not to, but if you are running this "
"algorithm in the post-processing "
"step of a live data run then you will need this to be false.");
}
/** Execute the algorithm.
*/
void ExtractMonitorWorkspace::exec() {
MatrixWorkspace_sptr inputWS = getProperty("InputWorkspace");
auto monitorWS = inputWS->monitorWorkspace();
if (!monitorWS) {
throw std::invalid_argument("The input workspace does not hold a monitor workspace");
}
setProperty("MonitorWorkspace", monitorWS);
// Now clear off the pointer on the input workspace, if desired
const bool clearPointer = getProperty("ClearFromInputWorkspace");
if (clearPointer)
inputWS->setMonitorWorkspace(MatrixWorkspace_sptr());
}
} // namespace DataHandling
} // namespace Mantid