Message: Re: How to switch the used visualisation tool of a Geant4 simulation for cmake-installed Geant? Not Logged In (login)
 Next-in-Thread Next-in-Thread
 Next-in-Forum Next-in-Forum

Note Re: How to switch the used visualisation tool of a Geant4 simulation for cmake-installed Geant? 

Forum: Installation and Configuration
Re: Question How to switch the used visualisation tool of a Geant4 simulation for cmake-installed Geant? (Erik Dietz-Laursonn)
Date: 14 Feb, 2012
From: Ben Morgan <Ben Morgan>

Hi Erik,

On Fri, 10 Feb 2012 11:34:49 GMT, Erik Dietz-Laursonn wrote:
> Hallo,
> with the pre-cmake-Geant, I could switch between visualisation of my Geant4 simulation with OpenGL or QT by just doing
> 
>    unset G4UI_USE_TCSH
>    export G4UI_USE_QT=1
>    (for using QT)
> 
> or
> 
>    export G4UI_USE_TCSH=1
>    unset G4UI_USE_QT
>    (for using OpenGL)
> 
> and then recompiling my simulation code. As with cmake Geant is not longer configured via system variables (if I got this correctly),
> this does not work anymore. But I still need both visualisation possibilities and do not want to reconfigure and recompile Geant just
> to switch the visualisation tool used for my simulation. Is there an easier way to do this?

For building Geant4 apps using CMake, Vis/UI drivers can be selected via "component" arguments to CMake's find_package command. There are several ways to use this to select the drivers you want.

If you just want everything that the Geant4 you're building against provides, you can copy what's done in the basic examples:

...
option(WITH_GEANT4_UIVIS "Build example with Geant4 UI and Vis drivers" ON)
if(WITH_GEANT4_UIVIS)
  find_package(Geant4 REQUIRED ui_all vis_all)
else()
  find_package(Geant4 REQUIRED)
endif()
...

Here, the CMake option WITH_GEANT4_UIVIS enables you to choose whether to build with interactivity or not. It's ON by default, and you can change it when you configure the build of your application.

The components in this case are ui_all and vis_all. These are shorthand for "all ui/vis drivers that are available", but more granular control is possible. All the available components are documented in the Geant4Config.cmake file, which is also listed in the Application Developer Guide Appendices (Apologies that this is still rather rough and ready!).

If you want to switch between Qt and Tcsh, then one could do something like the following in the CMakeLists.txt for your app:

...
# Always need Geant4!
find_package(Geant4 REQUIRED)

# Optionally enable Tcsh
option(WITH_GEANT4_TCSH "Build app with Geant4 Tcsh UI" ON)
if(WITH_GEANT4_TCSH)
  find_package(Geant4 REQUIRED ui_tcsh)
endif()

# Optionally enable Qt
option(WITH_GEANT4_QT "Build app with Geant4 Qt UI/Vis" OFF)
if(WITH_GEANT4_QT)
  find_package(Geant4 REQUIRED qt)
endif()
...

All we've done here is move the selection of Tcsh vs Qt from environment variables to CMake options. You can then configure your app setting those options as you wish to select Tcsh or Qt (if you select both, note John's earlier comment about Qt UI/Vis being integrated and preferred if you're using things like G4UI/VisExecutive!). The REQUIRED argument means that the configuration will fail should the Geant4 you're building against not provide the requested component.

I recommend the use of CMake options as a personal preference, and because it's easy to tell from CMake exactly how your app was built, but if you still wish to use environment variables, you could adapt the above CMake snippet to:

...
# Always need Geant4!
find_package(Geant4 REQUIRED)

# Enable Tcsh if G4UI_USE_TCSH is set
if($ENV{G4UI_USE_TCSH})
  find_package(Geant4 REQUIRED ui_tcsh)
endif()

# Enable Qt if G4UI_USE_QT is set
if($ENV{G4UI_USE_QT})
  find_package(Geant4 REQUIRED qt)
endif()
...

You can then set the environment variables as you need, run CMake and then build. Note though that if you want to change the UI, you'll need to change the environment variables, rerun CMake and rebuild (this is because CMake won't spot the environment has changed).

Apologies for the rather long (but probably rushed...) explanation. The above should work for your use case, but don't hesitate to reply if you have problems or further questions.

Cheers,

Ben.

Inline Depth:
 1 1
 All All
Outline Depth:
 1 1
 2 2
 All All
Add message: (add)

1 None: Re: How to switch the used visualisation tool of a Geant4 simulation for cmake-installed Geant?   (Erik Dietz-Laursonn - 16 Feb, 2012)
 Add Message Add Message
to: "Re: How to switch the used visualisation tool of a Geant4 simulation for cmake-installed Geant?"

 Subscribe Subscribe

This site runs SLAC HyperNews version 1.11-slac-98, derived from the original HyperNews


[ Geant 4 Home | Geant 4 HyperNews | Search | Request New Forum | Feedback ]