IAP GITLAB

Skip to content
Snippets Groups Projects
HistorySecondaryView.hpp 1.9 KiB
Newer Older
/*
 * (c) Copyright 2018 CORSIKA Project, corsika-project@lists.kit.edu
 *
 * This software is distributed under the terms of the GNU General Public
 * Licence version 3 (GPL Version 3). See file LICENSE for a full version of
 * the license.
 */

#pragma once

#include <corsika/stack/SecondaryView.h>
#include <corsika/history/Event.hpp>

#include <corsika/logging/Logging.h>

#include <memory>
#include <type_traits>
#include <utility>

namespace corsika::history {

  template <typename TView>
  class HistorySecondaryView : public TView {

Maximilian Reininghaus's avatar
Maximilian Reininghaus committed
    EventPtr event_;
  public:
    using StackIteratorValue = typename TView::StackIteratorValue;
    using StackIterator = typename TView::StackIterator;

  public:
    HistorySecondaryView(StackIteratorValue& p)
        : TView{p}
        , event_{std::make_shared<Event>()} {
      event_->setProjectileIndex(p.GetIndex());
Maximilian Reininghaus's avatar
Maximilian Reininghaus committed
      event_->setParentEvent(p.GetEvent());
    }

    template <typename... Args>
    StackIterator AddSecondary(Args&&... args) {
      C8LOG_TRACE("HistorySecondaryView::AddSecondary(Args&&)");
Maximilian Reininghaus's avatar
Maximilian Reininghaus committed
      auto stack_sec = TView::AddSecondary(std::forward<Args...>(args...));
Maximilian Reininghaus's avatar
Maximilian Reininghaus committed
      // store particles at production time in Event here
      auto const sec_index = event_->addSecondary(
          stack_sec.GetEnergy(), stack_sec.GetMomentum(), stack_sec.GetPID());
      stack_sec.SetParentEventIndex(sec_index);
      stack_sec.SetEvent(event_);

      // RU: consider if we can call
      // TView::AddSecondary twice instead: 1. for particle at production time
      // , 2. dynamic particle ... not sure, but would be extremely flexible.

Maximilian Reininghaus's avatar
Maximilian Reininghaus committed
      return stack_sec;

    template <typename... Args>
    StackIterator AddSecondary(StackIterator& proj, const Args... args) {
      C8LOG_TRACE("HistorySecondaryView::AddSecondary(StackIterator&, Args&&)");
      return TView::AddSecondary(proj, std::forward<Args...>(args...));
    }

  };

} // namespace corsika::history