Skip to content

Commit

Permalink
Merge pull request #19 from rest-for-physics/lobis-major-update
Browse files Browse the repository at this point in the history
Partial changes from `restGeant4` parallel project
  • Loading branch information
lobis authored Oct 11, 2021
2 parents 9029088 + 2634ebe commit e1d7e84
Show file tree
Hide file tree
Showing 48 changed files with 1,393 additions and 1,324 deletions.
26 changes: 13 additions & 13 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ stages:
- examples

before_script:
- export USER="rest"
- pwd
- if [ -f "/opt/root/install/bin/thisroot.sh" ]; then source /opt/root/install/bin/thisroot.sh; fi
- root-config --version
- if [ -f "/opt/geant4/install/bin/geant4.sh" ]; then source /opt/geant4/install/bin/geant4.sh; fi
- geant4-config --version
- python3 --version
- apt update && apt install -y wget
- export USER="rest"
- pwd
- if [ -f "/opt/root/install/bin/thisroot.sh" ]; then source /opt/root/install/bin/thisroot.sh; fi
- root-config --version
- if [ -f "/opt/geant4/install/bin/geant4.sh" ]; then source /opt/geant4/install/bin/geant4.sh; fi
- geant4-config --version
- python3 --version
- apt update && apt install -y wget

# This is the one we use to run validations tests. We save the installation as an artifact.
build:
Expand All @@ -27,8 +27,8 @@ build:
- git submodule init source/libraries/geant4
- git submodule update source/libraries/geant4
- cd source/libraries/geant4/
# We attempt to pull a branch from geant4lib named as the one at restG4.
# If not it will pull master by default
# We attempt to pull a branch from geant4lib named as the one at restG4.
# If not it will pull master by default
- ../../../scripts/checkoutRemoteBranch.sh ${CI_COMMIT_BRANCH}
- cd ../../../
- git submodule init source/packages/restG4
Expand All @@ -39,7 +39,7 @@ build:
- if [ -d build ]; then rm -rf build; fi
- mkdir build
- cd build
- cmake ../ -DREST_WELCOME=ON -DREST_G4=ON -DINSTALL_PREFIX=${CI_PROJECT_DIR}/install
- cmake ../ -DREST_WELCOME=ON -DREST_G4=ON -DCMAKE_INSTALL_PREFIX=${CI_PROJECT_DIR}/install
- make install -j2
artifacts:
paths:
Expand Down Expand Up @@ -70,7 +70,7 @@ build:
## - if [ -d build2 ]; then rm -rf build2; fi
## - mkdir build2
## - cd build2
## - cmake ../ -DREST_WELCOME=ON -DREST_G4=ON -DINSTALL_PREFIX=${CI_PROJECT_DIR}/install2
## - cmake ../ -DREST_WELCOME=ON -DREST_G4=ON -DCMAKE_INSTALL_PREFIX=${CI_PROJECT_DIR}/install2
## - make install -j2

loadRESTLibs:
Expand Down Expand Up @@ -138,7 +138,7 @@ loadRESTLibs:
- restG4 singleDecay.rml
- restRoot -b -q Validate.C'("Run00002_Be7_SingleChainDecay.root", 1)'


09_Pb210_Shielding:
type: examples
script:
Expand Down
161 changes: 73 additions & 88 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,96 +1,81 @@
#-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
#Setup the project
# Setup the project
project(restG4)
message("=============== restG4 ==============")

message("=============== ${PROJECT_NAME} ==============")
set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/../../cmake ${CMAKE_MODULE_PATH})

#find REST
IF(NOT DEFINED REST_PATH)
IF(DEFINED ENV{REST_PATH})
set(REST_PATH $ENV{REST_PATH})
ELSE()
message(FATAL_ERROR "ERROR ::: REST_PATH must be defined as an environment variable and point to REST install directory")
return()
ENDIF()
ENDIF()
set(CMAKE_INSTALL_PREFIX ${REST_PATH})
message(STATUS "Using REST PATH: " ${REST_PATH})


if(NOT CMAKE_CXX_FLAGS)
SET(CMAKE_CXX_FLAGS "-std=c++1y")
endif()

#-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
#Find Geant4 package, activating all available UI and Vis drivers by default
#You can set WITH_GEANT4_UIVIS to OFF via the command line or ccmake / cmake - gui
#to build a batch mode only executable
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()
message ("-- Found Geant4 in version : ${Geant4_VERSION}" )

if(${Geant4_VERSION} VERSION_GREATER "10.2.9")
add_definitions(-DG4104)
endif()

include(FindROOT)

#-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
#Set include and lib
if(DEFINED rest_include_dirs)
set(incdir ${PROJECT_SOURCE_DIR}/include ${ROOT_INCLUDE_DIRS} ${rest_include_dirs} ${Geant4_INCLUDE_DIR})
else()
set(incdir ${PROJECT_SOURCE_DIR}/include ${ROOT_INCLUDE_DIRS} ${REST_PATH}/include ${Geant4_INCLUDE_DIR})
endif()


set(lnklib ${Geant4_LIBRARIES} ${ROOT_LIBRARIES} -lGui -lGeom -lGdml -lMinuit RestGeant4 )
string(STRIP "${lnklib}" lnklib)

#-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
#Locate sources and headers for this project
#
include(${Geant4_USE_FILE})
include_directories(${incdir})
# Find ROOT
find_package(ROOT REQUIRED COMPONENTS RIO Geom)
execute_process(COMMAND root-config --cflags OUTPUT_VARIABLE ROOT_CFLAGS)
string(STRIP ${ROOT_CFLAGS} ROOT_CFLAGS)
message(STATUS "-- Found ROOT version: ${ROOT_VERSION} with compilation flags: ${ROOT_CFLAGS} and libraries: ${ROOT_LIBRARIES}")

file(GLOB sources ${PROJECT_SOURCE_DIR}/src/*.cc)
# Geant4 was depending on detector that was depending on Garfield ...
#file(GLOB headers ${PROJECT_SOURCE_DIR}/include/*.hh ${Garfield_INCLUDE_DIRS}/*.hh )
file(GLOB headers ${PROJECT_SOURCE_DIR}/include/*.hh )
# Find Geant4
find_package(Geant4 REQUIRED ui_all vis_all)
include(${Geant4_USE_FILE})
message("-- Found Geant4 version: ${Geant4_VERSION}")

if (${Geant4_VERSION} VERSION_GREATER "10.2.9")
add_definitions(-DG4104)
endif ()

# Fix to allow compatibility with older Geant4 versions that don't have G4RunManagerFactory
if (NOT EXISTS "${Geant4_INCLUDE_DIRS}/G4RunManagerFactory.hh")
add_definitions(-DWITHOUT_G4RunManagerFactory)
endif ()

# Find REST
if (NOT DEFINED REST_PATH)
if (DEFINED ENV{REST_PATH})
set(REST_PATH $ENV{REST_PATH})
else ()
message(FATAL_ERROR "ERROR ::: REST_PATH must be defined as an environment variable and point to REST install directory")
return()
endif ()
endif ()

if (NOT DEFINED rest_include_dirs)
set(rest_include_dirs ${REST_PATH}/include)
endif ()

if (NOT DEFINED CMAKE_INSTALL_PREFIX)
set(CMAKE_INSTALL_PREFIX ${REST_PATH})
endif ()
message(STATUS "Using REST_PATH: ${REST_PATH}")
message(STATUS "Using rest_include_dirs: ${rest_include_dirs}")
message(STATUS "Package ${PROJECT_NAME} will be installed in ${CMAKE_INSTALL_PREFIX}")

if (NOT CMAKE_CXX_FLAGS)
set(CMAKE_CXX_FLAGS " -std=c++1y")
endif ()

# Set include and lib
set(INCLUDE_DIRS ${PROJECT_SOURCE_DIR}/include ${ROOT_INCLUDE_DIRS} ${rest_include_dirs} ${Geant4_INCLUDE_DIR})

set(LINK_LIBRARIES ${Geant4_LIBRARIES} ${ROOT_LIBRARIES} -lGui -lGeom -lGdml -lMinuit RestGeant4)
string(STRIP "${LINK_LIBRARIES}" LINK_LIBRARIES)

file(GLOB sources ${PROJECT_SOURCE_DIR}/src/*.cxx)
file(GLOB headers ${PROJECT_SOURCE_DIR}/include/*.h)

#----------------------------------------------------------------------------
# Add the executable, and link it to the Geant4 libraries
##
#message( STATUS "lnklib G4: ${lnklib}" )
#message( STATUS "sources G4: ${sources}" )
#message( STATUS "headers G4: ${headers}" )
add_executable(restG4 restG4.cc ${sources} ${headers})
target_link_libraries(restG4 ${lnklib})


#----------------------------------------------------------------------------
# Copy all scripts to the build directory, i.e. the directory in which we
# build sphereSimLab. This is so that we can run the executable directly because it
# relies on these scripts being in the current working directory.

install( DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/examples
DESTINATION .
COMPONENT install
)

install( DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/mac
DESTINATION macros
COMPONENT install
)

#----------------------------------------------------------------------------
add_executable(${PROJECT_NAME} restG4.cxx ${sources} ${headers})
target_link_libraries(${PROJECT_NAME} ${LINK_LIBRARIES})
target_include_directories(${PROJECT_NAME} SYSTEM PUBLIC ${INCLUDE_DIRS})

# Copy scripts to the build directory
install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/examples
DESTINATION .
COMPONENT install
)

install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/mac
DESTINATION macros
COMPONENT install
)

# Install the executable to 'bin' directory under CMAKE_INSTALL_PREFIX
#
install(TARGETS restG4 DESTINATION bin)
install(TARGETS ${PROJECT_NAME} DESTINATION bin)

set(package_added "restG4")
set(package_added ${package_added} PARENT_SCOPE)
set(package_added "${PROJECT_NAME} ")
set(package_added ${package_added} PARENT_SCOPE)
Loading

0 comments on commit e1d7e84

Please sign in to comment.