20 #include "SheafSystem/record_set.h" 22 #include "SheafSystem/data_converter.h" 23 #include "SheafSystem/error_message.h" 24 #include "SheafSystem/namespace_poset.h" 25 #include "SheafSystem/record_index.h" 26 #include "SheafSystem/assert_contract.h" 27 #include "SheafSystem/sheaf_file.h" 28 #include "SheafSystem/record.h" 61 ensure(is_same_type(result));
81 result = result && any::invariant();
87 disable_invariant_check();
89 invariance(file().is_open());
90 invariance(!name().empty());
91 invariance(record_buffer_ub() >= 0);
92 invariance(record_buffer_ct() >= 0);
93 invariance(record_buffer_ct() <= record_buffer_ub());
97 enable_invariant_check();
121 bool result =
dynamic_cast<const record_set*
>(other) != 0;
138 _name(xscaffold.structure().name()),
139 _record_buffer_ub(xrecord_buffer_ub),
146 require(xrecord_buffer_ub > 0);
231 string result(
_name);
235 ensure(!result.empty());
295 static const string result;
318 if(
scaffold().structure_is_namespace())
324 result = xname +
suffix();
350 if(
scaffold().structure_is_namespace())
356 result = xname +
suffix();
385 string::size_type lname_begin;
388 lname_begin = lprefix_len;
399 string::size_type lname_len = lsuffix_begin - lname_begin;
401 string result(
_name.substr(lname_begin, lname_len));
458 #ifdef DIAGNOSTIC_OUTPUT 460 cout <<
"record_set::open: opening dataset " <<
alias() << endl;
477 if(
file().
mode() == sheaf_file::READ_WRITE)
481 #ifdef DIAGNOSTIC_OUTPUT 482 cout << endl <<
"record_set::open: open failed, creating dataset " <<
name() << endl << endl;
499 post_fatal_error_message(
"dataset doesn't exist");
509 if(
file().mode() == sheaf_file::READ_ONLY)
537 post_fatal_error_message(
"unable to get dataspace of open dataset");
543 post_fatal_error_message(
"unable to get data type of open dataset");
549 post_fatal_error_message(
"unable to get dimensions of open dataset");
597 if(
file().mode() == sheaf_file::READ_WRITE)
724 require(
file().mode() == sheaf_file::READ_WRITE);
773 #ifdef DIAGNOSTIC_OUTPUT 775 cout <<
"record_set::extend_dataset: dataspace extent:" 776 <<
"xdims_ub= " << xdims_ub <<
"xdims= ";
777 for(
int i=0; i<xdims_ub; i++)
779 cout <<
" " << xdims[i];
786 herr_t status = H5Dextend(
_hdf_id, xdims);
789 post_fatal_error_message(
"can't extend member record dataset");
797 post_fatal_error_message(
"can't close member record set dataspace");
805 post_fatal_error_message(
"can't get extended member record set dataspace");
808 #ifdef DIAGNOSTIC_OUTPUT 809 cout <<
"record_set::extend_dataset: dataspace extent:";
822 post_fatal_error_message(
"unable to get dimensions of extended dataset");
825 #ifdef DIAGNOSTIC_OUTPUT 826 cout <<
"record_set::extend_dataset: dataspace extent:";
837 ensure(unexecutable(
"for all 0 <= i < ext_dataspace_rank(): ext_dataspace_dim(i) == xdims[i]"));
864 post_fatal_error_message(
"can't create soft link for alias");
869 ensure(unexecutable(
"link from alias to data set exists"));
894 herr_t status = H5Gget_objinfo(
file().
hdf_id(),
_alias.c_str(), lfalse, &lstatbuf);
897 post_fatal_error_message(
"can't get_objinfo for alias");
902 char* lname =
new char[lstatbuf.linklen];
903 status = H5Gget_linkval(
file().
hdf_id(),
_alias.c_str(), lstatbuf.linklen, lname);
906 post_fatal_error_message(
"can't get_linkval for alias");
919 ensure(!
name().empty());
1013 ensure(unexecutable(
"all attributes opened, read, and closed"));
1035 ensure(unexecutable(
"all attributes created, written, and closed"));
1048 const std::string& xatt_name)
1053 require(xatt_values == 0);
1054 require(xatt_ct == 0);
1055 require(xatt_conv != 0);
1056 require(!xatt_name.empty());
1061 #ifdef DIAGNOSTIC_OUTPUT 1063 cout <<
"record_set::read_attribute poset name: " 1072 hid_t latt_hdf_id = H5Aopen_name(
_hdf_id, xatt_name.c_str());
1073 if(latt_hdf_id >= 0)
1077 hid_t latt_dataspace_hdf_id = H5Aget_space(latt_hdf_id);
1078 if(latt_dataspace_hdf_id < 0)
1080 string lmsg(
"Unable to get dataspace for attribute ");
1082 post_fatal_error_message(lmsg.c_str());
1086 lstatus = H5Sget_simple_extent_dims(latt_dataspace_hdf_id, &latt_ct, NULL);
1089 string lmsg(
"Unable to get extent for attribute ");
1091 post_fatal_error_message(lmsg.c_str());
1099 xatt_values =
new char[xatt_ct];
1103 lstatus = H5Aread(latt_hdf_id, xatt_conv->
internal_type(),
const_cast<char*&
>(xatt_values));
1106 string lmsg(
"Unable to read attribute ");
1108 post_fatal_error_message(lmsg.c_str());
1113 H5Sclose(latt_dataspace_hdf_id);
1114 H5Aclose(latt_hdf_id);
1124 ensure((xatt_values == 0) == (xatt_ct == 0));
1138 const std::string& xatt_name)
1142 require(xatt_values != 0);
1143 require(xatt_ct > 0);
1144 require(xatt_conv != 0);
1145 require(!xatt_name.empty());
1157 lstatus = H5Adelete(
_hdf_id, xatt_name.c_str());
1161 hid_t latt_dataspace_hdf_id = H5Screate(H5S_SIMPLE);
1162 if(latt_dataspace_hdf_id < 0)
1164 string lmsg(
"Unable to create dataspace for attribute ");
1167 post_fatal_error_message(lmsg.c_str());
1172 hsize_t hatt_ct = xatt_ct;
1173 lstatus = H5Sset_extent_simple(latt_dataspace_hdf_id, 1, &hatt_ct, NULL);
1176 string lmsg(
"Unable to set extent for attribute ");
1178 post_fatal_error_message(lmsg.c_str());
1184 hid_t latt_hdf_id = H5Acreate1(
_hdf_id,
1187 latt_dataspace_hdf_id,
1191 string lmsg(
"Unable to create attribute ");
1193 post_fatal_error_message(lmsg.c_str());
1198 lstatus = H5Awrite(latt_hdf_id, xatt_conv->
internal_type(), xatt_values);
1201 string lmsg(
"Unable to write attribute ");
1203 post_fatal_error_message(lmsg.c_str());
1208 H5Sclose(latt_dataspace_hdf_id);
1211 H5Aclose(latt_hdf_id);
An encapsulation of an HDF file containing sheaf data.
sheaf_file & _file
The file this record_set belongs to.
int _ext_dataspace_rank
The rank of the dataspace for the record_set.
virtual void open()
Opens the record_set.
hsize_t * _ext_dataspace_dims
The current dimensions of the external dataspace.
void reset_record_buffer_ct()
The set the number of active records in record buffer to 0.
hid_t external_type() const
The external type identifier.
size_t internal_size() const
The size in bytes of the internal type.
bool record_buffer_is_full() const
True if there are no inactive records in the buffer.
hsize_t ext_dataspace_dim(int xi)
The dimension of xi-th index of the external dataspace.
virtual void close()
Closes the record_set.
std::string data_set_alias(const std::string &xname) const
The data set alias for a poset with name xname.
virtual void create_int_data_type()=0
Creates a new HDF internal data type. Defined in descendants.
static const std::string & name_space_prefix()
The reserved, standard prefix for namespace dataser names.
std::string poset_name() const
The name of the poset this represents, extracted from the name of the dataset.
record_set(const sheaf_file &xfile, int xrecord_buffer_ub, const poset_scaffold &xscaffold)
Creates an instance attached to the record_set with name xname in the file xfile, using record packet...
int record_buffer_ct() const
The number of active records in record buffer.
void extend_dataset(const hsize_t *xdims, int xdims_ub)
Extends the dataset dimensions to at least the dimensions given xdims, an array of length xdims_ub...
virtual record_set * clone() const
Virtual constructor; makes a new instance of the same type as this. Not implemented since this class ...
int _record_buffer_ub
The maximum number of records the buffer can hold.
virtual bool is_ancestor_of(const any *other) const
Conformance test; true if other conforms to this.
bool record_buffer_is_empty() const
True if there are no active records in the buffer.
bool is_open() const
True if this record_set is open.
poset_scaffold & _scaffold
The poset scaffold associated with this.
hid_t int_data_type_hdf_id()
The HDF internal data type id for this record set.
std::string alias() const
The standard alias for this data set.
static const std::string & name_space_alias()
The reserved, standard alias for the namespace in the file.
hid_t _hdf_id
The HDF id for this record set.
virtual bool invariant() const
Class invariant.
Abstract base class with useful features for all objects.
std::string _alias
The standard alias for this record_set.
hid_t _ext_data_type_hdf_id
The HDF external data type id for this record set.
A poset specific collection of data converters, various buffers and other data used while transferrin...
hid_t _int_data_type_hdf_id
The HDF internal data type id for this record set.
bool is_open() const
True if this file is open.
std::string _name
The name of this record_set.
hid_t hdf_id()
The HDF id for this record set.
hid_t int_dataspace_hdf_id()
The hdf5 id of the internal dataspace associated with the record buffer.
virtual ~record_set()
Destructor.
int record_buffer_ub() const
The maximum number of records the buffer can hold.
int ext_dataspace_rank()
The rank of the dataspace for the record_set.
hid_t ext_data_type_hdf_id()
The HDF external data type id for this record set.
unsigned long size_type
An unsigned integral type used to represent sizes and capacities.
An abstract, indexed collection of records on secondary storage.
std::string data_set_name(const std::string &xname) const
The data set name for a poset with name xname.
access_mode mode() const
The current access mode.
static std::string reserved_prefix()
Prefix for identifying member names reserved by the sheaf system.
poset_scaffold & scaffold()
Scaffold for constructing poset associated with this record set (mutable version).
virtual std::string name() const
The name of this poset.
poset_state_handle & structure()
The handle for the poset being transferred. (Name chosen to void name conflict with class poset...
virtual void read_dataset_attributes()
Opens and reads the dataset attribute objects from the file. A stub in this class, intended to be redefined in descendants.
std::string name() const
The name of this data set.
void inc_record_buffer_ct()
The increment the number of active records in record buffer.
virtual hid_t create_dataset()=0
Creates a new HDF datset. Defined in descendants.
virtual const std::string & suffix() const
The name suffix for this data set.
poset_data_type_map & type_map()
Data type map for this poset (mutable version)
const sheaf_file & file() const
The file this record_set belongs to.
virtual void write_dataset_attributes()
Writes the dataset attribute objects into the file. A stub in this class, intended to be redefined in...
Function object to convert between internal and external data formats.
poset_data_type_map & type_map()
Data type map for records in this record set (mutable version)
void write_attribute(const void *xatt_values, size_type xatt_ct, const data_converter *xatt_conv, const std::string &xatt_name)
Writes the attribute with name xatt_name into the file.
hid_t ext_dataspace_hdf_id()
The HDF id for the external dataspace of this record set.
A poset specific collection of data converters, various buffers and other data used while transferrin...
void create_alias()
Creates a soft link from alias to the data set.
static const hid_t NOT_AN_HDF_ID
Value indicating an invalid HDf object id. /.
hid_t internal_type() const
The HDF type identifier for the internal type.
void read_attribute(const char *&xatt_values, size_type &xatt_ct, const data_converter *xatt_conv, const std::string &xatt_name)
Reads the attribute with name xatt_name from the file.
void set_name_from_alias()
Sets the primary name of the dataset from the alias.
hid_t _ext_dataspace_hdf_id
The HDF id for the external dataspace of this record set.
int _record_buffer_ct
The number of active records in record buffer.
hid_t _int_dataspace_hdf_id
The hdf5 id of the dataspace associated with the record buffer.