Skip to content

Commit

Permalink
Merge branch 'main' into fix/gcc14-false-positive
Browse files Browse the repository at this point in the history
  • Loading branch information
kodiakhq[bot] authored Nov 12, 2024
2 parents dce08ed + b14548d commit 39a7946
Show file tree
Hide file tree
Showing 289 changed files with 2,769 additions and 2,107 deletions.
10 changes: 10 additions & 0 deletions .github/workflows/checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,16 @@ jobs:
- name: Check
run: >
CI/check_spelling
math_macros:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: '3.12'
- name: Check
run: >
CI/check_math_macros.py . --exclude "thirdparty/*"
missing_includes:
runs-on: ubuntu-latest
steps:
Expand Down
2 changes: 0 additions & 2 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@ clang_tidy:
-DCMAKE_CXX_COMPILER=clang++
-DCMAKE_C_COMPILER=clang
-DPython_EXECUTABLE=$(which python3)
-DACTS_RUN_CLANG_TIDY=ON
-DACTS_BUILD_ODD=OFF
# Main clang-tidy run during cmake compilation
- CI/clang_tidy/run_clang_tidy.sh clang-tidy build
Expand Down
8 changes: 8 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -93,3 +93,11 @@ repos:
name: Leftover conflict markers
language: system
entry: git diff --staged --check

- repo: local
hooks:
- id: math_macros
name: math_macros
language: system
entry: CI/check_math_macros.py
files: \.(cpp|hpp|ipp|cu|cuh)$
120 changes: 120 additions & 0 deletions CI/check_math_macros.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
#!/usr/bin/env python3

from pathlib import Path
import os
import argparse
from fnmatch import fnmatch
import re
import sys


math_constants = [
("M_PI", "std::numbers::pi"),
("M_PI_2", "std::numbers::pi / 2."),
("M_PI_4", "std::numbers::pi / 4."),
("M_1_PI", "std::numbers::inv_pi"),
("M_2_PI", "2. * std::numbers::inv_pi"),
("M_2_SQRTPI", "2. * std::numbers::inv_sqrtpi"),
("M_E", "std::numbers::e"),
("M_LOG2E", "std::numbers::log2e"),
("M_LOG10E", "std::numbers::log10e"),
("M_LN2", "std::numbers::ln2"),
("M_LN10", "std::numbers::ln10"),
("M_SQRT2", "std::numbers::sqrt2"),
("M_SQRT1_2", "1. / std::numbers::sqrt2"),
("M_SQRT3", "std::numbers::sqrt3"),
("M_INV_SQRT3", "std::numbers::inv_sqrt3"),
("M_EGAMMA", "std::numbers::egamma"),
("M_PHI", "std::numbers::phi"),
]


github = "GITHUB_ACTIONS" in os.environ


def handle_file(
file: Path, fix: bool, math_const: tuple[str, str]
) -> list[tuple[int, str]]:
ex = re.compile(rf"(?<!\w){math_const[0]}(?!\w)")

content = file.read_text()
lines = content.splitlines()

changed_lines = []

for i, oline in enumerate(lines):
line, n_subs = ex.subn(rf"{math_const[1]}", oline)
lines[i] = line
if n_subs > 0:
changed_lines.append((i, oline))

if fix and len(changed_lines) > 0:
file.write_text("\n".join(lines) + "\n")

return changed_lines


def main():
p = argparse.ArgumentParser()
p.add_argument("input", nargs="+")
p.add_argument("--fix", action="store_true", help="Attempt to fix M_* macros.")
p.add_argument("--exclude", "-e", action="append", default=[])

args = p.parse_args()

exit_code = 0

inputs = []

if len(args.input) == 1 and os.path.isdir(args.input[0]):
# walk over all files
for root, _, files in os.walk(args.input[0]):
root = Path(root)
for filename in files:
# get the full path of the file
filepath = root / filename
if filepath.suffix not in (
".hpp",
".cpp",
".ipp",
".h",
".C",
".c",
".cu",
".cuh",
):
continue

if any([fnmatch(str(filepath), e) for e in args.exclude]):
continue

inputs.append(filepath)
else:
for file in args.input:
inputs.append(Path(file))

for filepath in inputs:
for math_const in math_constants:
changed_lines = handle_file(
file=filepath, fix=args.fix, math_const=math_const
)
if len(changed_lines) > 0:
exit_code = 1
print()
print(filepath)
for i, oline in changed_lines:
print(f"{i}: {oline}")

if github:
print(
f"::error file={filepath},line={i+1},title=Do not use macro {math_const[0]}::Replace {math_const[0]} with std::{math_const[1]}"
)

if exit_code == 1 and github:
print(f"::info You will need in each flagged file #include <numbers>")

return exit_code


if "__main__" == __name__:
sys.exit(main())
5 changes: 5 additions & 0 deletions CI/physmon/config/pythia8_ttbar.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,8 @@ exclude:
- particle
- generation
- sub_particle
- e_loss
- total_x0
- total_l0
- number_of_hits
- outcome
6 changes: 2 additions & 4 deletions CI/physmon/workflows/physmon_simulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,7 @@
preSelectParticles=None,
postSelectParticles=ParticleSelectorConfig(removeSecondaries=True),
inputParticles="particles_input",
outputParticlesInitial="particles_initial_fatras",
outputParticlesFinal="particles_final_fatras",
outputParticles="particles_fatras",
outputSimHits="simhits_fatras",
outputDirRoot=tp / "fatras",
)
Expand All @@ -99,8 +98,7 @@
killAfterTime=25 * u.ns,
killSecondaries=True,
inputParticles="particles_input",
outputParticlesInitial="particles_initial_geant4",
outputParticlesFinal="particles_final_geant4",
outputParticles="particles_geant4",
outputSimHits="simhits_geant4",
outputDirRoot=tp / "geant4",
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include <cstddef>
#include <map>
#include <memory>
#include <numbers>
#include <string>
#include <tuple>
#include <vector>
Expand Down Expand Up @@ -103,8 +104,8 @@ class ScoreBasedAmbiguityResolution {
double pTMin = 0 * UnitConstants::GeV;
double pTMax = 1e5 * UnitConstants::GeV;

double phiMin = -M_PI * UnitConstants::rad;
double phiMax = M_PI * UnitConstants::rad;
double phiMin = -std::numbers::pi * UnitConstants::rad;
double phiMax = std::numbers::pi * UnitConstants::rad;

double etaMin = -5;
double etaMax = 5;
Expand Down
4 changes: 3 additions & 1 deletion Core/include/Acts/Definitions/Units.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

#pragma once

#include <numbers>

namespace Acts {

/// @verbatim embed:rst:leading-slashes
Expand Down Expand Up @@ -170,7 +172,7 @@ constexpr double h = 3600.0 * s;
// Angles, native unit radian
constexpr double mrad = 1e-3;
constexpr double rad = 1.0;
constexpr double degree = 0.017453292519943295; // = M_PI / 180.0 * rad;
constexpr double degree = std::numbers::pi / 180. / rad;
// Energy/mass/momentum, native unit GeV
constexpr double GeV = 1.0;
constexpr double eV = 1e-9 * GeV;
Expand Down
3 changes: 2 additions & 1 deletion Core/include/Acts/EventData/ProxyAccessor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ struct ProxyAccessorBase {

/// Create the accessor from a string key
/// @param _key the key
ProxyAccessorBase(const std::string& _key) : key{hashString(_key)} {}
constexpr ProxyAccessorBase(const std::string& _key)
: key{hashString(_key)} {}

/// Access the stored key on the proxy given as an argument. Mutable version
/// @tparam proxy_t the type of the proxy
Expand Down
7 changes: 5 additions & 2 deletions Core/include/Acts/EventData/TransformationHelpers.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
#include "Acts/Utilities/Result.hpp"
#include "Acts/Utilities/detail/periodic.hpp"

#include <numbers>

namespace Acts {

class Surface;
Expand All @@ -25,8 +27,9 @@ class Surface;
/// @return Reflected bound track parameters vector
inline BoundVector reflectBoundParameters(const BoundVector& boundParams) {
BoundVector reflected = boundParams;
auto [phi, theta] = detail::normalizePhiTheta(
boundParams[eBoundPhi] - M_PI, M_PI - boundParams[eBoundTheta]);
auto [phi, theta] =
detail::normalizePhiTheta(boundParams[eBoundPhi] - std::numbers::pi,
std::numbers::pi - boundParams[eBoundTheta]);
reflected[eBoundPhi] = phi;
reflected[eBoundTheta] = theta;
reflected[eBoundQOverP] = -boundParams[eBoundQOverP];
Expand Down
96 changes: 0 additions & 96 deletions Core/include/Acts/EventData/detail/CalculateResiduals.hpp

This file was deleted.

7 changes: 4 additions & 3 deletions Core/include/Acts/EventData/detail/ParameterTraits.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include <algorithm>
#include <cmath>
#include <cstddef>
#include <numbers>

namespace Acts::detail {

Expand Down Expand Up @@ -106,12 +107,12 @@ struct CyclicParameterTraits {
//
// The functions names are chosen to be consistent w/ std::numeric_limits
struct PhiBoundParameterLimits {
static constexpr double lowest() { return -M_PI; }
static constexpr double max() { return M_PI; }
static constexpr double lowest() { return -std::numbers::pi; }
static constexpr double max() { return std::numbers::pi; }
};
struct ThetaBoundParameterLimits {
static constexpr double lowest() { return 0; }
static constexpr double max() { return M_PI; }
static constexpr double max() { return std::numbers::pi; }
};

// Traits implementation structs for single parameters.
Expand Down
6 changes: 4 additions & 2 deletions Core/include/Acts/Geometry/CylinderVolumeBounds.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include <initializer_list>
#include <iosfwd>
#include <memory>
#include <numbers>
#include <ostream>
#include <vector>

Expand Down Expand Up @@ -105,8 +106,9 @@ class CylinderVolumeBounds : public VolumeBounds {
/// @param bevelMinZ The bevel angle, in radians, for the negative side
/// @param bevelMaxZ The bevel angle, in radians, for the positive side
CylinderVolumeBounds(ActsScalar rmin, ActsScalar rmax, ActsScalar halfz,
ActsScalar halfphi = M_PI, ActsScalar avgphi = 0.,
ActsScalar bevelMinZ = 0., ActsScalar bevelMaxZ = 0.);
ActsScalar halfphi = std::numbers::pi_v<ActsScalar>,
ActsScalar avgphi = 0., ActsScalar bevelMinZ = 0.,
ActsScalar bevelMaxZ = 0.);

/// Constructor - from a fixed size array
///
Expand Down
Loading

0 comments on commit 39a7946

Please sign in to comment.