From 297869ec76ba35231404f1eab48f4237f8c9467b Mon Sep 17 00:00:00 2001 From: jmcarcell Date: Wed, 28 May 2025 22:16:25 +0200 Subject: [PATCH 1/4] Add pre-commit --- .github/scripts/clang-format-hook | 21 +++++++++++++++++++ .github/workflows/pre-commit.yml | 34 +++++++++++++++++++++++++++++++ .pre-commit-config.yaml | 14 +++++++++++++ 3 files changed, 69 insertions(+) create mode 100755 .github/scripts/clang-format-hook create mode 100644 .github/workflows/pre-commit.yml create mode 100644 .pre-commit-config.yaml diff --git a/.github/scripts/clang-format-hook b/.github/scripts/clang-format-hook new file mode 100755 index 0000000..731de08 --- /dev/null +++ b/.github/scripts/clang-format-hook @@ -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} diff --git a/.github/workflows/pre-commit.yml b/.github/workflows/pre-commit.yml new file mode 100644 index 0000000..5a079b4 --- /dev/null +++ b/.github/workflows/pre-commit.yml @@ -0,0 +1,34 @@ +name: pre-commit + +on: + push: + branches: + - master + pull_request: + workflow_dispatch: + +jobs: + pre-commit: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: cvmfs-contrib/github-action-cvmfs@v4 + - uses: aidasoft/run-lcg-view@v4 + with: + container: el9 + view-path: /cvmfs/sw-nightlies.hsf.org/key4hep + run: | + echo "::group::Setup pre-commit" + # Newer versions of git are more cautious around the github runner + # environment and without this git rev-parse --show-cdup in pre-commit + # fails + git config --global --add safe.directory $(pwd) + python -m venv /root/pre-commit-venv + source /root/pre-commit-venv/bin/activate + pip install pre-commit + echo "::endgroup::" + echo "::group::Run pre-commit" + pre-commit run --show-diff-on-failure \ + --color=always \ + --all-files + echo "::endgroup::" diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..f10bde8 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,14 @@ +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 + types: [c++] + language: system \ No newline at end of file From b1e024672540483487af6c0b74094effb9682280 Mon Sep 17 00:00:00 2001 From: jmcarcell Date: Wed, 28 May 2025 22:33:34 +0200 Subject: [PATCH 2/4] Format using pre-commit, including clang-format --- .clang-format | 4 ++-- .zenodo.json | 32 +++++++++++++------------- cmake/clang-cpp-checks.cmake | 6 ++--- include/Cell.h | 4 ++-- include/ConformalTracking.h | 4 ++-- include/ConformalTrackingV2.h | 2 +- include/DebugTool.h | 6 ++--- include/KDTrack.h | 4 ++-- include/KDTree.h | 2 +- include/KalmanTrack.h | 6 ++--- include/kdtree2.h | 4 ++-- source/test/TestConfig.cpp | 2 +- src/ConformalTracking.cc | 42 +++++++++++++++++------------------ src/ConformalTrackingV2.cc | 4 ++-- src/KDTrack.C | 2 +- src/KalmanTrack.C | 8 +++---- 16 files changed, 66 insertions(+), 66 deletions(-) diff --git a/.clang-format b/.clang-format index 9713f62..2093eeb 100644 --- a/.clang-format +++ b/.clang-format @@ -19,7 +19,7 @@ AlwaysBreakBeforeMultilineStrings: true AlwaysBreakTemplateDeclarations: false BinPackArguments: true BinPackParameters: true -BraceWrapping: +BraceWrapping: AfterClass: false AfterControlStatement: false AfterEnum: false @@ -47,7 +47,7 @@ DerivePointerAlignment: false DisableFormat: false ExperimentalAutoDetectBinPacking: false ForEachMacros: [ foreach, Q_FOREACH, BOOST_FOREACH ] -IncludeCategories: +IncludeCategories: - Regex: '^<.*\.h>' Priority: 1 - Regex: '^<.*' diff --git a/.zenodo.json b/.zenodo.json index c93fdf5..ccf1e12 100644 --- a/.zenodo.json +++ b/.zenodo.json @@ -1,43 +1,43 @@ { "license": "GPL-3.0", "contributors": [ - ], - "notes": "webpage: http://github.com/ilcsoft/ConformalTracking", - "language": "eng", - "upload_type": "software", + ], + "notes": "webpage: http://github.com/ilcsoft/ConformalTracking", + "language": "eng", + "upload_type": "software", "keywords": [ "Track Reconstruction, ConformalTracking, Pattern Recognition" ], "creators": [ { - "affiliation": "CERN", + "affiliation": "CERN", "name": "Hynds, Daniel" - }, + }, { - "affiliation": "CERN", + "affiliation": "CERN", "name": "Leogrande, Emilia" - }, + }, { - "affiliation": "CERN", + "affiliation": "CERN", "name": "Petric, Marko" - }, + }, { - "affiliation": "CERN", + "affiliation": "CERN", "name": "Sailer, Andre" }, { - "affiliation": "CERN", + "affiliation": "CERN", "name": "Brondolin, Erica" }, { - "affiliation": "DESY", + "affiliation": "DESY", "name": "Gaede, Frank" }, { - "affiliation": "CERN", + "affiliation": "CERN", "name": "Simoniello, Rosa" - } + } - ], + ], "access_right": "open" } diff --git a/cmake/clang-cpp-checks.cmake b/cmake/clang-cpp-checks.cmake index 2a628fb..66b1507 100644 --- a/cmake/clang-cpp-checks.cmake +++ b/cmake/clang-cpp-checks.cmake @@ -41,12 +41,12 @@ IF(CLANG_FORMAT) ${CLANG_FORMAT} -style=file -output-replacements-xml - ${CHECK_CXX_SOURCE_FILES} + ${CHECK_CXX_SOURCE_FILES} # print output - | tee ${CMAKE_BINARY_DIR}/check_format_file.txt | grep -c "replacement " | + | tee ${CMAKE_BINARY_DIR}/check_format_file.txt | grep -c "replacement " | tr -d "[:cntrl:]" && echo " replacements necessary" && cat ${CMAKE_BINARY_DIR}/check_format_file.txt # WARNING: fix to stop with error if there are problems - COMMAND ! grep -c "replacement " + COMMAND ! grep -c "replacement " ${CMAKE_BINARY_DIR}/check_format_file.txt > /dev/null COMMENT "Checking format compliance" ) diff --git a/include/Cell.h b/include/Cell.h index d88762c..b4666a3 100644 --- a/include/Cell.h +++ b/include/Cell.h @@ -28,8 +28,8 @@ class Cell { public: // Constructors, main initialisation is with two kd hits Cell() { m_weight = 0; } - Cell(const Cell&) = delete; - Cell(Cell&&) = default; + Cell(const Cell&) = delete; + Cell(Cell&&) = default; Cell& operator=(const Cell&) = delete; Cell(SKDCluster const& hit1, SKDCluster const& hit2) diff --git a/include/ConformalTracking.h b/include/ConformalTracking.h index f6b039b..d12087e 100644 --- a/include/ConformalTracking.h +++ b/include/ConformalTracking.h @@ -35,7 +35,7 @@ class ConformalTracking : public Processor { ConformalTracking(); ConformalTracking(std::string const& procName); - ConformalTracking(const ConformalTracking&) = delete; + ConformalTracking(const ConformalTracking&) = delete; ConformalTracking& operator=(const ConformalTracking&) = delete; // Initialisation - run at the beginning to start histograms, etc. @@ -54,7 +54,7 @@ class ConformalTracking : public Processor { virtual void processEvent(LCEvent* evt); // Run at the end of each event - virtual void check(LCEvent*){}; + virtual void check(LCEvent*) {}; // Called at the very end for cleanup, histogram saving, etc. virtual void end(); diff --git a/include/ConformalTrackingV2.h b/include/ConformalTrackingV2.h index 1b09459..0c6de12 100644 --- a/include/ConformalTrackingV2.h +++ b/include/ConformalTrackingV2.h @@ -8,7 +8,7 @@ class ConformalTrackingV2 : public ConformalTracking { virtual Processor* newProcessor() { return new ConformalTrackingV2; } ConformalTrackingV2(); - ConformalTrackingV2(const ConformalTrackingV2&) = delete; + ConformalTrackingV2(const ConformalTrackingV2&) = delete; ConformalTrackingV2& operator=(const ConformalTrackingV2&) = delete; // Called at the beginning of every run diff --git a/include/DebugTool.h b/include/DebugTool.h index f72bcb2..e68ec9b 100644 --- a/include/DebugTool.h +++ b/include/DebugTool.h @@ -28,10 +28,10 @@ using SLCRelationNavigator = std::shared_ptr; class ConformalDebugger { public: //--- Constructor and destructor - ConformalDebugger(){}; - ~ConformalDebugger(){}; + ConformalDebugger() {}; + ~ConformalDebugger() {}; - ConformalDebugger(const ConformalDebugger&) = delete; + ConformalDebugger(const ConformalDebugger&) = delete; ConformalDebugger& operator=(const ConformalDebugger&) = delete; //--- Member variables diff --git a/include/KDTrack.h b/include/KDTrack.h index 5cc8fdc..fb47cd1 100644 --- a/include/KDTrack.h +++ b/include/KDTrack.h @@ -23,7 +23,7 @@ class KDTrack { KDTrack(Parameters const& par); ~KDTrack(); - KDTrack(const KDTrack&) = default; + KDTrack(const KDTrack&) = default; KDTrack& operator=(const KDTrack&) = delete; //--- Functions to add and remove clusters @@ -36,7 +36,7 @@ class KDTrack { m_nPoints++; } void remove(int clusterN) { - if(clusterN < 0 || clusterN >= int(m_clusters.size())) { + if (clusterN < 0 || clusterN >= int(m_clusters.size())) { throw std::out_of_range("KDTrack::remove: clusterN out of range"); } m_clusters.erase(m_clusters.begin() + clusterN); diff --git a/include/KDTree.h b/include/KDTree.h index 1783f15..e42dddb 100644 --- a/include/KDTree.h +++ b/include/KDTree.h @@ -37,7 +37,7 @@ class KDTree { explicit KDTree(const SharedKDClusters& pts, double overlapTheta, bool sort); ~KDTree(); - KDTree(const KDTree&) = delete; + KDTree(const KDTree&) = delete; KDTree& operator=(const KDTree&) = delete; void nearestNeighbours( diff --git a/include/KalmanTrack.h b/include/KalmanTrack.h index 7924535..794677c 100644 --- a/include/KalmanTrack.h +++ b/include/KalmanTrack.h @@ -15,7 +15,7 @@ class KalmanNode { public: // Constructor - KalmanNode(){}; + KalmanNode() {}; KalmanNode(SKDCluster measurement, bool rotated) { if (!rotated) { m_uMeasured = measurement->getU(); @@ -29,7 +29,7 @@ class KalmanNode { }; // Destructor - ~KalmanNode(){}; + ~KalmanNode() {}; // Functions @@ -68,7 +68,7 @@ class KalmanTrack { KalmanTrack(); KalmanTrack(KDTrack*); - KalmanTrack(const KalmanTrack&) = default; + KalmanTrack(const KalmanTrack&) = default; KalmanTrack& operator=(const KalmanTrack&) = default; // Destructor diff --git a/include/kdtree2.h b/include/kdtree2.h index a327704..8adfbc5 100644 --- a/include/kdtree2.h +++ b/include/kdtree2.h @@ -101,7 +101,7 @@ namespace kdtree2 { KDTree(KDTreeArray& data_in, bool rearrange_in = true, int dim_in = -1); - KDTree(const KDTree&) = delete; + KDTree(const KDTree&) = delete; KDTree& operator=(const KDTree&) = delete; // destructor @@ -180,7 +180,7 @@ namespace kdtree2 { // destructor ~KDTreeNode(); - KDTreeNode(const KDTreeNode&) = delete; + KDTreeNode(const KDTreeNode&) = delete; KDTreeNode& operator=(const KDTreeNode&) = delete; private: diff --git a/source/test/TestConfig.cpp b/source/test/TestConfig.cpp index 81cc220..358adbe 100644 --- a/source/test/TestConfig.cpp +++ b/source/test/TestConfig.cpp @@ -112,7 +112,7 @@ int main() { } else { std::cout << "\\x" << std::setw(2) << std::setfill('0') << std::hex << static_cast(c); } //if - } //while + } //while std::cout << std::endl; return 1; } //if diff --git a/src/ConformalTracking.cc b/src/ConformalTracking.cc index 36ecff0..f820eaa 100644 --- a/src/ConformalTracking.cc +++ b/src/ConformalTracking.cc @@ -52,9 +52,9 @@ using namespace AIDA; ConformalTracking aConformalTracking; /* - + Pattern recognition code for the CLIC detector, using conformal mapping and cellular automaton - + */ class TooManyTracksException : public marlin::SkipEventException { @@ -625,55 +625,55 @@ void ConformalTracking::processEvent(LCEvent* evt) { /*std::sort(conformalTracks.begin(),conformalTracks.end(),sort_by_length); for(int existingTrack=0;existingTrack= 2) { clone = true; - + // Calculate the new and existing chi2 values double newchi2 = (conformalTracks[existingTrack]->chi2ndofZS()*conformalTracks[existingTrack]->chi2ndofZS() + conformalTracks[existingTrack]->chi2ndof()*conformalTracks[existingTrack]->chi2ndof()); double oldchi2 = (conformalTracksFinal[savedTrack]->chi2ndofZS()*conformalTracksFinal[savedTrack]->chi2ndofZS() + conformalTracksFinal[savedTrack]->chi2ndof()*conformalTracksFinal[savedTrack]->chi2ndof()); - + double deltachi2ZS = (conformalTracks[existingTrack]->chi2ndofZS()-conformalTracksFinal[savedTrack]->chi2ndofZS()); double deltachi2 = (conformalTracks[existingTrack]->chi2ndof()-conformalTracksFinal[savedTrack]->chi2ndof()); - + // If the new track is a subtrack of an existing track, don't consider it further (already try removing bad hits from tracks if(nOverlappingHits == conformalTracks[existingTrack]->m_clusters.size()) break; - + // Otherwise take the longest if the delta chi2 is not too much else if(conformalTracks[existingTrack]->m_clusters.size() >= conformalTracksFinal[savedTrack]->m_clusters.size()){ // New track longer/equal in length - + // Increase in chi2 is too much (double) if( (newchi2 - oldchi2) > oldchi2) break; - + // Otherwise take it delete conformalTracksFinal[savedTrack]; conformalTracksFinal[savedTrack] = conformalTracks[existingTrack]; saved = true; } else if(conformalTracks[existingTrack]->m_clusters.size() < conformalTracksFinal[savedTrack]->m_clusters.size()){ // Old track longer - + // Must improve chi2 by factor two if( (newchi2 - 0.5*oldchi2) > 0.) break; - + // Otherwise take it delete conformalTracksFinal[savedTrack]; conformalTracksFinal[savedTrack] = conformalTracks[existingTrack]; saved = true; } - + break; } } - + if(!clone){ conformalTracksFinal.push_back(conformalTracks[existingTrack]); }else{ if(!saved) delete conformalTracks[existingTrack]; } - + } //*/ @@ -2384,7 +2384,7 @@ void ConformalTracking::getLowestChi2(UniqueKDTracks& finalTracks, UniqueKDTrack // double lowestChi2ndof = *std::min_element(trackChi2ndofs.begin(),trackChi2ndofs.end()); UKDTrack& lowestChi2ndofTrack = trackContainer[0]; double lowestChi2ndof = sqrt(lowestChi2ndofTrack->chi2ndof() * lowestChi2ndofTrack->chi2ndof() + - lowestChi2ndofTrack->chi2ndofZS() * lowestChi2ndofTrack->chi2ndofZS()); + lowestChi2ndofTrack->chi2ndofZS() * lowestChi2ndofTrack->chi2ndofZS()); for (auto& itTrack : trackContainer) { double chi2ndof = sqrt(itTrack->chi2ndof() * itTrack->chi2ndof() + itTrack->chi2ndofZS() * itTrack->chi2ndofZS()); @@ -2535,12 +2535,12 @@ void ConformalTracking::fitWithPoint(KDTrack kdTrack, SKDCluster& hit, double& d double chi2 = kdTrack.chi2ndof(); double chi2zs = kdTrack.chi2ndofZS(); /*if(m_debugPlots){ - + double xMeasured = hit->getU(); double yMeasured = hit->getV(); double dx = hit->getErrorU(); double dv = hit->getErrorV(); - + if(kdTrack.m_rotated){ double newxMeasured = yMeasured; double newyMeasured = -1. * xMeasured; @@ -2555,9 +2555,9 @@ void ConformalTracking::fitWithPoint(KDTrack kdTrack, SKDCluster& hit, double& d // Get the error on the hit position double term = kdTrack.m_gradient + 2. * kdTrack.m_quadratic * xMeasured; double dy2 = (dv * dv) + (term * term * dx * dx); - + streamlog_out(DEBUG7)<<"- hit has delta chi2 of "<<(residualY * residualY) / (dy2)< M_PI){ if(prevPhi > M_PI) phi += (2.*M_PI); else phi = (2.*M_PI) - phi; diff --git a/src/KalmanTrack.C b/src/KalmanTrack.C index 418e2e9..d3d9eac 100644 --- a/src/KalmanTrack.C +++ b/src/KalmanTrack.C @@ -151,7 +151,7 @@ double KalmanTrack::addCluster(SKDCluster cluster) { /* double b = 1./(2.*m_conformalTrack->intercept()); double a = -1.*b*m_conformalTrack->gradient(); - + double db = 0; double da = 0; @@ -166,7 +166,7 @@ double KalmanTrack::addCluster(SKDCluster cluster) { dx = cluster->getErrorY(); dy = cluster->getErrorX(); } - + double s = atan2(yMb,xMa); double ratio = yMb/xMa; @@ -174,10 +174,10 @@ double KalmanTrack::addCluster(SKDCluster cluster) { double residualZ = (m_conformalTrack->gradientZS()*s + m_conformalTrack->interceptZS()) - cluster->getZ(); double ds = errorS; double dz = cluster->getErrorZ(); - + double ds2 = (dz*dz) + (m_conformalTrack->gradientZS()*m_conformalTrack->gradientZS() * ds*ds); // double ds2 = (m_gradientZS*m_gradientZS * dz*dz); - + // std::cout<<"- residual is "< Date: Mon, 2 Jun 2025 09:38:32 +0200 Subject: [PATCH 3/4] Default d'tors and c'tors and remove unused overload --- include/ConformalTracking.h | 3 --- include/DebugTool.h | 4 ++-- include/KalmanTrack.h | 4 ++-- 3 files changed, 4 insertions(+), 7 deletions(-) diff --git a/include/ConformalTracking.h b/include/ConformalTracking.h index d12087e..d3e87b5 100644 --- a/include/ConformalTracking.h +++ b/include/ConformalTracking.h @@ -53,9 +53,6 @@ class ConformalTracking : public Processor { // Run over each event - the main algorithm virtual void processEvent(LCEvent* evt); - // Run at the end of each event - virtual void check(LCEvent*) {}; - // Called at the very end for cleanup, histogram saving, etc. virtual void end(); diff --git a/include/DebugTool.h b/include/DebugTool.h index e68ec9b..d6a79ee 100644 --- a/include/DebugTool.h +++ b/include/DebugTool.h @@ -28,8 +28,8 @@ using SLCRelationNavigator = std::shared_ptr; class ConformalDebugger { public: //--- Constructor and destructor - ConformalDebugger() {}; - ~ConformalDebugger() {}; + ConformalDebugger() = default; + ~ConformalDebugger() = default; ConformalDebugger(const ConformalDebugger&) = delete; ConformalDebugger& operator=(const ConformalDebugger&) = delete; diff --git a/include/KalmanTrack.h b/include/KalmanTrack.h index 794677c..7114c6c 100644 --- a/include/KalmanTrack.h +++ b/include/KalmanTrack.h @@ -15,7 +15,7 @@ class KalmanNode { public: // Constructor - KalmanNode() {}; + KalmanNode() = default; KalmanNode(SKDCluster measurement, bool rotated) { if (!rotated) { m_uMeasured = measurement->getU(); @@ -29,7 +29,7 @@ class KalmanNode { }; // Destructor - ~KalmanNode() {}; + ~KalmanNode() = default; // Functions From 8afdc16da7172161205009e348be580425bee429 Mon Sep 17 00:00:00 2001 From: Thomas Madlener Date: Mon, 2 Jun 2025 09:40:17 +0200 Subject: [PATCH 4/4] Remove unnecessary comments --- source/test/TestConfig.cpp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/source/test/TestConfig.cpp b/source/test/TestConfig.cpp index 358adbe..a65aa69 100644 --- a/source/test/TestConfig.cpp +++ b/source/test/TestConfig.cpp @@ -90,8 +90,7 @@ int main() { It startString = begin(configString), endString = end(configString); bool ok = qi::phrase_parse(startString, endString, myGrammar, qi::blank, parsed); - std::cout << "--- File ---" - << "\n"; + std::cout << "--- File ---\n"; std::cout << "parsed = " << std::boolalpha << ok << "\n"; if (ok) { std::cout << "Number " << parsed.size() << std::endl; @@ -111,8 +110,8 @@ int main() { std::cout << c; } else { std::cout << "\\x" << std::setw(2) << std::setfill('0') << std::hex << static_cast(c); - } //if - } //while + } + } std::cout << std::endl; return 1; } //if