From 8684d4fc307500c83be1a1807a24e6e4cb747312 Mon Sep 17 00:00:00 2001 From: Maximilian Reininghaus <maximilian.reininghaus@tu-dortmund.de> Date: Fri, 2 Oct 2020 18:23:16 +0200 Subject: [PATCH] compile-time detection of history --- Framework/Cascade/Cascade.h | 19 +++++++++++-------- Framework/StackInterface/SecondaryView.h | 2 ++ Stack/History/HistorySecondaryProducer.hpp | 3 +++ 3 files changed, 16 insertions(+), 8 deletions(-) diff --git a/Framework/Cascade/Cascade.h b/Framework/Cascade/Cascade.h index 7353b9a84..c4f07d647 100644 --- a/Framework/Cascade/Cascade.h +++ b/Framework/Cascade/Cascade.h @@ -17,8 +17,7 @@ #include <corsika/stack/SecondaryView.h> #include <corsika/units/PhysicalUnits.h> #include <corsika/stack/history/EventType.hpp> - -#include <corsika/logging/Logging.h> +#include <corsika/stack/history/HistorySecondaryProducer.hpp> #include <corsika/setup/SetupTrajectory.h> @@ -326,9 +325,11 @@ namespace corsika::cascade { actual_decay_time); const auto sample_process = uniDist(fRNG); units::si::InverseTimeType inv_decay_count = units::si::InverseTimeType::zero(); - auto const returnCode = fProcessSequence.SelectDecay(particle, view, sample_process, - inv_decay_count); - view.GetProjectile().GetEvent()->set_type(history::EventType::Decay); + auto const returnCode = + fProcessSequence.SelectDecay(particle, view, sample_process, inv_decay_count); + if constexpr (TStackView::has_event) { + view.GetProjectile().GetEvent()->setEventType(history::EventType::Decay); + } return returnCode; } @@ -342,9 +343,11 @@ namespace corsika::cascade { current_inv_length); const auto sample_process = uniDist(fRNG); auto inv_lambda_count = units::si::InverseGrammageType::zero(); - auto const returnCode = fProcessSequence.SelectInteraction(particle, view, sample_process, - inv_lambda_count); - view.GetProjectile().GetEvent()->set_type(history::EventType::Interaction); + auto const returnCode = fProcessSequence.SelectInteraction( + particle, view, sample_process, inv_lambda_count); + if constexpr (TStackView::has_event) { + view.GetProjectile().GetEvent()->setEventType(history::EventType::Interaction); + } return returnCode; } diff --git a/Framework/StackInterface/SecondaryView.h b/Framework/StackInterface/SecondaryView.h index 8ab305a81..ae8b62c66 100644 --- a/Framework/StackInterface/SecondaryView.h +++ b/Framework/StackInterface/SecondaryView.h @@ -405,6 +405,8 @@ namespace corsika::stack { using View = SecondaryView<T1, T2, DefaultSecondaryProducer>; public: + static bool constexpr has_event{false}; + /** * Method is called after a new secondary has been created on the * SecondaryView. Extra logic can be introduced here. diff --git a/Stack/History/HistorySecondaryProducer.hpp b/Stack/History/HistorySecondaryProducer.hpp index 0d3a88124..792a83d95 100644 --- a/Stack/History/HistorySecondaryProducer.hpp +++ b/Stack/History/HistorySecondaryProducer.hpp @@ -13,6 +13,8 @@ #include <corsika/logging/Logging.h> +#include <boost/type_index.hpp> + #include <memory> #include <type_traits> #include <utility> @@ -24,6 +26,7 @@ namespace corsika::history { class HistorySecondaryProducer { public: EventPtr event_; + static bool constexpr has_event{true}; public: template <typename Particle> -- GitLab