CORSIKA  @c8_version@
The framework to simulate particle cascades for astroparticle physics
Stack.hpp
Go to the documentation of this file.
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 
12 #include <corsika/framework/stack/StackIteratorInterface.hpp>
13 #include <corsika/framework/stack/DefaultSecondaryProducer.hpp>
14 #include <corsika/framework/stack/SecondaryView.hpp>
15 
16 #include <stdexcept>
17 #include <string>
18 #include <vector>
19 #include <utility>
20 #include <type_traits>
21 
46 namespace corsika {
47 
74  template <typename TStackData, template <typename> typename MParticleInterface,
75  template <typename T1, template <class> class T2> class MSecondaryProducer =
76  DefaultSecondaryProducer>
77  class Stack {
78 
79  typedef typename std::remove_reference<TStackData>::type value_type;
80 
81  public:
82  typedef TStackData stack_data_type;
83 
87 
88  template <typename TStackIterator>
89  using pi_type = MParticleInterface<TStackIterator>;
90 
98  typedef StackIteratorInterface<value_type, MParticleInterface, MSecondaryProducer,
99  Stack>
101 
102  typedef ConstStackIteratorInterface<value_type, MParticleInterface,
103  MSecondaryProducer, Stack>
105 
109  typedef typename stack_iterator_type::particle_interface_type particle_interface_type;
115 
121  : nDeleted_(0)
122  , data_()
123  , deleted_(std::vector<bool>(data_.getSize(), false)) {}
124 
125  Stack(Stack&) = delete;
126 
127  Stack& operator=(Stack&) =
128  delete;
129 
134  template <typename UType = TStackData,
135  typename = typename std::enable_if<std::is_reference<UType>::value>::type>
136  Stack(TStackData vD)
137  : nDeleted_(0)
138  , data_(vD)
139  , deleted_(std::vector<bool>(data_.getSize(), false)) {}
140 
150  template <typename... TArgs, typename UType = TStackData,
151  typename = typename std::enable_if<std::is_reference<UType>::value>::type>
152  Stack(TArgs... args)
153  : nDeleted_(0)
154  , data_(args...)
155  , deleted_(std::vector<bool>(data_.getSize(), false)) {}
156 
161  unsigned int getCapacity() const { return data_.getCapacity(); }
162 
163  unsigned int getErased() const { return nDeleted_; }
164 
165  unsigned int getEntries() const { return getSize() - getErased(); }
166 
167  template <typename... TArgs>
168  void clear(TArgs... args);
170 
175  stack_iterator_type begin();
176 
177  stack_iterator_type end();
178 
179  stack_iterator_type last();
180 
181  const_stack_iterator_type begin() const;
182 
183  const_stack_iterator_type end() const;
184 
185  const_stack_iterator_type last() const;
186 
187  const_stack_iterator_type cbegin() const;
188 
189  const_stack_iterator_type cend() const;
190 
191  const_stack_iterator_type clast() const;
192 
193  stack_iterator_type at(unsigned int i);
194 
195  const_stack_iterator_type at(unsigned int i) const;
196 
197  stack_iterator_type first();
198 
199  const_stack_iterator_type cfirst() const;
200 
201  stack_iterator_type getNextParticle();
202 
206  template <typename... TArgs>
207  stack_iterator_type addParticle(const TArgs... v);
208 
210 
212 
213  void copy(const_stack_iterator_type a, stack_iterator_type b);
214 
215  void erase(stack_iterator_type p);
220  void erase(particle_interface_type p);
221 
225  bool isEmpty();
226 
231  bool isErased(const stack_iterator_type& p) const;
232 
233  bool isErased(const const_stack_iterator_type& p) const;
234 
235  bool isErased(const particle_interface_type& p) const;
236 
242  bool purgeLastIfDeleted();
243 
252  void purge();
253 
254  unsigned int getSize() const;
255 
256  std::string asString() const;
257 
258  protected:
266  template <typename... TArgs>
267  stack_iterator_type addSecondary(stack_iterator_type& parent, const TArgs... v);
268 
269  void swap(unsigned int const a, unsigned int const b);
270 
271  void copy(unsigned int const a, unsigned int const b);
272 
273  bool isErased(unsigned int const i) const;
274 
275  void erase(unsigned int const i);
276 
281  void purge(unsigned int i);
282 
289  unsigned int getIndexFromIterator(const unsigned int vI) const;
295  value_type& getStackData();
296 
297  const value_type& getStackData() const;
298 
299  friend class StackIteratorInterface<value_type, MParticleInterface,
300  MSecondaryProducer, Stack>;
301  friend class ConstStackIteratorInterface<value_type, MParticleInterface,
302  MSecondaryProducer, Stack>;
303  template <typename T1, //=TStackData,
304  template <typename> typename M1, //=MParticleInterface,
305  template <class T2, template <class> class T3> class M2>
306  friend class SecondaryView;
307 
308  friend class ParticleBase<stack_iterator_type>;
309 
310  protected:
311  unsigned int nDeleted_ = 0;
312 
313  private:
314  TStackData data_;
315  std::vector<bool> deleted_;
316  }; // namespace corsika
317 
318 } // namespace corsika
319 
320 #include <corsika/detail/framework/stack/Stack.inl>
bool isEmpty()
check if there are no further non-deleted particles on stack
Stack(TStackData vD)
if TStackData is a reference member we HAVE to initialize it in the constructor, this is typically ne...
Definition: Stack.hpp:136
void purge()
Function to ultimatively remove all entries from the stack marked as deleted.
Stack(TArgs... args)
This constructor takes any argument and passes it on to the TStackData user class.
Definition: Stack.hpp:152
StackIteratorInterface< value_type, MParticleInterface, MSecondaryProducer, Stack > stack_iterator_type
Via the StackIteratorInterface and ConstStackIteratorInterface specialization, the type of the stack_...
Definition: Stack.hpp:100
Stack()
create a new Stack, if there is already data associated prepare needed initialization.
Definition: Stack.hpp:120
The Stack class provides (and connects) the main particle data storage machinery. ...
Definition: Stack.hpp:77
STL namespace.
bool purgeLastIfDeleted()
Function to ultimatively remove the last entry from the stack, if it was marked as deleted before...
stack_iterator_type::particle_interface_type particle_interface_type
this is the full type of the user-declared MParticleInterface
Definition: Stack.hpp:109
CORSIKA8 logging utilities.
TStackData stack_data_type
this is the type of the user-provided data structure
Definition: Stack.hpp:82
`, since they are used everywhere as integral part of the framework.
stack_iterator_type addSecondary(stack_iterator_type &parent, const TArgs... v)
increase stack size, create new particle at end of stack, related to parent particle/projectile ...
bool isErased(const stack_iterator_type &p) const
check if this particle was already deleted
SecondaryView can only be constructed by giving a valid Projectile particle, following calls to addSe...
unsigned int getIndexFromIterator(const unsigned int vI) const
Function to perform eventual transformation from StackIterator::getIndex() to index in data stored in...
stack_iterator_type addParticle(const TArgs... v)
increase stack size, create new particle at end of stack
The base class to define the readout of particle properties from a particle stack.
Stack & operator=(Stack &)=delete
since Stack can be very big, we don&#39;t want to copy it
This is the iterator class for const-access to stack data.
The StackIteratorInterface is the main interface to iterator over particles on a stack.
stack_iterator_type particle_type
In all programming context, the object to access, copy, and transport particle data is via the stack_...
Definition: Stack.hpp:114