From 01d42f723578a6d0847d7f2690a7277718bd8e03 Mon Sep 17 00:00:00 2001 From: ralfulrich <ralf.ulrich@kit.edu> Date: Sat, 8 Sep 2018 21:42:25 +0200 Subject: [PATCH] added missing Stack directory, containing SuperStupidStack --- Stack/CMakeLists.txt | 2 + Stack/SuperStupidStack/CMakeLists.txt | 28 +++++++ Stack/SuperStupidStack/SuperStupidStack.h | 93 +++++++++++++++++++++++ 3 files changed, 123 insertions(+) create mode 100644 Stack/CMakeLists.txt create mode 100644 Stack/SuperStupidStack/CMakeLists.txt create mode 100644 Stack/SuperStupidStack/SuperStupidStack.h diff --git a/Stack/CMakeLists.txt b/Stack/CMakeLists.txt new file mode 100644 index 000000000..4971f73f8 --- /dev/null +++ b/Stack/CMakeLists.txt @@ -0,0 +1,2 @@ + +add_subdirectory (SuperStupidStack) diff --git a/Stack/SuperStupidStack/CMakeLists.txt b/Stack/SuperStupidStack/CMakeLists.txt new file mode 100644 index 000000000..7fe01a910 --- /dev/null +++ b/Stack/SuperStupidStack/CMakeLists.txt @@ -0,0 +1,28 @@ + +set (SuperStupidStack_HEADERS SuperStupidStack.h) +set (SuperStupidStack_NAMESPACE stack/super_stupid) + +add_library (SuperStupidStack INTERFACE) + +CORSIKA_COPY_HEADERS_TO_NAMESPACE (SuperStupidStack ${SuperStupidStack_NAMESPACE} ${SuperStupidStack_HEADERS}) + +target_link_libraries ( + SuperStupidStack + INTERFACE + CORSIKAstackinterface + CORSIKAunits + ) + +target_include_directories ( + SuperStupidStack + INTERFACE + $<BUILD_INTERFACE:${PROJECT_BINARY_DIR}/include> + $<INSTALL_INTERFACE:include> + ) + +install ( + FILES + ${SuperStupidStack_HEADERS} + DESTINATION + include/${SuperStupidStack_NAMESPACE} + ) diff --git a/Stack/SuperStupidStack/SuperStupidStack.h b/Stack/SuperStupidStack/SuperStupidStack.h new file mode 100644 index 000000000..ab6d65e98 --- /dev/null +++ b/Stack/SuperStupidStack/SuperStupidStack.h @@ -0,0 +1,93 @@ +#ifndef _include_superstupidstack_h_ +#define _include_superstupidstack_h_ + +#include <string> +#include <vector> + +#include <fwk/ParticleProperties.h> +#include <fwk/PhysicalUnits.h> +#include <fwk/Stack.h> + +using namespace fwk::literals; + +namespace stack { + + namespace super_stupid { + + /** + * Example of a particle object on the stack. + */ + + template <typename _Stack> + class ParticleRead : public StackIteratorInfo<_Stack, ParticleRead<_Stack> > { + + using StackIteratorInfo<_Stack, ParticleRead>::GetIndex; + using StackIteratorInfo<_Stack, ParticleRead>::GetStack; + + public: + void SetId(const fwk::particle::Code id) { GetStack().SetId(GetIndex(), id); } + void SetEnergy(const fwk::Energy& e) { GetStack().SetEnergy(GetIndex(), e); } + + fwk::particle::Code GetId() const { return GetStack().GetId(GetIndex()); } + const fwk::Energy& GetEnergy() const { return GetStack().GetEnergy(GetIndex()); } + }; + + /** + * + * Memory implementation of the most simple (stupid) particle stack object. + */ + + class SuperStupidStackImpl { + + public: + void Clear() { + fDataE.clear(); + fDataId.clear(); + } + + int GetSize() const { return fDataId.size(); } + int GetCapacity() const { return fDataId.size(); } + + void SetId(const int i, const fwk::particle::Code id) { fDataId[i] = id; } + void SetEnergy(const int i, const fwk::Energy& e) { fDataE[i] = e; } + + const fwk::particle::Code GetId(const int i) const { return fDataId[i]; } + const fwk::Energy& GetEnergy(const int i) const { return fDataE[i]; } + + /** + * Function to copy particle at location i2 in stack to i1 + */ + void Copy(const int i1, const int i2) { + fDataE[i2] = fDataE[i1]; + fDataId[i2] = fDataId[i1]; + } + + protected: + void IncrementSize() { + fDataE.push_back(0_GeV); + fDataId.push_back(fwk::particle::Code::unknown); + } + void DecrementSize() { + if (fDataE.size() > 0) { + fDataE.pop_back(); + fDataId.pop_back(); + } + } + + private: + /// the actual memory to store particle data + + std::vector<fwk::particle::Code> fDataId; + std::vector<fwk::Energy> fDataE; + + }; // end class SuperStupidStackImpl + + typedef StackIterator<SuperStupidStackImpl, ParticleRead<SuperStupidStackImpl> > + Particle; + typedef Stack<SuperStupidStackImpl, Particle> SuperStupidStack; + + } // namespace super_stupid + +} // namespace stack + +#endif -- GitLab