Skip to content

Commit

Permalink
Add pre-commit and clang-format configuration and fix all issues (#173)
Browse files Browse the repository at this point in the history
  • Loading branch information
tmadlener authored Aug 23, 2022
1 parent e94e6df commit b290a32
Show file tree
Hide file tree
Showing 27 changed files with 912 additions and 710 deletions.
110 changes: 110 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
---
Language: Cpp
# BasedOnStyle: LLVM
AccessModifierOffset: -2
AlignAfterOpenBracket: Align
# AlignConsecutiveAssignments: true
# AlignConsecutiveDeclarations: true
AlignEscapedNewlines: Right
AlignOperands: false
AlignTrailingComments: true
AllowAllParametersOfDeclarationOnNextLine: true
AllowShortBlocksOnASingleLine: Never
AllowShortCaseLabelsOnASingleLine: false
AllowShortFunctionsOnASingleLine: None
AllowShortIfStatementsOnASingleLine: Never
AllowShortLoopsOnASingleLine: false
AlwaysBreakAfterDefinitionReturnType: None
AlwaysBreakAfterReturnType: None
AlwaysBreakBeforeMultilineStrings: false
AlwaysBreakTemplateDeclarations: true
BinPackArguments: true
BinPackParameters: true
BraceWrapping:
AfterClass: false
AfterControlStatement: false
AfterEnum: false
AfterFunction: false
AfterNamespace: false
AfterObjCDeclaration: false
AfterStruct: false
AfterUnion: false
AfterExternBlock: false
BeforeCatch: false
BeforeElse: false
IndentBraces: false
SplitEmptyFunction: false
SplitEmptyRecord: false
SplitEmptyNamespace: false
BreakBeforeBinaryOperators: None
BreakBeforeBraces: Custom
BreakBeforeInheritanceComma: false
BreakBeforeTernaryOperators: true
BreakConstructorInitializersBeforeComma: false
BreakConstructorInitializers: AfterColon
BreakAfterJavaFieldAnnotations: false
BreakStringLiterals: true
ColumnLimit: 120
CommentPragmas: '^ IWYU pragma:'
CompactNamespaces: false
ConstructorInitializerAllOnOneLineOrOnePerLine: true
ConstructorInitializerIndentWidth: 4
ContinuationIndentWidth: 4
Cpp11BracedListStyle: true
DerivePointerAlignment: false
DisableFormat: false
ExperimentalAutoDetectBinPacking: false
FixNamespaceComments: true
ForEachMacros:
- foreach
- Q_FOREACH
- BOOST_FOREACH
IncludeBlocks: Preserve
IncludeCategories:
- Regex: '^(<|"(gtest|gmock|isl|json)/)'
Priority: 4
- Regex: '.*'
Priority: 3
IncludeIsMainRegex: '(Test)?$'
IndentCaseLabels: false
IndentPPDirectives: None
IndentWidth: 2
IndentWrappedFunctionNames: false
JavaScriptQuotes: Leave
JavaScriptWrapImports: true
KeepEmptyLinesAtTheStartOfBlocks: true
MacroBlockBegin: ''
MacroBlockEnd: ''
MaxEmptyLinesToKeep: 1
NamespaceIndentation: Inner
PenaltyBreakAssignment: 2
PenaltyBreakBeforeFirstCallParameter: 19
PenaltyBreakComment: 60
PenaltyBreakFirstLessLess: 120
PenaltyBreakString: 1000
PenaltyBreakTemplateDeclaration: 10
PenaltyExcessCharacter: 1000000
PenaltyReturnTypeOnItsOwnLine: 60
PointerAlignment: Left
ReflowComments: true
SortIncludes: true
SortUsingDeclarations: true
SpaceAfterCStyleCast: false
SpaceAfterTemplateKeyword: true
SpaceBeforeAssignmentOperators: true
SpaceBeforeCpp11BracedList: false
SpaceBeforeCtorInitializerColon: true
SpaceBeforeInheritanceColon: true
SpaceBeforeParens: ControlStatements
SpaceBeforeRangeBasedForLoopColon: true
SpaceInEmptyParentheses: false
SpacesBeforeTrailingComments: 1
SpacesInAngles: false
SpacesInContainerLiterals: true
SpacesInCStyleCastParentheses: false
SpacesInParentheses: false
SpacesInSquareBrackets: false
Standard: c++17
TabWidth: 8
UseTab: Never
...
21 changes: 21 additions & 0 deletions .github/scripts/clang-format-hook
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/usr/bin/env bash

# Thin wrapper around clang-format for easier to parse output from the
# pre-commit hook.
#
# Needs to work with multiple input files as pre-commit passes multiple files to
# the "executables"

# Make sure that diff is actually recent enough (diffutils >= 3.4) to support
# colored output
COLOR_OUTPUT=$(diff --color=always <(echo) <(echo) > /dev/null 2>&1 && echo "--color=always")

success=0
for file in ${@}; do
if ! $(clang-format --style=file --Werror --dry-run ${file} > /dev/null 2>&1); then
echo "Necessary changes for: '${file}' (run 'clang-format --style=file -i ${file}' to fix it)"
diff ${COLOR_OUTPUT} -u ${file} <(clang-format --style=file ${file}) | tail -n +3
success=1
fi
done
exit ${success}
7 changes: 6 additions & 1 deletion .github/workflows/lcg_linux_with_podio.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ jobs:
release-platform: ${{ matrix.LCG }}
run: |
STARTDIR=$(pwd)
echo "::group::Build podio"
echo "Building podio @"$(git log -1 --format=%H)
git clone --depth 1 https://github.com/AIDASoft/podio
cd podio
Expand All @@ -37,6 +38,8 @@ jobs:
unset CPATH
export CMAKE_PREFIX_PATH=$(pwd)/install:$CMAKE_PREFIX_PATH
export LD_LIBRARY_PATH=$(pwd)/install/lib:$(pwd)/install/lib64:$LD_LIBRARY_PATH
echo "::endgroup::"
echo "::group::Build edm4hep"
cd $STARTDIR
echo "Building edm4hep"
mkdir build install
Expand All @@ -49,7 +52,8 @@ jobs:
ctest --output-on-failure
ninja install
cd -
echo "Test downstream usage"
echo "::endgroup::"
echo "::group::Test downstream usage"
export CMAKE_PREFIX_PATH=$PWD/install:$CMAKE_PREFIX_PATH
cd test/downstream-project-cmake-test
mkdir build
Expand All @@ -58,3 +62,4 @@ jobs:
-DCMAKE_INSTALL_PREFIX=../install \
-G Ninja
ninja -k0
echo "::endgroup::"
53 changes: 53 additions & 0 deletions .github/workflows/pre-commit.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
name: pre-commit

on: [push, pull_request]

jobs:
pre-commit:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: cvmfs-contrib/github-action-cvmfs@v2
- uses: aidasoft/run-lcg-view@v3
with:
release-platform: LCG_99/x86_64-centos7-clang10-opt
run: |
STARTDIR=$(pwd)
echo "::group::Build podio"
echo "Building podio @"$(git log -1 --format=%H)
git clone --depth 1 https://github.com/AIDASoft/podio
cd podio
mkdir build install
cd build
cmake .. -DCMAKE_CXX_STANDARD=17 \
-DENABLE_SIO=ON \
-DBUILD_TESTING=OFF \
-DCMAKE_INSTALL_PREFIX=$(pwd)/../install \
-G Ninja
ninja -k0
ninja install
cd ..
export ROOT_INCLUDE_PATH=$(pwd)/install/include:$ROOT_INCLUDE_PATH:$CPATH
unset CPATH
export CMAKE_PREFIX_PATH=$(pwd)/install:$CMAKE_PREFIX_PATH
export LD_LIBRARY_PATH=$(pwd)/install/lib:$(pwd)/install/lib64:$LD_LIBRARY_PATH
echo "::endgroup::"
echo "::group::Run pre-commit"
cd $STARTDIR
export PYTHONPATH=$(python -m site --user-site):$PYTHONPATH
export PATH=/root/.local/bin:$PATH
pip install argparse --user
pip install pre-commit --user
mkdir build
cd build
cmake .. -DENABLE_SIO=ON \
-DCMAKE_CXX_STANDARD=17 \
-DCMAKE_CXX_FLAGS=" -fdiagnostics-color=always -Werror "\
-DCMAKE_EXPORT_COMPILE_COMMANDS=ON \
-DUSE_EXTERNAL_CATCH2=OFF
ln -s $(pwd)/compile_commands.json ../
cd ..
pre-commit run --show-diff-on-failure \
--color=always \
--all-files
echo "::endgroup::"
12 changes: 6 additions & 6 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@

# -- Gitlab CI configuration for EDM4HEP -----------------------------
#
# This file configures the deployment of the code reference generated
#
# This file configures the deployment of the code reference generated
# by doxygen to a web site. The site produced in the generate-docs
# is static and relocatable, the html files can simply be hosted by any
# server. Here, the CERN gitlab and eos infrastructure is used to publish
# to https://edm4hep.web.cern.ch (shorter alias: cern.ch/edm4hep)


# -- Run Doxygen ------------------------------
# -- Run Doxygen ------------------------------
# Doxygen is set up in CMake, so need to load all
# dependencies to run it. This step requires a runner
# that can build edm4hep and run doxygen. The easiest way to
# ensure this is require cvmfs access on the runner and take the
# software from there.
# software from there.
generate-docs:
# need a runner with cvmfs installed. On the CERN gitlab instance,
# these are usually tagged with "cvmfs"
Expand All @@ -36,7 +36,7 @@ generate-docs:



# -- Deploy to EOS ----------------------------
# -- Deploy to EOS ----------------------------
# Use the standard workflow to publish to eos
# see https://gitlab.cern.ch/ci-tools/ci-web-deployer
# The variables for this particular deployment:
Expand All @@ -49,7 +49,7 @@ generate-docs:
# which mirrors https://github.com/key4hep/edm4hep
# In particular, the service account key4hep is used to write
# to the eos space /eos/project/k/key4hep/www/edm4hep
# Other accounts which are part of the e-groups
# Other accounts which are part of the e-groups
# cernbox-project-key4hep-{readers|writers} may be used.
# The eos path and website are configured using https://webeos.cern.ch/
deployment:
Expand Down
15 changes: 15 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v3.4.0
hooks:
- id: mixed-line-ending
- id: trailing-whitespace
exclude: (doc/ReleaseNotes.md)
- repo: local
hooks:
- id: clang-format
name: clang-format
entry: .github/scripts/clang-format-hook
exclude: (edm4hep/(edm4hep|src)/.*(h|cc)$|EDM4HEPVersion.h)
types: [c++]
language: system
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ This project is in a beta stage -- feedback and use of it in production is encou
Required:

* [PODIO](https://github.com/AIDASoft/podio) >= v00-09-02
* [ROOT](https://github.com/root-project/root) >= v6.18/04
* [ROOT](https://github.com/root-project/root) >= v6.18/04

Optional:

Expand All @@ -50,7 +50,7 @@ cd EDM4hep; mkdir build; cd build
cmake ..
make
make test
```
```

The library files and dictionaries (`libedm4hep.so`, ...) must be put somewhere in `LD_LIBRARY_PATH`.

Expand Down
2 changes: 1 addition & 1 deletion cmake/EDM4HEP.pc.in
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ includedir=${prefix}@CMAKE_INSTALL_INCLUDEDIR@

Name: @PROJECT_NAME@
Version: @PROJECT_VERSION@
Description: "Description of @PROJECT_NAME@"
Description: "Description of @PROJECT_NAME@"
Libs: -L${libdir} -lexamplelibrary
Cflags: -I${includedir}
2 changes: 1 addition & 1 deletion cmake/EDM4HEPBuild.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ macro(edm4hep_set_compiler_flags)
message( STATUS "NOT Adding ${FLAG} to CXX_FLAGS" )
ENDIF()
ENDFOREACH()

# resolve which linker we use
execute_process(COMMAND ${CMAKE_CXX_COMPILER} -Wl,--version OUTPUT_VARIABLE stdout ERROR_QUIET)
if("${stdout}" MATCHES "GNU ")
Expand Down
14 changes: 7 additions & 7 deletions dataframe/edm4hepRDF.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@

namespace edm4hep {

std::vector<float> pt (std::vector<MCParticleData> const& in){
std::vector<float> pt(std::vector<MCParticleData> const& in) {
std::vector<float> result;
for (size_t i = 0; i < in.size(); ++i) {
result.push_back(std::sqrt(in[i].momentum.x * in[i].momentum.x + in[i].momentum.y * in[i].momentum.y));
}
return result;
}

std::vector<float> eta(std::vector<MCParticleData> const& in){
std::vector<float> eta(std::vector<MCParticleData> const& in) {
std::vector<float> result;
ROOT::Math::PxPyPzMVector lv;
for (size_t i = 0; i < in.size(); ++i) {
Expand All @@ -21,7 +21,7 @@ std::vector<float> eta(std::vector<MCParticleData> const& in){
return result;
}

std::vector<float> cos_theta(std::vector<MCParticleData> const& in){
std::vector<float> cos_theta(std::vector<MCParticleData> const& in) {
std::vector<float> result;
ROOT::Math::PxPyPzMVector lv;
for (size_t i = 0; i < in.size(); ++i) {
Expand All @@ -31,12 +31,12 @@ std::vector<float> cos_theta(std::vector<MCParticleData> const& in){
return result;
}

std::vector<double> r (std::vector<SimTrackerHitData> const& in) {
std::vector<double> r(std::vector<SimTrackerHitData> const& in) {
std::vector<double> result;
for (size_t i = 0; i < in.size(); ++i) {
result.push_back(std::sqrt(in[i].position.x*in[i].position.x + in[i].position.y*in[i].position.y));
result.push_back(std::sqrt(in[i].position.x * in[i].position.x + in[i].position.y * in[i].position.y));
}
return result;
return result;
}

}
} // namespace edm4hep
13 changes: 6 additions & 7 deletions dataframe/edm4hepRDF.h
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
#ifndef RDF_UTILITYLAMBDAS_H
#define RDF_UTILITYLAMBDAS_H
#ifndef RDF_UTILITYLAMBDAS_H
#define RDF_UTILITYLAMBDAS_H

#include <cmath>
#include <vector>

#include "edm4hep/MCParticleData.h"
#include "edm4hep/SimTrackerHitData.h"
#include "edm4hep/Vector3f.h"
#include "edm4hep/Vector3d.h"

#include "edm4hep/Vector3f.h"

namespace edm4hep {

/// get transverse momenta (GeV) of a MCParticle collection
std::vector<float> pt (std::vector<MCParticleData> const& in);
std::vector<float> pt(std::vector<MCParticleData> const& in);

/// get pseudorapidities of a MCParticle collection
std::vector<float> eta(std::vector<MCParticleData> const& in);
Expand All @@ -22,8 +21,8 @@ std::vector<float> eta(std::vector<MCParticleData> const& in);
std::vector<float> cos_theta(std::vector<MCParticleData> const& in);

/// get transverse radial distances of the coordinates of a SimTrackerHit Collection
std::vector<double> r (std::vector<SimTrackerHitData> const& in);
std::vector<double> r(std::vector<SimTrackerHitData> const& in);

}
} // namespace edm4hep

#endif
Loading

0 comments on commit b290a32

Please sign in to comment.