Mantid
Loading...
Searching...
No Matches
LoadNexusMonitors.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 +
8
11#include "MantidAPI/Workspace.h"
13
16
17namespace Mantid::DataHandling {
18
19DECLARE_ALGORITHM(LoadNexusMonitors)
20
21
22void LoadNexusMonitors::init() {
23 declareProperty(std::make_unique<API::FileProperty>("Filename", "", API::FileProperty::Load, ".nxs"),
24 "The name (including its full or relative path) of the NeXus file to "
25 "attempt to load. The file extension must either be .nxs or .NXS");
26
27 declareProperty(
28 std::make_unique<API::WorkspaceProperty<API::Workspace>>("OutputWorkspace", "", Kernel::Direction::Output),
29 "The name of the output workspace in which to load the NeXus monitors.");
30}
31
37 // Use version 2 of this algorithm
38 auto alg = createChildAlgorithm("LoadNexusMonitors", -1, -1, true, 2);
39 alg->setRethrows(true);
40
41 // Forward algorithm properties
42 alg->setPropertyValue("Filename", getPropertyValue("Filename"));
43 alg->setPropertyValue("OutputWorkspace", getPropertyValue("OutputWorkspace"));
44
45 // Run new algorithm
46 alg->execute();
47
48 // Output workspace of new algorithm
49 Workspace_sptr ws = alg->getProperty("OutputWorkspace");
50
51 // If it's a group workspace, we need to create additional output workspaces
52 // to match this version's previous behaviour. This doesn't create additional
53 // workspaces in the ADS, but it does have side-effects:
54 // - Rename all the children of the group to _1, _2, _3, etc
55 // - Cause the return value in Python to be a tuple that contains the group
56 // workspace, followed by references to its children as siblings
57 auto ws_group = std::dynamic_pointer_cast<WorkspaceGroup>(ws);
58 if (ws_group) {
59 auto child_count = ws_group->size();
60 for (decltype(child_count) i = 0; i < child_count; ++i) {
61 // create additional output workspace property
62 std::stringstream ssWsName;
63 ssWsName << "_" << i + 1;
64 std::stringstream ssPropName;
65 ssPropName << "OutputWorkspace"
66 << "_" << i + 1;
67 declareProperty(std::make_unique<API::WorkspaceProperty<API::Workspace>>(ssPropName.str(), ssWsName.str(),
69 "Additional output workspace for multi period monitors.");
70 setProperty(ssPropName.str(), ws_group->getItem(i));
71 }
72 }
73
74 setProperty("OutputWorkspace", ws);
75}
76
77} // 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
std::string getPropertyValue(const std::string &name) const override
Get the value of a property as a string.
Definition: Algorithm.cpp:2026
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
@ Load
allowed here which will be passed to the algorithm
Definition: FileProperty.h:52
Class to hold a set of workspaces.
A property class for workspaces.
DataHandling/LoadNexusMonitors.h.
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< Workspace > Workspace_sptr
shared pointer to Mantid::API::Workspace
Definition: Workspace_fwd.h:20
@ Output
An output workspace.
Definition: Property.h:54