20#include "MantidNexus/NexusFile.h"
26using namespace Kernel;
28using namespace DataObjects;
33 :
API::
Algorithm(), m_includeError(false), m_overwriteFile(false), m_spectraCount(0), m_filename(
""),
40 auto wsValidator = std::make_shared<CompositeValidator>();
48 "The name of the workspace(s) to save - this can be the name of a single "
49 "Workspace2D or the name of a WorkspaceGroup in which case all the "
50 "Workspace2Ds included in the group will be saved.");
53 std::make_unique<API::FileProperty>(
"Filename",
"",
FileProperty::Save, std::vector<std::string>(1,
".nxs")),
54 "The name of the NXTomo file to write, as a full or relative path");
57 "Replace any existing file of the same name instead of appending data?");
60 "Write the error values to NXTomo file?");
70 m_workspaces.emplace_back(std::dynamic_pointer_cast<Workspace2D>(
m));
86 for (
int i = 0; i < groupWS->getNumberOfEntries(); ++i) {
87 m_workspaces.emplace_back(std::dynamic_pointer_cast<Workspace2D>(groupWS->getItem(i)));
109 const std::string workspaceID =
workspace->id();
111 if ((workspaceID.find(
"Workspace2D") == std::string::npos) &&
112 (workspaceID.find(
"RebinnedOutput") == std::string::npos))
179 m_nxFile->makeGroup(
"entry1",
"NXentry",
true);
182 m_nxFile->makeGroup(
"log_info",
"NXsubentry",
false);
185 m_nxFile->makeGroup(
"tomo_entry",
"NXsubentry",
true);
191 m_nxFile->writeData(
"definition",
"NXtomo");
197 m_nxFile->writeData(
"program_name",
"mantid");
204 m_nxFile->makeGroup(
"instrument",
"NXinstrument",
true);
210 m_nxFile->makeGroup(
"detector",
"NXdetector",
true);
222 m_nxFile->makeGroup(
"sample",
"NXsample",
true);
233 m_nxFile->makeGroup(
"control",
"NXmonitor",
true);
237 m_nxFile->makeGroup(
"data",
"NXdata",
true);
238 m_nxFile->putAttr<
int>(
"NumFiles", 0);
253 m_nxFile->openGroup(
"instrument",
"NXinstrument");
254 m_nxFile->openGroup(
"detector",
"NXdetector");
269 m_nxFile->openAddress(
"/entry1/tomo_entry/data");
271 throw std::runtime_error(
"Unable to create a valid NXTomo file");
275 m_nxFile->getAttr(
"NumFiles", numFiles);
282 std::vector<double> rotValue;
283 rotValue.emplace_back(0);
285 if (
workspace->run().hasProperty(
"Rotation")) {
286 std::string tmpVal =
workspace->run().getLogData(
"Rotation")->value();
288 rotValue[0] = boost::lexical_cast<double>(tmpVal);
294 m_nxFile->openData(
"rotation_angle");
295 m_nxFile->putSlab(rotValue, numFiles, 1);
305 bool spectrumPerPixel = (1 ==
workspace->y(0).size());
309 if (spectrumPerPixel) {
321 m_nxFile->putAttr(
"NumFiles", numFiles + 1);
335 m_nxFile->openAddress(
"/entry1/tomo_entry/instrument/detector");
337 throw std::runtime_error(
"Unable to create a valid NXTomo file");
341 std::vector<double> keyValue(1, 0);
343 if (
workspace->run().hasProperty(
"ImageKey")) {
344 std::string tmpVal =
workspace->run().getLogData(
"ImageKey")->value();
346 keyValue[0] = boost::lexical_cast<double>(tmpVal);
353 m_nxFile->putSlab(keyValue, thisFileInd, 1);
364 m_nxFile->openAddress(
"/entry1/log_info");
366 throw std::runtime_error(
"Unable to create a valid NXTomo file");
371 const auto &logVals =
workspace->run().getLogData();
373 for (
const auto &prop : logVals) {
374 if (prop->name() !=
"ImageKey" && prop->name() !=
"Rotation" && prop->name() !=
"Intensity" &&
375 prop->name() !=
"Axis1" && prop->name() !=
"Axis2") {
383 auto valueAsStr = prop->value();
384 size_t strSize = valueAsStr.length();
392 m_nxFile->putSlab(valueAsStr.data(), start, size);
402 m_nxFile->openAddress(
"/entry1/tomo_entry/control");
404 throw std::runtime_error(
"Unable to create a valid NXTomo file");
407 std::vector<double> intensityValue;
408 intensityValue.emplace_back(1);
410 if (
workspace->run().hasProperty(
"Intensity")) {
411 std::string tmpVal =
workspace->run().getLogData(
"Intensity")->value();
413 intensityValue[0] = boost::lexical_cast<double>(tmpVal);
420 m_nxFile->putSlab(intensityValue, thisFileInd, 1);
#define DECLARE_ALGORITHM(classname)
double value
The value of the point.
IPeaksWorkspace_sptr workspace
constexpr Mantid::Nexus::dimsize_t NX_UNLIMITED(-1)
std::string getName(const IMDDimension &self)
Base class from which all concrete algorithm classes should be derived.
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.
void progress(double p, const std::string &msg="", double estimatedTime=0.0, int progressPrecision=0)
Sends ProgressNotification.
@ Save
to specify a file to write to, the file may or may not exist
A validator which checks that a workspace contains histogram data (the default) or point data as requ...
Helper class for reporting progress from algorithms.
Class to hold a set of workspaces.
A property class for workspaces.
static const std::string NXTOMO_VER
file format version
Nexus::DimVector m_slabSize
bool processGroups() override
Alternative execution code when operating on a WorkspaceGroup.
void processAll()
Main exec routine, called for group or individual workspace processing.
std::vector< DataObjects::Workspace2D_sptr > m_workspaces
Nexus::DimVector m_infDimensions
void writeImageKeyValue(const DataObjects::Workspace2D_sptr &workspace, std::size_t thisFileInd)
void init() override
Initialisation code.
void writeLogValues(const DataObjects::Workspace2D_sptr &workspace, std::size_t thisFileInd)
Write various pieces of data from the workspace log with checks on the structure of the nexus file.
void setupFile()
Creates the format for the output file if it doesn't exist.
Nexus::DimVector m_dimensions
void exec() override
Execution code : Single workspace.
void writeSingleWorkspace(const DataObjects::Workspace2D_sptr &workspace)
Writes a single workspace into the file.
Nexus::DimVector m_slabStart
void writeIntensityValue(const DataObjects::Workspace2D_sptr &workspace, std::size_t thisFileInd)
std::unique_ptr< Nexus::File > m_nxFile
std::string m_filename
The filename of the output file.
Marks code as not implemented yet.
static const char * version()
The full version number.
The concrete, templated class for properties.
Class that provides for a standard Nexus exception.
static unsigned short constexpr UINT8
static unsigned short constexpr FLOAT64
std::shared_ptr< WorkspaceGroup > WorkspaceGroup_sptr
shared pointer to Mantid::API::WorkspaceGroup
std::shared_ptr< MatrixWorkspace > MatrixWorkspace_sptr
shared pointer to the matrix workspace base class
std::shared_ptr< Workspace2D > Workspace2D_sptr
shared pointer to Mantid::DataObjects::Workspace2D
std::vector< dimsize_t > DimVector
@ Input
An input workspace.
Represents a link between entries in a Nexus file.