Mantid
Loading...
Searching...
No Matches
SaveNexusProcessedHelper.h
Go to the documentation of this file.
1// Mantid Repository : https://github.com/mantidproject/mantid
2//
3// Copyright © 2007 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#pragma once
8#include "MantidAPI/Column.h"
11#include "MantidAPI/Progress.h"
12#include "MantidDataHandling/DllConfig.h"
18#include "MantidNexus/NexusFile.h"
19
20#include <boost/date_time/c_local_time_adjustor.hpp>
21#include <boost/date_time/local_time_adjustor.hpp>
22#include <boost/date_time/posix_time/posix_time.hpp>
23#include <boost/scoped_array.hpp>
24
25#include <climits>
26#include <memory>
27#include <optional>
28
29namespace Mantid {
30namespace Nexus {
39class MANTID_DATAHANDLING_DLL NexusFileIO {
40
41public:
42 // Helper typedef
43 using optional_size_t = std::optional<size_t>;
44
47
50
53
55 void openNexusWrite(const std::string &fileName, optional_size_t entryNumber = optional_size_t(),
56 const bool append_to_file = true);
58 int writeNexusProcessedHeader(const std::string &title, const std::string &wsName = "") const;
60 void closeNexusFile();
62 void closeGroup();
64 int writeNexusProcessedData2D(const API::MatrixWorkspace_const_sptr &localworkspace, const bool &uniformSpectra,
65 const bool &raggedSpectra, const std::vector<int> &indices,
66 const std::string &group_name, bool write2Ddata) const;
67
69 int writeNexusTableWorkspace(const API::ITableWorkspace_const_sptr &itableworkspace, const char *group_name) const;
70
71 int writeNexusProcessedDataEventCombined(const DataObjects::EventWorkspace_const_sptr &ws,
72 std::vector<int64_t> const &indices, double const *tofs,
73 float const *weights, float const *errorSquareds, int64_t const *pulsetimes,
74 bool compress) const;
75
76 template <typename NumT>
77 void writeData(const char *name, NXnumtype datatype, Nexus::DimVector dims_array, NumT const *data,
78 bool compress = false) const;
79
81 bool writeNexusBinMasking(const API::MatrixWorkspace_const_sptr &ws) const;
82
84 void resetProgress(Mantid::API::Progress *prog);
85
87 std::shared_ptr<Nexus::File> filehandle() const { return m_filehandle; }
88
89private:
91 std::shared_ptr<Nexus::File> m_filehandle;
97 bool writeNxValue(const std::string &name, const std::string &value, const std::vector<std::string> &attributes,
98 const std::vector<std::string> &avalues) const;
100 int findMantidWSEntries() const;
101
103 std::string m_filename;
104
106 template <typename VecType, typename ElemType>
107 void writeNexusVectorColumn(const API::Column_const_sptr &col, const std::string &columnName, NXnumtype nexusType,
108 const std::string &interpret_as) const;
109
111 template <typename ColumnT, typename NexusT>
112 void writeTableColumn(NXnumtype type, const std::string &interpret_as, const API::Column &col,
113 const std::string &columnName) const;
114};
115
126inline bool NexusFileIO::writeNxValue(const std::string &name, const std::string &value,
127 const std::vector<std::string> &attributes,
128 const std::vector<std::string> &avalues) const {
129 try {
130 m_filehandle->writeData(name, value);
131
132 // open it again to add attributes
133 m_filehandle->openData(name);
134 for (unsigned int it = 0; it < attributes.size(); ++it) {
135 m_filehandle->putAttr(attributes[it], avalues[it]);
136 }
137 m_filehandle->closeData();
138 } catch (Nexus::Exception const &) {
139 return false;
140 }
141
142 return true;
143}
144
146using NexusFileIO_sptr = std::shared_ptr<NexusFileIO>;
147
148} // namespace Nexus
149} // namespace Mantid
std::string name
Definition Run.cpp:60
double value
The value of the point.
Definition FitMW.cpp:51
NXcompression
The available compression types:
Column is the base class for columns of TableWorkspace.
Definition Column.h:35
Helper class for reporting progress from algorithms.
Definition Progress.h:25
Class that provides for a standard Nexus exception.
Utility methods for saving Mantid Workspaces in NeXus format.
std::shared_ptr< Nexus::File > m_filehandle
C++ API file handle.
bool writeNxValue(const std::string &name, const std::string &value, const std::vector< std::string > &attributes, const std::vector< std::string > &avalues) const
Write a simple value plus possible attributes.
API::Progress * m_progress
Allow an externally supplied progress object to be used.
std::shared_ptr< Nexus::File > filehandle() const
Nexus file handle.
NXcompression m_nexuscompression
Nexus compression method.
std::string m_filename
nexus file name
std::optional< size_t > optional_size_t
The primitive types published by this API.
std::shared_ptr< const ITableWorkspace > ITableWorkspace_const_sptr
shared pointer to Mantid::API::ITableWorkspace (const version)
std::shared_ptr< const MatrixWorkspace > MatrixWorkspace_const_sptr
shared pointer to the matrix workspace base class (const version)
std::shared_ptr< const Column > Column_const_sptr
Definition Column.h:233
std::shared_ptr< const EventWorkspace > EventWorkspace_const_sptr
shared pointer to a const Workspace2D
std::vector< dimsize_t > DimVector
std::shared_ptr< NexusFileIO > NexusFileIO_sptr
Helper typedef for a shared pointer of a NexusFileIO.
Helper class which provides the Collimation Length for SANS instruments.