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

Commit 99f63c48 authored by Pierre Aubert's avatar Pierre Aubert
Browse files

Add test on getRow

parent 9cd9377f
Pipeline #92669 passed with stages
in 2 minutes and 29 seconds
......@@ -12,3 +12,11 @@ add_test(NAME TestTableConfig
COMMAND ${CMAKE_CURRENT_BINARY_DIR}/test_table_config
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
add_executable(test_table_config_full main_full.cpp)
target_link_libraries(test_table_config_full test_table_config_lib ${HDF5_CXX_LIBRARIES})
add_test(NAME TestTableConfigFull
COMMAND ${CMAKE_CURRENT_BINARY_DIR}/test_table_config_full
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
/***************************************
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){
size_t eventId(0lu);
double timestamp(0.0);
unsigned short * waveform = NULL;
float * tabSignal = NULL;
table.getRow(i, eventId, timestamp, waveform, tabSignal);
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;
}
}
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_full.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;
}
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