Mantid
Loading...
Searching...
No Matches
SaveNexusGeometry.cpp
Go to the documentation of this file.
1// Mantid Repository : https://github.com/mantidproject/mantid
2//
3// Copyright © 2019 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/* SaveNexusGeometry : A thin Algorithm wrapper over
8 * NexusGeometry::saveInstrument allowing user to save the geometry from
9 * instrument attached to a workspace.
10 *
11 * @author Takudzwa Makoni, RAL (UKRI), ISIS
12 * @date 16/08/2019
13 */
21#include "MantidNexusGeometry/NexusGeometrySave.h"
22
23#include <memory>
24#include <utility>
25
26namespace Mantid::DataHandling {
29
30// Register the algorithm into the AlgorithmFactory
31DECLARE_ALGORITHM(SaveNexusGeometry)
32
33//----------------------------------------------------------------------------------------------
34
35
36
37const std::string SaveNexusGeometry::name() const { return "SaveNexusGeometry"; }
38
40
41int SaveNexusGeometry::version() const { return 1; }
42
44
45const std::string SaveNexusGeometry::category() const { return "DataHandling\\Instrument"; }
46
48
49const std::string SaveNexusGeometry::summary() const {
50 return "Save the instrument from a workspace to a Nexus-format"
51 " HDF file. WARNING: shapes are NOT saved in the present version "
52 "(1.0).";
53}
54
55//----------------------------------------------------------------------------------------------
56
60
61 // TODO resolve linkererror for experimentinfo, replace MatrixWorkspace with
62 // base class ExperimentInfo.
63 declareProperty(std::make_unique<WorkspaceProperty<API::MatrixWorkspace>>("InputWorkspace", "", Direction::Input),
64 "Workspace containing the Instrument.");
65
66 declareProperty(std::make_unique<API::FileProperty>("Filename", "", API::FileProperty::OptionalSave),
67 "Full path to save destination file");
68
69 declareProperty("EntryName", "entry" /*default*/,
70 "(optional) Name of the H5 root group in which the "
71 "Instrument is to be saved. Default name: 'entry'.");
72}
73
74//----------------------------------------------------------------------------------------------
79 std::string destinationFile = getPropertyValue("FileName");
80 std::string parentEntryName = getPropertyValue("EntryName");
81
82 auto ws = workspace.get();
83 const auto &compInfo = ws->componentInfo();
84 const auto &detInfo = ws->detectorInfo();
85
86 NexusGeometry::LogAdapter<Kernel::Logger> adapter(&g_log);
87 Mantid::NexusGeometry::NexusGeometrySave::saveInstrument(compInfo, detInfo, destinationFile, parentEntryName,
88 adapter);
89}
90
91} // namespace Mantid::DataHandling
std::string name
Definition Run.cpp:60
#define DECLARE_ALGORITHM(classname)
Definition Algorithm.h:538
IPeaksWorkspace_sptr workspace
void declareProperty(std::unique_ptr< Kernel::Property > p, const std::string &doc="") override
Add a property to the list of managed properties.
std::string getPropertyValue(const std::string &name) const override
Get the value of a property as a string.
TypedValue getProperty(const std::string &name) const override
Get the value of a property.
Kernel::Logger & g_log
Definition Algorithm.h:422
@ OptionalSave
to specify a file to write to but an empty string is
A property class for workspaces.
void exec() override
Execute the algorithm.
const std::string summary() const override
Algorithm's summary for use in the GUI and help.
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.
std::shared_ptr< const MatrixWorkspace > MatrixWorkspace_const_sptr
shared pointer to the matrix workspace base class (const version)
STL namespace.
Describes the direction (within an algorithm) of a Property.
Definition Property.h:50
@ Input
An input workspace.
Definition Property.h:53