icedb  version 0.5.1
Snow particle scattering database API
Public Types | Public Member Functions | Static Public Member Functions | Public Attributes | Static Public Attributes | Protected Member Functions | List of all members
icedb::Shapes::Shape Class Reference

A high-level class to manipulate particle shapes. More...

#include <shape.hpp>

Inheritance diagram for icedb::Shapes::Shape:
Inheritance graph
[legend]
Collaboration diagram for icedb::Shapes::Shape:
Collaboration graph
[legend]

Public Types

typedef std::unique_ptr< ShapeShape_Type
 The preferred C++ type for referencing a shape. More...
 
- Public Types inherited from icedb::Groups::Group
typedef std::unique_ptr< Groups::GroupGroup_ptr
 
typedef std::shared_ptr< H5::Group > Group_HDF_shared_ptr
 

Public Member Functions

virtual ~Shape ()
 
bool isShape () const
 Is this object actually a shape? More...
 
bool isValid (std::ostream *out=nullptr) const
 Is this object a valid shape, according to the spec? More...
 
- Public Member Functions inherited from icedb::Groups::Group
virtual ~Group ()
 
virtual Group_ptr createGroup (const std::string &groupName)=0
 Create a group. More...
 
virtual Group_ptr openGroup (const std::string &groupName) const =0
 Opens a group. More...
 
virtual bool doesGroupExist (const std::string &groupName) const =0
 Does a group with this name exist? More...
 
virtual std::set< std::string > getGroupNames () const =0
 Get the names of all sub-groups within the current group. More...
 
virtual void deleteGroup (const std::string &groupName)=0
 Unlink the specified child group. More...
 
virtual Group_HDF_shared_ptr getHDF5Group () const =0
 Get the fundamental HDF5 object that the group is built on. More...
 
- Public Member Functions inherited from icedb::Attributes::CanHaveAttributes
 ~CanHaveAttributes ()
 
bool doesAttributeExist (const std::string &attributeName) const
 Does the object have an attribute with the given name? More...
 
std::type_index getAttributeTypeId (const std::string &attributeName) const
 Returns the type of an attribute. More...
 
template<class Type >
bool isAttributeOfType (const std::string &attributeName) const
 Is the type of the attribute "Type"? More...
 
std::set< std::string > getAttributeNames () const
 List all attributes attached to this object. More...
 
void deleteAttribute (const std::string &attributeName)
 Delete an attribute, by name, that is attached to this object. More...
 
template<class DataType >
void readAttributeData (const std::string &attributeName, std::vector< size_t > &dimensions, std::vector< DataType > &data) const
 Function to read the data from an attribute using the provided input vectors. More...
 
template<class DataType >
void writeAttributeData (const std::string &attributeName, const std::vector< size_t > &dimensionas, const std::vector< DataType > &data)
 Function to write an attribute to an object, with the provided raw data. More...
 
template<class DataType >
Attribute< DataType > readAttribute (const std::string &attributeName) const
 Convenience function to read an attribute's data and return an Attribute object. More...
 
template<class DataType >
void writeAttribute (const Attribute< DataType > &attribute)
 Convenience function to write an Attribute to an object. More...
 
template<class DataType >
void writeAttribute (const std::string &name, std::initializer_list< size_t > dims, std::initializer_list< DataType > data)
 Convenience function to write a small Attribute to an object, using initializer lists. More...
 
- Public Member Functions inherited from icedb::Tables::CanHaveTables
 ~CanHaveTables ()
 
std::set< std::string > getTableNames () const
 Lists all table names that are children of this object. More...
 
bool doesTableExist (const std::string &tableName) const
 Does a table exist with the given name. More...
 
void unlinkTable (const std::string &tableName)
 Unlink a table. In HDF5, this is not the same as erasing a table, which never actually happens. More...
 
Table::Table_Type openTable (const std::string &tableName)
 
std::vector< size_t > getChunkStrategy (const std::vector< size_t > &dims)
 The default chunking strategy for this table. Used for storage i/o speed, and for compression. More...
 
template<class DataType >
Table::Table_Type createTable (const std::string &tableName, const std::vector< size_t > &dims, const std::vector< size_t > *chunks=nullptr)
 Create a table. More...
 
template<class DataType >
Table::Table_Type createTable (const std::string &tableName, std::initializer_list< size_t > dims, const std::vector< size_t > *chunks=nullptr)
 Create a table. More...
 
template<class DataType >
Table::Table_Type createTable (const std::string &tableName, std::initializer_list< size_t > dims, std::initializer_list< DataType > data, const std::vector< size_t > *chunks=nullptr)
 Create a table and writes initial data. Used with small tables. More...
 
template<class DataType >
Table::Table_Type createTable (const std::string &tableName, std::initializer_list< size_t > dims, const std::vector< DataType > &data, const std::vector< size_t > *chunks=nullptr)
 Create a table and sets the table's initial data. More...
 
template<class DataType >
Table::Table_Type createTable (const std::string &tableName, std::initializer_list< size_t > dims, const gsl::span< DataType > &data, const std::vector< size_t > *chunks=nullptr)
 Create a table and sets the table's initial data. More...
 
template<class DataType >
Table::Table_Type createTable (const std::string &tableName, std::initializer_list< size_t > dims, const gsl::span< const DataType > &data, const std::vector< size_t > *chunks=nullptr)
 Create a table and sets the table's initial data. More...
 

Static Public Member Functions

static bool isShape (Groups::Group &owner, const std::string &name)
 Is this object a shape? More...
 
static bool isShape (gsl::not_null< H5::Group *> group)
 Is this object a group? More...
 
static bool isValid (gsl::not_null< H5::Group *> group, std::ostream *out=nullptr)
 Is "group" a valid shape, according to the spec.? More...
 
static Shape_Type openShape (Groups::Group &grpshp)
 
static Shape_Type openShape (Groups::Group &owner, const std::string &name)
 Open a group's subgroup as a shape. More...
 
static Shape_Type openShape (Groups::Group::Group_HDF_shared_ptr shape)
 Re-open an open HDF5 group as a shape. More...
 
static Shape_Type createShape (Groups::Group &grpshp, const std::string &uid, gsl::not_null< const NewShapeRequiredProperties *> required, const NewShapeCommonOptionalProperties *optional=nullptr)
 Create a new shape. More...
 
static Shape_Type createShape (Groups::Group &owner, const std::string &name, const std::string &uid, gsl::not_null< const NewShapeRequiredProperties *> required, const NewShapeCommonOptionalProperties *optional=nullptr)
 Create a new shape. More...
 
static Shape_Type createShape (Groups::Group::Group_HDF_shared_ptr newShapeLocation, const std::string &uid, gsl::not_null< const NewShapeRequiredProperties *> required, const NewShapeCommonOptionalProperties *optional=nullptr)
 Create a new shape. More...
 
- Static Public Member Functions inherited from icedb::Groups::Group
static Group_ptr createGroup (const std::string &name, gsl::not_null< H5::Group *> parent)
 Create a group with a specified parent (static function) More...
 
static Group_ptr createGroup (const std::string &name, gsl::not_null< H5::H5File *> parent)
 Create a group with a specified parent (static function) More...
 
static Group_ptr createGroup (const std::string &name, gsl::not_null< const Group *> parent)
 Create a group with a specified parent (static function) More...
 
static Group_ptr openGroup (const std::string &name, gsl::not_null< H5::Group *> parent)
 Open a group under the specified parent (static function) More...
 
static Group_ptr openGroup (const std::string &name, gsl::not_null< H5::H5File *> parent)
 Open a group under the specified parent (static function) More...
 
static Group_ptr openGroup (const std::string &name, gsl::not_null< const Group *> parent)
 Open a group under the specified parent (static function) More...
 
static Group_ptr openGroup (Group_HDF_shared_ptr group)
 Open an icedb group from an HDF5 group object. More...
 
static Group_ptr mount (const std::string &subdirname, gsl::not_null< const Group *> containingParent, gsl::not_null< H5::H5File *> pointsTo)
 Mount an HDF5 file as a child 'group'. More...
 
- Static Public Member Functions inherited from icedb::Attributes::CanHaveAttributes
static bool doesAttributeExist (gsl::not_null< const H5::H5Object *> parent, const std::string &attributeName)
 Does an object (parent) have an attribute with the given name? More...
 
static std::type_index getAttributeTypeId (gsl::not_null< const H5::H5Object *> parent, const std::string &attributeName)
 Returns the type of an attribute. More...
 
template<class DataType >
static void readAttributeData (gsl::not_null< const H5::H5Object *> parent, const std::string &attributeName, std::vector< size_t > &dimensions, std::vector< DataType > &data)
 Function to read the data from an attribute. More...
 
template<class DataType >
static Attribute< DataType > readAttribute (gsl::not_null< const H5::H5Object *> obj, const std::string &attributeName)
 Convenience function to read an attribute's data and return an Attribute object. More...
 

Public Attributes

const std::string particle_unique_id
 This is the unique identifier for this shape. More...
 
- Public Attributes inherited from icedb::Groups::Group
const std::string name
 The name of the group. More...
 

Static Public Attributes

static const std::string _icedb_obj_type_shape_identifier = "shape"
 Each shape 'group' has an attribute with this identifier. Used for shape collection and searching. More...
 
- Static Public Attributes inherited from icedb::Groups::Group
static const std::string _icedb_obj_type_identifier = { "_icedb_obj_type" }
 The tag used in icedb to identify a group. More...
 

Protected Member Functions

 Shape (const std::string &uid)
 
- Protected Member Functions inherited from icedb::Groups::Group
 Group ()
 
 Group (const std::string &name)
 
- Protected Member Functions inherited from icedb::Attributes::CanHaveAttributes
 CanHaveAttributes ()
 
virtual void _setAttributeParent (std::shared_ptr< H5::H5Object > obj)=0
 
virtual std::shared_ptr< H5::H5Object > _getAttributeParent () const =0
 
- Protected Member Functions inherited from icedb::Tables::CanHaveTables
 CanHaveTables ()
 Trivial constructor used when CanHaveTables is a virtual base class. More...
 
virtual void _setTablesParent (std::shared_ptr< H5::Group > obj)=0
 CanHaveTables needs post-constructor setup. This sets the base HDF5 object that gets manipulated. More...
 
virtual std::shared_ptr< H5::Group > _getTablesParent () const =0
 Gets the base HDF5 object that is manipulated. More...
 

Detailed Description

A high-level class to manipulate particle shapes.

Shapes are implemented as a set of tables and attributes, contained within a discrete Group. This class provides a higl-level interface to accessing and manipulating shapes. It acts as an "overlay" to an alreagy-existing group. It adds additional functions and "value".

Definition at line 112 of file shape.hpp.

Member Typedef Documentation

◆ Shape_Type

typedef std::unique_ptr<Shape> icedb::Shapes::Shape::Shape_Type

The preferred C++ type for referencing a shape.

Definition at line 145 of file shape.hpp.

Constructor & Destructor Documentation

◆ Shape()

icedb::Shapes::Shape::Shape ( const std::string &  uid)
protected

Definition at line 160 of file Shapes.cpp.

References _icedb_obj_type_shape_identifier.

160 : particle_unique_id{ uid } {}
const std::string particle_unique_id
This is the unique identifier for this shape.
Definition: shape.hpp:194

◆ ~Shape()

icedb::Shapes::Shape::~Shape ( )
virtual

Definition at line 159 of file Shapes.cpp.

159 {}

Member Function Documentation

◆ createShape() [1/3]

Shape::Shape_Type icedb::Shapes::Shape::createShape ( Groups::Group grpshp,
const std::string &  uid,
gsl::not_null< const NewShapeRequiredProperties *>  required,
const NewShapeCommonOptionalProperties optional = nullptr 
)
static

Create a new shape.

Parameters
uidis a unique name for the shape
grpshpis the opened group that is converted into a shape
Exceptions
ifthe group has any already-existing tables or attributes that conflict with the new shape object
Parameters
requiredis a pointer to the NewShapeRequiredProperties structure, that provides the "required" shape data.
optionalis a pointer to the Common Optional Properties structure, that provides optional, supplementary data.
Returns
the new shape on success
Exceptions
onfailure

Definition at line 231 of file Shapes.cpp.

References icedb::Groups::Group::getHDF5Group().

Referenced by createShape(), main(), and icedb::Examples::Shapes::ShapeDataBasic::toShape().

235  {
236  return createShape(grpshp.getHDF5Group(), uid, required, optional);
237  }
static Shape_Type createShape(Groups::Group &grpshp, const std::string &uid, gsl::not_null< const NewShapeRequiredProperties *> required, const NewShapeCommonOptionalProperties *optional=nullptr)
Create a new shape.
Definition: Shapes.cpp:231
Here is the call graph for this function:
Here is the caller graph for this function:

◆ createShape() [2/3]

Shape::Shape_Type icedb::Shapes::Shape::createShape ( Groups::Group owner,
const std::string &  name,
const std::string &  uid,
gsl::not_null< const NewShapeRequiredProperties *>  required,
const NewShapeCommonOptionalProperties optional = nullptr 
)
static

Create a new shape.

Parameters
owneris the "parent" of the shape - a shape is constructed as a child of the owner
nameis the name of the new group that gets created
uidis a unique name for the shape
Exceptions
ifthe group has any already-existing tables or attributes that conflict with the new shape object
Parameters
requiredis a pointer to the NewShapeRequiredProperties structure, that provides the "required" shape data.
optionalis a pointer to the Common Optional Properties structure, that provides optional, supplementary data.
Returns
the new shape on success
Exceptions
onfailure

Definition at line 239 of file Shapes.cpp.

References icedb::Groups::Group::createGroup(), createShape(), icedb::Groups::Group::doesGroupExist(), and icedb::Groups::Group::openGroup().

243  {
244  if (owner.doesGroupExist(name)) {
245  const auto grp = owner.openGroup(name);
246  return createShape(grp->getHDF5Group(), uid, required, optional);
247  }
248  else {
249  const auto grp = owner.createGroup(name);
250  return createShape(grp->getHDF5Group(), uid, required, optional);
251  }
252  }
static Shape_Type createShape(Groups::Group &grpshp, const std::string &uid, gsl::not_null< const NewShapeRequiredProperties *> required, const NewShapeCommonOptionalProperties *optional=nullptr)
Create a new shape.
Definition: Shapes.cpp:231
const std::string name
The name of the group.
Definition: Group.hpp:34
Here is the call graph for this function:

◆ createShape() [3/3]

Shape::Shape_Type icedb::Shapes::Shape::createShape ( Groups::Group::Group_HDF_shared_ptr  newShapeLocation,
const std::string &  uid,
gsl::not_null< const NewShapeRequiredProperties *>  required,
const NewShapeCommonOptionalProperties optional = nullptr 
)
static

Create a new shape.

Parameters
newShapeLocationis the "parent" of the shape - a shape is constructed as a child of the owner
uidis a unique name for the shape
Exceptions
ifthe group has any already-existing tables or attributes that conflict with the new shape object
Parameters
requiredis a pointer to the NewShapeRequiredProperties structure, that provides the "required" shape data.
optionalis a pointer to the Common Optional Properties structure, that provides optional, supplementary data.
Returns
the new shape on success
Exceptions
onfailure

Definition at line 254 of file Shapes.cpp.

References icedb::Shapes::NewShapeCommonOptionalProperties::hint_max_scattering_element_dimension, icedb::Shapes::NewShapeCommonOptionalProperties::isValid(), icedb::Shapes::NewShapeCommonOptionalProperties::particle_constituent_number, icedb::Shapes::NewShapeCommonOptionalProperties::particle_constituent_single_name, icedb::Shapes::NewShapeCommonOptionalProperties::particle_scattering_element_composition_fractional, icedb::Shapes::NewShapeCommonOptionalProperties::particle_scattering_element_composition_whole, icedb::Shapes::NewShapeCommonOptionalProperties::particle_scattering_element_number, icedb::Shapes::NewShapeCommonOptionalProperties::particle_scattering_element_radius, icedb::Shapes::NewShapeCommonOptionalProperties::particle_scattering_element_spacing, icedb::Tables::Table::setDimensionScale(), and icedb::Tables::Table::writeAll().

258  {
259  Expects(required->isValid(&(std::cerr)));
260  if (required->requiresOptionalPropertiesStruct()) Expects(optional);
261  if (optional) Expects(optional->isValid(required));
262 
263  Shape::Shape_Type res = std::make_unique<Shape_impl>(uid, newShapeLocation);
264 
265  // Write required attributes
266  res->writeAttribute<std::string>(Group::_icedb_obj_type_identifier, { 1 }, { Shape::_icedb_obj_type_shape_identifier });
267  res->writeAttribute<std::string>("particle_id", { 1 }, { required->particle_id });
268 
269  // Write required dimensions
270 
271  // This table is created, but if it is trivial, then it is unset (i.e. internally set only to the fill value)
272  bool createTblPSEN = false;
273  if (optional) {
274  if (optional->particle_scattering_element_number.size()) createTblPSEN = true;
275  }
276  if (required->NC4_compat) createTblPSEN = true;
277 
278  std::unique_ptr<icedb::Tables::Table> tblPSEN;
279  if (createTblPSEN) {
280  tblPSEN = res->createTable<uint64_t>("particle_scattering_element_number",
281  { static_cast<size_t>(required->number_of_particle_scattering_elements) });
282  if (optional) {
283  if (!optional->particle_scattering_element_number.empty()) {
284  tblPSEN->writeAll<uint64_t>(optional->particle_scattering_element_number);
285  }
286  }
287  // NOTE: The HDF5 dimension scale specification explicitly allows for dimensions to not have assigned values.
288  tblPSEN->setDimensionScale("particle_scattering_element_number");
289  }
290 
291  bool createTblPCN = false;
292  if (optional) {
293  if (optional->particle_constituent_number.size()) createTblPCN = true;
294  }
295  if (required->NC4_compat) createTblPCN = true;
296 
297  std::unique_ptr<icedb::Tables::Table> tblPCN;
298  if (createTblPCN) {
299  tblPCN = res->createTable<uint8_t>("particle_constituent_number",
300  { static_cast<size_t>(required->number_of_particle_constituents) });
301  if (optional) {
302  if (!optional->particle_constituent_number.empty()) {
303  tblPCN->writeAll<uint8_t>(optional->particle_constituent_number);
304  }
305  }
306  tblPCN->setDimensionScale("particle_constituent_number");
307  }
308 
309  std::unique_ptr<icedb::Tables::Table> tblXYZ;
310  if (required->NC4_compat) {
311  tblXYZ = res->createTable<uint8_t>("particle_axis", { 3 }, { 0, 1, 2 });
312  tblXYZ->setDimensionScale("particle_axis");
313  }
314 
315  constexpr size_t max_x = 20000;
316  const std::vector<size_t> chunks{
317  (max_x < required->number_of_particle_scattering_elements) ?
318  max_x : required->number_of_particle_scattering_elements, 3 };
319 
320  // Determine if we can store the data as integers.
321  // If non-integral coordinates, no.
322  bool considerInts = (required->particle_scattering_element_coordinates_are_integral) ? true : false;
323  bool useUint16s = false, useUint8s = false;
324  if (considerInts) {
325  // This minmax check is very slow.....
326  //const auto bounds = std::minmax_element(required->particle_scattering_element_coordinates.cbegin(), required->particle_scattering_element_coordinates.cend());
327  //if (*(bounds.first) > 0) {
328  // if (*(bounds.second) < UINT8_MAX - 2) useUint8s = true;
329  // else if (*(bounds.second) < UINT16_MAX - 2) useUint16s = true;
330  //}
331  float mx = -1;
332  if (optional) {
333  if (optional->hint_max_scattering_element_dimension > 0) {
334  mx = optional->hint_max_scattering_element_dimension > 0;
335  }
336  }
337  if (mx < 0) {
338  auto me = std::max_element(required->particle_scattering_element_coordinates.cbegin(), required->particle_scattering_element_coordinates.cend());
339  mx = *me;
340  }
341  if (mx < UINT8_MAX - 2) useUint8s = true;
342  else if (mx < UINT16_MAX - 2) useUint16s = true;
343  }
344 
345  if (useUint8s) {
346  std::vector<uint8_t> crds_ints(required->number_of_particle_scattering_elements * 3);
347  for (size_t i = 0; i < crds_ints.size(); ++i) {
348  crds_ints[i] = static_cast<uint8_t>(required->particle_scattering_element_coordinates[i]);
349  }
350  auto tblPSEC = res->createTable<uint8_t>(
351  "particle_scattering_element_coordinates",
352  { static_cast<size_t>(required->number_of_particle_scattering_elements), 3 },
353  crds_ints, &chunks);
354  if (tblPSEN) tblPSEC->attachDimensionScale(0, tblPSEN.get());
355  if (tblXYZ) tblPSEC->attachDimensionScale(1, tblXYZ.get());
356  }
357  else if (useUint16s) {
358  std::vector<uint16_t> crds_ints(required->number_of_particle_scattering_elements*3);
359  for (size_t i = 0; i < crds_ints.size(); ++i) {
360  crds_ints[i] = static_cast<uint16_t>(required->particle_scattering_element_coordinates[i]);
361  }
362  auto tblPSEC = res->createTable<uint16_t>(
363  "particle_scattering_element_coordinates",
364  { static_cast<size_t>(required->number_of_particle_scattering_elements), 3 },
365  crds_ints, &chunks);
366  if (tblPSEN) tblPSEC->attachDimensionScale(0, tblPSEN.get());
367  if (tblXYZ) tblPSEC->attachDimensionScale(1, tblXYZ.get());
368  } else {
369  auto tblPSEC = res->createTable<float>("particle_scattering_element_coordinates",
370  { static_cast<size_t>(required->number_of_particle_scattering_elements), 3 },
371  required->particle_scattering_element_coordinates, &chunks);
372  if (tblPSEN) tblPSEC->attachDimensionScale(0, tblPSEN.get());
373  if (tblXYZ) tblPSEC->attachDimensionScale(1, tblXYZ.get());
374  }
375 
376 
377  if (optional) {
378 
379  // TODO: if (optional->particle_constituent_name.size()) {}
380 
381 
382  if (optional->particle_constituent_single_name.size()) {
383  res->writeAttribute<std::string>("particle_single_constituent_name",
384  { 1 }, { optional->particle_constituent_single_name });
385  }
386 
387  if (optional->particle_scattering_element_composition_fractional.size()) {
388  const std::vector<size_t> cs{
389  (max_x < required->number_of_particle_scattering_elements) ?
390  max_x : required->number_of_particle_scattering_elements,
391  static_cast<size_t>(required->number_of_particle_constituents)
392  };
393  auto tblPSEC2a = res->createTable<float>("particle_scattering_element_composition_fractional",
394  { static_cast<size_t>(required->number_of_particle_scattering_elements),
395  static_cast<size_t>(required->number_of_particle_constituents) },
396  optional->particle_scattering_element_composition_fractional, &cs);
397  if (tblPSEN) tblPSEC2a->attachDimensionScale(0, tblPSEN.get());
398  if (tblPCN) tblPSEC2a->attachDimensionScale(1, tblPCN.get());
399  }
400 
401  if (optional->particle_scattering_element_composition_whole.size()) {
402  const std::vector<size_t> cs{
403  (max_x < required->number_of_particle_scattering_elements) ?
404  max_x : required->number_of_particle_scattering_elements
405  };
406  auto tblPSEC2b = res->createTable<uint8_t>(
407  "particle_scattering_element_composition_whole",
408  { static_cast<size_t>(required->number_of_particle_scattering_elements) },
409  optional->particle_scattering_element_composition_whole, &cs);
410  if (tblPSEN) tblPSEC2b->attachDimensionScale(0, tblPSEN.get());
411  }
412 
413 
414 
415  // Write common optional attributes
416  if (optional->particle_scattering_element_spacing > 0)
417  res->writeAttribute<float>("particle_scattering_element_spacing", { 1 }, { optional->particle_scattering_element_spacing });
418 
419  // Write common optional variables
420  if (optional->particle_scattering_element_radius.size()) {
421  auto tblPSER = res->createTable<float>("particle_scattering_element_radius",
422  { static_cast<size_t>(required->number_of_particle_scattering_elements) },
423  optional->particle_scattering_element_radius);
424  if (tblPSEN) tblPSER->attachDimensionScale(0, tblPSEN.get());
425  }
426 
427  }
428 
429  return res;
430  }
void setDimensionScale(const std::string &dimensionScaleName)
Designate this table as a dimension scale.
Definition: Tables.cpp:106
static const std::string _icedb_obj_type_shape_identifier
Each shape &#39;group&#39; has an attribute with this identifier. Used for shape collection and searching...
Definition: shape.hpp:118
void writeAll(const gsl::span< const DataType > &outData) const
Write the passed data to the table. Writes whole table.
Definition: Table.hpp:100
std::unique_ptr< Shape > Shape_Type
The preferred C++ type for referencing a shape.
Definition: shape.hpp:145
Here is the call graph for this function:

◆ isShape() [1/3]

bool icedb::Shapes::Shape::isShape ( Groups::Group owner,
const std::string &  name 
)
static

Is this object a shape?

Parameters
owneris the parent group
nameis the sub-group that is being tested
Exceptions
ifthe group "name" does not exist
Returns
true if it is a shape, false otherwise.

Definition at line 163 of file Shapes.cpp.

References icedb::Groups::Group::doesGroupExist(), isShape(), and icedb::Groups::Group::openGroup().

163  {
164  if (!owner.doesGroupExist(name)) return false;
165  auto grp = owner.openGroup(name);
166  return isShape(grp->getHDF5Group().get());
167  }
bool isShape() const
Is this object actually a shape?
Definition: Shapes.cpp:178
const std::string name
The name of the group.
Definition: Group.hpp:34
Here is the call graph for this function:

◆ isShape() [2/3]

bool icedb::Shapes::Shape::isShape ( gsl::not_null< H5::Group *>  group)
static

Is this object a group?

Parameters
groupis the HDF5 group
Exceptions
ifthe object pointed to by group is not a valid HDF5 group.
Returns
true if it is a shape, false otherwise

Definition at line 168 of file Shapes.cpp.

References icedb::Attributes::Attribute< DataType >::data, icedb::Attributes::CanHaveAttributes::doesAttributeExist(), and icedb::Attributes::CanHaveAttributes::getAttributeTypeId().

168  {
169  if (!Attributes::CanHaveAttributes::doesAttributeExist(group, Group::_icedb_obj_type_identifier)) return false;
170  if (Attributes::CanHaveAttributes::getAttributeTypeId(group, Group::_icedb_obj_type_identifier) != typeid(std::string)) return false;
171 
172  Attributes::Attribute<std::string> obj_type
173  = Attributes::CanHaveAttributes::readAttribute<std::string>(group, Group::_icedb_obj_type_identifier);
174  if (obj_type.data.size() != 1) return false;
175  if (obj_type.data[0] != Shape::_icedb_obj_type_shape_identifier) return false;
176  return true;
177  }
static const std::string _icedb_obj_type_shape_identifier
Each shape &#39;group&#39; has an attribute with this identifier. Used for shape collection and searching...
Definition: shape.hpp:118
std::type_index getAttributeTypeId(const std::string &attributeName) const
Returns the type of an attribute.
Definition: Attributes.cpp:50
bool doesAttributeExist(const std::string &attributeName) const
Does the object have an attribute with the given name?
Definition: Attributes.cpp:61
Here is the call graph for this function:

◆ isShape() [3/3]

bool icedb::Shapes::Shape::isShape ( ) const

Is this object actually a shape?

Definition at line 178 of file Shapes.cpp.

References icedb::Groups::Group::getHDF5Group().

Referenced by isShape(), isValid(), and openShape().

178  {
179  return isShape(getHDF5Group().get());
180  }
virtual Group_HDF_shared_ptr getHDF5Group() const =0
Get the fundamental HDF5 object that the group is built on.
bool isShape() const
Is this object actually a shape?
Definition: Shapes.cpp:178
Here is the call graph for this function:
Here is the caller graph for this function:

◆ isValid() [1/2]

bool icedb::Shapes::Shape::isValid ( gsl::not_null< H5::Group *>  group,
std::ostream *  out = nullptr 
)
static

Is "group" a valid shape, according to the spec.?

Parameters
groupis the HDF5 group
Exceptions
ifthe object pointed to by group is not a valid HDF5 group.
Parameters
outis an output stream to which diagnostic messages can be written. Diagnostics include why an object is not a shape (e.g. missing an essential parameter).
Exceptions
ifthe output stream is somehow invalid

Check for the existence of the standard tables, dimensions and attributes, and that they have the appropriate sizes.

Todo:
Finish this, and tucn checks on attributes and variables into template functions!!!

Definition at line 183 of file Shapes.cpp.

References icedb::Groups::Group::_icedb_obj_type_identifier, icedb::Attributes::CanHaveAttributes::doesAttributeExist(), icedb::Attributes::CanHaveAttributes::getAttributeTypeId(), and isShape().

Referenced by isValid().

183  {
186 
188 
189  bool good = true;
190  if (!isShape(group)) {
191  good = false;
192  if (out) (*out) << "This is not a valid shape. Missing the appropriate "
193  << Groups::Group::_icedb_obj_type_identifier << " attribute." << std::endl;
194  return good;
195  }
196 
197  if (!Attributes::CanHaveAttributes::doesAttributeExist(group, "particle_id")) {
198  good = false;
199  if (out) (*out) << "Missing the particle_id attribute." << std::endl;
200  }
201  else if (Attributes::CanHaveAttributes::getAttributeTypeId(group, "particle_id") != typeid(std::string)) {
202  good = false;
203  if (out) (*out) << "The particle_id attribute has the wrong type." << std::endl;
204  }
205  else {
206  auto attr = Attributes::CanHaveAttributes::readAttribute<std::string>(group, "particle_id");
207  if (attr.data.size() != 1) {
208  good = false;
209  if (out) (*out) << "The particle_id attribute has the wrong size. It should be a scalar." << std::endl;
210  }
211  else {
212  if (!attr.data[0].size()) {
213  good = false;
214  if (out) (*out) << "The particle_id attribute is empty." << std::endl;
215  }
216  }
217  }
218  if (out) (*out) << "TODO: Finish these checks!" << std::endl;
219  return good;
220  }
bool isShape() const
Is this object actually a shape?
Definition: Shapes.cpp:178
std::type_index getAttributeTypeId(const std::string &attributeName) const
Returns the type of an attribute.
Definition: Attributes.cpp:50
static const std::string _icedb_obj_type_identifier
The tag used in icedb to identify a group.
Definition: Group.hpp:29
bool doesAttributeExist(const std::string &attributeName) const
Does the object have an attribute with the given name?
Definition: Attributes.cpp:61
Here is the call graph for this function:
Here is the caller graph for this function:

◆ isValid() [2/2]

bool icedb::Shapes::Shape::isValid ( std::ostream *  out = nullptr) const

Is this object a valid shape, according to the spec?

Parameters
outis an output stream to which diagnostic messages can be written. Diagnostics include why an object is not a shape (e.g. missing an essential parameter).
Exceptions
ifthe output stream is somehow invalid

Definition at line 182 of file Shapes.cpp.

References icedb::Groups::Group::getHDF5Group(), and isValid().

182 { return isValid(this->getHDF5Group().get(), out); }
static bool isValid(gsl::not_null< H5::Group *> group, std::ostream *out=nullptr)
Is "group" a valid shape, according to the spec.?
Definition: Shapes.cpp:183
virtual Group_HDF_shared_ptr getHDF5Group() const =0
Get the fundamental HDF5 object that the group is built on.
Here is the call graph for this function:

◆ openShape() [1/3]

Shape::Shape_Type icedb::Shapes::Shape::openShape ( Groups::Group grpshp)
static

Re-open a group as a shape

Returns
the shape object on success
Exceptions
ifthe group is not a valid shape

Definition at line 227 of file Shapes.cpp.

References icedb::Groups::Group::getHDF5Group().

Referenced by openShape().

227  {
228  return openShape(grpshp.getHDF5Group());
229  }
static Shape_Type openShape(Groups::Group &grpshp)
Definition: Shapes.cpp:227
Here is the call graph for this function:
Here is the caller graph for this function:

◆ openShape() [2/3]

Shape::Shape_Type icedb::Shapes::Shape::openShape ( Groups::Group owner,
const std::string &  name 
)
static

Open a group's subgroup as a shape.

Definition at line 222 of file Shapes.cpp.

References icedb::Groups::Group::doesGroupExist(), icedb::Groups::Group::openGroup(), and openShape().

222  {
223  assert(owner.doesGroupExist(name));
224  return openShape(owner.openGroup(name)->getHDF5Group());
225  }
static Shape_Type openShape(Groups::Group &grpshp)
Definition: Shapes.cpp:227
const std::string name
The name of the group.
Definition: Group.hpp:34
Here is the call graph for this function:

◆ openShape() [3/3]

Shape::Shape_Type icedb::Shapes::Shape::openShape ( Groups::Group::Group_HDF_shared_ptr  shape)
static

Re-open an open HDF5 group as a shape.

Definition at line 432 of file Shapes.cpp.

References isShape().

432  {
433  // Get UUID
434  //res->writeAttribute<std::string>("particle_id", { 1 }, { required->particle_id });
435  Expects(isShape(shape.get()));
436  //Expects(shape->attrExists("particle_id")); // Expects(isShape(shape.get())) subsumes this.
437  auto id = Attributes::CanHaveAttributes::readAttribute<std::string>(shape.get(),"particle_id");
438 
439  Shape::Shape_Type res = std::make_unique<Shape_impl>(id.data[0], shape);
440  return res;
441  }
bool isShape() const
Is this object actually a shape?
Definition: Shapes.cpp:178
std::unique_ptr< Shape > Shape_Type
The preferred C++ type for referencing a shape.
Definition: shape.hpp:145
Here is the call graph for this function:

Member Data Documentation

◆ _icedb_obj_type_shape_identifier

const std::string icedb::Shapes::Shape::_icedb_obj_type_shape_identifier = "shape"
static

Each shape 'group' has an attribute with this identifier. Used for shape collection and searching.

Definition at line 118 of file shape.hpp.

Referenced by Shape().

◆ particle_unique_id

const std::string icedb::Shapes::Shape::particle_unique_id

This is the unique identifier for this shape.

Definition at line 194 of file shape.hpp.


The documentation for this class was generated from the following files: