Skip to content

Commit

Permalink
Merge pull request #95 from rest-for-physics/lobis-pre-commit
Browse files Browse the repository at this point in the history
Implement pre-commit checks and format files
  • Loading branch information
lobis authored Feb 10, 2023
2 parents 51dd631 + 97a5f83 commit f8a92da
Show file tree
Hide file tree
Showing 62 changed files with 260 additions and 209 deletions.
10 changes: 10 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Our style is based on the Google style
# https://google.github.io/styleguide/cppguide.html
BasedOnStyle: Google

# we use left pointer alignment
DerivePointerAlignment: false
PointerAlignment: Left

IndentWidth: 4
ColumnLimit: 110
6 changes: 6 additions & 0 deletions .cmake-format.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# https://cmake-format.readthedocs.io/en/latest/configuration.html

format:
tab_size: 4
separate_ctrl_name_with_space: true
separate_fn_name_with_space: false
4 changes: 4 additions & 0 deletions .github/workflows/validation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@ jobs:
./scripts/checkoutRemoteBranch.sh ${{ env.BRANCH_NAME }}
git log -1 --stat
- uses: actions/checkout@v3
- name: Verify pre-commit config files match
run: |
cd $GITHUB_WORKSPACE
python ${{ env.REST_FRAMEWORK_SOURCE_DIR }}/scripts/validatePreCommitConfig.py
- name: Setup, build and install
run: |
cd ${{ env.REST_FRAMEWORK_SOURCE_DIR }}
Expand Down
35 changes: 35 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
hooks:
- id: check-added-large-files
- id: check-case-conflict
- id: check-merge-conflict
- id: check-symlinks
- id: check-yaml
- id: check-xml
- id: requirements-txt-fixer
- id: end-of-file-fixer
exclude: external/.*$
- id: mixed-line-ending
exclude: external/.*$
- id: trailing-whitespace
exclude: external/.*$

- repo: https://github.com/pre-commit/mirrors-clang-format
rev: v15.0.6
hooks:
- id: clang-format
exclude: external/.*$

- repo: https://github.com/cheshirekow/cmake-format-precommit
rev: v0.6.13
hooks:
- id: cmake-format
additional_dependencies: [ pyyaml ]
# - id: cmake-lint

- repo: https://github.com/psf/black
rev: 22.12.0
hooks:
- id: black
71 changes: 43 additions & 28 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,31 @@
project(restG4)

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

if (${CMAKE_PROJECT_NAME} STREQUAL ${PROJECT_NAME})
# this will only be accessed when build restG4 as a standalone package, not when building the framework
CMAKE_MINIMUM_REQUIRED(VERSION 3.16)
# this will only be accessed when build restG4 as a standalone package, not
# when building the framework
cmake_minimum_required(VERSION 3.16)
find_package(REST REQUIRED)
string(FIND ${REST_LIBRARIES} "RestGeant4" REST_GEANT4_FOUND)
If (${REST_GEANT4_FOUND} EQUAL -1)
message(SEND_ERROR "REST found but 'RestGeant4' library is not present. Please install REST with Geant4Lib")
if (${REST_GEANT4_FOUND} EQUAL -1)
message(
SEND_ERROR
"REST found but 'RestGeant4' library is not present. Please install REST with Geant4Lib"
)
endif ()
endif ()

# 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}")
message(
STATUS
"-- Found ROOT version: ${ROOT_VERSION} with compilation flags: ${ROOT_CFLAGS} and libraries: ${ROOT_LIBRARIES}"
)

# Find Geant4
find_package(Geant4 REQUIRED ui_all vis_all)
Expand All @@ -28,15 +36,19 @@ message("-- Found Geant4 version: ${Geant4_VERSION}")
# Check Geant4 C++ standard is correct
execute_process(COMMAND geant4-config --cxxstd OUTPUT_VARIABLE GEANT4_CXX_STD)
if (NOT ${GEANT4_CXX_STD} MATCHES "17")
message(FATAL_ERROR "Geant4 installation was compiled with C++${GEANT4_CXX_STD} standard, but C++17 is required for REST")
message(
FATAL_ERROR
"Geant4 installation was compiled with C++${GEANT4_CXX_STD} standard, but C++17 is required for REST"
)
endif ()

# Fix for older Geant4 versions
if (${Geant4_VERSION} VERSION_LESS 11.0.0)
add_compile_definitions(GEANT4_VERSION_LESS_11_0_0)
endif ()

# Fix to allow compatibility with older Geant4 versions that don't have G4RunManagerFactory
# Fix to allow compatibility with older Geant4 versions that don't have
# G4RunManagerFactory
if (NOT EXISTS "${Geant4_INCLUDE_DIRS}/G4RunManagerFactory.hh")
add_compile_definitions(GEANT4_WITHOUT_G4RunManagerFactory)
endif ()
Expand All @@ -45,62 +57,65 @@ if (NOT DEFINED CMAKE_INSTALL_PREFIX)
set(CMAKE_INSTALL_PREFIX ${REST_PATH})
endif ()

message(STATUS "Package ${PROJECT_NAME} will be installed in ${CMAKE_INSTALL_PREFIX}")
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} ${Geant4_INCLUDE_DIR} ${REST_INCLUDE_DIRS})
set(INCLUDE_DIRS ${PROJECT_SOURCE_DIR}/include ${ROOT_INCLUDE_DIRS}
${Geant4_INCLUDE_DIR} ${REST_INCLUDE_DIRS})

if (NOT ${CMAKE_PROJECT_NAME} STREQUAL ${PROJECT_NAME})
set(INCLUDE_DIRS ${INCLUDE_DIRS} ${rest_include_dirs})
endif ()

set(LINK_LIBRARIES ${Geant4_LIBRARIES} ${ROOT_LIBRARIES} RestFramework RestGeant4)
set(LINK_LIBRARIES ${Geant4_LIBRARIES} ${ROOT_LIBRARIES} RestFramework
RestGeant4)
string(STRIP "${LINK_LIBRARIES}" LINK_LIBRARIES)

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

# Create a library, necessary to enable testing
set(LIBRARY RestRestG4) # this way the `ADD_LIBRARY_TEST` macro will pick the library name correctly
set(LIBRARY RestRestG4) # this way the `ADD_LIBRARY_TEST` macro will pick the
# library name correctly
add_library(${LIBRARY} SHARED)

target_sources(${LIBRARY} PUBLIC ${sources})
target_link_libraries(${LIBRARY} ${LINK_LIBRARIES})
target_include_directories(${LIBRARY} SYSTEM PUBLIC ${INCLUDE_DIRS})

if (NOT ${CMAKE_PROJECT_NAME} STREQUAL ${PROJECT_NAME})
ADD_LIBRARY_TEST()
add_library_test()
endif ()

# Add the executable
add_executable(${PROJECT_NAME} main.cxx)
target_link_libraries(
${PROJECT_NAME} PUBLIC
${LIBRARY}
)
target_link_libraries(${PROJECT_NAME} PUBLIC ${LIBRARY})

file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/examples
DESTINATION ${CMAKE_CURRENT_BINARY_DIR}
)
DESTINATION ${CMAKE_CURRENT_BINARY_DIR})

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

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

install(TARGETS ${PROJECT_NAME} DESTINATION bin)
install(TARGETS ${LIBRARY} DESTINATION lib)

if (NOT ${CMAKE_PROJECT_NAME} STREQUAL ${PROJECT_NAME})
set(package_added "${PROJECT_NAME} ")
set(package_added ${package_added} PARENT_SCOPE)
set(package_added
${package_added}
PARENT_SCOPE)
endif ()
2 changes: 1 addition & 1 deletion examples/01.NLDBD/NLDBD.rml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
First concept author J. Galan (26-Apr-2015)
-->

<!--
<!--
By default REST units are mm, keV and degrees
-->

Expand Down
2 changes: 1 addition & 1 deletion examples/01.NLDBD/geometry/myGeometryTemplate.gdml
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,4 @@
</volume>
<!-- }}} -->

</structure>
</structure>
2 changes: 1 addition & 1 deletion examples/01.NLDBD/geometry/mySetupTemplate.gdml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<gdml xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://service-spi.web.cern.ch/service-spi/app/releases/GDML/schema/gdml.xsd">

<!-- Just an example of main geometry file : myGeometryTemplate.gdml
<!-- Just an example of main geometry file : myGeometryTemplate.gdml
This file just defines de parameters of the geometry.
The geometry it is defined in geometry/myGeometryDefinition.gdml
The materials are defined in geometry/materials.xml
Expand Down
5 changes: 2 additions & 3 deletions examples/02.TREXDM/g4Analysis.rml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>

<!--This file is an example of REST simulation functionality. We process the output root file
from restG4, converting its TRestGeant4Event to TRestDetectorSignalEvent. Observables and processes's
<!--This file is an example of REST simulation functionality. We process the output root file
from restG4, converting its TRestGeant4Event to TRestDetectorSignalEvent. Observables and processes's
internal values are saved.
-->

Expand Down Expand Up @@ -47,4 +47,3 @@ internal values are saved.
<addTask type="processEvents" value="ON"/>

</TRestManager>

4 changes: 2 additions & 2 deletions examples/02.TREXDM/geometry/README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
This geometry was extracted from the [trexdm-geometry](https://lfna.unizar.es/gifna/trexdm-geometry) project. Check there for the most official and updated TREX-DM geometries.

These files define a very basic geometry without great detail but integrating the most important components.
These files define a very basic geometry without great detail but integrating the most important components.

- Complete enclosing vessel
- Complete enclosing vessel

- Mylar cathode

Expand Down
2 changes: 1 addition & 1 deletion examples/03.Fluorescence/electron.rml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
First concept author J. Galan (26-Apr-2015)
-->

<!--
<!--
By default REST units are mm, keV and degrees
-->

Expand Down
5 changes: 2 additions & 3 deletions examples/03.Fluorescence/g4Analysis.rml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>

<!--This file is an example of REST simulation functionality. We process the output root file
from restG4, converting its TRestGeant4Event to TRestDetectorSignalEvent. Observables and processes's
<!--This file is an example of REST simulation functionality. We process the output root file
from restG4, converting its TRestGeant4Event to TRestDetectorSignalEvent. Observables and processes's
internal values are saved.
-->

Expand Down Expand Up @@ -46,4 +46,3 @@ internal values are saved.
<addTask type="processEvents" value="ON"/>

</TRestManager>

2 changes: 1 addition & 1 deletion examples/03.Fluorescence/gamma.rml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
First concept author J. Galan (26-Apr-2015)
-->

<!--
<!--
By default REST units are mm, keV and degrees
-->

Expand Down
2 changes: 1 addition & 1 deletion examples/03.Fluorescence/geometry/setup.gdml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<gdml xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://service-spi.web.cern.ch/service-spi/app/releases/GDML/schema/gdml.xsd">

<!-- Just an example of main geometry file : myGeometryTemplate.gdml
<!-- Just an example of main geometry file : myGeometryTemplate.gdml
This file just defines de parameters of the geometry.
The geometry it is defined in geometry/myGeometryDefinition.gdml
The materials are defined in geometry/materials.xml
Expand Down
7 changes: 3 additions & 4 deletions examples/05.PandaXIII/README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
The following example has been extracted from the pipeline validation at the main framework, where
The following example has been extracted from the pipeline validation at the main framework, where
the full data processing Montecarlo chain is validated.

We use Xe136bb0n.rml to run restG4 for Geant4 simulation. Use ValidateG4.C to check if the simulation
goes smoothly. i.e. all 500 events are simulated and metadata is correctly recorded. The output file will
We use Xe136bb0n.rml to run restG4 for Geant4 simulation. Use ValidateG4.C to check if the simulation
goes smoothly. i.e. all 500 events are simulated and metadata is correctly recorded. The output file will
be used later on

1 change: 0 additions & 1 deletion examples/05.PandaXIII/geometry/AcrylicPart.gdml
Original file line number Diff line number Diff line change
Expand Up @@ -371,4 +371,3 @@
<second ref="AcrylicCoverSolid" />
<positionref ref="AcrylicCoverPosition" />
</union>

2 changes: 1 addition & 1 deletion examples/05.PandaXIII/geometry/CopperRings.gdml
Original file line number Diff line number Diff line change
Expand Up @@ -346,4 +346,4 @@
<first ref="CopperRing_57" />
<second ref="CopperRing" />
<positionref ref="ringPositionBottom_29" />
</union>
</union>
1 change: 0 additions & 1 deletion examples/05.PandaXIII/geometry/LeadShelding.gdml
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,3 @@
<second ref="LeadSheldingCap" />
<position name="Position_guagua3" x="0" y="0" z="-0.5*(LeadSheldingLength+LeadSheldingCapLength)" />
</union>

1 change: 0 additions & 1 deletion examples/05.PandaXIII/geometry/OtherXeTMAGas.gdml
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,3 @@
<second ref="ResistanceSolid"/>
<positionref ref="ResistancePosition" />
</subtraction>

2 changes: 1 addition & 1 deletion examples/05.PandaXIII/geometry/Resistance.gdml
Original file line number Diff line number Diff line change
Expand Up @@ -340,4 +340,4 @@
<first ref="Resistance_56" />
<second ref="Resistance" />
<positionref ref="ringPositionBottom_29" />
</union>
</union>
4 changes: 2 additions & 2 deletions examples/05.PandaXIII/geometry/Th232_SS_01.rml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>

<!--
<!--
File : isotopeFromVolume.rml
Authors : J. Galan / H.Liang
Date : 9th-Apr-2016
Expand Down Expand Up @@ -77,5 +77,5 @@
<physicsList name="G4EmExtraPhysics"> </physicsList>

</TRestGeant4PhysicsLists>

</restG4>
1 change: 0 additions & 1 deletion examples/05.PandaXIII/geometry/XeTMAGas_new.gdml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,3 @@
<second ref="ResistanceSolid"/>
<positionref ref="ResistancePosition" />
</subtraction>

1 change: 0 additions & 1 deletion examples/06.IonRecoils/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,3 @@ restG4 recoils.rml
```

See also `Validation.C` for validation routines executed in the pipeline.

2 changes: 1 addition & 1 deletion examples/06.IonRecoils/geometry/setup.gdml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<gdml xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://service-spi.web.cern.ch/service-spi/app/releases/GDML/schema/gdml.xsd">

<!-- Just an example of main geometry file : myGeometryTemplate.gdml
<!-- Just an example of main geometry file : myGeometryTemplate.gdml
This file just defines de parameters of the geometry.
The geometry it is defined in geometry/myGeometryDefinition.gdml
The materials are defined in geometry/materials.xml
Expand Down
2 changes: 1 addition & 1 deletion examples/06.IonRecoils/recoils.rml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
First concept author J. Galan (26-Apr-2015)
-->

<!--
<!--
By default REST units are mm, keV and degrees
-->

Expand Down
1 change: 0 additions & 1 deletion examples/07.FullChainDecay/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,3 @@ restG4 singleDecay.rml
```

See also `Validation.C` for validation routines executed in the pipeline.

Loading

0 comments on commit f8a92da

Please sign in to comment.