Skip to content

Commit

Permalink
chore: Update particle data script (#4081)
Browse files Browse the repository at this point in the history
- Encode the `particle` package version used to run (also you can run this with `uv run` now)
- Make the output use `std::type_t` as per our guidelines
- Make the output use `std::array` over C-style arrays
  • Loading branch information
paulgessinger authored Feb 13, 2025
1 parent 36cc0cb commit 260a143
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 deletions.
9 changes: 5 additions & 4 deletions Core/src/Definitions/ParticleDataTable.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

#pragma once

#include <array>
#include <cstdint>
#include <limits>

Expand All @@ -21,7 +22,7 @@
// within all column arrays.

static constexpr std::uint32_t kParticlesCount = 6502u;
static const std::int32_t kParticlesPdgNumber[kParticlesCount] = {
static const std::array<std::int32_t, kParticlesCount> kParticlesPdgNumber = {
// Og294~
-1001182940,
// Ts294~
Expand Down Expand Up @@ -13027,7 +13028,7 @@ static const std::int32_t kParticlesPdgNumber[kParticlesCount] = {
// Og294
1001182940,
};
static const std::int16_t kParticlesThreeCharge[kParticlesCount] = {
static const std::array<std::int16_t, kParticlesCount> kParticlesThreeCharge = {
// Og294~
-354,
// Ts294~
Expand Down Expand Up @@ -26033,7 +26034,7 @@ static const std::int16_t kParticlesThreeCharge[kParticlesCount] = {
// Og294
354,
};
static const float kParticlesMassMeV[kParticlesCount] = {
static const std::array<float, kParticlesCount> kParticlesMassMeV = {
// Og294~
0.0f,
// Ts294~
Expand Down Expand Up @@ -39039,7 +39040,7 @@ static const float kParticlesMassMeV[kParticlesCount] = {
// Og294
0.0f,
};
static const char* const kParticlesName[kParticlesCount] = {
static const std::array<const char* const, kParticlesCount> kParticlesName = {
"Og294~",
"Ts294~",
"Lv293~",
Expand Down
16 changes: 12 additions & 4 deletions Fatras/scripts/generate_particle_data_table.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
#!/usr/bin/env python3

# /// script
# dependencies = [
# "particle==0.24.0",
# ]
# ///

#
# use scikit-hep/particle to generate c++ code for the particle data table.
#
Expand Down Expand Up @@ -40,6 +47,7 @@ def main(output_file):
#pragma once
#include <cstdint>
#include <array>
#include <limits>
// Rows within the particle data table are sorted by their signed PDG particle
Expand All @@ -59,10 +67,10 @@ def generate_code(table):
num_rows = len(table)
# name, c++ type, and output format for each column
columns = [
("PdgNumber", "int32_t", "{}"),
("ThreeCharge", "int16_t", "{}"),
("PdgNumber", "std::int32_t", "{}"),
("ThreeCharge", "std::int16_t", "{}"),
("MassMeV", "float", "{}f"),
("Name", "char* const ", '"{}"'),
("Name", " const char* const", '"{}"'),
]
lines = [
CODE_HEADER,
Expand All @@ -71,7 +79,7 @@ def generate_code(table):
# build a separate array for each column
for i, (variable_name, type_name, value_format) in enumerate(columns):
lines.append(
f"static const {type_name} kParticles{variable_name}[kParticlesCount] = {{"
f"static const std::array<{type_name}, kParticlesCount> kParticles{variable_name} = {{"
)

for row in table:
Expand Down

0 comments on commit 260a143

Please sign in to comment.