33 if(pathParts.second.length()==0)
40 if((
path.length()==1) && (
path.at(0)==
'/')){
41 file->CreateGroup(pathParts.first);
44 file->CreateGroup(
path + pathParts.first);
48 return children[pathParts.first].CreatePlaceholder(pathParts.second);
51 return children[pathParts.first].CreatePlaceholder(pathParts.second);
59 if(
file->DoesGroupExist(
path + grpName))
60 return (*
this)[grpName];
67 file->CreateGroup(
path + pathParts.first);
70 if(pathParts.second.length()!=0){
71 return children[pathParts.first].CreateGroup(pathParts.second);
77 return children[pathParts.first].CreateGroup(pathParts.second);
86 if(targetPath.length()==0){
89 throw std::runtime_error(
"Error in H5Object::operator[], can't return child \"" + targetPath +
"\" because this object (\"" +
path +
"\" is a dataset not a group.");
94 return children.at(pathParts.first)[pathParts.second];
123 Eigen::VectorXi shape =
file->GetDataSetSize(
path);
124 assert(shape.size()>0);
125 assert(startRow+numRows <= shape(0));
127 assert(startCol+numCols <= shape(1));
137 return block(0,0,numRows,numCols);
142 return block(
rows()-numRows,0,numRows,numCols);
147 return block(0,
cols()-numCols, numRows, numCols);
152 return block(
rows()-numRows,
cols()-numCols, numRows, numCols);
178 Eigen::VectorXi shape =
file->GetDataSetSize(
path);
186 Eigen::VectorXi shape =
file->GetDataSetSize(
path);
193 return block(startInd, 0, numInds, 1);
199 Eigen::VectorXi shape =
file->GetDataSetSize(
path);
202 std::cerr <<
"\nERROR: The dataset, " <<
path <<
", does not exist.\n" << std::endl;
203 assert(shape.size()>0);
207 return block(0,0,numInds,1);
208 }
else if(shape(0)==1){
209 return block(0,0,1,numInds);
210 }
else if(shape(1)==1){
211 return block(0,0,numInds,1);
213 std::cerr <<
"\nERROR: The head() function requires the dataset to be one dimensional and \"" <<
path <<
"\" does not seem to be one dimensional.\n" << std::endl;
215 return block(0,0,numInds,1);
221 return block(
rows()-numInds, 0, numInds, 1);
228 throw std::runtime_error(
"Attempted to call H5Object::rows() on a group object.");
230 Eigen::VectorXi shape =
file->GetDataSetSize(
path);
237 throw std::runtime_error(
"Attempted to call H5Object::cols() on a group object.");
239 Eigen::VectorXi shape =
file->GetDataSetSize(
path);
249 throw std::runtime_error(
"Attempted to call H5Object::size() on a group object.");
251 Eigen::VectorXi shape =
file->GetDataSetSize(
path);
258 return file->ReadPartialMatrix(
path,i,0,1,1)(0);
267 return file->ReadPartialMatrix(
path, i,j,1,1)(0,0);
283 std::cout << prefix +
path << std::endl;
285 child.second.Print(prefix +
" ");
291 std::string
const& groupName)
294 if(file->IsDataSet(groupName))
295 return H5Object(file,groupName,
true);
298 H5Object output(file, groupName,
false);
301 std::vector<std::string> children = file->GetChildren(groupName);
303 for(
auto& childPath : children)
305 std::string fullChildPath = groupName;
307 if(groupName.at(fullChildPath.length()-1)!=
'/')
308 fullChildPath +=
"/";
309 fullChildPath += childPath;
323 std::shared_ptr<HDF5File> file = std::make_shared<HDF5File>(filename);
BlockDataset rightCols(unsigned numCols) const
H5Object & CreateGroup(std::string const &grpName)
BlockDataset bottomLeftCorner(unsigned numRows, unsigned numCols) const
BlockDataset topRows(unsigned numRows) const
BlockDataset col(unsigned col) const
H5Object & CreatePlaceholder(std::string const &grpName)
std::map< std::string, H5Object > children
void Print(std::string prefix="") const
BlockDataset segment(unsigned startInd, unsigned numInds) const
BlockDataset row(unsigned row) const
void ExactCopy(H5Object const &otherObj)
Creates an exact copy.
BlockDataset topLeftCorner(unsigned numRows, unsigned numCols) const
BlockDataset topRightCorner(unsigned numRows, unsigned numCols) const
H5Object & operator[](std::string const &targetPath)
BlockDataset head(unsigned numInds) const
BlockDataset block(unsigned startRow, unsigned startCol, unsigned numRows, unsigned numCols) const
BlockDataset tail(unsigned numInds) const
std::shared_ptr< HDF5File > file
void DeepCopy(H5Object const &otherObj)
BlockDataset bottomRightCorner(unsigned numRows, unsigned numCols) const
double operator()(int i) const
H5Object & operator=(boost::any const &val)
BlockDataset bottomRows(unsigned numRows) const
BlockDataset leftCols(unsigned numCols) const
std::pair< std::string, std::string > SplitString(std::string const &path)
Splits a string on the first forward slash.
H5Object OpenFile(std::string const &filename)
Open an HDF5 file and return the root object.
H5Object AddChildren(std::shared_ptr< HDF5File > file, std::string const &groupName)
Recursively add children to create an HDF5 file hierarchy.