CORSIKA  @c8_version@
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 
73  template <typename T, typename TEvent>
74  class HistoryDataInterface : public T {
75  protected:
76  using T::getStack;
77  using T::getStackData;
78 
79  public:
80  using T::getIndex;
81 
82  public:
83  // create a new particle from scratch
84  void setParticleData() {
85  CORSIKA_LOG_TRACE("HistoyDatatInterface::setParticleData()");
86  getStackData().setParentEventIndex(getIndex(), -1);
87  }
88 
89  // create a new particle as secondary of a parent
90  void setParticleData(HistoryDataInterface& /*parent*/) {
91  CORSIKA_LOG_TRACE("HistoyDatatInterface::setParticleData(parnt)");
92  setParticleData();
93  }
94 
95  void setEvent(const std::shared_ptr<TEvent>& v) {
96  getStackData().setEvent(getIndex(), v);
97  }
98 
99  void setParentEventIndex(int index) {
100  getStackData().setParentEventIndex(getIndex(), index);
101  }
102 
103  std::shared_ptr<TEvent> getEvent() const {
104  return getStackData().getEvent(getIndex());
105  }
106 
107  int getParentEventIndex() const {
108  return getStackData().getParentEventIndex(getIndex());
109  }
110 
111  std::string asString() const {
112  return fmt::format("i_parent={}, [evt: {}]", getParentEventIndex(),
113  (bool(getEvent()) ? getEvent()->as_string() : "n/a"));
114  }
115  };
116 
117  template <typename T, typename TEvent>
120  };
121 
122 } // namespace corsika::history
123 
124 // for user-friendlyness we create the HistoryDataInterface type
125 // with the histoy::Event data content right here:
126 
127 #include <corsika/stack/history/Event.hpp>
128 
129 namespace corsika::history {
130 
131  template <typename TStackIter>
132  using HistoryEventDataInterface =
134 
136 
137 } // namespace corsika::history
corresponding definition of a stack-readout object, the iteractor dereference operator will deliver a...
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.