Mantid
Loading...
Searching...
No Matches
SaveNexusESS.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 +
8#include "MantidNexusGeometry/NexusGeometrySave.h"
9#include <H5Cpp.h>
10
11namespace Mantid::DataHandling {
14
15// Register the algorithm into the AlgorithmFactory
16DECLARE_ALGORITHM(SaveNexusESS)
17
18//----------------------------------------------------------------------------------------------
19
20
21const std::string SaveNexusESS::name() const { return "SaveNexusESS"; }
22
24int SaveNexusESS::version() const { return 1; }
25
27const std::string SaveNexusESS::category() const { return "DataHandling\\Nexus"; }
28
30const std::string SaveNexusESS::summary() const {
31 return "Saves intermediate, also known as 'processed' nexus file with data "
32 "and geometry";
33}
34
40 throw std::invalid_argument("SaveNexusESS does not currently support operations on groups");
41}
42
43void SaveNexusESS::saveNexusGeometry(const Mantid::API::MatrixWorkspace &ws, const std::string &filename) {
44
45 try {
46 NexusGeometry::LogAdapter<Kernel::Logger> adapter(&g_log);
47 NexusGeometry::NexusGeometrySave::saveInstrument(ws, filename, "mantid_workspace_1", adapter, true);
48 } catch (std::exception &e) {
49 g_log.error(std::string(e.what()) + " Nexus Geometry may be absent or incomplete "
50 "from processed Nexus file");
51 } catch (H5::Exception &ex) {
52 g_log.error(ex.getDetailMsg() + " Nexus Geometry may be absent or incomplete "
53 "from processed Nexus file");
54 }
55}
56
58 /*A hard No on this one. Mantids's current NXDetector, NXMonitor ... types do
59 * not have information needed for loading and just cause down-stream
60 * problems. Best not to save them in the first place.*/
61 return false;
62}
63
64//----------------------------------------------------------------------------------------------
68 // Take same properties as base.
70}
71
72//----------------------------------------------------------------------------------------------
76 // Run the base algorithm. Template method approach used to call ESS
77 // specifics.
78
79 API::Workspace_sptr ws = getProperty("InputWorkspace");
80 const std::string filename = getProperty("Filename");
81 auto matrixWs = std::dynamic_pointer_cast<API::MatrixWorkspace>(ws);
82 if (!matrixWs)
83 throw std::runtime_error("SaveNexusESS expects a MatrixWorkspace as input");
85
86 // Now append nexus geometry
87 saveNexusGeometry(*matrixWs, filename);
88 // Now write spectrum to detector maps;
89 return;
90}
91} // namespace Mantid::DataHandling
#define DECLARE_ALGORITHM(classname)
Definition: Algorithm.h:576
TypedValue getProperty(const std::string &name) const override
Get the value of a property.
Definition: Algorithm.cpp:2076
Base MatrixWorkspace Abstract Class.
A property class for workspaces.
SaveNexusESS : Save algorithm to save a NeXus organised hdf5 file containing data and geometry from r...
Definition: SaveNexusESS.h:23
int version() const override
Algorithm's version for identification.
virtual bool saveLegacyInstrument() override
const std::string category() const override
Algorithm's category for identification.
void saveNexusGeometry(const Mantid::API::MatrixWorkspace &ws, const std::string &filename)
void exec() override
Execute the algorithm.
void init() override
Initialize the algorithm's properties.
bool processGroups() override
SaveNexusESS::processGroups.
const std::string summary() const override
Algorithm's summary for use in the GUI and help.
void init() override
Overwrites Algorithm method.
void exec() override
Overwrites Algorithm method.
void error(const std::string &msg)
Logs at error level.
Definition: Logger.cpp:77
std::shared_ptr< Workspace > Workspace_sptr
shared pointer to Mantid::API::Workspace
Definition: Workspace_fwd.h:20
Kernel::Logger g_log("ExperimentInfo")
static logger object
STL namespace.
Describes the direction (within an algorithm) of a Property.
Definition: Property.h:50