A tool to convert Geant4 geometries into shared libraries
g42so, a simple Python script that compiles
Geant4 detector-construction and
primary-generator-action classes, wraps them in C-style (unmangled) adapter
functions and produces a shared library. The library can then be loaded via
dlopen by third-party code, allowing instantiation of a Geant4 detector
construction or primary generator action even if the name of the specific class
is not known in advance.
Compilation is delegated to
g++ by default (no, I did
gcc from scratch), but this can be configured.
./g42so -h gives a list of available options. You will typically want
to run something along the lines of the following:
$ ./g42so -I /path/to/include/ \ /path/to/src/MyDetectorConstruction.cc /path/to/src/MyPrimaryGeneratorAction.cc
The recommended installation procedure for
g42so is to use
$ pip install g42so
Geant4 must be installed and the
geant4-configscript must be in the
$PATH, or its location can be specified with the
g42sotries to automatically detect the names of the classes you want to wrap. If it fails or is unsure, it will ask you to explicitly specify your class names.
If your class constructors require arguments, you will need to customise the C wrappers generated by the code. First run
$ ./g42so --dump-detector-wrapper >detectorWrapper.cc
to dump the relevant wrapper. Modify it to your needs and pass it to
g42soalong with the
--custom-detector-wrapperoption, which tells
g42sonot to include its default wrapper. For instance:
$ ./g42so --custom-detector-wrapper -I /path/to/include/ \ /path/to/src/MyDetectorConstruction.cc detectorWrapper.cc
--custom-pga-wrapperdo the same job for primary-generator-action classes.
dlopening shared libraries that link to Geant4 is likely to fail if Geant4 was compiled is multi-threaded mode (the
GEANT4_BUILD_MULTITHREADEDCMake flag is set to ON) with the default value for the
GEANT4_BUILD_TLS_MODEL(the default is
initial-exec). If you want to
dlopenthe libraries created by
g42so(which is the whole point of this tool, really!), then you should make sure that either Geant4 was compiled in single-threaded mode, or
GEANT4_BUILD_TLS_MODELwas set to
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
|Filename, size & hash SHA256 hash help||File type||Python version||Upload date|
|g42so-0.2.0-py2-none-any.whl (10.3 kB) Copy SHA256 hash SHA256||Wheel||py2|
|g42so-0.2.0.tar.gz (8.1 kB) Copy SHA256 hash SHA256||Source||None|