2 #include "../icedb/Table.hpp" 3 #include "../icedb/Group.hpp" 4 #include "../private/Table_impl.hpp" 5 #include "../private/Attribute_impl.hpp" 6 #include "../private/hdf5_supplemental.hpp" 31 Expects(scale->valid());
34 auto tblscaleptr = scale->_getTableSelf();
35 const herr_t res = H5DSattach_scale(selfptr->getId(), tblscaleptr->getId(),
static_cast<unsigned int>(DimensionNumber));
41 Expects(scale->valid());
44 auto tblscaleptr = scale->_getTableSelf();
45 const herr_t res = H5DSdetach_scale(selfptr->getId(), tblscaleptr->getId(),
static_cast<unsigned int>(DimensionNumber));
100 const htri_t res = H5DSis_scale(selfptr->getId());
102 if (res > 0)
return true;
110 const htri_t res = H5DSset_scale(selfptr->getId(), dimensionScaleName.c_str());
118 const htri_t res = H5DSset_label(selfptr->getId(),
static_cast<unsigned int>(DimensionNumber), label.c_str());
126 constexpr
size_t max_label_size = 1000;
127 std::array<char, max_label_size> label;
129 const ssize_t res = H5DSget_label(selfptr->getId(),
static_cast<unsigned int>(DimensionNumber), label.data(), max_label_size);
132 label[max_label_size - 1] =
'\0';
133 return std::string(label.data());
139 constexpr
size_t max_label_size = 1000;
140 std::array<char, max_label_size> label;
142 const ssize_t res = H5DSget_scale_name(selfptr->getId(), label.data(), max_label_size);
145 label[max_label_size - 1] =
'\0';
146 return std::string(label.data());
152 if (fs::hdf5::isType<uint64_t, H5::DataSet>(selfptr.get()))
return (
typeid(uint64_t));
153 if (fs::hdf5::isType<int64_t, H5::DataSet>(selfptr.get()))
return (
typeid(int64_t));
154 if (fs::hdf5::isType<uint32_t, H5::DataSet>(selfptr.get()))
return (
typeid(uint32_t));
155 if (fs::hdf5::isType<int32_t, H5::DataSet>(selfptr.get()))
return (
typeid(int32_t));
156 if (fs::hdf5::isType<uint16_t, H5::DataSet>(selfptr.get()))
return (
typeid(uint16_t));
157 if (fs::hdf5::isType<int16_t, H5::DataSet>(selfptr.get()))
return (
typeid(int16_t));
158 if (fs::hdf5::isType<uint8_t, H5::DataSet>(selfptr.get()))
return (
typeid(uint8_t));
159 if (fs::hdf5::isType<int8_t, H5::DataSet>(selfptr.get()))
return (
typeid(int8_t));
160 if (fs::hdf5::isType<double, H5::DataSet>(selfptr.get()))
return (
typeid(
double));
161 if (fs::hdf5::isType<float, H5::DataSet>(selfptr.get()))
return (
typeid(
float));
162 if (fs::hdf5::isType<char, H5::DataSet>(selfptr.get()))
return (
typeid(
char));
163 if (fs::hdf5::isType<std::string, H5::DataSet>(selfptr.get()))
return (
typeid(std::string));
167 template <
class DataType,
class ObjectType>
169 std::vector<size_t> &dims,
170 std::vector<DataType> &tdata,
171 gsl::not_null<ObjectType*> obj)
174 for (
const auto &s : dims) sz *= s;
176 icedb::fs::hdf5::readDatasetArray<DataType, H5::DataSet>(obj, tdata.data());
179 template <
class DataType>
181 std::vector<size_t> &dims,
182 std::vector<DataType> &data)
const 188 for (
const auto &s : dims) sz *= s;
191 pullData<DataType, H5::DataSet>(dims, data, selfptr.get());
194 template <
class DataType,
class ObjectType>
196 const std::vector<size_t> &dims,
197 gsl::not_null<ObjectType*> obj,
198 const std::vector<DataType> &data)
201 for (
const auto &s : dims) numElems *= s;
202 Expects(numElems > 0);
204 icedb::fs::hdf5::writeDatasetArray<DataType, ObjectType>(dims, obj, data.data());
220 template <
class DataType>
223 Expects(isTableOfType<DataType>());
227 for (
const auto &d : dimensionality) sz *= d;
228 Expects(outData.size() == sz);
229 icedb::fs::hdf5::writeDatasetArray<DataType, H5::DataSet>(dimensionality, selfptr.get(), outData.data());
233 #define INST_WRITE_TBL_INNER_TYPE(x) \ 234 template void Table::writeAllInner<x>(const gsl::span<const x> &outData) const; 238 #define INST_READ_TBL_TYPE(x) \ 239 template void Table::readAll<x>( \ 240 std::vector<size_t> &dims, \ 241 std::vector<x> &data) const; 251 const std::string &tableName,
252 const std::type_index& type_id,
253 const std::vector<size_t> &dims,
254 const std::vector<size_t> &chunks)
257 std::vector<hsize_t> hdata;
258 for (
const auto &d : dims) hdata.push_back(static_cast<hsize_t>(d));
259 std::vector<hsize_t> cdata;
260 for (
const auto &c : chunks) cdata.push_back(static_cast<hsize_t>(c));
265 std::shared_ptr<H5::DSetCreatPropList> plist = std::make_shared<H5::DSetCreatPropList>();
267 plist->setFillValue(H5::PredType::NATIVE_INT, &fillvalue);
268 plist->setChunk(static_cast<int>(cdata.size()), cdata.data());
272 #if ICEDB_H5_CREATEPROPLIST_SETATTRCRTORDER == 1 273 plist->setAttrCrtOrder(H5P_CRT_ORDER_TRACKED | H5P_CRT_ORDER_INDEXED);
276 hid_t
id = plist->getId();
277 herr_t e = H5Pset_attr_creation_order(
id, H5P_CRT_ORDER_TRACKED | H5P_CRT_ORDER_INDEXED);
282 if (type_id ==
typeid(uint64_t))fs::hdf5::createDatasetRaw<uint64_t, H5::Group>(_getTablesParent().get(), tableName.c_str(), dims, plist);
283 else if (type_id ==
typeid(int64_t))fs::hdf5::createDatasetRaw<int64_t, H5::Group>(_getTablesParent().get(), tableName.c_str(), dims, plist);
284 else if (type_id ==
typeid(uint32_t))fs::hdf5::createDatasetRaw<uint32_t, H5::Group>(_getTablesParent().get(), tableName.c_str(), dims, plist);
285 else if (type_id ==
typeid(int32_t))fs::hdf5::createDatasetRaw<int32_t, H5::Group>(_getTablesParent().get(), tableName.c_str(), dims, plist);
286 else if (type_id ==
typeid(uint16_t))fs::hdf5::createDatasetRaw<uint16_t, H5::Group>(_getTablesParent().get(), tableName.c_str(), dims, plist);
287 else if (type_id ==
typeid(int16_t))fs::hdf5::createDatasetRaw<int16_t, H5::Group>(_getTablesParent().get(), tableName.c_str(), dims, plist);
288 else if (type_id ==
typeid(uint8_t))fs::hdf5::createDatasetRaw<uint8_t, H5::Group>(_getTablesParent().get(), tableName.c_str(), dims, plist);
289 else if (type_id ==
typeid(int8_t))fs::hdf5::createDatasetRaw<int8_t, H5::Group>(_getTablesParent().get(), tableName.c_str(), dims, plist);
290 else if (type_id ==
typeid(
float))fs::hdf5::createDatasetRaw<float, H5::Group>(_getTablesParent().get(), tableName.c_str(), dims, plist);
291 else if (type_id ==
typeid(
double))fs::hdf5::createDatasetRaw<double, H5::Group>(_getTablesParent().get(), tableName.c_str(), dims, plist);
292 else if (type_id ==
typeid(
char))fs::hdf5::createDatasetRaw<char, H5::Group>(_getTablesParent().get(), tableName.c_str(), dims, plist);
293 else if (type_id ==
typeid(std::string))fs::hdf5::createDatasetRaw<std::string, H5::Group>(_getTablesParent().get(), tableName.c_str(), dims, plist);
294 else throw(std::invalid_argument(
"Unhandled data type"));
299 auto base = _getTablesParent();
301 std::set<std::string> res;
302 for (
const auto &o : objs)
304 if (o.second == H5G_obj_t::H5G_DATASET) res.insert(o.first);
310 const auto tnames = getTableNames();
311 if (tnames.count(tableName))
return true;
317 auto base = _getTablesParent();
318 base->unlink(tableName.c_str());
323 const auto base = _getTablesParent();
324 const auto tbl = std::make_shared<H5::DataSet>(base->openDataSet(tableName));
size_t getNumDimensions() const
Returns the number of dimensions of a table.
void _setTableSelf(std::shared_ptr< H5::DataSet > obj) override
Associates the icedb table with the fundamental HDF5 DataSet. Only used internally.
void unlinkTable(const std::string &tableName)
Unlink a table. In HDF5, this is not the same as erasing a table, which never actually happens...
std::unique_ptr< Table > Table_Type
The preferred method of access of a Table is through std::unique_ptr.
Table(const std::string &name="")
Default constructor, used by CanHaveTables.
const std::string name
The name of the Table.
void setDimensionScale(const std::string &dimensionScaleName)
Designate this table as a dimension scale.
INST_ATTR(INST_WRITE_TBL_INNER_TYPE)
bool doesTableExist(const std::string &tableName) const
Does a table exist with the given name.
virtual void _setAttributeParent(std::shared_ptr< H5::H5Object > obj) override
CanHaveTables()
Trivial constructor used when CanHaveTables is a virtual base class.
void readAll(std::vector< size_t > &dims, std::vector< DataType > &data) const
Read all of the data in the associated table.
void attachDimensionScale(size_t DimensionNumber, gsl::not_null< const Table *> scale)
std::string getDimensionScaleName() const
Get the name of this table's defined dimension scale.
Table::Table_Type openTable(const std::string &tableName)
bool valid() const
Checks that the class is well-formed, constructed and activated. CanHaveTables needs post-constructor...
virtual ~CanHaveTables_impl()
void _setTablesParent(std::shared_ptr< H5::Group > obj) override
CanHaveTables needs post-constructor setup. This sets the base HDF5 object that gets manipulated...
Dimensions_Type getDimensions() const
Returns a vector containing the dimensions of the table.
bool isDimensionScale() const
Is this Table used as a dimension scale?
std::shared_ptr< H5::DataSet > _getTableSelf() const override
Gets the fundamental HDF5 DataSet associated with the table. Only used internally.
void writeAllInner(const gsl::span< const DataType > &outData) const
std::vector< size_t > Dimensions_Type
The dimensions of a Table are expressed as a vector of unsigned integers.
void readDatasetDimensions(gsl::not_null< H5::DataSet *> dataset, std::vector< size_t > &dims)
Table_impl(std::shared_ptr< H5::DataSet > obj, const std::string &name="")
#define INST_READ_TBL_TYPE(x)
bool valid() const
Checks that Table is well-formed during runtime. Only used internally.
std::shared_ptr< H5::Group > _getTablesParent() const override
Gets the base HDF5 object that is manipulated.
void setDimensionScaleAxisLabel(size_t DimensionNumber, const std::string &label)
Set the axis label for the dimension designated by DimensionNumber.
std::string getDimensionScaleAxisLabel(size_t DimensionNumber) const
Get the axis label for the dimension designated by DimensionNumber.
void pushData(const std::vector< size_t > &dims, gsl::not_null< ObjectType *> obj, const std::vector< DataType > &data)
std::shared_ptr< H5::DataSet > obj
void detachDimensionScale(size_t DimensionNumber, gsl::not_null< const Table *> scale)
Detaches a dimension scale from this table.
void _createTable(const std::string &tableName, const std::type_index &type, const std::vector< size_t > &dims, const std::vector< size_t > &chunks)
Internal function to create a table. Does not write data.
size_t readDatasetNumDimensions(gsl::not_null< H5::DataSet *> dataset)
std::map< std::string, H5G_obj_t > getGroupMembersTypes(const ICEDB_H5_GETNUMOBJS_OWNER &base)
std::set< std::string > getTableNames() const
Lists all table names that are children of this object.
#define INST_WRITE_TBL_INNER_TYPE(x)
void pullData(std::vector< size_t > &dims, std::vector< DataType > &tdata, gsl::not_null< ObjectType *> obj)
virtual std::shared_ptr< H5::DataSet > _getTableSelf() const =0
Gets the fundamental HDF5 DataSet associated with the table. Only used internally.
std::type_index getTableTypeId() const
Get the type of the table (i.e. int64_t, float, etc.)