hdf5: preliminary append (init) table test
This commit is contained in:
parent
6faaf7ea15
commit
58fa19f514
9 changed files with 66 additions and 11 deletions
|
@ -243,6 +243,12 @@ namespace CNORXZ
|
|||
return mSpace[pos];
|
||||
}
|
||||
|
||||
template <typename MetaType>
|
||||
const MetaType* URange<MetaType>::get() const
|
||||
{
|
||||
return mSpace.data();
|
||||
}
|
||||
|
||||
template <typename MetaType>
|
||||
SizeT URange<MetaType>::getMeta(const MetaType& meta) const
|
||||
{
|
||||
|
|
|
@ -99,6 +99,7 @@ namespace CNORXZ
|
|||
virtual RangePtr extend(const RangePtr& r) const override final;
|
||||
|
||||
const MetaType& get(SizeT pos) const;
|
||||
const MetaType* get() const;
|
||||
SizeT getMeta(const MetaType& metaPos) const;
|
||||
|
||||
private:
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
|
||||
#include "cnorxz.h"
|
||||
#include <hdf5.h>
|
||||
#include <hdf5_hl.h>
|
||||
|
||||
namespace CNORXZ
|
||||
{
|
||||
|
|
|
@ -19,7 +19,17 @@ namespace CNORXZ
|
|||
const RangePtr& fields)
|
||||
{
|
||||
CXZ_ASSERT(this->isOpen(), "tried to extend closed group");
|
||||
|
||||
Vector<String> nvec({name});
|
||||
Vector<DType> dvec({DType(name)});
|
||||
auto extr = URangeFactory<String>( nvec ).create();
|
||||
mCont.extend(extr);
|
||||
auto ii = mCont.begin();
|
||||
ii.at(dvec); // 'at' returns YIndex&, so cannot use it inline...
|
||||
auto tab = std::make_shared<STable<Ts...>>(name, this, fields);
|
||||
for(auto& d: data){
|
||||
tab->appendRecord(d);
|
||||
}
|
||||
*ii = tab;
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
|
|
@ -31,20 +31,20 @@ namespace CNORXZ
|
|||
|
||||
Tuple<Ts...> x;
|
||||
if(mRecords == nullptr) {
|
||||
auto mOffsets = MArray<SizeT>( mFields, iter<0,N>
|
||||
( [&](auto i) { return &std::get<i>(x) - &x; },
|
||||
mOffsets = MArray<SizeT>( mFields, iter<0,N>
|
||||
( [&](auto i) { return getTupleOffset(x, i); },
|
||||
[](const auto&... e) { return Vector<SizeT>({e...}); }) );
|
||||
auto mSizes = MArray<SizeT>( mFields, iter<0,N>
|
||||
mSizes = MArray<SizeT>( mFields, iter<0,N>
|
||||
( [&](auto i) { return sizeof(std::get<i>(x)); },
|
||||
[](const auto&... e) { return Vector<SizeT>({e...}); }) );
|
||||
auto mTypes = MArray<hid_t>( mFields, iter<0,N>
|
||||
mTypes = MArray<hid_t>( mFields, iter<0,N>
|
||||
( [&](auto i) { return getTypeId(std::get<i>(x)); },
|
||||
[](const auto&... e) { return Vector<hid_t>({e...}); }) );
|
||||
}
|
||||
else {
|
||||
iter<0,N>( [&](auto i) { CXZ_ASSERT
|
||||
( &std::get<i>(x) - &x == mOffsets.data()[i],
|
||||
"wrong offset for field " << i << ": " << &std::get<i>(x) - &x
|
||||
( getTupleOffset(x, i) == mOffsets.data()[i],
|
||||
"wrong offset for field " << i << ": " << getTupleOffset(x, i)
|
||||
<< " vs " << mOffsets.data()[i] ); }, NoF{} );
|
||||
iter<0,N>( [&](auto i) { CXZ_ASSERT
|
||||
( sizeof(std::get<i>(x)) == mSizes.data()[i],
|
||||
|
@ -60,15 +60,25 @@ namespace CNORXZ
|
|||
template <typename... Ts>
|
||||
STable<Ts...>& STable<Ts...>::appendRecord(const Tuple<Ts...>& t)
|
||||
{
|
||||
constexpr hsize_t chunk_size = sizeof(t);
|
||||
constexpr Int compress = 0;
|
||||
RangePtr appr = CRangeFactory(1).create();
|
||||
if(mRecords == nullptr){
|
||||
mRecords = appr;
|
||||
Vector<const char*> fields(mFields->size());
|
||||
auto fr = std::dynamic_pointer_cast<URange<String>>(mFields);
|
||||
for(auto fi = fr->begin(); fi != fr->end(); ++fi){
|
||||
fields[fi.lex()] = (*fi).c_str();
|
||||
}
|
||||
H5TBmake_table(mName.c_str(), mParent->id(), mName.c_str(), mFields->size(),
|
||||
mRecords->size(), sizeof(t), fields.data(), mOffsets.data(),
|
||||
mTypes.data(), chunk_size, NULL, compress, &t);
|
||||
}
|
||||
else {
|
||||
mRecords = mRecords->extend(appr);
|
||||
H5TBappend_records(mParent->id(), mName.c_str(), 1, sizeof(t),
|
||||
mOffsets.data(), mSizes.data(), &t);
|
||||
}
|
||||
H5TBappend_records(mParent->id(), mName, 1, sizeof(t),
|
||||
mOffsets.data(), mSizes.data(), &t);
|
||||
return *this;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -26,7 +26,7 @@ namespace CNORXZ
|
|||
Table& appendRecord(SizeT n, const char* data);
|
||||
Table& readRecord(SizeT pos, SizeT n, char* data);
|
||||
|
||||
private:
|
||||
protected:
|
||||
RangePtr mRecords;
|
||||
RangePtr mFields; // -> FIndex (position -> offset)
|
||||
MArray<SizeT> mSizes;
|
||||
|
|
|
@ -2,10 +2,24 @@
|
|||
#ifndef __cxz_h5_types_cc_h__
|
||||
#define __cxz_h5_types_cc_h__
|
||||
|
||||
#include "base/types.h"
|
||||
|
||||
namespace CNORXZ
|
||||
{
|
||||
namespace hdf5
|
||||
{
|
||||
template <SizeT N, typename... Ts>
|
||||
SizeT getTupleOffset(const Tuple<Ts...>& t, CSizeT<N> i)
|
||||
{
|
||||
const PtrId beg = reinterpret_cast<PtrId>(&t);
|
||||
const PtrId pos = reinterpret_cast<PtrId>(&std::get<i>(t));
|
||||
return pos - beg;
|
||||
}
|
||||
|
||||
/**************
|
||||
* TypeId *
|
||||
**************/
|
||||
|
||||
template <typename T>
|
||||
inline hid_t TypeId<T>::get()
|
||||
{
|
||||
|
@ -34,6 +48,10 @@ namespace CNORXZ
|
|||
return arrtype;
|
||||
}
|
||||
|
||||
/*****************
|
||||
* getTypeId *
|
||||
*****************/
|
||||
|
||||
template <typename T>
|
||||
hid_t getTypeId(T x)
|
||||
{
|
||||
|
|
|
@ -6,6 +6,8 @@ namespace CNORXZ
|
|||
{
|
||||
namespace hdf5
|
||||
{
|
||||
template <SizeT N, typename... Ts>
|
||||
SizeT getTupleOffset(const Tuple<Ts...>& t, CSizeT<N> i);
|
||||
|
||||
/**************
|
||||
* TypeId *
|
||||
|
@ -31,7 +33,7 @@ namespace CNORXZ
|
|||
*****************/
|
||||
|
||||
template <typename T>
|
||||
hid_t getTypeId(const T& x);
|
||||
hid_t getTypeId(T x);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -67,6 +67,13 @@ namespace
|
|||
h5f.addGroup("gr1");
|
||||
h5f.addGroup("gr2");
|
||||
EXPECT_EQ(h5f.get().size(), 2u);
|
||||
|
||||
// move to separate test:
|
||||
RangePtr rs = CRangeFactory(2).create();
|
||||
RangePtr fs = URangeFactory<String>(Vector<String>({"field1","second","real"})).create();
|
||||
Vector<Tuple<SizeT,Int,Double>> v({ {0, -6, 3.141}, {3, -8, 0.789} });
|
||||
MArray<Tuple<SizeT,Int,Double>> a(rs, std::move(v));
|
||||
std::dynamic_pointer_cast<Group>(h5f.get().data()[0])->addTable("tab1", a, fs);
|
||||
}
|
||||
|
||||
TEST_F(Group_Test, Read)
|
||||
|
|
Loading…
Reference in a new issue