mirror of
https://github.com/paboyle/Grid.git
synced 2025-06-17 15:27:06 +01:00
HDF5 serial IO implemented and tested
This commit is contained in:
@ -11,11 +11,8 @@ Hdf5Writer::Hdf5Writer(const std::string &fileName)
|
||||
, file_(fileName.c_str(), H5F_ACC_TRUNC)
|
||||
{
|
||||
group_ = file_.openGroup("/");
|
||||
}
|
||||
|
||||
Hdf5Writer::~Hdf5Writer(void)
|
||||
{
|
||||
file_.close();
|
||||
writeSingleAttribute(dataSetThres_, HDF5_GRID_GUARD "dataset_threshold",
|
||||
*Hdf5Type<unsigned int>::type);
|
||||
}
|
||||
|
||||
void Hdf5Writer::push(const std::string &s)
|
||||
@ -47,12 +44,8 @@ template <>
|
||||
void Hdf5Writer::writeDefault(const std::string &s, const std::string &x)
|
||||
{
|
||||
StrType strType(PredType::C_S1, x.size());
|
||||
Attribute attribute;
|
||||
hsize_t attrDim = 1;
|
||||
DataSpace attrSpace(1, &attrDim);
|
||||
|
||||
attribute = group_.createAttribute(s, strType, attrSpace);
|
||||
attribute.write(strType, x.data());
|
||||
writeSingleAttribute(*(x.data()), s, strType);
|
||||
}
|
||||
|
||||
void Hdf5Writer::writeDefault(const std::string &s, const char *x)
|
||||
@ -64,21 +57,55 @@ void Hdf5Writer::writeDefault(const std::string &s, const char *x)
|
||||
|
||||
// Reader implementation ///////////////////////////////////////////////////////
|
||||
Hdf5Reader::Hdf5Reader(const std::string &fileName)
|
||||
: fileName_(fileName)
|
||||
, file_(fileName.c_str(), H5F_ACC_RDONLY)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
Hdf5Reader::~Hdf5Reader(void)
|
||||
{
|
||||
|
||||
group_ = file_.openGroup("/");
|
||||
readSingleAttribute(dataSetThres_, HDF5_GRID_GUARD "dataset_threshold",
|
||||
*Hdf5Type<unsigned int>::type);
|
||||
}
|
||||
|
||||
void Hdf5Reader::push(const std::string &s)
|
||||
{
|
||||
|
||||
group_ = group_.openGroup(s);
|
||||
path_.push_back(s);
|
||||
}
|
||||
|
||||
void Hdf5Reader::pop(void)
|
||||
{
|
||||
path_.pop_back();
|
||||
if (path_.empty())
|
||||
{
|
||||
group_ = file_.openGroup("/");
|
||||
}
|
||||
else
|
||||
{
|
||||
auto binOp = [](const std::string &a, const std::string &b)->std::string
|
||||
{
|
||||
return a + "/" + b;
|
||||
};
|
||||
|
||||
group_ = group_.openGroup(std::accumulate(path_.begin(), path_.end(),
|
||||
std::string(""), binOp));
|
||||
}
|
||||
}
|
||||
|
||||
template <>
|
||||
void Hdf5Reader::readDefault(const std::string &s, std::string &x)
|
||||
{
|
||||
Attribute attribute;
|
||||
|
||||
attribute = group_.openAttribute(s);
|
||||
StrType strType = attribute.getStrType();
|
||||
|
||||
x.resize(strType.getSize());
|
||||
attribute.read(strType, &(x[0]));
|
||||
|
||||
std::cout << "length: " << strType.getSize() << std::endl;
|
||||
std::cout << "string: |";
|
||||
for (auto &c: x)
|
||||
{
|
||||
std::cout << "'" << c << "'|";
|
||||
}
|
||||
std::cout << std::endl;
|
||||
}
|
||||
|
Reference in New Issue
Block a user