Docker-in-Docker (DinD) capabilities of public runners deactivated. More info

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

Add test with several table

parent f8490f77
Pipeline #92664 passed with stages
in 2 minutes and 48 seconds
......@@ -12,4 +12,5 @@ include(callGenerator.cmake)
add_subdirectory(TEST_BASE_CONFIG)
add_subdirectory(TEST_TYPE)
add_subdirectory(TEST_TYPE_T)
add_subdirectory(TEST_TABLE_CONFIG)
project(Phoenix)
cmake_minimum_required(VERSION 2.8)
include_directories(${CMAKE_CURRENT_BINARY_DIR})
call_generator(test_table_config_lib configTable.ph5)
add_executable(test_table_config main.cpp)
target_link_libraries(test_table_config test_table_config_lib ${HDF5_CXX_LIBRARIES})
add_test(NAME TestTableConfig
COMMAND ${CMAKE_CURRENT_BINARY_DIR}/test_table_config
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
///Table of types
TableEvent{
///Event id
size_t eventId;
///Timestamp
double timestamp;
///Waveform
Tensor(unsigned short, nbSlice, nbPixel) waveform;
///Short value
Tensor(float, nbPixel) calibSignal;
}
/***************************************
Auteur : Pierre Aubert
Mail : aubertp7@gmail.com
Licence : CeCILL-C
****************************************/
#include "configTable.h"
///Test to write data
/** @param fileName : name of the file to be written
* @return true on success, false otherwise
*/
bool testWriteData(const std::string & fileName){
TableEvent table;
size_t nbRow(10lu), nbSlice(40lu), nbPixel(1855lu);
table.setAllDim(nbPixel, nbSlice);
table.resize(nbRow);
//Let's set some values in the Table
for(size_t i(0lu); i < nbRow; ++i){
table.setEventId(i, i);
table.setTimestamp(i, 2lu*i);
unsigned short * waveform = table.getWaveform(i);
for(size_t j(0lu); j < nbSlice; ++j){
for(size_t k(0lu); k < nbPixel; ++k){
waveform[j*nbPixel + k] = 29lu*(i*nbRow +j*nbPixel + k) % 19lu;
}
}
float * tabSignal = table.getCalibSignal(i);
for(size_t k(0lu); k < nbPixel; ++k){
tabSignal[k] = 43lu*(i*nbRow + k) % 17lu;
}
}
//Now let's open a file
H5::H5File file(fileName, H5F_ACC_TRUNC);
//And write our table directly in it
table.write(file);
//We can also explicitly cloase the file, otherwise it will do it automatically
file.close();
return true;
}
///Test to read data
/** @param fileName : name of the file to be read
* @return true on success, false otherwise
*/
bool testReadData(const std::string & fileName){
//First let's open a file in read only mode (better for concurencial access)
H5::H5File file(fileName, H5F_ACC_RDONLY);
//Let's create our table
TableEvent table;
//Add read the file
table.read(file);
//Now we can close the file and use the Table directly
file.close();
//Get the number of rows and number of columns
size_t nbRow = table.getNbRow(), nbPixel = table.getNbPixel(), nbSlice = table.getNbSlice();
bool b(true);
for(size_t i(0lu); i < nbRow; ++i){
b &= table.getEventId(i) == i;
b &= table.getTimestamp(i) == 2lu*i;
unsigned short * waveform = table.getWaveform(i);
for(size_t j(0lu); j < nbSlice; ++j){
for(size_t k(0lu); k < nbPixel; ++k){
b &= waveform[j*nbPixel + k] == 29lu*(i*nbRow +j*nbPixel + k) % 19lu;
}
}
float * tabSignal = table.getCalibSignal(i);
for(size_t k(0lu); k < nbPixel; ++k){
b &= tabSignal[k] == 43lu*(i*nbRow + k) % 17lu;
}
}
return b;
}
int main(int argc, char** argv){
std::string fileName("configTable.h5");
if(!testWriteData(fileName)){
std::cerr << "Cannot write file '"<<fileName<<"'" << std::endl;
return -1;
}
if(!testReadData(fileName)){
std::cerr << "Cannot read file '"<<fileName<<"'" << std::endl;
return -1;
}
return 0;
}
......@@ -4,7 +4,7 @@ TableType{
///Float value
float valFloat;
///Double value
float valDouble;
double valDouble;
///In value
int valInt;
///Short value
......
......@@ -70,7 +70,7 @@ std::string ph5_backendTableHeaderOffset(const PTable & table){
std::string body("");
const PVecAttribute & vecAttriute = table.getVecAttribute();
for(PVecAttribute::const_iterator it(vecAttriute.begin()); it != vecAttriute.end(); ++it){
body += "\t\tstatic size_t getOffset" + firstToUpper(it->getName()) + "();\n";
body += "\t\tsize_t getOffset" + firstToUpper(it->getName()) + "() const;\n";
}
return body;
}
......@@ -453,11 +453,11 @@ std::string ph5_backendTableSourceOffset(const PTable & table){
body += "///Get the offset of the attribute " + it->getName() + "\n";
body += "/**\t@return offset of the attribute in bytes\n";
body += "*/\n";
body += "size_t " + name + "::getOffset" + firstToUpper(it->getName()) + "(){\n" ;
body += "size_t " + name + "::getOffset" + firstToUpper(it->getName()) + "() const{\n" ;
if(prevAttribute == "" && prevAttributeSize == ""){
body += "\treturn 0lu;\n";
}else{
body += "\treturn " + name + "::getOffset" + firstToUpper(prevAttribute) + "() + " + prevAttributeSize + ";\n";
body += "\treturn getOffset" + firstToUpper(prevAttribute) + "() + " + prevAttributeSize + ";\n";
}
body += "}\n\n";
prevAttribute = it->getName();
......@@ -514,6 +514,8 @@ std::string ph5_cTypeToHDF5(const std::string & type){
else if(type == "unsigned short" || type == "uint16_t"){return "H5::PredType::NATIVE_UINT16";}
else if(type == "int" || type == "int32_t"){return "H5::PredType::NATIVE_INT32";}
else if(type == "unsigned int" || type == "uint32_t"){return "H5::PredType::NATIVE_UINT32";}
else if(type == "size_t" || type == "uint64_t"){return "H5::PredType::NATIVE_UINT64";}
else if(type == "ssize_t" || type == "int64_t"){return "H5::PredType::NATIVE_INT64";}
else if(type == "float"){return "H5::PredType::NATIVE_FLOAT";}
else if(type == "double"){return "H5::PredType::NATIVE_DOUBLE";}
return "";
......@@ -531,6 +533,7 @@ std::string ph5_getTypeHDF5(const PAttribute & attr){
size_t i(0lu);
for(PVecDim::const_iterator it(vecDim.begin()); it != vecDim.end(); ++it){
body += "\tdims["+convertToString(i)+"] = "+ ph5_dimentionToStr(*it, "p_") +";\n";
++i;
}
body += "\tH5::ArrayType arrayType("+ph5_cTypeToHDF5(attr.getType())+", "+convertToString(vecDim.size())+", dims);\n";
body += "\treturn arrayType;\n";
......
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