Merge branch 'dev' of git.f3l.de:chizeta/cnorxz into dev

This commit is contained in:
Christian Zimmermann 2023-01-28 02:12:38 +01:00
commit 32ef2ef921
12 changed files with 158 additions and 53 deletions

View file

@ -1,4 +1,4 @@
#include "h5_types.cc.h"
#include "h5_type_id.cc.h"
#include "h5_group.cc.h"
#include "h5_table.cc.h"

View file

@ -3,6 +3,6 @@
#include "h5_file.h"
#include "h5_group.h"
#include "h5_table.h"
#include "h5_types.h"
#include "h5_type_id.h"
#include "cnorxz_hdf5.cc.h"

View file

@ -2,9 +2,9 @@
#ifndef __cxz_h5_file_h__
#define __cxz_h5_file_h__
#include "h5_types.h"
#include "h5_content_base.h"
#include "h5_group.h"
//#include <hdf5.h>
namespace CNORXZ
{

View file

@ -2,10 +2,31 @@
#ifndef __cxz_h5_group_cc_h__
#define __cxz_h5_group_cc_h__
#include "h5_group.h"
namespace CNORXZ
{
namespace hdf5
{
template <typename... Ts>
Sptr<STable<Ts...>> Group::getTable(const String& name, Tuple<Ts...> proto)
{
auto i = this->getIndexTo(name);
auto tab = std::dynamic_pointer_cast<Table>( *i );
if(tab == nullptr){
auto stab = std::dynamic_pointer_cast<STable<Ts...>>(*i);
CXZ_ASSERT(stab != nullptr, "wrong format for table '" << name << "'");
return stab;
}
else {
const RangePtr fields = tab->fields();
(*i)->close();
*i = std::make_shared<STable<Ts...>>(name, this, fields);
return *i;
}
}
template <typename T>
Group& Group::addData(const String& name, const ArrayBase<T>& data)
{

View file

@ -2,6 +2,7 @@
#ifndef __cxz_h5_group_h__
#define __cxz_h5_group_h__
#include "h5_types.h"
#include "h5_content_base.h"
namespace CNORXZ
@ -26,6 +27,11 @@ namespace CNORXZ
const ContentPtr& get(const String& name) const;
Sptr<Group> getGroup(const String& name) const;
Sptr<Table> getTable(const String& name) const;
template <typename... Ts>
Sptr<STable<Ts...>> getTable(const String& name, Tuple<Ts...> proto);
const MArray<ContentPtr>& get() const;
Group& addGroup(const String& name);
@ -40,6 +46,8 @@ namespace CNORXZ
MArray<ContentPtr> mCont;
void mkCont();
AIndex<ContentPtr> getIndexTo(const String& name) const;
BIndex<ContentPtr> getIndexTo(const String& name);
};
}
}

View file

@ -3,7 +3,7 @@
#define __cxz_h5_table_cc_h__
#include "h5_table.h"
#include "h5_types.h"
#include "h5_type_id.h"
namespace CNORXZ
{
@ -66,24 +66,12 @@ 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<FieldID>>(mFields);
for(auto fi = fr->begin(); fi != fr->end(); ++fi){
fields[fi.lex()] = (*fi).second.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);
initTable(1, &t, sizeof(t), sizeof(t));
}
else {
mRecords = mRecords->extend(appr);
H5TBappend_records(mParent->id(), mName.c_str(), 1, sizeof(t),
mOffsets.data(), mSizes.data(), &t);
Table::appendRecord(1, &t, sizeof(t));
}
return *this;
}

View file

@ -2,6 +2,7 @@
#ifndef __cxz_h5_table_h__
#define __cxz_h5_table_h__
#include "h5_types.h"
#include "h5_content_base.h"
namespace CNORXZ
@ -25,8 +26,11 @@ namespace CNORXZ
virtual String filename() const override final;
Table& initFieldNames(const Vector<String>& fnames);
Table& appendRecord(SizeT n, const char* data);
Table& initTable(SizeT n, const void* data, SizeT dsize, SizeT chunk_size);
Table& appendRecord(SizeT n, const void* data, SizeT dsize);
Table& readRecord(SizeT pos, SizeT n, char* data);
const RangePtr& fields() const;
const RangePtr& records() const;
protected:
RangePtr mRecords;
@ -35,7 +39,6 @@ namespace CNORXZ
MArray<SizeT> mOffsets;
MArray<hid_t> mTypes;
hid_t mType = 0;
bool mCheckedFile = false;
};
template <typename... Ts>

View file

@ -1,6 +1,6 @@
#ifndef __cxz_h5_types_cc_h__
#define __cxz_h5_types_cc_h__
#ifndef __cxz_h5_type_id_cc_h__
#define __cxz_h5_type_id_cc_h__
#include "base/types.h"

View file

@ -0,0 +1,40 @@
#ifndef __cxz_h5_type_id_h__
#define __cxz_h5_type_id_h__
namespace CNORXZ
{
namespace hdf5
{
template <SizeT N, typename... Ts>
SizeT getTupleOffset(const Tuple<Ts...>& t, CSizeT<N> i);
/**************
* TypeId *
**************/
template <typename T>
struct TypeId { static inline hid_t get(); };
template <>
struct TypeId<SizeT> { static inline hid_t get(); };
template <>
struct TypeId<Int> { static inline hid_t get(); };
template <>
struct TypeId<Double> { static inline hid_t get(); };
template <typename T, SizeT N>
struct TypeId<Arr<T,N>> { static inline hid_t get(); };
/*****************
* getTypeId *
*****************/
template <typename T>
hid_t getTypeId(T x);
}
}
#endif

View file

@ -1,39 +1,27 @@
#ifndef __cxz_h5_types_h__
#define __cxz_h5_types_h__
#ifndef __h5_types_h__
#define __h5_types_h__
namespace CNORXZ
{
namespace hdf5
{
template <SizeT N, typename... Ts>
SizeT getTupleOffset(const Tuple<Ts...>& t, CSizeT<N> i);
// definition -> h5_content_base.h
class ContentBase;
/**************
* TypeId *
**************/
// definition -> h5_group.h
class Group;
template <typename T>
struct TypeId { static inline hid_t get(); };
// definition -> h5_file.h
class File;
template <>
struct TypeId<SizeT> { static inline hid_t get(); };
// definition -> h5_table.h
class Table;
template <>
struct TypeId<Int> { static inline hid_t get(); };
// definition -> h5_table.h
template <typename... Ts>
class STable;
template <>
struct TypeId<Double> { static inline hid_t get(); };
template <typename T, SizeT N>
struct TypeId<Arr<T,N>> { static inline hid_t get(); };
/*****************
* getTypeId *
*****************/
template <typename T>
hid_t getTypeId(T x);
}
}

View file

@ -73,10 +73,7 @@ namespace CNORXZ
const ContentPtr& Group::get(const String& name) const
{
CXZ_ASSERT(this->isOpen(), "tried to get content of closed group");
auto dvec = [](const String& n) { return Vector<DType>({DType(n)}); };
auto i = mCont.begin();
i.at(dvec(name));
auto i = this->getIndexTo(name);
return *i;
}
@ -191,5 +188,23 @@ namespace CNORXZ
initCont, reinterpret_cast<void*>(&icd) );
}
AIndex<ContentPtr> Group::getIndexTo(const String& name) const
{
CXZ_ASSERT(this->isOpen(), "tried to get content of closed group");
auto dvec = [](const String& n) { return Vector<DType>({DType(n)}); };
auto i = mCont.begin();
i.at(dvec(name));
return i;
}
BIndex<ContentPtr> Group::getIndexTo(const String& name)
{
CXZ_ASSERT(this->isOpen(), "tried to get content of closed group");
auto dvec = [](const String& n) { return Vector<DType>({DType(n)}); };
auto i = mCont.begin();
i.at(dvec(name));
return i;
}
}
}

View file

@ -96,5 +96,47 @@ namespace CNORXZ
mFields = URangeFactory<FieldID>(fields).create();
return *this;
}
Table& Table::initTable(SizeT n, const void* data, SizeT dsize, SizeT chunk_size)
{
const Int compress = 0;
mRecords = CRangeFactory(n).create();
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();
}
const herr_t err = H5TBmake_table
(mName.c_str(), mParent->id(), mName.c_str(), mFields->size(), mRecords->size(), dsize,
fields.data(), mOffsets.data(), mTypes.data(), chunk_size, NULL, compress, data);
CXZ_ASSERT(err >= 0, "error while initialzing table: error code = " << err);
return *this;
}
Table& Table::appendRecord(SizeT n, const void* data, SizeT dsize)
{
mRecords = mRecords->extend( CRangeFactory(1).create() );
const herr_t err = H5TBappend_records(mParent->id(), mName.c_str(), n, dsize,
mOffsets.data(), mSizes.data(), data);
CXZ_ASSERT(err >= 0, "error while appending record to table: error code = " << err);
return *this;
}
Table& Table::readRecord(SizeT pos, SizeT n, char* data)
{
CXZ_ERROR("not implemented!!!");
return *this;
}
const RangePtr& Table::fields() const
{
return mFields;
}
const RangePtr& Table::records() const
{
return mRecords;
}
}
}