CORSIKA8  0.0.0
The framework to simulate particle cascades for astroparticle physics
HistoryStackExtension.hpp
1 /*
2  * (c) Copyright 2020 CORSIKA Project, corsika-project@lists.kit.edu
3  *
4  * This software is distributed under the terms of the GNU General Public
5  * Licence version 3 (GPL Version 3). See file LICENSE for a full version of
6  * the license.
7  */
8 
9 #pragma once
10 
13 
14 #include <memory>
15 #include <utility>
16 #include <vector>
17 
18 namespace corsika::history {
19 
27  template <typename TEvent>
28  class HistoryData {
29  using EventPtr =
30  std::shared_ptr<TEvent>;
31  using ParentEventIndex = int;
32  using DataType = std::pair<EventPtr, ParentEventIndex>;
33 
34  public:
35  // these functions are needed for the Stack interface
36  void clear() { historyData_.clear(); }
37  unsigned int getSize() const { return historyData_.size(); }
38  unsigned int getCapacity() const { return historyData_.size(); }
39  void copy(const int i1, const int i2) { historyData_[i2] = historyData_[i1]; }
40  void swap(const int i1, const int i2) {
41  std::swap(historyData_[i1], historyData_[i2]);
42  }
43 
44  // custom data access function
45  void setEvent(const int i, EventPtr v) { historyData_[i].first = std::move(v); }
46  const EventPtr& getEvent(const int i) const { return historyData_[i].first; }
47  EventPtr& getEvent(const int i) { return historyData_[i].first; }
48 
49  void setParentEventIndex(const int i, ParentEventIndex v) {
50  historyData_[i].second = std::move(v);
51  }
52  ParentEventIndex getParentEventIndex(const int i) const {
53  return historyData_[i].second;
54  }
55 
56  // these functions are also needed by the Stack interface
57  void incrementSize() { historyData_.push_back(DataType{}); }
58  void decrementSize() {
59  if (historyData_.size() > 0) { historyData_.pop_back(); }
60  }
61 
62  // custom private data section
63  private:
64  std::vector<DataType> historyData_;
65  };
66 
75  template <typename T, typename TEvent>
76  class HistoryDataInterface : public T {
77  protected:
78  using T::getStack;
79  using T::getStackData;
80 
81  public:
82  using T::getIndex;
83 
84  public:
85  // create a new particle from scratch
86  void setParticleData() {
87  CORSIKA_LOG_TRACE("HistoyDatatInterface::setParticleData()");
88  getStackData().setParentEventIndex(getIndex(), -1);
89  }
90 
91  // create a new particle as secondary of a parent
92  void setParticleData(HistoryDataInterface& /*parent*/) {
93  CORSIKA_LOG_TRACE("HistoyDatatInterface::setParticleData(parnt)");
94  setParticleData();
95  }
96 
97  void setEvent(const std::shared_ptr<TEvent>& v) {
98  getStackData().setEvent(getIndex(), v);
99  }
100 
101  void setParentEventIndex(int index) {
102  getStackData().setParentEventIndex(getIndex(), index);
103  }
104 
105  std::shared_ptr<TEvent> getEvent() const {
106  return getStackData().getEvent(getIndex());
107  }
108 
109  int getParentEventIndex() const {
110  return getStackData().getParentEventIndex(getIndex());
111  }
112 
113  std::string asString() const {
114  return fmt::format("i_parent={}, [evt: {}]", getParentEventIndex(),
115  (bool(getEvent()) ? getEvent()->as_string() : "n/a"));
116  }
117  };
118 
119  template <typename T, typename TEvent>
122  };
123 
124 } // namespace corsika::history
125 
126 // for user-friendlyness we create the HistoryDataInterface type
127 // with the histoy::Event data content right here:
128 
129 #include <corsika/stack/history/Event.hpp>
130 
131 namespace corsika::history {
132 
133  template <typename TStackIter>
134  using HistoryEventDataInterface =
136 
138 
139 } // namespace corsika::history
corresponding defintion of a stack-readout object, the iteractor dereference operator will deliver ...
definition of stack-data object to store history information this is vector with shared_ptr<TEvent>, where TEvent is a free template parameter for customization.
CORSIKA8 logging utilities.
Description of particle stacks.