10 from particle
import Particle
15 Generate the code and write it to the given output file.
19 for p
in Particle.all():
20 table.append((int(p.pdgid), int(p.three_charge), p.mass, p.name))
24 output_file.write(code)
28 // This file is part of the Acts project.
30 // Copyright (C) 2020 CERN for the benefit of the Acts project
32 // This Source Code Form is subject to the terms of the Mozilla Public
33 // License, v. 2.0. If a copy of the MPL was not distributed with this
34 // file, You can obtain one at http://mozilla.org/MPL/2.0/.
36 // The entries within this file have been automatically created using the
37 // particle data files from the 2019 edition of the Review of Particle Physics
38 // by the Berkeley Particle Data Group.
44 // Rows within the particle data table are sorted by their signed PDG particle
45 // number and are then stored column-wise. Since the PDG particle number column
46 // is sorted it can be used to quickly search for the index of a particle
47 // within all column arrays.
57 table = sorted(table, key=
lambda _: _[0])
61 (
"PdgNumber",
"int32_t",
"{}"),
62 (
"ThreeCharge",
"int8_t",
"{}"),
63 (
"MassMeV",
"float",
"{}f"),
64 (
"Name",
"char* const ",
'"{}"'),
68 f
"static constexpr uint32_t kParticlesCount = {num_rows}u;",
71 for i, (variable_name, type_name, value_format)
in enumerate(columns):
73 f
"static const {type_name} kParticles{variable_name}[kParticlesCount] = {{"
76 " " +
", ".
join(value_format.format(row[i])
for row
in table) +
","
81 return "\n".
join(lines)
86 Format the given content using clang-format and return it.
90 "--assume-filename=ParticleData.hpp",
93 process = subprocess.run(
101 return process.stdout
104 if __name__ ==
"__main__":
105 if 2 < len(sys.argv):
106 print(
"usage: {} [<output_file>]".
format(sys.argv[0]))
108 if len(sys.argv) == 1:
109 output_file = sys.stdout
112 output_file = io.open(sys.argv[1], mode=
"wt", encoding=
"utf-8")