Commit d949871e authored by Pierre Aubert's avatar Pierre Aubert
Browse files

Add read/write

parent aaacd0e4
...@@ -106,6 +106,8 @@ std::string ph5_backendTableHeader(const PTable & table){ ...@@ -106,6 +106,8 @@ std::string ph5_backendTableHeader(const PTable & table){
body += ph5_backendTableHeaderDataType(table); body += ph5_backendTableHeaderDataType(table);
body += "\tprivate:\n"; body += "\tprivate:\n";
body += "\t\tvoid readDataSet(const H5::DataSet & dataset);\n";
body += "\t\tvoid writeDataSet(H5::DataSet & dataset) const;\n";
body += "\t\tvoid allocate(size_t nbRow);\n"; body += "\t\tvoid allocate(size_t nbRow);\n";
body += "\t\t///Number of rows in the table "+name+"\n"; body += "\t\t///Number of rows in the table "+name+"\n";
body += "\t\tsize_t p_nbRow;\n"; body += "\t\tsize_t p_nbRow;\n";
...@@ -169,7 +171,59 @@ std::string ph5_backendTableSourceClear(const PTable & table){ ...@@ -169,7 +171,59 @@ std::string ph5_backendTableSourceClear(const PTable & table){
return body; return body;
} }
///Save the source of the given PTable
/** @param table : PTable to be used
* @return corresponding string
*/
std::string ph5_backendTableSourceRead(const PTable & table){
std::string body(""), name(table.getName());
body += "///Read the table " + name + " from given file\n";
body += "/**\t@param file : HDF5 file to be used\n";
body += "*/\n";
body += "void " + name + "::read(const H5::H5File & file){\n";
body += "\tH5::DataSet dataset = file.openDataSet(\""+table.getDataSetName()+"\");\n";
body += "\treadDataSet(dataset);\n";
body += "}\n\n";
body += "///Read the table " + name + " from given group\n";
body += "/**\t@param group : HDF5 group to be used\n";
body += "*/\n";
body += "void " + name + "::read(const H5::Group & group){\n";
body += "\tH5::DataSet dataset = group.openDataSet(\""+table.getDataSetName()+"\");\n";
body += "\treadDataSet(dataset);\n";
body += "}\n\n";
return body;
}
///Save the source of the given PTable
/** @param table : PTable to be used
* @return corresponding string
*/
std::string ph5_backendTableSourceWrite(const PTable & table){
std::string body(""), name(table.getName());
body += "///Create and write the table " + name + " in given file\n";
body += "/**\t@param file : HDF5 file to be used\n";
body += "*/\n";
body += "void " + name + "::write(const H5::H5File & file) const{\n";
body += "\thsize_t dim[1];\n";
body += "\tdim[0] = p_nbRow;\n";
body += "\tH5::DataSpace space(1, dim);\n";
body += "\tH5::DataSet dataset = file.createDataSet(\""+table.getDataSetName()+"\", " + name + "::getCompTypeAll(), space);\n";
body += "\twriteDataSet(dataset);\n";
body += "}\n\n";
body += "///Create and write the table " + name + " in given file\n";
body += "/**\t@param group : HDF5 group to be used\n";
body += "*/\n";
body += "void " + name + "::write(const H5::Group & group) const{\n";
body += "\thsize_t dim[1];\n";
body += "\tdim[0] = p_nbRow;\n";
body += "\tH5::DataSpace space(1, dim);\n";
body += "\tH5::DataSet dataset = group.createDataSet(\""+table.getDataSetName()+"\", " + name + "::getCompTypeAll(), space);\n";
body += "\twriteDataSet(dataset);\n";
body += "}\n\n";
return body;
}
///Get the size of a column ///Get the size of a column
/** @param attr : PAttribute to be used /** @param attr : PAttribute to be used
...@@ -221,11 +275,12 @@ std::string ph5_backendTableSourceCompType(const PTable & table){ ...@@ -221,11 +275,12 @@ std::string ph5_backendTableSourceCompType(const PTable & table){
for(PVecAttribute::const_iterator it(vecAttriute.begin()); it != vecAttriute.end(); ++it){ for(PVecAttribute::const_iterator it(vecAttriute.begin()); it != vecAttriute.end(); ++it){
if(addPlus){body += " + ";} if(addPlus){body += " + ";}
body += ph5_getSizeOfCol(*it); body += ph5_getSizeOfCol(*it);
addPlus = true;
} }
body += ");\n"; body += ");\n";
body += "\tH5::CompType typeCol(sizeAll);\n"; body += "\tH5::CompType typeCol(sizeAll);\n";
for(PVecAttribute::const_iterator it(vecAttriute.begin()); it != vecAttriute.end(); ++it){ for(PVecAttribute::const_iterator it(vecAttriute.begin()); it != vecAttriute.end(); ++it){
body += "\ttypeCol.insertMember(\""+it->getColName()+"\", " + name + "::getOffset" + firstToUpper(it->getName()) + "(),"+ body += "\ttypeCol.insertMember(\""+it->getColName()+"\", " + name + "::getOffset" + firstToUpper(it->getName()) + "(), "+
name+"::getType" + firstToUpper(it->getName()) + "());\n"; name+"::getType" + firstToUpper(it->getName()) + "());\n";
} }
body += "\treturn typeCol;\n"; body += "\treturn typeCol;\n";
...@@ -273,10 +328,10 @@ std::string ph5_getTypeHDF5(const PAttribute & attr){ ...@@ -273,10 +328,10 @@ std::string ph5_getTypeHDF5(const PAttribute & attr){
for(PVecDim::const_iterator it(vecDim.begin()); it != vecDim.end(); ++it){ for(PVecDim::const_iterator it(vecDim.begin()); it != vecDim.end(); ++it){
body += "\tdims["+convertToString(i)+"] = "+ ph5_dimentionToStr(*it) +";\n"; body += "\tdims["+convertToString(i)+"] = "+ ph5_dimentionToStr(*it) +";\n";
} }
body += "H5::ArrayType arrayType("+ph5_cTypeToHDF5(attr.getType())+", "+convertToString(vecDim.size())+", dims);\n"; body += "\tH5::ArrayType arrayType("+ph5_cTypeToHDF5(attr.getType())+", "+convertToString(vecDim.size())+", dims);\n";
body += "return arrayType;"; body += "\treturn arrayType;\n";
}else{ }else{
body += "return " + ph5_cTypeToHDF5(attr.getType()); body += "\treturn " + ph5_cTypeToHDF5(attr.getType()) + ";\n";
} }
return body; return body;
} }
...@@ -299,6 +354,45 @@ std::string ph5_backendTableSourceDataType(const PTable & table){ ...@@ -299,6 +354,45 @@ std::string ph5_backendTableSourceDataType(const PTable & table){
return body; return body;
} }
///Save the header of the given PTable
/** @param table : PTable to be used
* @return corresponding string
*/
std::string ph5_backendTableSourceReadDataSet(const PTable & table){
std::string body(""), name(table.getName());
body += "///Read the given DataSet and fill the Table with it\n";
body += "/**\t@param dataset : dataset to be used\n";
body += "*/\n";
body += "void "+name+"::readDataSet(const H5::DataSet & dataset){\n";
body += "\tH5::DataSpace dataSpace = dataset.getSpace();\n";
body += "\tsize_t nbEntries(dataSpace.getSimpleExtentNpoints());\n";
body += "\tresize(nbEntries);\n";
const PVecAttribute & vecAttriute = table.getVecAttribute();
for(PVecAttribute::const_iterator it(vecAttriute.begin()); it != vecAttriute.end(); ++it){
body += "\tdataset.read(p_"+it->getName()+", "+name+"::getCompType" + firstToUpper(it->getName()) + "());\n";
}
body += "}\n\n";
return body;
}
///Save the header of the given PTable
/** @param table : PTable to be used
* @return corresponding string
*/
std::string ph5_backendTableSourceWriteDataSet(const PTable & table){
std::string body(""), name(table.getName());
body += "///Write the given DataSet and fill the Table with it\n";
body += "/**\t@param[out] dataset : dataset to be modified\n";
body += "*/\n";
body += "void "+name+"::writeDataSet(H5::DataSet & dataset) const{\n";
const PVecAttribute & vecAttriute = table.getVecAttribute();
for(PVecAttribute::const_iterator it(vecAttriute.begin()); it != vecAttriute.end(); ++it){
body += "\tdataset.write(p_"+it->getName()+", "+name+"::getCompType" + firstToUpper(it->getName()) + "());\n";
}
body += "}\n\n";
return body;
}
///Save the source of the given PTable ///Save the source of the given PTable
/** @param table : PTable to be used /** @param table : PTable to be used
* @return corresponding string * @return corresponding string
...@@ -312,7 +406,7 @@ std::string ph5_backendTableSourceAllocate(const PTable & table){ ...@@ -312,7 +406,7 @@ std::string ph5_backendTableSourceAllocate(const PTable & table){
body += "\tp_nbRow = nbRow;\n"; body += "\tp_nbRow = nbRow;\n";
const PVecAttribute & vecAttriute = table.getVecAttribute(); const PVecAttribute & vecAttriute = table.getVecAttribute();
for(PVecAttribute::const_iterator it(vecAttriute.begin()); it != vecAttriute.end(); ++it){ for(PVecAttribute::const_iterator it(vecAttriute.begin()); it != vecAttriute.end(); ++it){
body += "\tp_"+it->getName()+" = new "+it->getType()+"[p_nbRow];}\n"; body += "\tp_"+it->getName()+" = new "+it->getType()+"[p_nbRow];\n";
} }
body += "}\n\n"; body += "}\n\n";
return body; return body;
...@@ -340,10 +434,16 @@ std::string ph5_backendTableSource(const PTable & table){ ...@@ -340,10 +434,16 @@ std::string ph5_backendTableSource(const PTable & table){
body += ph5_backendTableSourceResize(table); body += ph5_backendTableSourceResize(table);
body += ph5_backendTableSourceClear(table); body += ph5_backendTableSourceClear(table);
body += ph5_backendTableSourceRead(table);
body += ph5_backendTableSourceWrite(table);
body += ph5_backendTableSourceOffset(table); body += ph5_backendTableSourceOffset(table);
body += ph5_backendTableSourceCompType(table); body += ph5_backendTableSourceCompType(table);
body += ph5_backendTableSourceDataType(table); body += ph5_backendTableSourceDataType(table);
body += ph5_backendTableSourceReadDataSet(table);
body += ph5_backendTableSourceWriteDataSet(table);
body += ph5_backendTableSourceAllocate(table); body += ph5_backendTableSourceAllocate(table);
return body; return body;
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment