Merge branch 'restructure-rename' into dev

This commit is contained in:
Christian Zimmermann 2023-01-22 15:42:06 +01:00
commit 69a9344790
5 changed files with 161 additions and 8 deletions

View file

@ -0,0 +1,25 @@
#ifndef __cxz_h5_table_cc_h__
#define __cxz_h5_table_cc_h__
#include "h5_table.h"
namespace CNORXZ
{
namespace hdf5
{
template <class F>
decltype(auto) iterRecords(F&& f) const
{
}
template <typename... Ts>
Table& appendRecord(const Tuple<Ts...>& t) const
{
}
}
}
#endif

View file

@ -22,15 +22,24 @@ namespace CNORXZ
virtual String path() const override final; virtual String path() const override final;
virtual String filename() const override final; virtual String filename() const override final;
Table& openDSet();
template <class F> template <class F>
decltype(auto) readRecords(F&& f) const; decltype(auto) iterRecords(F&& f) const;
template <typename... Ts>
Table& appendRecord(const Tuple<Ts...>& t) const;
template <typename... Ts>
Table& appendRecord(const MArray<Tuple<Ts...>>& t) const;
private: private:
RangePtr mRecords; RangePtr mRecords;
RangePtr mFields; // -> FIndex (position -> offset) RangePtr mFields; // -> FIndex (position -> offset)
MArray mSizes; MArray<SizeT> mSizes;
MArray mOffsets; MArray<SizeT> mOffsets;
MArray mTypes; MArray<hid_t> mTypes;
hid_t mType;
}; };
} }
} }

View file

@ -3,6 +3,7 @@ set(libcnorxzhdf5_a_SOURCES
${CMAKE_CURRENT_SOURCE_DIR}/h5_content_base.cc ${CMAKE_CURRENT_SOURCE_DIR}/h5_content_base.cc
${CMAKE_CURRENT_SOURCE_DIR}/h5_file.cc ${CMAKE_CURRENT_SOURCE_DIR}/h5_file.cc
${CMAKE_CURRENT_SOURCE_DIR}/h5_group.cc ${CMAKE_CURRENT_SOURCE_DIR}/h5_group.cc
${CMAKE_CURRENT_SOURCE_DIR}/h5_table.cc
) )
add_library(cnorxzhdf5_obj OBJECT add_library(cnorxzhdf5_obj OBJECT

View file

@ -1,5 +1,6 @@
#include "h5_group.h" #include "h5_group.h"
#include "h5_table.h"
namespace CNORXZ namespace CNORXZ
{ {
@ -110,6 +111,26 @@ namespace CNORXZ
return 0; return 0;
} }
static bool isTable(hid_t id)
{
if(not H5Aexists(id, "CLASS")){
return false;
}
hid_t attrid = H5Aopen(id, "CLASS", H5P_DEFAULT);
const hid_t atype = H5Aget_type(attrid);
const SizeT asize = H5Tget_size(atype);
Vector<char> buff(asize);
const herr_t ret = H5Aread(attrid, atype, buff.data());
H5Tclose(atype);
H5Aclose(attrid);
if(ret != 0){
return false;
}
else {
return String(buff.data()) == "TABLE";
}
}
static herr_t initCont(hid_t id, const char* name, const H5L_info_t* info, void* x) static herr_t initCont(hid_t id, const char* name, const H5L_info_t* info, void* x)
{ {
const String sname(name); const String sname(name);
@ -129,11 +150,17 @@ namespace CNORXZ
case H5O_TYPE_GROUP: { case H5O_TYPE_GROUP: {
*index = std::make_shared<Group>(sname, icd->parent); *index = std::make_shared<Group>(sname, icd->parent);
break; break;
}/* }
case H5O_TYPE_DATASET: { case H5O_TYPE_DATASET: {
*index = std::make_shared<DSet>(sname, ); if(isTable(id)){
*index = std::make_shared<Table>(sname, icd->parent);
}
else {
CXZ_ERROR("IMPLEMENT!!!");
//*index = std::make_shared<DSet>(sname, icd->parent);
}
break; break;
}*/ }
default: default:
return 1; return 1;
} }

View file

@ -0,0 +1,91 @@
#include <hdf5_hl.h>
#include "h5_table.h"
namespace CNORXZ
{
namespace hdf5
{
Table::Table(const String& name, const ContentBase* _parent) :
ContentBase(name, _parent)
{}
Table::~Table()
{
this->close();
}
ContentType Table::type() const
{
return ContentType::TABLE;
}
bool Table::ro() const
{
return mParent->ro();
}
Table& Table::open()
{
if(H5Oexists_by_name(mParent->id(), mName.c_str(), H5P_DEFAULT)){
hsize_t nfields = 0;
hsize_t nrecords = 0;
H5TBget_table_info(mParent->id(), mName.c_str(), &nfields, &nrecords);
mRecords = CRangeFactory( nrecords ).create();
Vector<char*> fieldsptr(nfields);
Vector<SizeT> offsets(nfields);
Vector<SizeT> sizes(nfields);
SizeT typesize = 0;
H5TBget_field_info(mParent->id(), mName.c_str(), fieldsptr.data(), sizes.data(),
offsets.data(), &typesize);
Vector<String> fields(nfields);
for(SizeT i = 0; i != nfields; ++i){
fields[i] = fieldsptr[i];
}
mFields = URangeFactory<String>( std::move(fields) ).create();
mSizes = MArray<SizeT>(mFields, std::move(sizes));
mOffsets = MArray<SizeT>(mFields, std::move(offsets));
this->openDSet();
const SizeT n = H5Tget_nmembers(mType);
CXZ_ASSERT(n == mFields->size(),
"number of dataset members does not match number of fields: "
<< n << " vs " << mFields->size());
Vector<hid_t> types(n);
for(SizeT i = 0; i != n; ++i){
types[i] = H5Tget_member_class( mType, i );
}
mTypes = MArray<hid_t>(mFields, std::move(types));
}
return *this;
}
Table& Table::close()
{
if(mId != 0){
H5Tclose(mType);
H5Dclose(mId);
}
return *this;
}
String Table::path() const
{
return mParent->path() + "/" + mName;
}
String Table::filename() const
{
return mParent->filename();
}
Table& Table::openDSet()
{
if(mId == 0){
mId = H5Dopen(mParent->id(), mName.c_str(), H5P_DEFAULT);
mType = H5Dget_type(mId);
}
return *this;
}
}
}