Newer
Older
#include "MantidDataHandling/LoadNexusMonitors.h"
#include "MantidAPI/Algorithm.h"
Michael Reuter
committed
#include "MantidAPI/FileProperty.h"
#include "MantidAPI/Workspace.h"
#include "MantidAPI/WorkspaceGroup.h"
Michael Reuter
committed
using Mantid::API::Workspace_sptr;
using Mantid::API::WorkspaceGroup;
namespace Mantid {
namespace DataHandling {
Michael Reuter
committed
DECLARE_ALGORITHM(LoadNexusMonitors)
LoadNexusMonitors::LoadNexusMonitors() : Algorithm() {}
Michael Reuter
committed
LoadNexusMonitors::~LoadNexusMonitors() {}
Michael Reuter
committed
/// Initialization method.
Michael Reuter
committed
declareProperty(
new API::FileProperty("Filename", "", API::FileProperty::Load, ".nxs"),
"The name (including its full or relative path) of the NeXus file to "
"attempt to load. The file extension must either be .nxs or .NXS");
Federico Montesino Pouzols
committed
declareProperty(
new API::WorkspaceProperty<API::Workspace>("OutputWorkspace", "",
Kernel::Direction::Output),
"The name of the output workspace in which to load the NeXus monitors.");
declareProperty(new Kernel::PropertyWithValue<bool>("MonitorsAsEvents", true,
Kernel::Direction::Input),
"If enabled (by default), load the monitors as events (into "
"an EventWorkspace), as long as there is event data. If "
"disabled, load monitors as spectra (into a Workspace2D, "
"regardless of whether event data is found.");
Michael Reuter
committed
}
/**
* Executes the algorithm. Reading in the file and creating and populating
* the output workspace
*/
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
// Use version 2 of this algorithm
auto alg = createChildAlgorithm("LoadNexusMonitors", -1, -1, true, 2);
alg->setRethrows(true);
// Forward algorithm properties
alg->setPropertyValue("Filename", getPropertyValue("Filename"));
alg->setPropertyValue("OutputWorkspace", getPropertyValue("OutputWorkspace"));
alg->setPropertyValue("MonitorsAsEvents",
getPropertyValue("MonitorsAsEvents"));
// Run new algorithm
alg->execute();
// Output workspace of new algorithm
Workspace_sptr ws = alg->getProperty("OutputWorkspace");
// If it's a group workspace, we need to create additional output workspaces
// to match this version's previous behaviour. This doesn't create additional
// workspaces in the ADS, but it does have side-effects:
// - Rename all the children of the group to _1, _2, _3, etc
// - Cause the return value in Python to be a tuple that contains the group
// workspace, followed by references to its children as siblings
auto ws_group = boost::dynamic_pointer_cast<WorkspaceGroup>(ws);
if (ws_group) {
auto child_count = ws_group->size();
for (decltype(child_count) i = 0; i < child_count; ++i) {
// create additional output workspace property
std::stringstream ssWsName;
ssWsName << "_" << i + 1;
std::stringstream ssPropName;
ssPropName << "OutputWorkspace"
<< "_" << i + 1;
declareProperty(
new API::WorkspaceProperty<API::Workspace>(
ssPropName.str(), ssWsName.str(), Kernel::Direction::Output),
"Additional output workspace for multi period monitors.");
setProperty(ssPropName.str(), ws_group->getItem(i));
setProperty("OutputWorkspace", ws);
} // end DataHandling
Michael Reuter
committed
} // end Mantid