Skip to content

Commit e6b57f2

Browse files
committed
Add main
1 parent 527dbd4 commit e6b57f2

File tree

1 file changed

+55
-46
lines changed

1 file changed

+55
-46
lines changed

Common/Constants/include/CommonConstants/make_pdg_header.py

Lines changed: 55 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323

2424
import ROOT # pylint: disable=import-error
2525

26-
name_script = os.path.basename(__file__)
2726

2827
# Enum of PDG_t particles
2928
class PdgROOT(Enum):
@@ -149,6 +148,7 @@ class Pdg(Enum):
149148
kHyperHelium4Sigma = 1110020040
150149
kLambda1520_Py = 102134 # PYTHIA code different from PDG
151150

151+
152152
dbPdg = ROOT.o2.O2DatabasePDG
153153

154154

@@ -159,49 +159,58 @@ def mass(code):
159159
return dbPdg.Mass(code, success)
160160

161161

162-
def declare_mass(pdg, type="double") -> str:
162+
def declare_mass(pdg, val_type="double") -> str:
163163
"""Returns a C++ declaration of a particle mass constant."""
164-
return f"constexpr {type} Mass{pdg.name[1:]} = {mass(pdg.value)};\n"
165-
166-
167-
# Comment at the beginning of the output
168-
str_block_begin = f"""// BEGINNING OF THE GENERATED BLOCK.
169-
// DO NOT EDIT THIS BLOCK DIRECTLY!
170-
// It has been generated by the {name_script} script.
171-
// For modifications, edit the script and generate this block again.
172-
"""
173-
# Comment at the end of the output
174-
str_block_end = """// END OF THE GENERATED BLOCK
175-
"""
176-
# Start of enum declarations of additional particles
177-
str_enum_head = """/// \\brief Declarations of named PDG codes of particles missing in ROOT PDG_t
178-
/// \\note Follow kCamelCase naming convention
179-
/// \\link https://root.cern/doc/master/TPDGCode_8h.html
180-
enum Pdg {
181-
"""
182-
# End of enum declarations of additional particles
183-
str_enum_foot = "};\n"
184-
# Documentation string for mass declarations of additional particles
185-
str_mass_o2_head = """/// \\brief Declarations of masses for additional particles
186-
"""
187-
# Documentation string for mass declarations of PDG_t particles
188-
str_mass_root_head = """/// \\brief Declarations of masses for particles in ROOT PDG_t
189-
"""
190-
191-
# Additional particles
192-
str_enum = str_enum_head
193-
str_mass_o2 = str_mass_o2_head
194-
for c in Pdg:
195-
str_enum += f" {c.name} = {c.value},\n"
196-
str_mass_o2 += declare_mass(c)
197-
str_enum = str_enum[:-2] + "\n" # Remove the last comma.
198-
str_enum += str_enum_foot
199-
200-
# PDG_t particles
201-
str_mass_root = str_mass_root_head
202-
for d in PdgROOT:
203-
str_mass_root += declare_mass(d)
204-
205-
# Header body
206-
str_header = "\n".join((str_block_begin, str_enum, str_mass_o2, str_mass_root, str_block_end))
207-
print(str_header)
164+
return f"constexpr {val_type} Mass{pdg.name[1:]} = {mass(pdg.value)};\n"
165+
166+
167+
def main():
168+
"""Main function"""
169+
170+
name_script = os.path.basename(__file__)
171+
172+
# Comment at the beginning of the output
173+
str_block_begin = "// BEGINNING OF THE GENERATED BLOCK."
174+
# Preamble with instructions
175+
str_block_preamble = (
176+
"// DO NOT EDIT THIS BLOCK DIRECTLY!"
177+
f"\n// It has been generated by the {name_script} script."
178+
"\n// For modifications, edit the script and generate this block again.\n"
179+
)
180+
# Comment at the end of the output
181+
str_block_end = "// END OF THE GENERATED BLOCK"
182+
# Start of enum declarations of additional particles
183+
str_enum_head = (
184+
"/// \\brief Declarations of named PDG codes of particles missing in ROOT PDG_t"
185+
"\n/// \\note Follow kCamelCase naming convention"
186+
"\n/// \\link https://root.cern/doc/master/TPDGCode_8h.html"
187+
"\nenum Pdg {"
188+
)
189+
# End of enum declarations of additional particles
190+
str_enum_foot = "};\n"
191+
# Documentation string for mass declarations of additional particles
192+
str_mass_o2_head = "/// \\brief Declarations of masses for additional particles"
193+
# Documentation string for mass declarations of PDG_t particles
194+
str_mass_root_head = "/// \\brief Declarations of masses for particles in ROOT PDG_t"
195+
196+
# Additional particles
197+
str_enum = str_enum_head
198+
str_mass_o2 = str_mass_o2_head
199+
for c in Pdg:
200+
str_enum += f" {c.name} = {c.value},\n"
201+
str_mass_o2 += declare_mass(c)
202+
str_enum = str_enum[:-2] + "\n" # Remove the last comma.
203+
str_enum += str_enum_foot
204+
205+
# PDG_t particles
206+
str_mass_root = str_mass_root_head
207+
for d in PdgROOT:
208+
str_mass_root += declare_mass(d)
209+
210+
# Header body
211+
str_header = "\n".join((str_block_begin, str_block_preamble, str_enum, str_mass_o2, str_mass_root, str_block_end))
212+
print(str_header)
213+
214+
215+
if __name__ == "__main__":
216+
main()

0 commit comments

Comments
 (0)