9#include "MantidNexus/DllConfig.h"
10#include "MantidNexus/NexusFile.h"
14#include <boost/container/vector.hpp>
70 std::size_t
n()
const {
return m_values.size(); }
71 std::vector<std::string> names()
const;
72 std::vector<std::string> values()
const;
73 std::string operator()(
const std::string &
name)
const;
74 void set(
const std::string &
name,
const std::string &
value);
75 template <
typename T>
void set(
const std::string &
name, T
value);
94 NXObject(std::shared_ptr<File>
const &fileID,
NXClass const *parent, std::string
const &
name);
104 std::string
name()
const;
132 std::string
NX_class()
const override {
return "SDS"; }
138 std::size_t
rank()
const {
return m_info.rank; }
150 std::string
name()
const {
return m_info.nxname; }
163 template <
typename NumT>
void getData(NumT *data) {
164 m_fileID->openData(
name());
165 m_fileID->getData(data);
166 m_fileID->closeData();
180 m_fileID->openData(
name());
181 m_fileID->getSlab(data, start, size);
182 m_fileID->closeData();
187 void getAttributes();
191using container_T = std::conditional_t<std::is_same<T, bool>{}, boost::container::vector<bool>, std::vector<T>>;
214 throw std::runtime_error(
"Attempt to read uninitialized data from " +
address());
220 throw std::runtime_error(
"Attempt to read uninitialized data from " +
address());
234 throw std::runtime_error(
"Attempt to read uninitialized data from " +
address());
252 return const_cast<T &
>(
static_cast<const NXDataSetTyped &
>(*this)(i, j));
263 const T &
operator()(std::size_t i, std::size_t j, std::size_t k)
const {
267 return const_cast<T &
>(
static_cast<const NXDataSetTyped &
>(*this)(i, j, k));
277 const auto rank_local = this->
rank();
278 if (rank_local > 4) {
279 throw std::runtime_error(
"Cannot load dataset of rank greater than 4");
282 auto num_ele = this->
dim0();
283 if (rank_local > 1) {
284 num_ele *= this->
dim1();
285 if (rank_local > 2) {
286 num_ele *= this->
dim2();
287 if (rank_local > 3) {
288 num_ele *= this->
dim3();
292 if constexpr (std::is_same_v<T, char>) {
296 this->
alloc(
static_cast<std::size_t
>(num_ele));
301 if constexpr (std::is_same_v<T, char>) {
309 throw std::runtime_error(
"Cannot load dataset of rank greater than 4");
317 datastart = {i, 0, 0, 0};
319 }
else if (
rank() == 3) {
323 datastart = {i, 0, 0};
325 }
else if (
rank() == 2) {
333 datasize = {
m,
dim1()};
334 }
else if (
rank() == 1) {
339 datasize = {blocksize};
359 throw std::runtime_error(
"Cannot load dataset of rank greater than 4");
367 datastart = {i, j, 0, 0};
369 }
else if (
rank() == 3) {
376 datastart = {i, j, 0};
377 datasize = {1,
m,
dim2()};
378 }
else if (
rank() == 2) {
384 }
else if (
rank() == 1) {
389 datasize = {blocksize};
403 throw std::runtime_error(
"Attempt to load from an empty dataset " +
address());
411 std::ostringstream ostr;
412 ostr <<
"Cannot allocate " << new_size *
sizeof(T) <<
" bytes of memory to load the data";
413 throw std::runtime_error(ostr.str());
417 void rangeError()
const {
throw std::range_error(
"Nexus dataset range error"); }
460 std::string
NX_class()
const override {
return "NXClass"; }
467 bool isValid(
const std::string &address)
const;
538 std::string getString(
const std::string &
name)
const;
544 double getDouble(
const std::string &
name)
const;
550 float getFloat(
const std::string &
name)
const;
556 int32_t getInt(
const std::string &
name)
const;
559 std::vector<NXClassInfo> &
groups()
const {
return *m_groups; }
561 bool containsGroup(
const std::string &query)
const;
563 std::vector<NXInfo> &
datasets()
const {
return *m_datasets; }
569 NXInfo getDataSetInfo(
const std::string &
name)
const;
571 bool containsDataSet(
const std::string &query)
const;
582 bool openLocal(
const std::string &nxclass =
"");
585 std::shared_ptr<std::vector<NXClassInfo>>
m_groups;
607 std::string
NX_class()
const override {
return "NXdata"; }
610 for (std::vector<NXInfo>::const_iterator it = datasets().begin(); it != datasets().end(); ++it) {
614 return openNXDataSet<T>(it->nxname);
619 return openNXDataSet<T>(
"data");
639 std::string
NX_class()
const override {
return "NXdetector"; }
658 std::string
NX_class()
const override {
return "NXinstrument"; }
677 std::string
NX_class()
const override {
return "NXentry"; }
696 NXRoot(std::string fname);
698 NXRoot(std::string fname,
const std::string &entry);
702 std::string
NX_class()
const override {
return "NXroot"; }
705 bool isStandard()
const;
double value
The value of the point.
std::map< std::string, std::string > m_values
the list of attributes
std::size_t n() const
number of attributes
The base class for a Nexus class (group).
NXClass()
Private constructor.
std::vector< NXInfo > & datasets() const
Returns a list of all datasets in this NXClass.
NXFloat openNXFloat(const std::string &name) const
Creates and opens a float dataset.
std::vector< NXClassInfo > & groups() const
Returns a list of all classes (or groups) in this NXClass.
NXClass openNXGroup(const std::string &name) const
Creates and opens an arbitrary (non-standard) class (group).
std::shared_ptr< std::vector< NXClassInfo > > m_groups
Holds info about the child NXClasses.
NXChar openNXChar(const std::string &name) const
Creates and opens a char dataset.
std::shared_ptr< std::vector< NXInfo > > m_datasets
Holds info about the datasets in this NXClass.
NXInt openNXInt(const std::string &name) const
Creates and opens an integer dataset.
NX openNXClass(const std::string &name) const
Templated method for creating derived NX classes.
NXUInt64 openNXSize(const std::string &name) const
Creates and opens a size_t dataset.
NXDouble openNXDouble(const std::string &name) const
Creates and opens a double dataset.
std::string NX_class() const override
The NX class identifier.
NXDataSetTyped< T > openNXDataSet(const std::string &name) const
Templated method for creating datasets.
Templated class implementation of NXDataSet.
const T & operator()(std::size_t i, std::size_t j, std::size_t k) const
Returns a value assuming the data is a tree-dimensional array.
const T & operator[](std::size_t i) const
Returns the i-th value in the internal buffer.
std::size_t m_size
The buffer size.
void load(dimsize_t const blocksize, dimsize_t const i, dimsize_t const j)
Implementation of the virtual NXDataSet::load(...) method.
T & operator()(std::size_t i, std::size_t j)
container_T< T > m_data
The data buffer.
const T & operator()(std::size_t i, std::size_t j) const
Returns a value assuming the data is a two-dimensional array.
T & operator()(std::size_t i, std::size_t j, std::size_t k)
NXDataSetTyped(NXClass const &parent, std::string const &name)
Constructor.
void rangeError() const
A shortcut to "throw std::range_error("Nexus dataset range error");".
void load(dimsize_t const blocksize, dimsize_t const i)
void alloc(dimsize_t new_size)
Allocates memory for the data buffer.
T & operator[](std::size_t i)
const T * operator()() const
Returns a pointer to the internal data buffer.
void load()
Read all of the datablock in.
container_T< T > & vecBuffer()
Returns a the internal buffer.
std::size_t size() const
Returns the size of the data buffer.
Abstract base class for a Nexus data set.
void getData(NumT *data)
Wrapper to the NXgetdata.
dimsize_t dim0() const
Returns the number of elements along the first dimension.
NXAttributes attributes
Attributes.
NXnumtype type() const
Returns the Nexus type of the data. The types are defined in NexusFile_fwd.h.
dimsize_t dim3() const
Returns the number of elements along the fourth dimension.
NXInfo m_info
Holds the data info.
dimsize_t dims(std::size_t i) const
Returns the number of elements along i-th dimension.
dimsize_t dim2() const
Returns the number of elements along the third dimension.
void getSlab(NumT *data, DimVector const &start, DimVector const &size)
Wrapper to the NXgetslab.
std::string NX_class() const override
NX class name. Returns "SDS".
void open()
Opens the data set. Does not read in any data. Call load(...) to load the data.
std::size_t rank() const
Returns the rank (number of dimensions) of the data. The maximum is 4.
dimsize_t dim1() const
Returns the number of elements along the second dimension.
std::string name() const
Returns the name of the data set.
Implements NXdata Nexus class.
NXDataSetTyped< T > openData()
Opens the dataset within this NXData with signal=1 attribute.
NXDouble openDoubleData()
Opens data of double type.
std::string NX_class() const override
Nexus class id.
NXInt openIntData()
Opens data of int type.
NXFloat openFloatData()
Opens data of float type.
Implements NXdetector Nexus class.
NXFloat openPolarAngle()
Opens the dataset containing pixel polar angles.
std::string NX_class() const override
Nexus class id.
NXFloat openDistance()
Opens the dataset containing pixel distances.
NXFloat openAzimuthalAngle()
Opens the dataset containing pixel azimuthal angles.
NXDetector(const NXClass &parent, const std::string &name)
Constructor.
Implements NXentry Nexus class.
std::string NX_class() const override
Nexus class id.
NXEntry(const NXClass &parent, const std::string &name)
Constructor.
NXData openNXData(const std::string &name) const
Opens a NXData.
NXInstrument openNXInstrument(const std::string &name) const
Opens a NXInstrument.
Implements NXinstrument Nexus class.
NXInstrument(const NXClass &parent, const std::string &name)
Constructor.
std::string NX_class() const override
Nexus class id.
NXDetector openNXDetector(const std::string &name)
Opens a NXDetector.
The base abstract class for Nexus classes and data sets.
virtual std::string NX_class() const =0
Return the NX class name for a class (HDF group) or "SDS" for a data set;.
NexusAddress const & address() const
Returns the absolute address to the object.
virtual ~NXObject()=default
std::shared_ptr< File > m_fileID
Nexus file id.
NexusAddress m_address
Keeps the absolute address to the object.
bool m_open
Set to true if the object has been open.
Implements NXroot Nexus class.
const std::string m_filename
The file name.
std::string NX_class() const override
Return the NX class for a class (HDF group) or "SDS" for a data set;.
NXEntry openEntry(const std::string &name)
Opens an entry – a topmost Nexus class.
This simple class encapsulates some methods for working with paths inside a Nexus file.
The primitive types published by this API.
NXDataSetTyped< int32_t > NXUInt32
The integer dataset type.
NXDataSetTyped< int64_t > NXInt64
The integer dataset type.
const int g_processed_blocksize
Default block size for reading and writing processed files.
std::conditional_t< std::is_same< T, bool >{}, boost::container::vector< bool >, std::vector< T > > container_T
NXDataSetTyped< char > NXChar
The char dataset type.
std::array< dimsize_t, 4 > NXDimArray
C++ implementation of Nexus classes.
std::vector< dimsize_t > DimVector
std::pair< std::string, std::string > Entry
NXDataSetTyped< uint64_t > NXUInt64
The integer dataset type.
Helper class which provides the Collimation Length for SANS instruments.
This structure holds the type and dimensions of a primative field/array.
Information about a Nexus class.
bool allGood
return status
std::string nxclass
NX class of the object or "SDS" if a dataset.
std::string nxname
name of the object
NXnumtype datatype
NX data type if a dataset, e.g. NX_CHAR, FLOAT32; see NexusFile_fwd.h.
Structure for keeping information about a Nexus data set, such as the dimensions and the type.
bool allGood
return status
std::size_t rank
number of dimensions of the data
std::string nxname
name of the object
NXDimArray dims
sizes along each dimension
NXnumtype type
type of the data, e.g. NX_CHAR, FLOAT32; see NexusFile_fwd.h