16#include "MantidNexus/DllConfig.h"
18#include <boost/container/vector.hpp>
19#include <nexus/napi.h>
48 operator bool() {
return stat == NX_OK; }
60 operator bool() {
return stat == NX_OK; }
75 int n()
const {
return int(m_values.size()); }
76 std::vector<std::string> names()
const;
77 std::vector<std::string> values()
const;
78 std::string operator()(
const std::string &name)
const;
79 void set(
const std::string &name,
80 const std::string &
value);
81 void set(
const std::string &name,
99 NXObject(
const NXhandle fileID,
const NXClass *parent,
const std::string &name);
107 std::string
path()
const {
return m_path; }
109 std::string name()
const;
120 void getAttributes();
140 std::string
NX_class()
const override {
return "SDS"; }
147 int rank()
const {
return m_info.rank; }
149 int dims(
int i)
const {
return i < 4 ? m_info.dims[i] : 0; }
159 std::string
name()
const {
return m_info.nxname; }
161 int type()
const {
return m_info.type; }
180 virtual void load(
const int blocksize = 1,
int i = -1,
int j = -1,
int k = -1,
int l = -1) {
190 void getData(
void *data);
191 void getSlab(
void *data,
int start[],
int size[]);
198using container_T = std::conditional_t<std::is_same<T, bool>{}, boost::container::vector<bool>, std::vector<T>>;
219 throw std::runtime_error(
"Attempt to read uninitialized data from " +
path());
225 throw std::runtime_error(
"Attempt to read uninitialized data from " +
path());
237 throw std::runtime_error(
"Attempt to read uninitialized data from " +
path());
238 if (i < 0 || i >=
m_n)
289 void load(
const int blocksize = 1,
int i = -1,
int j = -1,
int k = -1,
int l = -1)
override {
291 throw std::runtime_error(
"Cannot load dataset of rank greater than 4");
351 }
else if (
rank() == 3) {
391 }
else if (
rank() == 2) {
417 }
else if (
rank() == 1) {
441 throw std::runtime_error(
"Attempt to load from an empty dataset " +
path());
449 std::ostringstream ostr;
450 ostr <<
"Cannot allocate " <<
n *
sizeof(T) <<
" bytes of memory to load the data";
451 throw std::runtime_error(ostr.str());
455 void rangeError()
const {
throw std::range_error(
"Nexus dataset range error"); }
498 std::string
NX_class()
const override {
return "NXClass"; }
512 bool isValid(
const std::string &path)
const;
519 template <
class NX> NX
openNXClass(
const std::string &name)
const {
546 NXInt openNXInt(
const std::string &name)
const {
return openNXDataSet<int>(name); }
566 NXSize openNXSize(
const std::string &name)
const {
return openNXDataSet<std::size_t>(name); }
571 std::string getString(
const std::string &name)
const;
576 double getDouble(
const std::string &name)
const;
581 float getFloat(
const std::string &name)
const;
586 int getInt(
const std::string &name)
const;
589 std::vector<NXClassInfo> &
groups()
const {
return *m_groups; }
591 bool containsGroup(
const std::string &query)
const;
593 std::vector<NXInfo> &
datasets()
const {
return *m_datasets; }
598 NXInfo getDataSetInfo(
const std::string &name)
const;
600 bool containsDataSet(
const std::string &query)
const;
613 bool openLocal(
const std::string &nxclass =
"");
616 std::shared_ptr<std::vector<NXClassInfo>>
m_groups;
638 std::string
NX_class()
const override {
return "NXlog"; }
642 Kernel::Property *createTimeSeries(
const std::string &start_time =
"",
const std::string &new_name =
"");
648 template <
class TYPE>
650 std::string start_time = (!time0.empty()) ? time0 : times.attributes(
"start");
651 if (start_time.empty()) {
652 start_time =
"2000-01-01T00:00:00";
654 auto start_t = Kernel::DateAndTimeHelpers::createFromSanitizedISO8601(start_time);
655 NXInfo vinfo = getDataSetInfo(
"value");
659 if (vinfo.
dims[0] != times.dim0())
662 if (vinfo.
type == NX_CHAR) {
667 for (
int i = 0; i <
value.dim0(); i++) {
668 auto t = start_t + boost::posix_time::seconds(
int(times[i]));
669 for (
int j = 0; j <
value.dim1(); j++) {
670 char *c = &
value(i, j);
674 logv->addValue(t, std::string(
value() + i *
value.dim1(),
value.dim1()));
677 }
else if (vinfo.
type == NX_FLOAT64) {
678 if (logName.find(
"running") != std::string::npos || logName.find(
"period ") != std::string::npos) {
683 for (
int i = 0; i <
value.dim0(); i++) {
684 auto t = start_t + boost::posix_time::seconds(
int(times[i]));
685 logv->addValue(t, (
value[i] == 0 ?
false :
true));
690 return loadValues<NXDouble, TYPE>(logName,
value, start_t, times);
691 }
else if (vinfo.
type == NX_FLOAT32) {
693 return loadValues<NXFloat, TYPE>(logName,
value, start_t, times);
694 }
else if (vinfo.
type == NX_INT32) {
696 return loadValues<NXInt, TYPE>(logName,
value, start_t, times);
707 template <
class NX_TYPE,
class TIME_TYPE>
709 const TIME_TYPE ×) {
713 for (
int i = 0; i <
value.dim0(); i++) {
714 if (i == 0 ||
value[i] !=
value[i - 1] || times[i] != times[i - 1]) {
715 auto t = start_t + boost::posix_time::seconds(
int(times[i]));
716 logv->addValue(t,
value[i]);
733 :
NXClass(parent, name), m_author_ok(), m_data_ok(), m_description_ok() {}
735 std::string
NX_class()
const override {
return "NXnote"; }
737 std::string author();
739 std::vector<std::string> &data();
741 std::string description();
763 std::vector<char> &binary();
804 std::string
NX_class()
const override {
return "NXdata"; }
808 for (std::vector<NXInfo>::const_iterator it = datasets().begin(); it != datasets().end(); ++it) {
814 return openNXDataSet<T>(it->nxname);
819 return openNXDataSet<T>(
"data");
846 std::string
NX_class()
const override {
return "NXdetector"; }
866 std::string
NX_class()
const override {
return "NXdisk_chopper"; }
882 std::string
NX_class()
const override {
return "NXinstrument"; }
907 std::string
NX_class()
const override {
return "NXentry"; }
925 NXRoot(std::string fname);
927 NXRoot(std::string fname,
const std::string &entry);
931 std::string
NX_class()
const override {
return "NXroot"; }
934 bool isStandard()
const;
double value
The value of the point.
Base class for properties.
A specialised Property class for holding a series of time-value pairs.
std::map< std::string, std::string > m_values
the list of attributes
int n() const
number of attributes
Implements NXnote Nexus class with binary data.
std::vector< char > m_binary
content
NXBinary(const NXClass &parent, const std::string &name)
Constructor.
The base class for a Nexus class (group).
std::vector< NXInfo > & datasets() const
Returns a list of all datasets in this NXClass.
NX openNXClass(const std::string &name) const
Templated method for creating derived NX classes.
NXSize openNXSize(const std::string &name) const
Creates and opens a size_t dataset.
NXInt openNXInt(const std::string &name) const
Creates and opens an integer dataset.
NXDouble openNXDouble(const std::string &name) const
Creates and opens a double dataset.
std::shared_ptr< std::vector< NXClassInfo > > m_groups
Holds info about the child NXClasses.
NXClass()
Pricate constructor.
std::string NX_class() const override
The NX class identifier.
NXClass openNXGroup(const std::string &name) const
Creates and opens an arbitrary (non-standard) class (group).
std::vector< NXClassInfo > & groups() const
Returns a list of all classes (or groups) in this NXClass.
std::shared_ptr< std::vector< NXInfo > > m_datasets
Holds info about the datasets in this NXClass.
NXDataSetTyped< T > openNXDataSet(const std::string &name) const
Templated method for creating datasets.
NXFloat openNXFloat(const std::string &name) const
Creates and opens a float dataset.
NXChar openNXChar(const std::string &name) const
Creates and opens a char dataset.
Templated class implementation of NXDataSet.
T & operator()(int i, int j)
const T & operator()(int i, int j) const
Returns a value assuming the data is a two-dimensional array.
NXDataSetTyped(const NXClass &parent, const std::string &name)
Constructor.
container_T< T > m_data
The data buffer.
int m_size[4]
The sizes of the loaded data.
T & operator()(int i, int j, int k)
container_T< T > & vecBuffer()
Returns a the internal buffer.
const T & operator[](int i) const
Returns the i-th value in the internal buffer.
void load(const int blocksize=1, int i=-1, int j=-1, int k=-1, int l=-1) override
Implementation of the virtual NXDataSet::load(...) method.
const T & operator()(int i, int j, int k) const
Returns a value assuming the data is a tree-dimensional array.
void rangeError() const
A shortcut to "throw std::range_error("Nexus dataset range error");".
void alloc(int n)
Allocates memory for the data buffer.
int size() const
Returns the size of the data buffer.
const T * operator()() const
Returns a pointer to the internal data buffer.
Abstract base class for a Nexus data set.
virtual void load(const int blocksize=1, int i=-1, int j=-1, int k=-1, int l=-1)
Load the data from the file.
int dim2() const
Returns the number of elements along the third dimension.
void getData(void *data)
Wrapper to the NXgetdata.
int dim0() const
Returns the number of elements along the first dimension.
void open()
Opens the data set.
std::string NX_class() const override
NX class name. Returns "SDS".
int type() const
Returns the Nexus type of the data. The types are defied in napi.h.
std::string name() const
Returns the name of the data set.
void getSlab(void *data, int start[], int size[])
Wrapper to the NXgetslab.
int rank() const
Returns the rank (number of dimensions) of the data. The maximum is 4.
int dim3() const
Returns the number of elements along the fourth dimension.
int dims(int i) const
Returns the number of elements along i-th dimension.
NXInfo m_info
Holds the data info.
int dim1() const
Returns the number of elements along the second dimension.
Implements NXdata Nexus class.
NXFloat openFloatData()
Opens data of float type.
NXDouble openDoubleData()
Opens data of double type.
std::string NX_class() const override
Nexus class id.
NXUInt openUIntData()
Opens data of unsigned int type.
NXInt openIntData()
Opens data of int type.
NXDataSetTyped< T > openData()
Opens the dataset within this NXData with signal=1 attribute.
NXSize openSizeData()
Opens data of size type.
Implements NXdetector Nexus class.
NXDetector(const NXClass &parent, const std::string &name)
Constructor.
NXFloat openAzimuthalAngle()
Opens the dataset containing pixel azimuthal angles.
NXFloat openDistance()
Opens the dataset containing pixel distances.
std::string NX_class() const override
Nexus class id.
NXFloat openPolarAngle()
Opens the dataset containing pixel polar angles.
Implements NXdisk_chopper Nexus class.
NXFloat openRotationSpeed()
Opens the dataset containing pixel distances.
std::string NX_class() const override
Nexus class id.
NXDiskChopper(const NXClass &parent, const std::string &name)
Constructor.
Implements NXentry Nexus class.
NXData openNXData(const std::string &name) const
Opens a NXData.
NXEntry(const NXClass &parent, const std::string &name)
Constructor.
std::string NX_class() const override
Nexus class id.
NXInstrument openNXInstrument(const std::string &name) const
Opens a NXInstrument.
Implements NXinstrument Nexus class.
NXDiskChopper openNXDiskChopper(const std::string &name)
Opens a NXDetector.
NXInstrument(const NXClass &parent, const std::string &name)
Constructor.
NXDetector openNXDetector(const std::string &name)
Opens a NXDetector.
std::string NX_class() const override
Nexus class id.
Implements NXlog Nexus class.
Kernel::Property * loadValues(const std::string &logName, NX_TYPE &value, Types::Core::DateAndTime start_t, const TIME_TYPE ×)
Loads the values in the log into the workspace.
Kernel::Property * parseTimeSeries(const std::string &logName, const TYPE ×, const std::string &time0="")
Parse a time series.
std::string NX_class() const override
Nexus class id.
NXLog(const NXClass &parent, const std::string &name)
Constructor.
Main class is the one that can contain auxiliary classes.
NXNote openNXNote(const std::string &name)
Opens a NXNote class.
NXMainClass(const NXClass &parent, const std::string &name)
Constructor.
NXLog openNXLog(const std::string &name)
Opens a NXLog class.
Implements NXnote Nexus class.
bool m_data_ok
data loaded indicator
std::string m_author
author
bool m_author_ok
author loaded indicator
std::string NX_class() const override
Nexus class id.
bool m_description_ok
description loaded indicator
NXNote(const NXClass &parent, const std::string &name)
Constructor.
std::string m_description
description
std::vector< std::string > m_data
content
The base abstract class for NeXus classes and data sets.
NXhandle m_fileID
Nexus file id.
std::string m_path
Keeps the absolute path to the object.
virtual ~NXObject()=default
bool m_open
Set to true if the object has been open.
NXObject()
Private default constructor.
std::string path() const
Returns the absolute path to the object.
virtual std::string NX_class() const =0
Return the NX class name for a class (HDF group) or "SDS" for a data set;.
NXAttributes attributes
Attributes.
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.
std::conditional_t< std::is_same< T, bool >{}, boost::container::vector< bool >, std::vector< T > > container_T
const int g_processed_blocksize
LoadNexusProcessed and SaveNexusProcessed need to share some attributes, put them at namespace level ...
Helper class which provides the Collimation Length for SANS instruments.
Information about a Nexus class.
std::string nxclass
NX class of the object or "SDS" if a dataset.
std::string nxname
name of the object
int datatype
NX data type if a dataset, e.g.
C++ implementation of NeXus classes.
NXstatus stat
return status
int rank
number of dimensions of the data
int type
type of the data, e.g. NX_CHAR, NX_FLOAT32, see napi.h
int dims[4]
sizes along each dimension
std::string nxname
name of the object