CORSIKA  @c8_version@
The framework to simulate particle cascades for astroparticle physics
GeometryNodeStackExtension.hpp
1 /*
2  * (c) Copyright 2018 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 <tuple>
15 #include <utility>
16 #include <vector>
17 
18 namespace corsika::node {
19 
32  template <typename T, typename TEnvType>
33  struct GeometryDataInterface : public T {
34 
35  typedef T super_type;
36 
37  public:
38  typedef typename TEnvType::BaseNodeType node_type;
39 
40  // default version for particle-creation from input data
41  void setParticleData(const std::tuple<node_type const*> v) {
42  setNode(std::get<0>(v));
43  }
44  void setParticleData(GeometryDataInterface& parent,
45  const std::tuple<node_type const*>) {
46  setNode(parent.getNode()); // copy Node from parent particle!
47  }
48  void setParticleData() { setNode(nullptr); }
49  void setParticleData(GeometryDataInterface& parent) {
50  setNode(parent.getNode()); // copy Node from parent particle!
51  }
52 
53  std::string asString() const { return fmt::format("node={}", fmt::ptr(getNode())); }
54 
55  void setNode(node_type const* v) {
56 
57  super_type::getStackData().setNode(super_type::getIndex(), v);
58  }
59 
60  node_type const* getNode() const {
61  return super_type::getStackData().getNode(super_type::getIndex());
62  }
63  };
64 
65  // definition of stack-data object to store geometry information
66 
72  template <typename TEnvType>
73  class GeometryData {
74 
75  public:
76  typedef typename TEnvType::BaseNodeType node_type;
77  typedef std::vector<const node_type*> node_vector_type;
78 
79  GeometryData() = default;
80 
81  GeometryData(GeometryData<TEnvType> const&) = default;
82 
84 
85  GeometryData<TEnvType>& operator=(GeometryData<TEnvType> const&) = default;
86 
87  GeometryData<TEnvType>& operator=(GeometryData<TEnvType>&&) = default;
88 
89  // these functions are needed for the Stack interface
90  void clear() { node_vector_.clear(); }
91 
92  unsigned int getSize() const { return node_vector_.size(); }
93 
94  unsigned int getCapacity() const { return node_vector_.size(); }
95 
96  void copy(const int i1, const int i2) { node_vector_[i2] = node_vector_[i1]; }
97 
98  void swap(const int i1, const int i2) {
99  std::swap(node_vector_[i1], node_vector_[i2]);
100  }
101 
102  // custom data access function
103  void setNode(const int i, node_type const* v) { node_vector_[i] = v; }
104 
105  node_type const* getNode(const int i) const { return node_vector_[i]; }
106 
107  // these functions are also needed by the Stack interface
108  void incrementSize() { node_vector_.push_back(nullptr); }
109 
110  void decrementSize() {
111  if (node_vector_.size() > 0) { node_vector_.pop_back(); }
112  }
113 
114  // custom private data section
115  private:
116  node_vector_type node_vector_;
117  };
118 
119  template <typename T, typename TEnv>
122  };
123 
124 } // namespace corsika::node
definition of stack-data object to store geometry information
CORSIKA8 logging utilities.
Description of particle stacks.
Describe "volume node" data on a Stack.