diff --git a/corsika/detail/modules/epos/InteractionModel.inl b/corsika/detail/modules/epos/InteractionModel.inl index 1582718c6b3f90da1f6c4248f3ee36355df36102..5d7996f9ae406c180cdf7dd149b181676b2e954e 100644 --- a/corsika/detail/modules/epos/InteractionModel.inl +++ b/corsika/detail/modules/epos/InteractionModel.inl @@ -34,8 +34,8 @@ namespace corsika::epos { data_path_ = (std::string(corsika_data("EPOS").c_str()) + "/").c_str(); } initialize(); + setParticlesStable(); } - setParticlesStable(); } inline void InteractionModel::setParticlesStable() const { @@ -45,15 +45,30 @@ namespace corsika::epos { if (!is_hadron(p)) continue; int const eid = convertToEposRaw(p); if (eid != 0) { - ::epos::nodcy_.nrnody = ::epos::nodcy_.nrnody + 1; - ::epos::nodcy_.nody[::epos::nodcy_.nrnody - 1] = eid; + // LCOV_EXCL_START + // this is only a safeguard against messing up the epos internals by initializing + // more than once. + unsigned int const n_particles_stable_epos = + ::epos::nodcy_.nrnody; // avoid waring -Wsign-compare + if (n_particles_stable_epos < ::epos::mxnody) { + CORSIKA_LOGGER_TRACE(logger_, "setting {} with EposId={} stable inside EPOS.", + p, eid); + ::epos::nodcy_.nrnody = ::epos::nodcy_.nrnody + 1; + ::epos::nodcy_.nody[::epos::nodcy_.nrnody - 1] = eid; + } else { + CORSIKA_LOGGER_ERROR(logger_, "List of stable particles too long for Epos!"); + throw std::runtime_error("Epos initialization error!"); + } + // LCOV_EXCL_STOP } else { - CORSIKA_LOG_DEBUG( + CORSIKA_LOG_TRACE( "particle conversion Corsika-->Epos not known for {}. Using {}. Setting " "unstable in Epos!", p, eid); } } + CORSIKA_LOGGER_DEBUG(logger_, "set {} particles stable inside Epos", + ::epos::nodcy_.nrnody); } inline bool InteractionModel::isValid(Code const projectileId, Code const targetId, diff --git a/corsika/modules/epos/InteractionModel.hpp b/corsika/modules/epos/InteractionModel.hpp index b371236221547c39e7e5a95611104a71e93c0b82..e9ab49ae5f5c4723c3489e4bd984f798c9466749 100644 --- a/corsika/modules/epos/InteractionModel.hpp +++ b/corsika/modules/epos/InteractionModel.hpp @@ -89,16 +89,18 @@ namespace corsika::epos { void doInteraction(TSecondaries&, Code const projectileId, Code const targetId, FourMomentum const& projectileP4, FourMomentum const& targetP4); - void initialize() const; void initializeEventCoM(Code const, int const, int const, Code const, int const, int const, HEPEnergyType const) const; void initializeEventLab(Code const, int const, int const, Code const, int const, int const, HEPEnergyType const) const; void configureParticles(Code const, int const, int const, Code const, int const, int const) const; - void setParticlesStable() const; private: + // initialize and setParticlesStable are private since they can only be called once at + // the beginning and are already called in the constructor! + void initialize() const; + void setParticlesStable() const; inline static bool isInitialized_ = false; std::string data_path_;