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 */
22#include "MantidNexusGeometry/NexusGeometrySave.h"
23
24#include <memory>
25#include <utility>
26
27namespace Mantid::DataHandling {
30
31// Register the algorithm into the AlgorithmFactory
32DECLARE_ALGORITHM(SaveNexusGeometry)
33
34//----------------------------------------------------------------------------------------------
35
36
37
38const std::string SaveNexusGeometry::name() const { return "SaveNexusGeometry"; }
39
41
42int SaveNexusGeometry::version() const { return 1; }
43
45
46const std::string SaveNexusGeometry::category() const { return "DataHandling\\Instrument"; }
47
49
50const std::string SaveNexusGeometry::summary() const {
51 return "Save the instrument from a workspace to a Nexus-format"
52 " HDF file. WARNING: shapes are NOT saved in the present version "
53 "(1.0).";
54}
55
56//----------------------------------------------------------------------------------------------
57
61
62 // TODO resolve linkererror for experimentinfo, replace MatrixWorkspace with
63 // base class ExperimentInfo.
64 declareProperty(std::make_unique<WorkspaceProperty<API::MatrixWorkspace>>("InputWorkspace", "", Direction::Input),
65 "Workspace containing the Instrument.");
66
67 declareProperty(std::make_unique<API::FileProperty>("Filename", "", API::FileProperty::OptionalSave),
68 "Full path to save destination file");
69
70 declareProperty("EntryName", "entry" /*default*/,
71 "(optional) Name of the H5 root group in which the "
72 "Instrument is to be saved. Default name: 'entry'.");
73}
74
75//----------------------------------------------------------------------------------------------
80 std::string destinationFile = getPropertyValue("FileName");
81 std::string rootFileName = getPropertyValue("EntryName");
82
83 auto ws = workspace.get();
84 const auto &compInfo = ws->componentInfo();
85 const auto &detInfo = ws->detectorInfo();
86
87 NexusGeometry::LogAdapter<Kernel::Logger> adapter(&g_log);
88 Mantid::NexusGeometry::NexusGeometrySave::saveInstrument(compInfo, detInfo, destinationFile, rootFileName, adapter);
89}
90
91} // namespace Mantid::DataHandling
#define DECLARE_ALGORITHM(classname)
Definition: Algorithm.h:576
IPeaksWorkspace_sptr workspace
Definition: IndexPeaks.cpp:114
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
TypedValue getProperty(const std::string &name) const override
Get the value of a property.
Definition: Algorithm.cpp:2076
Kernel::Logger & g_log
Definition: Algorithm.h:451
@ OptionalSave
to specify a file to write to but an empty string is
Definition: FileProperty.h:50
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