IAP GITLAB

Skip to content
Snippets Groups Projects
Commit ccea80ae authored by ralfulrich's avatar ralfulrich
Browse files

also add CamelCase particle names

parent e1fb6e92
No related branches found
No related tags found
No related merge requests found
......@@ -9,5 +9,14 @@
<particle id="-11" classname="Positron"> </particle>
<particle id="22" classname="Gamma"> </particle>
<particle id="130" classname="K0Long"> </particle>
<particle id="310" classname="K0Short"> </particle>
<particle id="2112" classname="Neutron"> </particle>
<particle id="-2112" classname="AntiNeutron"> </particle>
<particle id="2212" classname="Proton"> </particle>
<particle id="-2212" classname="AntiProton"> </particle>
</chapter>
......@@ -4716,14 +4716,15 @@
m0="9.89860" mWidth="0.01000" mMin="9.85500" mMax="9.89500">
<channel onMode="1" bRatio="1.0000000" meMode="91" products="21 21"/>
</particle>
-->
<particle id="13122" name="Lambda(1405)0" antiName="Lambda(1405)bar0" spinType="2" chargeType="0" colType="0"
m0="1.40510" mWidth="0.05000" mMin="1.32000" mMax="1.80000">
<channel onMode="1" bRatio="0.3333000" products="3222 -211"/>
<channel onMode="1" bRatio="0.3333000" products="3112 211"/>
<channel onMode="1" bRatio="0.3334000" products="3212 111"/>
</particle>
<!--
<particle id="14122" name="Lambda_c(2593)+" antiName="Lambda_c(2593)-" spinType="2" chargeType="3" colType="0"
m0="2.59225" mWidth="0.00260" mMin="2.57000" mMax="2.63000">
<channel onMode="1" bRatio="0.2400000" products="4222 -211"/>
......
......@@ -62,16 +62,16 @@ def class_names(filename):
#
# Automatically produce a string qualifying as C++ class name
#
# This function produces names of type "DELTA_PLUS_PLUS"
#
def c_identifier(name):
orig = name
name = name.upper()
for c in "() ":
for c in "() /":
name = name.replace(c, "_")
name = name.replace("BAR", "_BAR")
name = name.replace("0", "_0")
name = name.replace("/", "_")
name = name.replace("*", "_STAR")
name = name.replace("'", "_PRIME")
name = name.replace("+", "_PLUS")
......@@ -91,6 +91,70 @@ def c_identifier(name):
raise Exception("could not generate C identifier for '{:s}'".format(orig))
##############################################################
#
# Automatically produce a string qualifying as C++ class name
#
# This function produces names of type "DeltaPlusPlus"
#
def c_identifier_cammel(name):
orig = name
name = name[0].upper() + name[1:].lower() # all lower case
# name = "".join(c.upper() if i in indices else c for i, c in enumerate(s)) # first letter upper case
for c in "() /": # replace funny characters
name = name.replace(c, "_")
name = name.replace("bar", "Bar")
name = name.replace("*", "Star")
name = name.replace("'", "Prime")
name = name.replace("+", "Plus")
name = name.replace("-", "Minus")
# move "Bar" to end of name
ibar = name.find('Bar')
if (ibar>0 and ibar<len(name)-3) :
name = name[:ibar] + name[ibar+3:] + str('Bar')
print (str(ibar) + " " + name + " " + str(len(name)))
# cleanup "_"s
while True:
tmp = name.replace("__", "_")
if tmp == name:
break
else:
name = tmp
name.strip("_")
# remove all "_", if this does not by accident concatenate two number
istart = 0
while True:
i = name.find('_', istart)
if (i<1 or i>len(name)-1):
break
istart = i
if (name[i-1].isdigit() and name[i+1].isdigit()):
# there is a number on both sides
break
name = name[:i] + name[i+1:]
# and last, for example: make NuE out of Nue
if (name[i-1].islower() and name[i].islower()) :
if (i<len(name)-1) :
name = name[:i] + name[i].upper() + name[i+1:]
else :
name = name[:i] + name[i].upper()
print ("generate C identifier for '{:s}' name='{:s}'".format(orig, name))
# check if name is valid C++ identifier
pattern = re.compile(r'^[a-zA-Z_][a-zA-Z_0-9]*$')
if pattern.match(name):
return name
else:
raise Exception("could not generate C identifier for '{:s}' name='{:s}'".format(orig, name))
# ########################################################
#
......@@ -105,7 +169,7 @@ def build_pythia_db(filename, classnames):
if (pdg in classnames):
c_id = classnames[pdg]
else:
c_id = c_identifier(name)
c_id = c_identifier_cammel(name) # the cammel case names
#~ print(name, c_id, sep='\t', file=sys.stderr)
#~ enums += "{:s} = {:d}, ".format(c_id, corsika_id)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment