17 std::vector<std::string> out;
20 [](
const auto &
value) { return value.first; });
25 std::vector<std::string> out;
28 [](
const auto &
value) { return value.second; });
55 std::ostringstream ostr;
71 : m_fileID(fileID), m_open(false) {
72 if (parent && !
name.empty()) {
78 size_t i =
m_path.find_last_of(
'/');
79 if (i == std::string::npos)
94 std::vector<char> buff(128);
97 while (NXgetnextattr(
m_fileID, pName, &iLength, &iType) != NX_EOD) {
99 while (NXgetnextattra(
m_fileID, pName, &rank, dims, &iType) != NX_EOD) {
103 throw std::runtime_error(
"Encountered attribute with multi-dimensional array value");
106 if (iType != NX_CHAR && iLength != 1) {
107 throw std::runtime_error(
"Encountered attribute with array value");
113 if (iLength >= 0 && (
unsigned)iLength > buff.size()) {
114 buff.resize(iLength);
116 int nz = iLength + 1;
117 NXgetattr(
m_fileID, pName, buff.data(), &nz, &iType);
124 sprintf(buff.data(),
"%i",
value);
131 sprintf(buff.data(),
"%i",
value);
136 short unsigned int value;
138 sprintf(buff.data(),
"%u",
value);
153 char nxname[NX_MAXNAMELEN], nxclass[NX_MAXNAMELEN];
174 }
else if (info.
nxclass.substr(0, 2) ==
"NX" || info.
nxclass.substr(0, 2) ==
"IX") {
192 throw std::runtime_error(
"Cannot open group " +
name() +
" of class " +
NX_class() +
" (trying to open path " +
211 std::string className = nxclass.empty() ?
NX_class() : nxclass;
212 if (NX_ERROR == NXopengroup(
m_fileID,
name().c_str(), className.c_str())) {
227 if (NX_ERROR == NXclosegroup(
m_fileID)) {
228 throw std::runtime_error(
"Cannot close group " +
name() +
" of class " +
NX_class() +
" (trying to close path " +
237 m_groups.reset(
new std::vector<NXClassInfo>);
245 return std::string(buff(), buff.
dim0());
246 }
catch (std::runtime_error &) {
248 return std::string();
274 std::vector<NXClassInfo>::const_iterator end =
m_groups->end();
275 for (std::vector<NXClassInfo>::const_iterator i =
m_groups->begin(); i != end; ++i) {
276 if (i->nxname == query) {
290 for (std::vector<NXInfo>::const_iterator it =
datasets().begin(); it !=
datasets().end(); ++it) {
291 if (it->nxname ==
name)
294 info.
stat = NX_ERROR;
323 NXgetinfo(
m_fileID, &rank, dims, &type);
325 auto buffer =
new char[
n];
326 NXstatus stat = NXgetdata(
m_fileID, buffer);
329 if (stat == NX_ERROR) {
333 std::istringstream istr(std::string(buffer,
n));
337 while (getline(istr, line)) {
338 m_data.emplace_back(line);
362 NXgetinfo(
m_fileID, &rank, dims, &type);
382 if (stat == NX_ERROR) {
383 std::cout <<
"NXRoot: Error loading " <<
m_filename;
398 if (stat == NX_ERROR) {
412 throw std::runtime_error(
"NeXus file has no entries");
414 for (std::vector<NXClassInfo>::const_iterator grp =
groups().begin(); grp !=
groups().end(); ++grp) {
415 if (grp->nxclass ==
"NXentry") {
419 throw std::runtime_error(
"NeXus file has no entries");
432 size_t i =
name.find_last_of(
'/');
433 if (i == std::string::npos)
435 else if (
name.empty() || i ==
name.size() - 1)
436 throw std::runtime_error(
"Improper dataset name " +
name);
444 size_t i =
m_path.find_last_of(
'/');
445 if (i == std::string::npos || i == 0)
447 std::string group_path =
m_path.substr(0, i);
448 if (NX_ERROR == NXopenpath(
m_fileID, group_path.c_str())) {
449 throw std::runtime_error(
"Cannot open dataset " +
m_path);
452 throw std::runtime_error(
"Error opening data in group \"" +
name() +
"\"");
456 throw std::runtime_error(
"Error retrieving information for " +
name() +
" group");
465 throw std::runtime_error(
"Error opening data in group \"" +
name() +
"\"");
468 throw std::runtime_error(
"Error retrieving information for " +
name() +
" group");
481 throw std::out_of_range(
"NXDataSet::dim0() - Requested dimension greater than rank.");
493 throw std::out_of_range(
"NXDataSet::dim1() - Requested dimension greater than rank.");
505 throw std::out_of_range(
"NXDataSet::dim2() - Requested dimension greater than rank.");
517 throw std::out_of_range(
"NXDataSet::dim3() - Requested dimension greater than rank.");
528 if (NXgetdata(
m_fileID, data) != NX_OK)
529 throw std::runtime_error(
"Cannot read data from NeXus file");
546 if (NXgetslab(
m_fileID, data, start, size) != NX_OK)
547 throw std::runtime_error(
"Cannot read data slab from NeXus file");
566 if (vinfo.
stat == NX_ERROR) {
577 const std::string valAttr(
"value");
580 int nxType = vinfo.
type;
581 if (nxType == NX_FLOAT64) {
583 }
else if (nxType == NX_INT32) {
585 }
else if (nxType == NX_CHAR) {
587 }
else if (nxType == NX_UINT8) {
590 bool state =
value[0] != 0;
610 const std::string &logName = new_name.empty() ?
name() : new_name;
612 if (vinfo.
type == NX_FLOAT64) {
616 std::string units = times.
attributes(
"units");
617 if (units ==
"minutes") {
618 using std::placeholders::_1;
619 std::transform(times(), times() + times.
dim0(), times(), std::bind(std::multiplies<double>(), _1, 60));
620 }
else if (!units.empty() && units.substr(0, 6) !=
"second") {
624 }
else if (vinfo.
type == NX_FLOAT32) {
628 std::string units = times.
attributes(
"units");
629 if (units ==
"minutes") {
630 std::for_each(times(), times() + times.
dim0(), [](
float &val) { val *= 60.0f; });
631 }
else if (!units.empty() && units.substr(0, 6) !=
"second") {
double value
The value of the point.
Records the filename and the description of failure.
The concrete, templated class for properties.
Base class for properties.
std::map< std::string, std::string > m_values
the list of attributes
std::string operator()(const std::string &name) const
returns the value of attribute with name name
std::vector< std::string > values() const
Returns the list of attribute values.
std::vector< std::string > names() const
Returns the list of attribute names.
void set(const std::string &name, const std::string &value)
set the attribute's value
std::vector< char > m_binary
content
std::vector< char > & binary()
Return the binary data associated with the note.
The base class for a Nexus class (group).
int getInt(const std::string &name) const
Returns a int.
bool openLocal(const std::string &nxclass="")
Opens this NXClass using NXopengroup.
NXClassInfo getNextEntry()
Returns the class information about the next entry (class or dataset) in this class.
std::vector< NXInfo > & datasets() const
Returns a list of all datasets in this NXClass.
void open()
Opens this NXClass using NXopengrouppath. Can be slow (or is slow)
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.
void reset()
Creates a new object in the NeXus file at path path.
void close()
Close this class.
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.
void readAllInfo()
Fills in m_groups and m_datasets.
bool containsGroup(const std::string &query) const
Returns whether an individual group (or group) is present.
std::vector< NXClassInfo > & groups() const
Returns a list of all classes (or groups) in this NXClass.
void clear()
Deletes content of m_groups and m_datasets.
bool containsDataSet(const std::string &query) const
Returns whether an individual dataset is present.
NXInfo getDataSetInfo(const std::string &name) const
Returns NXInfo for a dataset.
std::shared_ptr< std::vector< NXInfo > > m_datasets
Holds info about the datasets in this NXClass.
float getFloat(const std::string &name) const
Returns a float.
NXFloat openNXFloat(const std::string &name) const
Creates and opens a float dataset.
bool isValid(const std::string &path) const
Check if a path exists relative to the current class path.
NXChar openNXChar(const std::string &name) const
Creates and opens a char dataset.
double getDouble(const std::string &name) const
Returns a double.
std::string getString(const std::string &name) const
Returns a string.
Templated class implementation of NXDataSet.
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.
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 name() const
Returns the name of the data set.
void getSlab(void *data, int start[], int size[])
Wrapper to the NXgetslab.
int dim3() const
Returns the number of elements along the fourth dimension.
NXInfo m_info
Holds the data info.
void openLocal()
Opens datasets faster but the parent group must be already open.
int dim1() const
Returns the number of elements along the second dimension.
NXData(const NXClass &parent, const std::string &name)
Constructor.
Implements NXentry Nexus class.
Kernel::Property * createSingleValueProperty()
Creates a single value property of the log.
Kernel::Property * createTimeSeries(const std::string &start_time="", const std::string &new_name="")
Creates a TimeSeriesProperty and returns a pointer to it.
Kernel::Property * parseTimeSeries(const std::string &logName, const TYPE ×, const std::string &time0="")
Parse a time series.
Kernel::Property * createProperty()
Creates a property wrapper around the log.
Main class is the one that can contain auxiliary classes.
bool m_data_ok
data loaded indicator
std::string m_author
author
std::vector< std::string > & data()
Returns the note's content.
std::string description()
Returns the description string.
std::string author()
Returns the note's author.
bool m_author_ok
author loaded indicator
bool m_description_ok
description loaded indicator
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 name() const
Returns the name of the object.
std::string m_path
Keeps the absolute path to the object.
friend class NXDataSet
a friend class declaration
void getAttributes()
Reads in attributes.
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.
friend class NXRoot
a friend class declaration
NXAttributes attributes
Attributes.
const std::string m_filename
The file name.
~NXRoot() override
Destructor.
bool isStandard() const
True if complies with our understanding of the www.nexusformat.org definition.
NXEntry openFirstEntry()
Open the first NXentry in the file.
NXEntry openEntry(const std::string &name)
Opens an entry – a topmost Nexus class.
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