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
Open sidebar
CTA-LAPP
PHOENIX_LIBS
PhoenixHDF5
Commits
19c5e4cd
Commit
19c5e4cd
authored
Nov 24, 2020
by
Pierre Aubert
Browse files
Add getter and setter for tensor dimention
parent
bf087d72
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
118 additions
and
12 deletions
+118
-12
TESTS/TEST_BASE_CONFIG/baseConfig.ph5
TESTS/TEST_BASE_CONFIG/baseConfig.ph5
+2
-0
src/BackEnd/backend.cpp
src/BackEnd/backend.cpp
+90
-12
src/Representation/representation.cpp
src/Representation/representation.cpp
+23
-0
src/Representation/representation.h
src/Representation/representation.h
+3
-0
No files found.
TESTS/TEST_BASE_CONFIG/baseConfig.ph5
View file @
19c5e4cd
...
...
@@ -5,6 +5,8 @@ TableParameters{
float x;
///Position on the y axis
float y;
///Table of value
Tensor(float, nbCol) tabValue;
}
...
...
src/BackEnd/backend.cpp
View file @
19c5e4cd
...
...
@@ -121,6 +121,8 @@ std::string ph5_backendTableHeaderAttribute(const PTable & table){
* @return corresponding string
*/
std
::
string
ph5_backendTableHeader
(
const
PTable
&
table
){
PVecStr
vecDimVar
=
ph5_getDimName
(
table
);
std
::
string
body
(
""
);
if
(
table
.
getDocString
()
!=
""
){
body
+=
"///"
+
table
.
getDocString
()
+
"
\n
"
;
...
...
@@ -147,12 +149,33 @@ std::string ph5_backendTableHeader(const PTable & table){
body
+=
ph5_backendTableHeaderCompType
(
table
);
body
+=
ph5_backendTableHeaderDataType
(
table
);
body
+=
"
\n\t\t
void setAllDim("
;
bool
addComma
(
false
);
for
(
PVecStr
::
iterator
it
(
vecDimVar
.
begin
());
it
!=
vecDimVar
.
end
();
++
it
){
if
(
addComma
){
body
+=
", "
;}
body
+=
"size_t "
+
(
*
it
);
addComma
=
true
;
}
body
+=
");
\n
"
;
for
(
PVecStr
::
iterator
it
(
vecDimVar
.
begin
());
it
!=
vecDimVar
.
end
();
++
it
){
body
+=
"
\t\t
void set"
+
firstToUpper
(
*
it
)
+
"(size_t val);
\n
"
;
body
+=
"
\t\t
size_t get"
+
firstToUpper
(
*
it
)
+
"() const;
\n
"
;
}
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
void allocate(size_t nbRow);
\n\n
"
;
body
+=
"
\t\t
///Number of rows in the table "
+
name
+
"
\n
"
;
body
+=
"
\t\t
size_t p_nbRow;
\n
"
;
body
+=
"
\t\t
size_t p__nbRow;
\n\n
"
;
for
(
PVecStr
::
iterator
it
(
vecDimVar
.
begin
());
it
!=
vecDimVar
.
end
();
++
it
){
body
+=
"
\t\t
///Tensor dimension "
+
(
*
it
)
+
"
\n
"
;
body
+=
"
\t\t
size_t p_"
+
(
*
it
)
+
";
\n
"
;
}
body
+=
"
\n
"
;
body
+=
ph5_backendTableHeaderAttribute
(
table
);
body
+=
"};
\n\n
"
;
...
...
@@ -188,7 +211,7 @@ std::string ph5_backendTableSourceResize(const PTable & table){
body
+=
"/*
\t
@param nbRow : new number of rows of the Table
\n
"
;
body
+=
"*/
\n
"
;
body
+=
"void "
+
name
+
"::resize(size_t nbRow){
\n
"
;
body
+=
"
\t
if(nbRow == p_nbRow){return;} //Nothing to do
\n
"
;
body
+=
"
\t
if(nbRow == p_
_
nbRow){return;} //Nothing to do
\n
"
;
body
+=
"
\t
clear()
\n
"
;
body
+=
"
\t
allocate(nbRow);
\n
"
;
body
+=
"}
\n\n
"
;
...
...
@@ -248,7 +271,7 @@ std::string ph5_backendTableSourceWrite(const PTable & table){
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
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
"
;
...
...
@@ -259,7 +282,7 @@ std::string ph5_backendTableSourceWrite(const PTable & table){
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
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
"
;
...
...
@@ -315,11 +338,11 @@ std::string ph5_backendTableSourceGetter(const PTable & table){
body
+=
docString
;
std
::
string
sizeElement
(
ph5_getFullAttributeElement
(
*
it
));
body
+=
"const "
+
type
+
" * "
+
name
+
"::get"
+
firstToUpper
(
it
->
getName
())
+
"(size_t i) const{
\n
"
;
body
+=
"return p_"
+
it
->
getName
()
+
" + i*"
+
sizeElement
+
";
\n
"
;
body
+=
"
\t
return p_"
+
it
->
getName
()
+
" + i*"
+
sizeElement
+
";
\n
"
;
body
+=
"}
\n\n
"
;
body
+=
docString
;
body
+=
type
+
" * "
+
name
+
"::get"
+
firstToUpper
(
it
->
getName
())
+
"(size_t i){
\n
"
;
body
+=
"return p_"
+
it
->
getName
()
+
" + i*
*
"
+
sizeElement
+
";
\n
"
;
body
+=
"
\t
return p_"
+
it
->
getName
()
+
" + i*"
+
sizeElement
+
";
\n
"
;
body
+=
"}
\n\n
"
;
}
else
{
std
::
string
docString
(
""
);
...
...
@@ -340,6 +363,50 @@ std::string ph5_backendTableSourceGetter(const PTable & table){
return
body
;
}
///Create all the dimention getter and setters of the Table
/** @param table : PTable to be used
* @return C++ string
*/
std
::
string
ph5_backendTableSourceDimGetterSetter
(
const
PTable
&
table
){
std
::
string
body
(
""
),
name
(
table
.
getName
());
PVecStr
vecDimVar
=
ph5_getDimName
(
table
);
body
+=
"///Set all the dimentions of the Tensor in the table
\n
"
;
std
::
string
docPrefix
(
"/**"
);
for
(
PVecStr
::
iterator
it
(
vecDimVar
.
begin
());
it
!=
vecDimVar
.
end
();
++
it
){
body
+=
docPrefix
+
"
\t
@param "
+
(
*
it
)
+
" : set the tensor dimention "
+
(
*
it
)
+
"
\n
"
;
docPrefix
=
" * "
;
}
body
+=
"*/
\n
"
;
body
+=
"void "
+
name
+
"::setAllDim("
;
bool
addComma
(
false
);
for
(
PVecStr
::
iterator
it
(
vecDimVar
.
begin
());
it
!=
vecDimVar
.
end
();
++
it
){
if
(
addComma
){
body
+=
", "
;}
body
+=
"size_t "
+
(
*
it
);
addComma
=
true
;
}
body
+=
"){
\n
"
;
for
(
PVecStr
::
iterator
it
(
vecDimVar
.
begin
());
it
!=
vecDimVar
.
end
();
++
it
){
body
+=
"
\t
set"
+
firstToUpper
(
*
it
)
+
"("
+
(
*
it
)
+
");
\n
"
;
}
body
+=
"}
\n\n
"
;
for
(
PVecStr
::
iterator
it
(
vecDimVar
.
begin
());
it
!=
vecDimVar
.
end
();
++
it
){
body
+=
"///Set the Tensor dimention "
+
(
*
it
)
+
"
\n
"
;
body
+=
"/**
\t
@param val : set the tensor dimention "
+
(
*
it
)
+
"
\n
"
;
body
+=
"*/
\n
"
;
body
+=
"void "
+
name
+
"::set"
+
firstToUpper
(
*
it
)
+
"(size_t val){
\n
"
;
body
+=
"
\t
p_"
+
(
*
it
)
+
" = val;
\n
"
;
body
+=
"}
\n\n
"
;
body
+=
"///Get the Tensor dimention "
+
(
*
it
)
+
"
\n
"
;
body
+=
"/**
\t
@return the tensor dimention "
+
(
*
it
)
+
"
\n
"
;
body
+=
"*/
\n
"
;
body
+=
"size_t "
+
name
+
"::get"
+
firstToUpper
(
*
it
)
+
"() const{
\n
"
;
body
+=
"
\t
return p_"
+
(
*
it
)
+
";
\n
"
;
body
+=
"}
\n\n
"
;
}
return
body
;
}
///Get the size of a column
/** @param attr : PAttribute to be used
* @return corresponding string
...
...
@@ -348,7 +415,7 @@ std::string ph5_getSizeOfCol(const PAttribute & attr){
std
::
string
body
(
"sizeof("
+
attr
.
getType
()
+
")"
);
const
PVecDim
&
vecDim
=
attr
.
getVecDim
();
for
(
PVecDim
::
const_iterator
it
(
vecDim
.
begin
());
it
!=
vecDim
.
end
();
++
it
){
body
+=
"*"
+
ph5_dimentionToStr
(
*
it
);
body
+=
"*"
+
ph5_dimentionToStr
(
*
it
,
"p_"
);
}
return
body
;
}
...
...
@@ -441,7 +508,7 @@ std::string ph5_getTypeHDF5(const PAttribute & attr){
body
+=
"
\t
hsize_t dims["
+
convertToString
(
vecDim
.
size
())
+
"];
\n
"
;
size_t
i
(
0lu
);
for
(
PVecDim
::
const_iterator
it
(
vecDim
.
begin
());
it
!=
vecDim
.
end
();
++
it
){
body
+=
"
\t
dims["
+
convertToString
(
i
)
+
"] = "
+
ph5_dimentionToStr
(
*
it
)
+
";
\n
"
;
body
+=
"
\t
dims["
+
convertToString
(
i
)
+
"] = "
+
ph5_dimentionToStr
(
*
it
,
"p_"
)
+
";
\n
"
;
}
body
+=
"
\t
H5::ArrayType arrayType("
+
ph5_cTypeToHDF5
(
attr
.
getType
())
+
", "
+
convertToString
(
vecDim
.
size
())
+
", dims);
\n
"
;
body
+=
"
\t
return arrayType;
\n
"
;
...
...
@@ -518,10 +585,15 @@ std::string ph5_backendTableSourceAllocate(const PTable & table){
body
+=
"/*
\t
@param nbRow : new number of rows of the Table
\n
"
;
body
+=
"*/
\n
"
;
body
+=
"void "
+
name
+
"::allocate(size_t nbRow){
\n
"
;
body
+=
"
\t
p_nbRow = nbRow;
\n
"
;
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
"
;
if
(
ph5_attributeIsTensor
(
*
it
)){
body
+=
"
\t
p_"
+
it
->
getName
()
+
" = new "
+
it
->
getType
()
+
"[p__nbRow*"
+
ph5_getFullAttributeElement
(
*
it
)
+
"];
\n
"
;
}
else
{
body
+=
"
\t
p_"
+
it
->
getName
()
+
" = new "
+
it
->
getType
()
+
"[p__nbRow];
\n
"
;
}
}
body
+=
"}
\n\n
"
;
return
body
;
...
...
@@ -535,7 +607,11 @@ std::string ph5_backendTableSource(const PTable & table){
std
::
string
body
(
""
),
name
(
table
.
getName
());
body
+=
"///Constructor of the class "
+
name
+
"
\n
"
;
body
+=
name
+
"::"
+
name
+
"(){
\n
"
;
body
+=
"
\t
p_nbRow = 0lu;
\n
"
;
body
+=
"
\t
p__nbRow = 0lu;
\n
"
;
PVecStr
vecDimVar
=
ph5_getDimName
(
table
);
for
(
PVecStr
::
iterator
it
(
vecDimVar
.
begin
());
it
!=
vecDimVar
.
end
();
++
it
){
body
+=
"
\t
p_"
+
(
*
it
)
+
" = 0lu;
\n
"
;
}
const
PVecAttribute
&
vecAttriute
=
table
.
getVecAttribute
();
for
(
PVecAttribute
::
const_iterator
it
(
vecAttriute
.
begin
());
it
!=
vecAttriute
.
end
();
++
it
){
body
+=
"
\t
p_"
+
it
->
getName
()
+
" = NULL;
\n
"
;
...
...
@@ -555,6 +631,8 @@ std::string ph5_backendTableSource(const PTable & table){
body
+=
ph5_backendTableSourceSetter
(
table
);
body
+=
ph5_backendTableSourceGetter
(
table
);
body
+=
ph5_backendTableSourceDimGetterSetter
(
table
);
body
+=
ph5_backendTableSourceOffset
(
table
);
body
+=
ph5_backendTableSourceCompType
(
table
);
body
+=
ph5_backendTableSourceDataType
(
table
);
...
...
src/Representation/representation.cpp
View file @
19c5e4cd
...
...
@@ -4,6 +4,7 @@
Licence : CeCILL-C
****************************************/
#include <map>
#include "convertToString.h"
#include "representation.h"
...
...
@@ -43,3 +44,25 @@ std::string ph5_getFullAttributeElement(const PAttribute & attr){
return
body
;
}
///Get all the variable which are a flexible dimention
/** @param table : PTable to be used
* @return vector of variables which are flexible dimention
*/
PVecStr
ph5_getDimName
(
const
PTable
&
table
){
std
::
map
<
std
::
string
,
bool
>
mapStr
;
const
PVecAttribute
&
vecAttr
=
table
.
getVecAttribute
();
for
(
PVecAttribute
::
const_iterator
itAttr
(
vecAttr
.
begin
());
itAttr
!=
vecAttr
.
end
();
++
itAttr
){
if
(
!
ph5_attributeIsTensor
(
*
itAttr
)){
continue
;}
const
PVecDim
&
vecDim
=
itAttr
->
getVecDim
();
for
(
PVecDim
::
const_iterator
it
(
vecDim
.
begin
());
it
!=
vecDim
.
end
();
++
it
){
if
(
it
->
getIsValue
()){
continue
;}
mapStr
[
it
->
getName
()]
=
true
;
}
}
PVecStr
vecString
;
for
(
std
::
map
<
std
::
string
,
bool
>::
iterator
it
(
mapStr
.
begin
());
it
!=
mapStr
.
end
();
++
it
){
vecString
.
push_back
(
it
->
first
);
}
return
vecString
;
}
src/Representation/representation.h
View file @
19c5e4cd
...
...
@@ -9,6 +9,7 @@
#include "PRepr.h"
typedef
std
::
vector
<
std
::
string
>
PVecStr
;
typedef
std
::
vector
<
PDimention
>
PVecDim
;
typedef
std
::
vector
<
PAttribute
>
PVecAttribute
;
typedef
std
::
vector
<
PTable
>
PVecTable
;
...
...
@@ -18,4 +19,6 @@ std::string ph5_dimentionToStr(const PDimention & dim, const std::string & prefi
bool
ph5_attributeIsTensor
(
const
PAttribute
&
attr
);
std
::
string
ph5_getFullAttributeElement
(
const
PAttribute
&
attr
);
PVecStr
ph5_getDimName
(
const
PTable
&
table
);
#endif
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