Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for building G4HepEm without Geant4 #102

Merged
merged 3 commits into from
Jul 26, 2023

Conversation

drbenmorgan
Copy link
Contributor

Following discussion with @mnovak42, this is a first pass at supporting building G4HepEm without its components that depend on Geant4, and hence Geant4 itself. There are no changes to code itself, just to organisation and build scripts:

  • The G4HepEm/{include, src} directories and the build of the g4HepEm library are moved to a subdirectory G4HepEm/G4HepEm to bring this in line with the other components and to simplify G4HepEm/CMakeLists.txt
  • A CMake option G4HepEm_GEANT4_BUILD is introduced and set to ON by default to retain existing default behaviour. When set to OFF the build:
    • Finds the CLHEP package in place of Geant4 for random number generation in G4HepEmRun
    • Hard codes (currently) a value for the G4VERSION_NUM macro needed in a couple of places
    • Does not build/install the G4HepEmInit and G4HepEm components
    • Enables testing, but does not actually build any tests as these currently all require Geant4 AFAICT.

I've tested build/use with this option ON/OFF and with CUDA ON/OFF, and things seem to work o.k. though this probably hasn't covered all possibilities.

The two issues to think about with the above are:

  1. How critical the CLHEP dependency is, or if we can template G4HepEmRandomEngine.hh on the random engine type
    instead of hiding via a void pointer. When Geant4 isn't used, it'd be up to the user to provide one, which they could also do in the Geant4-enabled case, and we could also provide a default.
  2. How to set the G4VERSION_NUM macro in G4HepEmRun when Geant4 isn't used. It's hardcoded for now, but could be made selectable.

Make structure clearer and in line with that of other components.
Use cases for G4HepEm not requiring use of Geant4 have recently been
identified, only needing the data and run components. Generation of
data would still be required, but can be persisted separately and
read in without needing Geant4 via G4HepEm's JSON persistency.

Add CMake option to enable support for Geant4, defaulting to ON to
match current behaviour. Update build so that when this is OFF, it

- Does not build the G4HepEm and G4HepEmInit components
- Finds the CLHEP package to support random number generation in
  G4HepEmRun
- Sets the G4VERSION_NUM to 1100 (TODO: make selectable)
- Add a "geant4" component in installed CMake config file to allow
  detection of this feature
- Adapt G4HepEm_LIBRARIES for both build variants
- Do not build tests even when testing enabled as they currently
  all require Geant4 or G4HepEm's support for it
@mnovak42
Copy link
Owner

Looks good so far.

Regrading your point 1. on the CLHEP dependency, the goal would be not to have even CLHEP dependence when G4HepEm_GEANT4_BUILD is OFF. Instead, when Geant4 is not used, we simple do not build the G4HepEmRun library so we do not need CLHEP neither. But what we still should do even in this case, is to install all .hh and .icc files from G4HepEmRun/include (and we do not care the G4HepEmRandomEngine::flat() and G4HepEmRandomEngine::flatArray() implementations that are in G4HepEmRun/src and depend on CHLEP).

These headers, together with the G4HepEmData and G4HepEmDataJsonIO libraries, would let the client to

  • load all the data generated previously and required for the simulation (so re-initialise G4HepEm)
  • pull-in the the .hh and .icc files from G4HepEmRun/include (already from the INSTALL/include/G4HepEm) and
  • provide the local implementations of the G4HepEmRandomEngine::flat() and G4HepEmRandomEngine::flatArray() methods but using the client own actual random engine type (it's possible with the current void pointer solution)
  • then the client can write its own simulation (stepping loops) relying on the physics given by the pulled-in G4HepEmRun/include .hh and .icc.

The client application would not depend on Geant4 nor CLHEP but only on G4HepEm: on its G4HepEmData and G4HepEmDataJsonIO libraries and only the .hh ad .icc files from G4HepEmRun/include.

I have an application that works very nicely like this now (with my locally modified G4HepEm build) and it's very convenient. The simulation application can then be shared without requiring all contributors to have their own Geant4 and complete G4HepEm installs also built with Geant4: a G4HepEm built without Geant4 is sufficient for the application.

We might think to have a nicer solution in the future for providing the actual random engine to G4HepEmRandomEngine instead of the current void pointer. However, the void pointer solution is still the one today that was the simplest and cleanest solution (templating would require to propagate it everywhere polluting the entire run directory that looked rather ugly).

The intent of building G4HepEm without Geant4 is to remove any
external dependency, leaving it to the consumer to implement the
core random number engine and wrapper functions.

Remove CLHEP dependency when building without Geant4, removing the
CPU-side implementation file with G4HepEmRandomEngine's flat and
flatArray member function definitions.

Link g4HepEmRun shared library with dynamic_lookup of undefined symbols
on Darwin only. Document reason for this and potential issues.

Update documentation of G4HepEmRandomEngine noting requirements for
users on implementing the host-device engine(s) and member functions.
@drbenmorgan
Copy link
Contributor Author

Thanks @mnovak42, that clarified things for me! Latest changes should remove the CLHEP dependency when building without Geant4. I've updated the docs for G4HepEmRandomEngine to note what the user must implement/link for both this and when using CUDA (either with/out Geant4).

@mnovak42 mnovak42 merged commit a5b9916 into mnovak42:master Jul 26, 2023
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants