From 2fd0b996ad8e7c5f18a42b611c5a8102eb0a3cbb Mon Sep 17 00:00:00 2001
From: Maximilian Reininghaus <maximilian.reininghaus@tu-dortmund.de>
Date: Fri, 2 Oct 2020 14:53:36 +0200
Subject: [PATCH] moved new_view() into constructors of mix-in classes

---
 Documentation/Examples/vertical_EAS.cc        |  2 +-
 Framework/StackInterface/SecondaryView.h      | 43 ++++++++++---------
 Setup/SetupStack.h                            |  4 +-
 Stack/History/CMakeLists.txt                  | 10 ++---
 Stack/History/Event.hpp                       |  2 +-
 ...onPlane.cc => HistoryObservationPlane.cpp} |  2 +-
 Stack/History/HistorySecondaryProducer.hpp    | 31 ++++---------
 ...kExtension.h => HistoryStackExtension.hpp} |  2 +-
 Stack/History/testHistoryStack.cc             |  2 +-
 Stack/History/testHistoryView.cc              |  8 ++--
 10 files changed, 46 insertions(+), 60 deletions(-)
 rename Stack/History/{HistoryObservationPlane.cc => HistoryObservationPlane.cpp} (97%)
 rename Stack/History/{HistoryStackExtension.h => HistoryStackExtension.hpp} (99%)

diff --git a/Documentation/Examples/vertical_EAS.cc b/Documentation/Examples/vertical_EAS.cc
index 7246ce77e..577ea4166 100644
--- a/Documentation/Examples/vertical_EAS.cc
+++ b/Documentation/Examples/vertical_EAS.cc
@@ -38,7 +38,7 @@
 #include <corsika/units/PhysicalUnits.h>
 #include <corsika/utl/CorsikaFenv.h>
 
-#include <corsika/history/HistoryObservationPlane.hpp>
+#include <corsika/stack/history/HistoryObservationPlane.hpp>
 
 #include <iomanip>
 #include <iostream>
diff --git a/Framework/StackInterface/SecondaryView.h b/Framework/StackInterface/SecondaryView.h
index 4d615a120..8ab305a81 100644
--- a/Framework/StackInterface/SecondaryView.h
+++ b/Framework/StackInterface/SecondaryView.h
@@ -132,10 +132,10 @@ namespace corsika::stack {
      **/
     SecondaryView(StackIteratorValue& particle)
         : Stack<StackDataType&, ParticleInterface>(particle.GetStackData())
+        , MSecondaryProducer<StackDataType, ParticleInterface>{particle}
         , inner_stack_(particle.GetStack())
         , projectile_index_(particle.GetIndex()) {
       C8LOG_TRACE("SecondaryView::SecondaryView(particle)");
-      MSecondaryProducer<StackDataType, ParticleInterface>::new_view(particle);
     }
     /**
      * Also allow to create a new View from a Projectile (StackIterator on View)
@@ -144,12 +144,12 @@ namespace corsika::stack {
      * terms of reference to the underlying data stack. It is not a "view to a view".
      */
     SecondaryView(ViewType& view, StackIterator& projectile)
-        : Stack<StackDataType&, ParticleInterface>(view.GetStackData())
-        , inner_stack_(view.inner_stack_)
-        , projectile_index_(view.GetIndexFromIterator(projectile.GetIndex())) {
-      C8LOG_TRACE("SecondaryView::SecondaryView(projectile)");
-      StackIteratorValue particle(inner_stack_, projectile_index_);
-      MSecondaryProducer<StackDataType, ParticleInterface>::new_view(particle);
+        : Stack<StackDataType&, ParticleInterface>{view.GetStackData()}
+        , MSecondaryProducer<StackDataType, ParticleInterface>{StackIteratorValue{
+              view.inner_stack_, view.GetIndexFromIterator(projectile.GetIndex())}}
+        , inner_stack_{view.inner_stack_}
+        , projectile_index_{view.GetIndexFromIterator(projectile.GetIndex())} {
+      C8LOG_TRACE("SecondaryView::SecondaryView(view, projectile)");
     }
 
     /**
@@ -397,7 +397,8 @@ namespace corsika::stack {
   };
 
   /**
-   * Class to handle the generation of new secondaries.
+   * Class to handle the generation of new secondaries. Used as default mix-in for
+   * SecondaryView.
    */
   template <class T1, template <class> class T2>
   class DefaultSecondaryProducer {
@@ -405,28 +406,28 @@ namespace corsika::stack {
 
   public:
     /**
-     * Method is called after a new SecondaryView has been
-     * created. Extra logic can be introduced here.
+     * Method is called after a new secondary has been created on the
+     * SecondaryView. Extra logic can be introduced here.
      *
-     * The input Particle is a reference object into the original
-     * parent stack! It is not a reference into the SecondaryView
-     * itself.
+     * The input Particle is the new secondary that was produced and
+     * is of course a reference into the SecondaryView itself.
      */
     template <typename Particle>
-    void new_view(Particle&) {
-      C8LOG_TRACE("DefaultSecondaryProducer::init");
+    auto new_secondary(Particle&) const {
+      C8LOG_TRACE("DefaultSecondaryProducer::new_secondary(Particle&)");
     }
 
     /**
-     * Method is called after a new Secondary has been created on the
-     * SecondaryView. Extra logic can be introduced here.
+     * Method is called when a new SecondaryView is being created
+     * created. Extra logic can be introduced here.
      *
-     * The input Particle is the new secondary that was produced and
-     * is of course a reference into the SecondaryView itself.
+     * The input Particle is a reference object into the original
+     * parent stack! It is not a reference into the SecondaryView
+     * itself.
      */
     template <typename Particle>
-    auto new_secondary(Particle&) {
-      C8LOG_TRACE("DefaultSecondaryProducer::produce(TView,Args&&)");
+    DefaultSecondaryProducer([[maybe_unused]] Particle const&) {
+      C8LOG_TRACE("DefaultSecondaryProducer::DefaultSecondaryProducer(Particle&)");
     }
   };
 
diff --git a/Setup/SetupStack.h b/Setup/SetupStack.h
index e72b191b3..8628f3df6 100644
--- a/Setup/SetupStack.h
+++ b/Setup/SetupStack.h
@@ -8,11 +8,11 @@
 
 #pragma once
 
-#include <corsika/history/HistoryStackExtension.h>
 #include <corsika/stack/CombinedStack.h>
 #include <corsika/stack/node/GeometryNodeStackExtension.h>
 #include <corsika/stack/nuclear_extension/NuclearStackExtension.h>
-#include <corsika/history/HistorySecondaryProducer.hpp>
+#include <corsika/stack/history/HistorySecondaryProducer.hpp>
+#include <corsika/stack/history/HistoryStackExtension.hpp>
 
 #include <corsika/setup/SetupEnvironment.h>
 
diff --git a/Stack/History/CMakeLists.txt b/Stack/History/CMakeLists.txt
index 9adb558a2..a1df0e255 100644
--- a/Stack/History/CMakeLists.txt
+++ b/Stack/History/CMakeLists.txt
@@ -3,18 +3,18 @@ set (
   Event.hpp
   HistorySecondaryProducer.hpp
   HistoryObservationPlane.hpp
-  HistoryStackExtension.h
+  HistoryStackExtension.hpp
   SecondaryParticle.hpp
   )
 
 set (
   HISTORY_NAMESPACE
-  corsika/history
+  corsika/stack/history
   )
 
 set (
   HISTORY_SOURCES
-  HistoryObservationPlane.cc
+  HistoryObservationPlane.cpp
 )
 
 #add_library (CORSIKAhistory INTERFACE)
@@ -29,8 +29,8 @@ target_link_libraries (
   CORSIKAsetup # for HistoryObservationPlane
   CORSIKAlogging
   SuperStupidStack
-  NuclearStackExtension
-  C8::ext::boost
+  NuclearStackExtension # for testHistoryView.cc
+  C8::ext::boost # for HistoryObservationPlane
   )
 
 target_include_directories (
diff --git a/Stack/History/Event.hpp b/Stack/History/Event.hpp
index 327fdf670..eb91de759 100644
--- a/Stack/History/Event.hpp
+++ b/Stack/History/Event.hpp
@@ -9,7 +9,7 @@
 #pragma once
 
 #include <corsika/particles/ParticleProperties.h>
-#include <corsika/history/SecondaryParticle.hpp>
+#include <corsika/stack/history/SecondaryParticle.hpp>
 #include <corsika/logging/Logging.h>
 
 #include <iostream>
diff --git a/Stack/History/HistoryObservationPlane.cc b/Stack/History/HistoryObservationPlane.cpp
similarity index 97%
rename from Stack/History/HistoryObservationPlane.cc
rename to Stack/History/HistoryObservationPlane.cpp
index d9374eee7..542478eb5 100644
--- a/Stack/History/HistoryObservationPlane.cc
+++ b/Stack/History/HistoryObservationPlane.cpp
@@ -7,7 +7,7 @@
  */
 
 #include <corsika/logging/Logging.h>
-#include <corsika/history/HistoryObservationPlane.hpp>
+#include <corsika/stack/history/HistoryObservationPlane.hpp>
 
 #include <boost/histogram/ostream.hpp>
 
diff --git a/Stack/History/HistorySecondaryProducer.hpp b/Stack/History/HistorySecondaryProducer.hpp
index 2d3d560a3..0d3a88124 100644
--- a/Stack/History/HistorySecondaryProducer.hpp
+++ b/Stack/History/HistorySecondaryProducer.hpp
@@ -9,7 +9,7 @@
 #pragma once
 
 #include <corsika/stack/SecondaryView.h>
-#include <corsika/history/Event.hpp>
+#include <corsika/stack/history/Event.hpp>
 
 #include <corsika/logging/Logging.h>
 
@@ -19,31 +19,17 @@
 
 namespace corsika::history {
 
+  //! mix-in class for SecondaryView that fills secondaries into an \class Event
   template <class T1, template <class> class T2>
   class HistorySecondaryProducer {
-
-    using TView = corsika::stack::SecondaryView<T1, T2, HistorySecondaryProducer>;
-
   public:
     EventPtr event_;
 
   public:
-    HistorySecondaryProducer() :
-        event_{std::make_shared<Event>()} {
-      C8LOG_TRACE("HistorySecondaryProducer::HistorySecondaryProducer");
-    }
-
-    /**
-     * Method is called after a new SecondaryView has been
-     * created. Extra logic can be introduced here.  
-     * 
-     * The input Particle is a reference object into the original
-     * parent stack! It is not a reference into the SecondaryView
-     * itself.
-     */
     template <typename Particle>
-    void new_view(Particle& p) {
-      C8LOG_TRACE("HistorySecondaryProducer::new_view");
+    HistorySecondaryProducer(Particle const& p)
+        : event_{std::make_shared<Event>()} {
+      C8LOG_TRACE("HistorySecondaryProducer::HistorySecondaryProducer");
       event_->setProjectileIndex(p.GetIndex());
       event_->setParentEvent(p.GetEvent());
     }
@@ -51,7 +37,7 @@ namespace corsika::history {
     /**
      * Method is called after a new Secondary has been created on the
      * SecondaryView. Extra logic can be introduced here.
-     * 
+     *
      * The input Particle is the new secondary that was produced and
      * is of course a reference into the SecondaryView itself.
      */
@@ -60,12 +46,11 @@ namespace corsika::history {
       C8LOG_TRACE("HistorySecondaryProducer::new_secondary(sec)");
 
       // store particles at production time in Event here
-      auto const sec_index = event_->addSecondary(
-          sec.GetEnergy(), sec.GetMomentum(), sec.GetPID());
+      auto const sec_index =
+          event_->addSecondary(sec.GetEnergy(), sec.GetMomentum(), sec.GetPID());
       sec.SetParentEventIndex(sec_index);
       sec.SetEvent(event_);
     }
-
   };
 
 } // namespace corsika::history
diff --git a/Stack/History/HistoryStackExtension.h b/Stack/History/HistoryStackExtension.hpp
similarity index 99%
rename from Stack/History/HistoryStackExtension.h
rename to Stack/History/HistoryStackExtension.hpp
index c9a0f289e..67a38b796 100644
--- a/Stack/History/HistoryStackExtension.h
+++ b/Stack/History/HistoryStackExtension.hpp
@@ -126,7 +126,7 @@ namespace corsika::history {
 // for user-friendlyness we create the HistoryDataInterface type
 // with the histoy::Event data content right here:
 
-#include <corsika/history/Event.hpp>
+#include <corsika/stack/history/Event.hpp>
 
 namespace corsika::history {
 
diff --git a/Stack/History/testHistoryStack.cc b/Stack/History/testHistoryStack.cc
index e332d7620..ed61b83b6 100644
--- a/Stack/History/testHistoryStack.cc
+++ b/Stack/History/testHistoryStack.cc
@@ -6,9 +6,9 @@
  * the license.
  */
 
-#include <corsika/history/HistoryStackExtension.h>
 #include <corsika/stack/CombinedStack.h>
 #include <corsika/stack/dummy/DummyStack.h>
+#include <corsika/stack/history/HistoryStackExtension.hpp>
 
 #include <catch2/catch.hpp>
 
diff --git a/Stack/History/testHistoryView.cc b/Stack/History/testHistoryView.cc
index d4c50e7a4..718daac6b 100644
--- a/Stack/History/testHistoryView.cc
+++ b/Stack/History/testHistoryView.cc
@@ -6,9 +6,9 @@
  * the license.
  */
 
-#include <corsika/history/HistoryStackExtension.h>
-#include <corsika/history/Event.hpp>
-#include <corsika/history/HistorySecondaryProducer.hpp>
+#include <corsika/stack/history/Event.hpp>
+#include <corsika/stack/history/HistorySecondaryProducer.hpp>
+#include <corsika/stack/history/HistoryStackExtension.hpp>
 
 #include <corsika/stack/CombinedStack.h>
 #include <corsika/stack/dummy/DummyStack.h>
@@ -62,7 +62,7 @@ using TheTestStackView =
 #endif
 
 using TestStackView =
-    TheTestStackView; // history::HistorySecondaryView<TheTestStackView>;
+    TheTestStackView; // history::HistorySecondaryProducer<TheTestStackView>;
 
 TEST_CASE("HistoryStackExtension", "[stack]") {
 
-- 
GitLab