17#ifndef VOTCA_XTP_CHECKPOINTTABLE_H
18#define VOTCA_XTP_CHECKPOINTTABLE_H
35#define CPT_MEM_FROM_STRUCT(m, s) HOFFSET(s, m)
36#define CPT_MEMBER(m, s) HOFFSET(s, m)
40using namespace checkpoint_utils;
45 CptTable(
const std::string& name,
const std::size_t& rowSize,
46 const std::size_t& nRows)
50 props_(H5::DSetCreatPropList(H5::DSetCreatPropList::DEFAULT)){};
52 CptTable(
const std::string& name,
const std::size_t& rowSize,
59 dp_.getSimpleExtentDims(dims,
nullptr);
64 void addCol(
const std::string& name,
const size_t& offset);
69 std::stringstream message;
71 message <<
"Checkpoint tables cannot be reinitialized. " <<
name_
72 <<
" has either already been initialized or already exists."
75 throw std::runtime_error(message.str());
84 props_.setLayout(H5D_layout_t::H5D_COMPACT);
89 }
catch (H5::Exception&) {
90 std::stringstream message;
91 message <<
"Could not write " <<
name_ <<
" from " <<
loc_.getFileName();
92 throw std::runtime_error(message.str());
98 void write(
void* buffer,
const std::size_t& startIdx,
99 const std::size_t& endIdx) {
102 std::stringstream message;
103 message <<
"Checkpoint table uninitialized." << std::endl;
104 throw std::runtime_error(message.str());
107 hsize_t s = (hsize_t)(startIdx);
108 hsize_t
e = (hsize_t)(endIdx);
111 hsize_t fStart[2] = {s, 0};
112 hsize_t fCount[2] = {l, 1};
114 hsize_t mStart[2] = {s, 0};
115 hsize_t mCount[2] = {l, 1};
117 hsize_t mDim[2] = {l, 1};
119 H5::DataSpace mspace(2, mDim);
121 dp_.selectHyperslab(H5S_SELECT_SET, fCount, fStart);
122 mspace.selectHyperslab(H5S_SELECT_SET, mCount, mStart);
125 }
catch (H5::Exception&) {
126 std::stringstream message;
127 message <<
"Could not write " <<
name_ <<
" from " <<
loc_.getFileName();
128 throw std::runtime_error(message.str());
133 write(buffer, idx, idx + 1);
136 template <
typename T>
137 void write(std::vector<T>& dataVec) {
138 write(dataVec.data(), 0, dataVec.size());
141 void read(
void* buffer,
const std::size_t& startIdx,
142 const std::size_t& endIdx) {
145 std::stringstream message;
146 message <<
"Checkpoint table uninitialized." << std::endl;
147 throw std::runtime_error(message.str());
150 hsize_t s = (hsize_t)(startIdx);
151 hsize_t
e = (hsize_t)(endIdx);
154 hsize_t fStart[2] = {s, 0};
155 hsize_t fCount[2] = {l, 1};
157 hsize_t mStart[2] = {s, 0};
158 hsize_t mCount[2] = {l, 1};
160 hsize_t mDim[2] = {l, 1};
162 H5::DataSpace mspace(2, mDim);
164 dp_.selectHyperslab(H5S_SELECT_SET, fCount, fStart);
165 mspace.selectHyperslab(H5S_SELECT_SET, mCount, mStart);
168 }
catch (H5::Exception&) {
169 std::stringstream message;
170 message <<
"Could not read " <<
name_ <<
" from " <<
loc_.getFileName();
171 throw std::runtime_error(message.str());
176 read(buffer, idx, idx + 1);
179 template <
typename T>
180 void read(std::vector<T>& dataVec) {
181 read(dataVec.data(), 0, dataVec.size());
203 std::is_fundamental<U>::value,
204 "Columns can only be added for fundamental types and 'const char*'");
209inline void CptTable::addCol<std::string>(
const std::string& name,
210 const size_t& offset) {
H5::DSetCreatPropList props_
static const std::size_t MaxStringSize
void write(void *buffer, const std::size_t &startIdx, const std::size_t &endIdx)
void initialize(const CptLoc &loc, bool compact)
void readFromRow(void *buffer, const std::size_t &idx)
CptTable(const std::string &name, const std::size_t &rowSize, const CptLoc &loc)
void write(std::vector< T > &dataVec)
void read(std::vector< T > &dataVec)
CptTable(const std::string &name, const std::size_t &rowSize, const std::size_t &nRows)
void writeToRow(void *buffer, const std::size_t idx)
H5::CompType rowStructure_
void read(void *buffer, const std::size_t &startIdx, const std::size_t &endIdx)
void addCol(const std::string &name, const size_t &offset)
base class for all analysis tools