fixes + keep correct ordering in h5 table fields names
This commit is contained in:
parent
24ea3339f8
commit
62b77921f5
9 changed files with 43 additions and 17 deletions
|
@ -55,6 +55,12 @@ namespace CNORXZ
|
||||||
} );
|
} );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <typename T, typename S>
|
||||||
|
String ToString<std::pair<T,S>>::func(const std::pair<T,S>& p)
|
||||||
|
{
|
||||||
|
return String("(") + toString(p.first) + "," + toString(p.second) + ")";
|
||||||
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
String toString(const T& a)
|
String toString(const T& a)
|
||||||
{
|
{
|
||||||
|
|
|
@ -36,6 +36,12 @@ namespace CNORXZ
|
||||||
static String func(const Tuple<Ts...>& t);
|
static String func(const Tuple<Ts...>& t);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
template <typename T, typename S>
|
||||||
|
struct ToString<std::pair<T,S>>
|
||||||
|
{
|
||||||
|
static String func(const std::pair<T,S>& t);
|
||||||
|
};
|
||||||
|
|
||||||
template <>
|
template <>
|
||||||
struct ToString<DType>
|
struct ToString<DType>
|
||||||
{
|
{
|
||||||
|
|
|
@ -233,7 +233,7 @@ namespace CNORXZ
|
||||||
{
|
{
|
||||||
std::sort(mSpace.begin(), mSpace.end(), std::less<MetaType>());
|
std::sort(mSpace.begin(), mSpace.end(), std::less<MetaType>());
|
||||||
auto itdupl = std::adjacent_find(mSpace.begin(), mSpace.end());
|
auto itdupl = std::adjacent_find(mSpace.begin(), mSpace.end());
|
||||||
CXZ_ASSERT(itdupl == mSpace.end(), "found duplicate: " << *itdupl);
|
CXZ_ASSERT(itdupl == mSpace.end(), "found duplicate: " << toString(*itdupl));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -16,7 +16,7 @@ namespace CNORXZ
|
||||||
|
|
||||||
template <typename... Ts>
|
template <typename... Ts>
|
||||||
Group& Group::addTable(const String& name, const ArrayBase<Tuple<Ts...>>& data,
|
Group& Group::addTable(const String& name, const ArrayBase<Tuple<Ts...>>& data,
|
||||||
const RangePtr& fields)
|
const Vector<String>& fnames)
|
||||||
{
|
{
|
||||||
CXZ_ASSERT(this->isOpen(), "tried to extend closed group");
|
CXZ_ASSERT(this->isOpen(), "tried to extend closed group");
|
||||||
Vector<String> nvec({name});
|
Vector<String> nvec({name});
|
||||||
|
@ -25,7 +25,7 @@ namespace CNORXZ
|
||||||
mCont.extend(extr);
|
mCont.extend(extr);
|
||||||
auto ii = mCont.begin();
|
auto ii = mCont.begin();
|
||||||
ii.at(dvec); // 'at' returns YIndex&, so cannot use it inline...
|
ii.at(dvec); // 'at' returns YIndex&, so cannot use it inline...
|
||||||
auto tab = std::make_shared<STable<Ts...>>(name, this, fields);
|
auto tab = std::make_shared<STable<Ts...>>(name, this, fnames);
|
||||||
for(auto& d: data){
|
for(auto& d: data){
|
||||||
tab->appendRecord(d);
|
tab->appendRecord(d);
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,7 +34,7 @@ namespace CNORXZ
|
||||||
|
|
||||||
template <typename... Ts>
|
template <typename... Ts>
|
||||||
Group& addTable(const String& name, const ArrayBase<Tuple<Ts...>>& data,
|
Group& addTable(const String& name, const ArrayBase<Tuple<Ts...>>& data,
|
||||||
const RangePtr& fields);
|
const Vector<String>& fnames);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
MArray<ContentPtr> mCont;
|
MArray<ContentPtr> mCont;
|
||||||
|
|
|
@ -18,13 +18,19 @@ namespace CNORXZ
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename... Ts>
|
template <typename... Ts>
|
||||||
STable<Ts...>::STable(const String& name, const ContentBase* _parent, const RangePtr& fields) :
|
STable<Ts...>::STable(const String& name, const ContentBase* _parent,
|
||||||
|
const Vector<String>& fnames) :
|
||||||
Table(name, _parent)
|
Table(name, _parent)
|
||||||
{
|
{
|
||||||
constexpr SizeT N = sizeof...(Ts);
|
constexpr SizeT N = sizeof...(Ts);
|
||||||
if(mFields == nullptr){
|
if(mFields == nullptr){
|
||||||
CXZ_ASSERT(fields != nullptr, "field names have to be initialized");
|
CXZ_ASSERT(fnames.size() != 0, "field names have to be initialized");
|
||||||
mFields = fields;
|
Vector<FieldID> fields(fnames.size());
|
||||||
|
for(SizeT i = 0; i != fields.size(); ++i){
|
||||||
|
fields[i].first = i;
|
||||||
|
fields[i].second = fnames[i];
|
||||||
|
}
|
||||||
|
mFields = URangeFactory<FieldID>(fields).create();
|
||||||
}
|
}
|
||||||
CXZ_ASSERT(mFields->size() == sizeof...(Ts), "expected tuple of size = " << mFields->size()
|
CXZ_ASSERT(mFields->size() == sizeof...(Ts), "expected tuple of size = " << mFields->size()
|
||||||
<< ", got: " << sizeof...(Ts));
|
<< ", got: " << sizeof...(Ts));
|
||||||
|
@ -66,9 +72,9 @@ namespace CNORXZ
|
||||||
if(mRecords == nullptr){
|
if(mRecords == nullptr){
|
||||||
mRecords = appr;
|
mRecords = appr;
|
||||||
Vector<const char*> fields(mFields->size());
|
Vector<const char*> fields(mFields->size());
|
||||||
auto fr = std::dynamic_pointer_cast<URange<String>>(mFields);
|
auto fr = std::dynamic_pointer_cast<URange<FieldID>>(mFields);
|
||||||
for(auto fi = fr->begin(); fi != fr->end(); ++fi){
|
for(auto fi = fr->begin(); fi != fr->end(); ++fi){
|
||||||
fields[fi.lex()] = (*fi).c_str();
|
fields[fi.lex()] = (*fi).second.c_str();
|
||||||
}
|
}
|
||||||
H5TBmake_table(mName.c_str(), mParent->id(), mName.c_str(), mFields->size(),
|
H5TBmake_table(mName.c_str(), mParent->id(), mName.c_str(), mFields->size(),
|
||||||
mRecords->size(), sizeof(t), fields.data(), mOffsets.data(),
|
mRecords->size(), sizeof(t), fields.data(), mOffsets.data(),
|
||||||
|
|
|
@ -11,6 +11,8 @@ namespace CNORXZ
|
||||||
class Table : public ContentBase
|
class Table : public ContentBase
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
typedef std::pair<SizeT,String> FieldID;
|
||||||
|
|
||||||
DEFAULT_MEMBERS(Table);
|
DEFAULT_MEMBERS(Table);
|
||||||
Table(const String& name, const ContentBase* _parent);
|
Table(const String& name, const ContentBase* _parent);
|
||||||
~Table();
|
~Table();
|
||||||
|
@ -41,7 +43,7 @@ namespace CNORXZ
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
DEFAULT_MEMBERS(STable);
|
DEFAULT_MEMBERS(STable);
|
||||||
STable(const String& name, const ContentBase* _parent, const RangePtr& fields);
|
STable(const String& name, const ContentBase* _parent, const Vector<String>& fnames);
|
||||||
|
|
||||||
STable& appendRecord(const Tuple<Ts...>& t);
|
STable& appendRecord(const Tuple<Ts...>& t);
|
||||||
STable& appendRecord(const MArray<Tuple<Ts...>>& t);
|
STable& appendRecord(const MArray<Tuple<Ts...>>& t);
|
||||||
|
|
|
@ -20,11 +20,12 @@ namespace CNORXZ
|
||||||
SizeT typesize = 0;
|
SizeT typesize = 0;
|
||||||
H5TBget_field_info(mParent->id(), mName.c_str(), fieldsptr.data(), sizes.data(),
|
H5TBget_field_info(mParent->id(), mName.c_str(), fieldsptr.data(), sizes.data(),
|
||||||
offsets.data(), &typesize);
|
offsets.data(), &typesize);
|
||||||
Vector<String> fields(nfields);
|
Vector<FieldID> fields(nfields);
|
||||||
for(SizeT i = 0; i != nfields; ++i){
|
for(SizeT i = 0; i != nfields; ++i){
|
||||||
fields[i] = fieldsptr[i];
|
fields[i].first = i;
|
||||||
|
fields[i].second = fieldsptr[i];
|
||||||
}
|
}
|
||||||
mFields = URangeFactory<String>( std::move(fields) ).create();
|
mFields = URangeFactory<FieldID>( std::move(fields) ).create();
|
||||||
mSizes = MArray<SizeT>(mFields, std::move(sizes));
|
mSizes = MArray<SizeT>(mFields, std::move(sizes));
|
||||||
mOffsets = MArray<SizeT>(mFields, std::move(offsets));
|
mOffsets = MArray<SizeT>(mFields, std::move(offsets));
|
||||||
this->open();
|
this->open();
|
||||||
|
@ -87,7 +88,12 @@ namespace CNORXZ
|
||||||
Table& Table::initFieldNames(const Vector<String>& fnames)
|
Table& Table::initFieldNames(const Vector<String>& fnames)
|
||||||
{
|
{
|
||||||
CXZ_ASSERT(mFields == nullptr, "fields already initialized");
|
CXZ_ASSERT(mFields == nullptr, "fields already initialized");
|
||||||
mFields = URangeFactory<String>(fnames).create();
|
Vector<FieldID> fields(fnames.size());
|
||||||
|
for(SizeT i = 0; i != fields.size(); ++i){
|
||||||
|
fields[i].first = i;
|
||||||
|
fields[i].second = fnames[i];
|
||||||
|
}
|
||||||
|
mFields = URangeFactory<FieldID>(fields).create();
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -40,7 +40,7 @@ namespace
|
||||||
{
|
{
|
||||||
mFileName = testh5file;
|
mFileName = testh5file;
|
||||||
mGrps = { "gr1", "gr2" };
|
mGrps = { "gr1", "gr2" };
|
||||||
mFs = URangeFactory<String>(Vector<String>({"field1","second","real"})).create();
|
mFs = {"field1","second","real"};
|
||||||
Vector<Tuple<SizeT,Int,Double>> v
|
Vector<Tuple<SizeT,Int,Double>> v
|
||||||
( { {0, -6, 3.141},
|
( { {0, -6, 3.141},
|
||||||
{3, -8, 0.789},
|
{3, -8, 0.789},
|
||||||
|
@ -55,7 +55,7 @@ namespace
|
||||||
String mFileName;
|
String mFileName;
|
||||||
Vector<String> mGrps;
|
Vector<String> mGrps;
|
||||||
|
|
||||||
RangePtr mFs;
|
Vector<String> mFs;
|
||||||
MArray<Tuple<SizeT,Int,Double>> mTabA;
|
MArray<Tuple<SizeT,Int,Double>> mTabA;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue