hdf5: group/table improvements
This commit is contained in:
parent
58fa19f514
commit
24ea3339f8
3 changed files with 47 additions and 9 deletions
|
@ -24,6 +24,8 @@ namespace CNORXZ
|
||||||
|
|
||||||
virtual Int exists() const;
|
virtual Int exists() const;
|
||||||
|
|
||||||
|
const ContentPtr& get(const String& name) const;
|
||||||
|
Sptr<Group> getGroup(const String& name) const;
|
||||||
const MArray<ContentPtr>& get() const;
|
const MArray<ContentPtr>& get() const;
|
||||||
Group& addGroup(const String& name);
|
Group& addGroup(const String& name);
|
||||||
|
|
||||||
|
@ -39,7 +41,6 @@ namespace CNORXZ
|
||||||
|
|
||||||
void mkCont();
|
void mkCont();
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -71,8 +71,26 @@ namespace CNORXZ
|
||||||
return H5Lexists(mParent->id(), mName.c_str(), H5P_DEFAULT) != 0 ? 1 : 0;
|
return H5Lexists(mParent->id(), mName.c_str(), H5P_DEFAULT) != 0 ? 1 : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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));
|
||||||
|
return *i;
|
||||||
|
}
|
||||||
|
|
||||||
|
Sptr<Group> Group::getGroup(const String& name) const
|
||||||
|
{
|
||||||
|
auto group = this->get(name);
|
||||||
|
CXZ_ASSERT(group->type() == ContentType::GROUP,
|
||||||
|
"element '" << name << "' is not of type GROUP");
|
||||||
|
return std::dynamic_pointer_cast<Group>( group );
|
||||||
|
}
|
||||||
|
|
||||||
const MArray<ContentPtr>& Group::get() const
|
const MArray<ContentPtr>& Group::get() const
|
||||||
{
|
{
|
||||||
|
CXZ_ASSERT(this->isOpen(), "tried to get content of closed group");
|
||||||
return mCont;
|
return mCont;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -13,6 +13,8 @@ namespace
|
||||||
using namespace CNORXZ;
|
using namespace CNORXZ;
|
||||||
using namespace CNORXZ::hdf5;
|
using namespace CNORXZ::hdf5;
|
||||||
|
|
||||||
|
static const String testh5file = "test_file.h5";
|
||||||
|
|
||||||
class NoFile_Test : public ::testing::Test
|
class NoFile_Test : public ::testing::Test
|
||||||
{
|
{
|
||||||
protected:
|
protected:
|
||||||
|
@ -36,14 +38,28 @@ namespace
|
||||||
|
|
||||||
Group_Test()
|
Group_Test()
|
||||||
{
|
{
|
||||||
mFileName = "test_file.h5";
|
mFileName = testh5file;
|
||||||
mGrps = { "gr1", "gr2" };
|
mGrps = { "gr1", "gr2" };
|
||||||
|
mFs = URangeFactory<String>(Vector<String>({"field1","second","real"})).create();
|
||||||
|
Vector<Tuple<SizeT,Int,Double>> v
|
||||||
|
( { {0, -6, 3.141},
|
||||||
|
{3, -8, 0.789},
|
||||||
|
{34, 4, 10.009},
|
||||||
|
{2, -777, -9.77},
|
||||||
|
{321, 0, -0.003}
|
||||||
|
} );
|
||||||
|
RangePtr rs = CRangeFactory(v.size()).create();
|
||||||
|
mTabA = MArray<Tuple<SizeT,Int,Double>>(rs, std::move(v));
|
||||||
}
|
}
|
||||||
|
|
||||||
String mFileName;
|
String mFileName;
|
||||||
Vector<String> mGrps;
|
Vector<String> mGrps;
|
||||||
|
|
||||||
|
RangePtr mFs;
|
||||||
|
MArray<Tuple<SizeT,Int,Double>> mTabA;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
TEST_F(NoFile_Test, NoFile)
|
TEST_F(NoFile_Test, NoFile)
|
||||||
{
|
{
|
||||||
File f(mNoFileName, true);
|
File f(mNoFileName, true);
|
||||||
|
@ -67,13 +83,16 @@ namespace
|
||||||
h5f.addGroup("gr1");
|
h5f.addGroup("gr1");
|
||||||
h5f.addGroup("gr2");
|
h5f.addGroup("gr2");
|
||||||
EXPECT_EQ(h5f.get().size(), 2u);
|
EXPECT_EQ(h5f.get().size(), 2u);
|
||||||
|
h5f.close();
|
||||||
|
}
|
||||||
|
|
||||||
// move to separate test:
|
TEST_F(Group_Test, CreateTable)
|
||||||
RangePtr rs = CRangeFactory(2).create();
|
{
|
||||||
RangePtr fs = URangeFactory<String>(Vector<String>({"field1","second","real"})).create();
|
File h5f(mFileName, false);
|
||||||
Vector<Tuple<SizeT,Int,Double>> v({ {0, -6, 3.141}, {3, -8, 0.789} });
|
h5f.open();
|
||||||
MArray<Tuple<SizeT,Int,Double>> a(rs, std::move(v));
|
h5f.getGroup("gr1")->open().addTable("tab1", mTabA, mFs);
|
||||||
std::dynamic_pointer_cast<Group>(h5f.get().data()[0])->addTable("tab1", a, fs);
|
h5f.getGroup("gr2")->open().addTable("tab1", mTabA, mFs);
|
||||||
|
h5f.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(Group_Test, Read)
|
TEST_F(Group_Test, Read)
|
||||||
|
|
Loading…
Reference in a new issue