Fix write and read of GeoFullPhysVol as root volume
Compare changes
This MR fixes #84 (closed).
While trying to read back a .db
file in which an instance of GeoFullPhysVol
was used as the Root volume, @todorova got a crash with this error message:
ERROR! A pointer to a GeoGraphNode instance is NULL {root getRootVolume [GeoPhysVol* GeoModelIO::ReadGeoModel::getRootVolume()]}. Exiting...ERROR! A pointer to a GeoGraphNode instance is NULL {root getRootVolume [GeoPhysVol* GeoModelIO::ReadGeoModel::getRootVolume()]}. Exiting...
The error came from GeoModelIO/GeoModelRead
.
I investigated and found that ReadGeoModel
crashed when trying to perform a dynamic cast to GeoPhysVol
when retrieving the Root volume with the getRootVolume
method.
All methods handling the Root volume, in fact, only handled instances of GeoPhysVol
, and that was for historical reasons only: when I started to develop GeoModelIO
, I initially had Root volumes as GeoPhysVol
and never modified them.
But, of course, a GeoFullPhysVol
can very correctly be used as the Root/World volume, so I modified the methods related to the Root to handle pointers to GeoVPhysVol
: in that way, instances of both GeoPhysVol and GeoFullPhysVol can now be safely used as Root volumes.
There was also another problem in the writing. In GeoModelIO/GeoModelWrite
, the method that stores an instance of GeoFullPhysVol
as the Root volume in the .db
file was wrongly storing the node as a GeoPhysVol
: it was clearly a typo left by poor copy-paste from my side, when copying from the method handling the GeoPhysVol
. This MR fixes that as well.
Also, the HelloGeoWrite and HelloGeoRead examples have been updated as well, in this MR, to reflect the above changes better.