Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Docker-in-Docker (DinD) capabilities of public runners deactivated.
More info
Open sidebar
CTA-LAPP
PHOENIX_LIBS
PhoenixHDF5
Commits
d949871e
Commit
d949871e
authored
Nov 24, 2020
by
Pierre Aubert
Browse files
Add read/write
parent
aaacd0e4
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
105 additions
and
5 deletions
+105
-5
src/BackEnd/backend.cpp
src/BackEnd/backend.cpp
+105
-5
No files found.
src/BackEnd/backend.cpp
View file @
d949871e
...
...
@@ -106,6 +106,8 @@ std::string ph5_backendTableHeader(const PTable & table){
body
+=
ph5_backendTableHeaderDataType
(
table
);
body
+=
"
\t
private:
\n
"
;
body
+=
"
\t\t
void readDataSet(const H5::DataSet & dataset);
\n
"
;
body
+=
"
\t\t
void writeDataSet(H5::DataSet & dataset) const;
\n
"
;
body
+=
"
\t\t
void allocate(size_t nbRow);
\n
"
;
body
+=
"
\t\t
///Number of rows in the table "
+
name
+
"
\n
"
;
body
+=
"
\t\t
size_t p_nbRow;
\n
"
;
...
...
@@ -169,7 +171,59 @@ std::string ph5_backendTableSourceClear(const PTable & table){
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
+=
"
\t
H5::DataSet dataset = file.openDataSet(
\"
"
+
table
.
getDataSetName
()
+
"
\"
);
\n
"
;
body
+=
"
\t
readDataSet(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
+=
"
\t
H5::DataSet dataset = group.openDataSet(
\"
"
+
table
.
getDataSetName
()
+
"
\"
);
\n
"
;
body
+=
"
\t
readDataSet(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
+=
"
\t
hsize_t dim[1];
\n
"
;
body
+=
"
\t
dim[0] = p_nbRow;
\n
"
;
body
+=
"
\t
H5::DataSpace space(1, dim);
\n
"
;
body
+=
"
\t
H5::DataSet dataset = file.createDataSet(
\"
"
+
table
.
getDataSetName
()
+
"
\"
, "
+
name
+
"::getCompTypeAll(), space);
\n
"
;
body
+=
"
\t
writeDataSet(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
+=
"
\t
hsize_t dim[1];
\n
"
;
body
+=
"
\t
dim[0] = p_nbRow;
\n
"
;
body
+=
"
\t
H5::DataSpace space(1, dim);
\n
"
;
body
+=
"
\t
H5::DataSet dataset = group.createDataSet(
\"
"
+
table
.
getDataSetName
()
+
"
\"
, "
+
name
+
"::getCompTypeAll(), space);
\n
"
;
body
+=
"
\t
writeDataSet(dataset);
\n
"
;
body
+=
"}
\n\n
"
;
return
body
;
}
///Get the size of a column
/** @param attr : PAttribute to be used
...
...
@@ -221,11 +275,12 @@ std::string ph5_backendTableSourceCompType(const PTable & table){
for
(
PVecAttribute
::
const_iterator
it
(
vecAttriute
.
begin
());
it
!=
vecAttriute
.
end
();
++
it
){
if
(
addPlus
){
body
+=
" + "
;}
body
+=
ph5_getSizeOfCol
(
*
it
);
addPlus
=
true
;
}
body
+=
");
\n
"
;
body
+=
"
\t
H5::CompType typeCol(sizeAll);
\n
"
;
for
(
PVecAttribute
::
const_iterator
it
(
vecAttriute
.
begin
());
it
!=
vecAttriute
.
end
();
++
it
){
body
+=
"
\t
typeCol.insertMember(
\"
"
+
it
->
getColName
()
+
"
\"
, "
+
name
+
"::getOffset"
+
firstToUpper
(
it
->
getName
())
+
"(),"
+
body
+=
"
\t
typeCol.insertMember(
\"
"
+
it
->
getColName
()
+
"
\"
, "
+
name
+
"::getOffset"
+
firstToUpper
(
it
->
getName
())
+
"(),
"
+
name
+
"::getType"
+
firstToUpper
(
it
->
getName
())
+
"());
\n
"
;
}
body
+=
"
\t
return typeCol;
\n
"
;
...
...
@@ -273,10 +328,10 @@ std::string ph5_getTypeHDF5(const PAttribute & attr){
for
(
PVecDim
::
const_iterator
it
(
vecDim
.
begin
());
it
!=
vecDim
.
end
();
++
it
){
body
+=
"
\t
dims["
+
convertToString
(
i
)
+
"] = "
+
ph5_dimentionToStr
(
*
it
)
+
";
\n
"
;
}
body
+=
"H5::ArrayType arrayType("
+
ph5_cTypeToHDF5
(
attr
.
getType
())
+
", "
+
convertToString
(
vecDim
.
size
())
+
", dims);
\n
"
;
body
+=
"return arrayType;"
;
body
+=
"
\t
H5::ArrayType arrayType("
+
ph5_cTypeToHDF5
(
attr
.
getType
())
+
", "
+
convertToString
(
vecDim
.
size
())
+
", dims);
\n
"
;
body
+=
"
\t
return arrayType;
\n
"
;
}
else
{
body
+=
"return "
+
ph5_cTypeToHDF5
(
attr
.
getType
());
body
+=
"
\t
return "
+
ph5_cTypeToHDF5
(
attr
.
getType
())
+
";
\n
"
;
}
return
body
;
}
...
...
@@ -299,6 +354,45 @@ std::string ph5_backendTableSourceDataType(const PTable & table){
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
+=
"
\t
H5::DataSpace dataSpace = dataset.getSpace();
\n
"
;
body
+=
"
\t
size_t nbEntries(dataSpace.getSimpleExtentNpoints());
\n
"
;
body
+=
"
\t
resize(nbEntries);
\n
"
;
const
PVecAttribute
&
vecAttriute
=
table
.
getVecAttribute
();
for
(
PVecAttribute
::
const_iterator
it
(
vecAttriute
.
begin
());
it
!=
vecAttriute
.
end
();
++
it
){
body
+=
"
\t
dataset.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
+=
"
\t
dataset.write(p_"
+
it
->
getName
()
+
", "
+
name
+
"::getCompType"
+
firstToUpper
(
it
->
getName
())
+
"());
\n
"
;
}
body
+=
"}
\n\n
"
;
return
body
;
}
///Save the source of the given PTable
/** @param table : PTable to be used
* @return corresponding string
...
...
@@ -312,7 +406,7 @@ std::string ph5_backendTableSourceAllocate(const PTable & table){
body
+=
"
\t
p_nbRow = nbRow;
\n
"
;
const
PVecAttribute
&
vecAttriute
=
table
.
getVecAttribute
();
for
(
PVecAttribute
::
const_iterator
it
(
vecAttriute
.
begin
());
it
!=
vecAttriute
.
end
();
++
it
){
body
+=
"
\t
p_"
+
it
->
getName
()
+
" = new "
+
it
->
getType
()
+
"[p_nbRow];
}
\n
"
;
body
+=
"
\t
p_"
+
it
->
getName
()
+
" = new "
+
it
->
getType
()
+
"[p_nbRow];
\n
"
;
}
body
+=
"}
\n\n
"
;
return
body
;
...
...
@@ -340,10 +434,16 @@ std::string ph5_backendTableSource(const PTable & table){
body
+=
ph5_backendTableSourceResize
(
table
);
body
+=
ph5_backendTableSourceClear
(
table
);
body
+=
ph5_backendTableSourceRead
(
table
);
body
+=
ph5_backendTableSourceWrite
(
table
);
body
+=
ph5_backendTableSourceOffset
(
table
);
body
+=
ph5_backendTableSourceCompType
(
table
);
body
+=
ph5_backendTableSourceDataType
(
table
);
body
+=
ph5_backendTableSourceReadDataSet
(
table
);
body
+=
ph5_backendTableSourceWriteDataSet
(
table
);
body
+=
ph5_backendTableSourceAllocate
(
table
);
return
body
;
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment