IAP GITLAB

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

added can-interact array

parent 86cf0814
No related branches found
No related tags found
No related merge requests found
......@@ -20,8 +20,8 @@
namespace corsika::process::sibyll {
enum class Code : int8_t;
using SibyllCodeIntType = std::underlying_type<Code>::type;
enum class SibyllCode : int8_t;
using SibyllCodeIntType = std::underlying_type<SibyllCode>::type;
#include <corsika/process/sibyll/Generated.inc>
......@@ -33,12 +33,12 @@ namespace corsika::process::sibyll {
return canInteract[static_cast<corsika::particles::CodeIntType>(pCode)];
}
Code constexpr ConvertToSibyll(corsika::particles::Code pCode) {
SibyllCode constexpr ConvertToSibyll(corsika::particles::Code pCode) {
//~ assert(handledBySibyll(pCode));
return static_cast<Code>(corsika2sibyll[static_cast<corsika::particles::CodeIntType>(pCode)]);
return static_cast<SibyllCode>(corsika2sibyll[static_cast<corsika::particles::CodeIntType>(pCode)]);
}
corsika::particles::Code constexpr ConvertFromSibyll(Code pCode) {
corsika::particles::Code constexpr ConvertFromSibyll(SibyllCode pCode) {
return sibyll2corsika[static_cast<SibyllCodeIntType>(pCode) - minSibyll];
}
......
......@@ -27,21 +27,23 @@ def read_sibyll_codes(filename, pythia_db):
for line in f:
line = line.strip()
if line[0] == '#':
continue
identifier, sib_code = line.split()
continue
identifier, sib_code, canInteractFlag = line.split()
try:
pythia_db[identifier]["sibyll_code"] = int(sib_code)
pythia_db[identifier]["sibyll_canInteract"] = int(canInteractFlag)
except KeyError as e:
raise Exception("Identifier '{:s}' not found in pythia_db".format(identifier))
# generates the enum to access sibyll particles by readable names
def generate_sibyll_enum(pythia_db):
output = "enum class Code : int8_t {\n"
for identifier, d in pythia_db.items():
if d.get('sibyll_code') != None:
output += " {:s} = {:d},\n".format(identifier, d['sibyll_code'])
output = "enum class SibyllCode : int8_t {\n"
for identifier, pData in pythia_db.items():
if pData.get('sibyll_code') != None:
output += " {:s} = {:d},\n".format(identifier, pData['sibyll_code'])
output += "};\n"
return output
......@@ -50,8 +52,8 @@ def generate_sibyll_enum(pythia_db):
# generates the look-up table to convert corsika codes to sibyll codes
def generate_corsika2sibyll(pythia_db):
string = "std::array<SibyllCodeIntType, {:d}> constexpr corsika2sibyll = {{".format(len(pythia_db))
for identifier, d in pythia_db.items():
sibCode = d.get("sibyll_code", 0)
for identifier, pData in pythia_db.items():
sibCode = pData.get("sibyll_code", 0)
string += " {:d}, // {:s}\n".format(sibCode, identifier if sibCode else identifier + " (not implemented in SIBYLL)")
string += "};\n"
return string
......@@ -88,14 +90,14 @@ def generate_sibyll2corsika(pythia_db) :
# generates the bitset for the flag whether Sibyll knows the particle
def generate_handles_particle(pythia_db):
def generate_known_particle(pythia_db):
num_particles = len(pythia_db)
num_bytes = num_particles // 32 + 1
string = "Bitset2::bitset2<{:d}> constexpr handleable{{ std::array<uint32_t, {:d}>{{{{\n".format(num_particles, num_bytes)
string = "Bitset2::bitset2<{:d}> constexpr isKnown{{ std::array<uint32_t, {:d}>{{{{\n".format(num_particles, num_bytes)
numeric = 0
for identifier, d in reversed(pythia_db.items()):
handledBySibyll = int("sibyll_code" in d) & 0x1
for identifier, pData in reversed(pythia_db.items()):
handledBySibyll = int("sibyll_code" in pData) & 0x1
numeric = (numeric << 1) | handledBySibyll
while numeric != 0:
......@@ -105,6 +107,28 @@ def generate_handles_particle(pythia_db):
string += "}}};\n"
return string
# generates the bitset for the flag whether Sibyll can use particle as projectile
def generate_interacting_particle(pythia_db):
num_particles = len(pythia_db)
num_bytes = num_particles // 32 + 1
string = "Bitset2::bitset2<{:d}> constexpr canInteract{{ std::array<uint32_t, {:d}>{{{{\n".format(num_particles, num_bytes)
numeric = 0
for identifier, pData in reversed(pythia_db.items()):
if 'sibyll_canInteract' in pData:
can = int(pData["sibyll_canInteract"]) & 0x1
numeric = (numeric << 1) | can
while numeric != 0:
low = numeric & 0xFFFFFFFF
numeric = numeric >> 32
string += " 0x{:0x},\n".format(low)
string += "}}};\n"
return string
......@@ -122,5 +146,5 @@ if __name__ == "__main__":
print("// this file is automatically generated\n// edit at your own risk!\n", file=f)
print(generate_sibyll_enum(pythia_db), file=f)
print(generate_corsika2sibyll(pythia_db), file=f)
print(generate_handles_particle(pythia_db), file=f)
print(generate_known_particle(pythia_db), file=f)
print(generate_sibyll2corsika(pythia_db), file=f)
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