17 for (std::size_t i = 0; i < xd.size(); i++) {
24 : nxname(
name), rank(info.dims.size()), dims(
nxdimArray(info.dims)), type(info.type), allGood(true) {}
27 std::vector<std::string> out;
30 [](
auto const &
value) -> std::string { return value.first; });
35 std::vector<std::string> out;
38 [](
auto const &
value) -> std::string { return value.second; });
82 if (parent && !
name.empty()) {
94 : m_fileID(fileID), m_open(false) {
95 if (parent && !
name.empty()) {
105 std::vector<char> buff(128);
108 throw std::runtime_error(
"Encountered attribute with array value");
111 switch (ainfo.type) {
141 for (
auto const &entry :
m_fileID->getEntries()) {
142 if (entry.second ==
"SDS") {
147 }
else if (entry.second.starts_with(
"NX") || entry.second.starts_with(
"IX")) {
172 std::string className = nxclass.empty() ?
NX_class() : nxclass;
187 throw std::runtime_error(
"Cannot close group " +
name() +
" of class " +
NX_class() +
" (trying to close address " +
194 m_groups.reset(
new std::vector<NXClassInfo>);
202 return std::string(buff(), buff.dim0());
203 }
catch (std::runtime_error &) {
205 return std::string();
232 [&query](
const auto &
group) { return group.nxname == query; });
242 [&
name](
const auto &dataset) {
return dataset.nxname ==
name; });
269 std::cout <<
"NXRoot: Error loading " <<
m_filename <<
"\" in read mode: " << e.what() <<
"\n";
301 throw std::runtime_error(
"Nexus file has no entries");
304 std::find_if(
groups().cbegin(),
groups().cend(), [](
const auto &
group) {
return group.nxclass ==
"NXentry"; });
305 if (it !=
groups().cend()) {
308 throw std::runtime_error(
"Nexus file has no entries");
321 size_t i =
name.find_last_of(
'/');
322 if (i == std::string::npos)
324 else if (
name.empty() || i ==
name.size() - 1)
325 throw std::runtime_error(
"Improper dataset name " +
name);
335 m_fileID->openAddress(group_address);
356 throw std::out_of_range(
"NXDataSet::dim0() - Requested dimension greater than rank.");
368 throw std::out_of_range(
"NXDataSet::dim1() - Requested dimension greater than rank.");
380 throw std::out_of_range(
"NXDataSet::dim2() - Requested dimension greater than rank.");
392 throw std::out_of_range(
"NXDataSet::dim3() - Requested dimension greater than rank.");
double value
The value of the point.
#define UNUSED_ARG(x)
Function arguments are sometimes unused in certain implmentations but are required for documentation ...
Class that provides for a standard Nexus exception.
std::map< std::string, std::string > m_values
the list of attributes
std::vector< std::string > names() const
Returns the list of attribute names.
std::vector< std::string > values() const
Returns the list of attribute values.
std::string operator()(const std::string &name) const
returns the value of attribute with name name
void set(const std::string &name, const std::string &value)
set the attribute's value from string
The base class for a Nexus class (group).
float getFloat(const std::string &name) const
Returns a float.
std::string getString(const std::string &name) const
Returns a string.
void open()
Opens this NXClass using File::openGroupAddress(). Can be slow (or is slow)
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.
NXClass()
Private constructor.
bool openLocal(const std::string &nxclass="")
Opens this NXClass using File::openGroup().
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.
double getDouble(const std::string &name) const
Returns a double.
void close()
Close this class.
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.
NXDouble openNXDouble(const std::string &name) const
Creates and opens a double dataset.
std::string NX_class() const override
The NX class identifier.
NXInfo getDataSetInfo(const std::string &name) const
Returns NXInfo for a dataset.
bool containsDataSet(const std::string &query) const
Returns whether an individual dataset is present.
int32_t getInt(const std::string &name) const
Returns a int.
bool isValid(const std::string &address) const
Check if a address exists relative to the current class address.
void clear()
Deletes content of m_groups and m_datasets.
Templated class implementation of NXDataSet.
void load()
Read all of the datablock in.
void getAttributes()
Reads in attributes.
dimsize_t dim0() const
Returns the number of elements along the first dimension.
void openLocal()
Opens datasets faster but the parent group must be already open.
NXAttributes attributes
Attributes.
dimsize_t dim3() const
Returns the number of elements along the fourth dimension.
NXInfo m_info
Holds the data info.
dimsize_t dim2() const
Returns the number of elements along the third dimension.
void open()
Opens the data set. Does not read in any data. Call load(...) to load the data.
dimsize_t dim1() const
Returns the number of elements along the second dimension.
std::string name() const
Returns the name of the data set.
NXData(const NXClass &parent, const std::string &name)
Constructor.
Implements NXentry Nexus class.
The base abstract class for Nexus classes and data sets.
friend class NXDataSet
a friend class declaration
std::string name() const
Returns the name of the object.
NexusAddress const & address() const
Returns the absolute address to the object.
std::shared_ptr< File > m_fileID
Nexus file id.
NXObject()
Private default constructor.
NexusAddress m_address
Keeps the absolute address to the object.
friend class NXRoot
a friend class declaration
bool m_open
Set to true if the object has been open.
const std::string m_filename
The file name.
bool isStandard() const
True if complies with our understanding of the www.nexusformat.org definition.
NXEntry openEntry(const std::string &name)
Opens an entry – a topmost Nexus class.
~NXRoot() override
Destructor.
NXEntry openFirstEntry()
Open the first NXentry in the file.
This simple class encapsulates some methods for working with paths inside a Nexus file.
NexusAddress parent_path() const
static NexusAddress root()
NexusAddress stem() const
static unsigned short constexpr UINT16
static unsigned short constexpr INT16
static unsigned short constexpr CHAR
static unsigned short constexpr INT32
Header for a base Nexus::Exception.
NXDataSetTyped< char > NXChar
The char dataset type.
std::array< dimsize_t, 4 > NXDimArray
C++ implementation of Nexus classes.
std::vector< dimsize_t > DimVector
static NXDimArray nxdimArray(const DimVector &xd)
std::string to_string(const wide_integer< Bits, Signed > &n)
Information about an attribute.
This structure holds the type and dimensions of a primative field/array.
Information about a Nexus class.
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