Skip to content
Snippets Groups Projects
Commit e0245cbe authored by Riccardo Maria Bianchi's avatar Riccardo Maria Bianchi :sunny: Committed by Johannes Junggeburth
Browse files

Clean I/O tests and add better log messages

parent f0c4a340
No related branches found
No related tags found
1 merge request!327New schema for the GeoModel SQLite database and updated I/O
...@@ -41,39 +41,26 @@ class TestIO { ...@@ -41,39 +41,26 @@ class TestIO {
const std::string db1_name = "geometry_db_test_1.db"; const std::string db1_name = "geometry_db_test_1.db";
const std::string db2_name = "geometry_db_test_2.db"; const std::string db2_name = "geometry_db_test_2.db";
//-----------------------------------------------// std:: cout << "1 -- Writing the geometry to file - 1st time" << std::endl;
// 1 -- Writing the geometry to file - 1st time
//-----------------------------------------------//
GMDBManager db1 = GeoModelIO::IO::saveToDB(world, db1_name, loglevel, forceDelete); GMDBManager db1 = GeoModelIO::IO::saveToDB(world, db1_name, loglevel, forceDelete);
//-----------------------------------------------// std::cout << "2 -- Get number of nodes from the DB we just saved" << std::endl;
// 2 -- Get number of nodes from the DB we just saved
//-----------------------------------------------//
std::map<std::string, unsigned long> mmap_1 = std::map<std::string, unsigned long> mmap_1 =
GeoModelIO::IO::countNodesFromDB(db1); GeoModelIO::IO::countNodesFromDB(db1);
//-----------------------------------------------// std::cout << "3 -- Reading back the geometry from file" << std::endl;
// 3 -- Reading back the geometry from file
//-----------------------------------------------//
const GeoVPhysVol* world2 = GeoModelIO::IO::loadDB(db1_name, loglevel); const GeoVPhysVol* world2 = GeoModelIO::IO::loadDB(db1_name, loglevel);
//-----------------------------------------------// std::cout << "4 -- Writing the geometry to file - 2nd time" << std::endl;
// 4 -- Writing the geometry to file - 2nd time
//-----------------------------------------------//
GMDBManager db2 = GeoModelIO::IO::saveToDB(world2, db2_name, loglevel, forceDelete); GMDBManager db2 = GeoModelIO::IO::saveToDB(world2, db2_name, loglevel, forceDelete);
//-----------------------------------------------// std::cout << "5 -- Get number of nodes from the DB we created from the restored GeoModel tree" << std::endl;
// 5 -- Get number of nodes from the DB we created from the restored
// GeoModel tree
//-----------------------------------------------//
std::map<std::string, unsigned long> mmap_2 = std::map<std::string, unsigned long> mmap_2 =
GeoModelIO::IO::countNodesFromDB(db2); GeoModelIO::IO::countNodesFromDB(db2);
//-----------------------------------------------// std::cout << "6 -- Comparison" << std::endl;
// 6 -- Comparison
//-----------------------------------------------//
bool testok = false; bool testok = false;
GeoModelIO::IO::checkTwoNodesMapsSameSize(mmap_1, mmap_2);
if (mmap_1 == mmap_2) { if (mmap_1 == mmap_2) {
if (loglevel >= 1) { if (loglevel >= 1) {
std::cout std::cout
...@@ -94,6 +81,7 @@ class TestIO { ...@@ -94,6 +81,7 @@ class TestIO {
if (loglevel >= 2) { if (loglevel >= 2) {
GeoModelIO::IO::printCompareTwoNodesMaps(mmap_1, mmap_2); GeoModelIO::IO::printCompareTwoNodesMaps(mmap_1, mmap_2);
} }
GeoModelIO::IO::printDifferencesBetweenTwoNodesMaps(mmap_1, mmap_2);
std::cout << "----\n"; std::cout << "----\n";
} }
testok = false; testok = false;
...@@ -140,6 +128,7 @@ class TestIO { ...@@ -140,6 +128,7 @@ class TestIO {
// TODO: add number-by-number comparison as with the other tests!! // TODO: add number-by-number comparison as with the other tests!!
bool testok = false; bool testok = false;
GeoModelIO::IO::checkTwoNodesMapsSameSize(mmap_1, mmap_2);
if (mmap_1 == mmap_2) { if (mmap_1 == mmap_2) {
if (loglevel >= 1) { if (loglevel >= 1) {
std::cout << "OK! The number of starting in-memory nodes is " std::cout << "OK! The number of starting in-memory nodes is "
...@@ -151,15 +140,16 @@ class TestIO { ...@@ -151,15 +140,16 @@ class TestIO {
} else { } else {
if (loglevel >= 1) { if (loglevel >= 1) {
std::cout std::cout
<< "!!! ERROR !!! The number of teh starting in-memory " << "!!! ERROR !!! The number of the starting in-memory "
"nodes is DIFFERENT from " "nodes is DIFFERENT from "
"the number of the restored in-memory nodes!!!\n"; "the number of the restored in-memory nodes!!!\n";
if (loglevel >= 2) { if (loglevel >= 2) {
std::cout << "Starting in-memory nodes:\n"; std::cout << "*** Starting in-memory nodes:\n";
GeoModelIO::IO::printNodesMap(mmap_1); GeoModelIO::IO::printNodesMap(mmap_1);
std::cout << "Restored in-memory nodes:\n"; std::cout << "*** Restored in-memory nodes:\n";
GeoModelIO::IO::printNodesMap(mmap_2); GeoModelIO::IO::printNodesMap(mmap_2);
} }
GeoModelIO::IO::printDifferencesBetweenTwoNodesMaps(mmap_1, mmap_2);
std::cout << "----\n"; std::cout << "----\n";
} }
testok = false; testok = false;
...@@ -196,6 +186,7 @@ class TestIO { ...@@ -196,6 +186,7 @@ class TestIO {
read.setLogLevel(loglevel); read.setLogLevel(loglevel);
} }
// load the data from the DB // load the data from the DB
std::cout << "-- 1: load data from the DB" << std::endl;
read.loadDB(); read.loadDB();
// count all nodes loaded from the DB by the Read action // count all nodes loaded from the DB by the Read action
...@@ -205,14 +196,16 @@ class TestIO { ...@@ -205,14 +196,16 @@ class TestIO {
GeoModelIO::IO::countLoadedNodesFromReadAction(read); GeoModelIO::IO::countLoadedNodesFromReadAction(read);
// build the GeoModel tree from the loaded nodes // build the GeoModel tree from the loaded nodes
std::cout << "-- 2: build the GeoModel tree and restore it into memory" << std::endl;
const GeoVPhysVol* rootVolume = read.buildGeoModel(); const GeoVPhysVol* rootVolume = read.buildGeoModel();
// count the number of all the restored nodes; // count the number of all restored nodes;
// i.e., the nodes of the restored in-memory GeoModel tree // i.e., the nodes of the restored in-memory GeoModel tree
std::map<std::string, unsigned long> mmap_restored = std::map<std::string, unsigned long> mmap_restored =
GeoModelIO::IO::countTreeMemoryNodesFromVolume(rootVolume); GeoModelIO::IO::countTreeMemoryNodesFromVolume(rootVolume);
bool testok = false; bool testok = false;
GeoModelIO::IO::checkTwoNodesMapsSameSize(mmap_loaded, mmap_restored);
if (mmap_loaded == mmap_restored) { if (mmap_loaded == mmap_restored) {
if (loglevel >= 1) { if (loglevel >= 1) {
std::cout << "OK! The number of loaded nodes is equal to the " std::cout << "OK! The number of loaded nodes is equal to the "
...@@ -225,11 +218,13 @@ class TestIO { ...@@ -225,11 +218,13 @@ class TestIO {
"DIFFERENT from " "DIFFERENT from "
"the number of restored nodes!!!\n"; "the number of restored nodes!!!\n";
if (loglevel >= 2) { if (loglevel >= 2) {
std::cout << "Loaded:\n"; std::cout << "\n*** -- Loaded:\n";
GeoModelIO::IO::printNodesMap(mmap_loaded); GeoModelIO::IO::printNodesMap(mmap_loaded);
std::cout << "Restored:\n"; std::cout << "\n*** -- Restored:\n";
GeoModelIO::IO::printNodesMap(mmap_restored); GeoModelIO::IO::printNodesMap(mmap_restored);
} }
GeoModelIO::IO::printDifferencesBetweenTwoNodesMaps(mmap_loaded, mmap_restored);
std::cout << "----\n";
} }
testok = false; testok = false;
} }
...@@ -275,7 +270,8 @@ class TestIO { ...@@ -275,7 +270,8 @@ class TestIO {
std::cout << "Single results: \n"; std::cout << "Single results: \n";
for (auto& tt : tests.second) { for (auto& tt : tests.second) {
std::cout << "test: '" << tt.first << "' ==> " << tt.second std::cout << "test: '" << tt.first << "' ==> " << tt.second
<< " [" << (testall ? "PASSED." : "FAILED!") << "]" << " [" << (tt.second ? "PASSED." : "FAILED!") << "]"
<< " -- [overall: " << (testall ? "PASSED." : "FAILED!") << "]"
<< std::endl; << std::endl;
} }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment