Introducing Helpers to conveniently perform I/O operations and tests
A new package has been introduced, which provides helper functions to conveniently write/load GeoModel .db files and test I/O operations.
This has been introduced in commit: 2522eafe
In particular, the new package offers two classes:
GeoModelIOHelpers/GMIO.h
GeoModelIOHelpers/GMTests_IO.h
The GeoModelIOHelpers/GMIO.h
class offers:
- A "saveDB" static helper function to conveniently save GeoModel
.db
files, by only providing a name for the output file and theGeoPhysVol
"world" volume, that is the "tip" of the GeoModel tree to be stored:
GMDBManager db2 = GeoModelIO::IO::saveToDB(world, filename);
Optionally, it accepts a loglevel
argument to set the verbosity of the GeoModel writer:
GMDBManager db2 = GeoModelIO::IO::saveToDB(world, filename, loglevel);
- A
loadDB
static function to load a given GeoModel.db
file and return theGeoPhysVol
"world" volume, that is the tip of the GeoModel tree that has been restored:
GeoPhysVol* world = GeoModelIO::IO::loadDB(filename);
Optionally, it accepts a loglevel
argument to set the verbosity of the GeoModel reader:
GeoPhysVol* world = GeoModelIO::IO::loadDB(filename, loglevel);
- A static function that accepts a GeoPhysVol volume and counts the number of all nodes in the GeoModel tree. It returns a map containing the number of nodes contained in the input tree, divided by GeoModel classes
static std::map<std::string, unsigned long> countTreeMemoryNodesFromVolume(
const GeoPhysVol* world, unsigned loglevel = 0)
The function inits a WriteGeoModel
instance, then traverse the tree starting with the input "world" volume, and it takes the number of nodes from the WriteGeoModel
action directly, without passing through the "save to DB" I/O layer; then it stores the numbers in a map and returns it:
GeoModelIO::WriteGeoModel dump;
...
world->exec(&dump); // visit all GeoModel nodes
unsigned long nphysvols = dump.getNPhysVols();
unsigned long nfullphysvols = dump.getNFullPhysVols();
unsigned long nlogvols = dump.getNLogVols();
...
mmap["PhysVol"] = nphysvols;
mmap["FullPhysVol"] = nfullphysvols;
mmap["LogVol"] = nlogvols;
...
The GeoModelIOHelpers/GMTests_IO.h
class currently offers:
- A static function tests the number of nodes belonging to a GeoModel tree passing through the Write-Read-Write workflow. In this test, a
GeoPhysVol
is taken as a 'world' volume and the GeoModel tree is persistified into a DB file. Then the file is loaded and the GeoModel tree restored. Then the in-memory GeoModel tree is persistified again into a new DB file. This tests the I/O tools that dump the in-memory GeoModel tree to file, the ones that restore it from the DB file into memory, and the DB I/O methods. The number of nodes are taken directly from the different DB files created at each step, by using the new tools offered by theGeoModelIOHelpers
and theGMDBManager
.
static std::pair<std::string, bool> test_compareWriteReadWriteFromVol(
const GeoPhysVol* world, unsigned loglevel = 0)
- A static function that accepts a
GeoPhysVol
"world" volume and compares the number of nodes of the in-memory GeoModel tree to the number of the saved-then-restored nodes. The numbers of nodes of the in-memory tree are taken from the cache of the GeoNodeAction that is used to traverse the GeoModel tree during the I/O operation (i.e., theWriteGeoModel
class), instead of being taken from the DB. It returns the name of the test plus 'true' if the number of all nodes of the GeoModel tree under the inputGeoPhysVol
"world" volume and the ones belonging to the restored in-memory GeoModel tree match, or 'false' otherwise.
static std::pair<std::string, bool> test_compareMemoryVsRestoredFromVol(
const GeoPhysVol* world, unsigned loglevel = 0)
- A static function that accepts a GeoModel SQLite
.db
file and compares the number of GeoModel objects read from the.db
file by theReadGeoModel
class and the number of objects subsequently restored in memory, as belonging to the restored in-memory GeoModel tree. It returns the name of the test plus 'true' if the number of all objects from the DB and the ones "in-memory" match, or 'false' if the numbers do not match.
static std::pair<std::string, bool> test_compareLoadedVsRestoredFromDB(
GMDBManager* db, unsigned loglevel = 0)
- A static function to run all tests; it takes a GeoModel "world"
GeoPhysVol
volume and some optional parameters to steer the verbosity, and returns a data structure containing the overall result of all tests, plus the single results of each test:
static std::pair<bool, std::map<std::string, bool>> runAllTests(
GeoPhysVol* world, unsigned loglevel = 0, unsigned printtests = 0)