10 from particle
import Particle
14 Generate the code and write it to the given output file.
18 for p
in Particle.all():
19 table.append((
int(p.pdgid),
int(p.three_charge), p.mass, p.name))
23 output_file.write(code)
26 // This file is part of the Acts project.
28 // Copyright (C) 2020 CERN for the benefit of the Acts project
30 // This Source Code Form is subject to the terms of the Mozilla Public
31 // License, v. 2.0. If a copy of the MPL was not distributed with this
32 // file, You can obtain one at http://mozilla.org/MPL/2.0/.
34 // The entries within this file have been automatically created using the
35 // particle data files from the 2019 edition of the Review of Particle Physics
36 // by the Berkeley Particle Data Group.
42 // Rows within the particle data table are sorted by their signed PDG particle
43 // number and are then stored column-wise. Since the PDG particle number column
44 // is sorted it can be used to quickly search for the index of a particle
45 // within all column arrays.
54 table = sorted(table, key=
lambda _: _[0])
58 (
'PdgNumber',
'int32_t',
'{}'),
59 (
'ThreeCharge',
'int8_t',
'{}'),
60 (
'MassMeV',
'float',
'{}f'),
61 (
'Name',
'char* const ',
'"{}"'),
65 f
'static constexpr uint32_t kParticlesCount = {num_rows}u;',
68 for i, (variable_name, type_name, value_format)
in enumerate(columns):
69 lines.append(f
'static const {type_name} kParticles{variable_name}[kParticlesCount] = {{')
70 lines.append(
' ' +
', '.join(value_format.format(row[i])
for row
in table) +
',')
74 return '\n'.join(lines)
78 Format the given content using clang-format and return it.
82 '--assume-filename=ParticleData.hpp',
85 process = subprocess.run(args, input=content, capture_output=
True,
86 check=
True, encoding=
'utf-8', text=
True)
89 if __name__ ==
'__main__':
90 if (2 < len(sys.argv)):
91 print(
'usage: {} [<output_file>]'.format(sys.argv[0]))
93 if len(sys.argv) == 1:
94 output_file = sys.stdout
97 output_file = io.open(sys.argv[1], mode=
'wt', encoding=
'utf-8')