9#include "MantidNexus/DllConfig.h"
10#include "MantidNexus/NexusFile.h"
14#include <boost/container/vector.hpp>
71 std::size_t
n()
const {
return m_values.size(); }
72 std::vector<std::string> names()
const;
73 std::vector<std::string> values()
const;
74 std::string operator()(
const std::string &
name)
const;
75 void set(
const std::string &
name,
const std::string &
value);
76 template <
typename T>
void set(
const std::string &
name, T
value);
95 NXObject(std::shared_ptr<File>
const &fileID,
NXClass const *parent, std::string
const &
name);
105 std::string
name()
const;
133 std::string
NX_class()
const override {
return "SDS"; }
139 std::size_t
rank()
const {
return m_info.rank; }
151 std::string
name()
const {
return m_info.nxname; }
164 template <
typename NumT>
void getData(NumT *data) {
165 m_fileID->openData(
name());
166 m_fileID->getData(data);
167 m_fileID->closeData();
181 m_fileID->openData(
name());
182 m_fileID->getSlab(data, start, size);
183 m_fileID->closeData();
189 void getAttributes();
193using container_T = std::conditional_t<std::is_same<T, bool>{}, boost::container::vector<bool>, std::vector<T>>;
216 throw std::runtime_error(
"Attempt to read uninitialized data from " +
address());
222 throw std::runtime_error(
"Attempt to read uninitialized data from " +
address());
236 throw std::runtime_error(
"Attempt to read uninitialized data from " +
address());
254 return const_cast<T &
>(
static_cast<const NXDataSetTyped &
>(*this)(i, j));
265 const T &
operator()(std::size_t i, std::size_t j, std::size_t k)
const {
269 return const_cast<T &
>(
static_cast<const NXDataSetTyped &
>(*this)(i, j, k));
279 const auto rank_local = this->
rank();
280 if (rank_local > 4) {
281 throw std::runtime_error(
"Cannot load dataset of rank greater than 4");
284 std::size_t num_ele = std::accumulate(this->
m_info.
dims.cbegin(), this->m_info.dims.cbegin() + rank_local,
285 static_cast<std::size_t
>(1), std::multiplies<std::size_t>());
286 if constexpr (std::is_same_v<T, char>) {
290 this->
alloc(
static_cast<std::size_t
>(num_ele));
295 if constexpr (std::is_same_v<T, char>) {
303 throw std::runtime_error(
"Cannot load dataset of rank greater than 4");
311 datastart = {i, 0, 0, 0};
313 }
else if (
rank() == 3) {
317 datastart = {i, 0, 0};
319 }
else if (
rank() == 2) {
327 datasize = {
m,
dim1()};
328 }
else if (
rank() == 1) {
333 datasize = {blocksize};
353 throw std::runtime_error(
"Cannot load dataset of rank greater than 4");
361 datastart = {i, j, 0, 0};
363 }
else if (
rank() == 3) {
370 datastart = {i, j, 0};
371 datasize = {1,
m,
dim2()};
372 }
else if (
rank() == 2) {
378 }
else if (
rank() == 1) {
383 datasize = {blocksize};
397 throw std::runtime_error(
"Attempt to load from an empty dataset " +
address());
405 std::ostringstream ostr;
406 ostr <<
"Cannot allocate " << new_size *
sizeof(T) <<
" bytes of memory to load the data";
407 throw std::runtime_error(ostr.str());
411 void rangeError()
const {
throw std::range_error(
"Nexus dataset range error"); }
454 std::string
NX_class()
const override {
return "NXClass"; }
461 bool isValid(
const std::string &address)
const;
532 std::string getString(
const std::string &
name)
const;
538 double getDouble(
const std::string &
name)
const;
544 float getFloat(
const std::string &
name)
const;
550 int32_t getInt(
const std::string &
name)
const;
553 std::vector<NXClassInfo> &
groups()
const {
return *m_groups; }
555 bool containsGroup(
const std::string &query)
const;
557 std::vector<NXInfo> &
datasets()
const {
return *m_datasets; }
563 NXInfo getDataSetInfo(
const std::string &
name)
const;
565 bool containsDataSet(
const std::string &query)
const;
576 bool openLocal(
const std::string &nxclass =
"");
579 std::shared_ptr<std::vector<NXClassInfo>>
m_groups;
601 std::string
NX_class()
const override {
return "NXdata"; }
604 for (std::vector<NXInfo>::const_iterator it = datasets().begin(); it != datasets().end(); ++it) {
608 return openNXDataSet<T>(it->nxname);
613 return openNXDataSet<T>(
"data");
633 std::string
NX_class()
const override {
return "NXdetector"; }
652 std::string
NX_class()
const override {
return "NXinstrument"; }
671 std::string
NX_class()
const override {
return "NXentry"; }
690 NXRoot(std::string fname);
692 NXRoot(std::string fname,
const std::string &entry);
696 std::string
NX_class()
const override {
return "NXroot"; }
699 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