From e1fb6e92150aa912a57d6031d5e8c4077b522618 Mon Sep 17 00:00:00 2001 From: ralfulrich <ralf.ulrich@kit.edu> Date: Fri, 7 Sep 2018 21:36:34 +0200 Subject: [PATCH] move stack implementation to new subdirectory --- CMakeLists.txt | 3 +- Documentation/Examples/CMakeLists.txt | 4 +- Documentation/Examples/stack_example.cc | 11 ++-- Framework/CMakeLists.txt | 1 - Framework/ParticleStack/CMakeLists.txt | 40 ------------- Framework/ParticleStack/StackIterator.h | 70 ---------------------- Framework/ParticleStack/StackOne.h | 80 ------------------------- Framework/StackInterface/CMakeLists.txt | 18 +++--- 8 files changed, 18 insertions(+), 209 deletions(-) delete mode 100644 Framework/ParticleStack/CMakeLists.txt delete mode 100644 Framework/ParticleStack/StackIterator.h delete mode 100644 Framework/ParticleStack/StackOne.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 9def1d5e6..0f3362bf1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -40,8 +40,9 @@ find_package (Eigen3 REQUIRED) # order of subdirectories add_subdirectory (ThirdParty) -add_subdirectory (Documentation) add_subdirectory (Framework) +add_subdirectory (Stack) #add_subdirectory (Processes) +add_subdirectory (Documentation) add_subdirectory (Main) diff --git a/Documentation/Examples/CMakeLists.txt b/Documentation/Examples/CMakeLists.txt index cfd964737..d4efb2fc7 100644 --- a/Documentation/Examples/CMakeLists.txt +++ b/Documentation/Examples/CMakeLists.txt @@ -11,10 +11,10 @@ target_link_libraries (logger_example CORSIKAunits CORSIKAlogging) install (TARGETS logger_example DESTINATION share/examples) add_executable (stack_example stack_example.cc) -target_link_libraries (stack_example CORSIKAstack CORSIKAunits CORSIKAlogging) +target_link_libraries (stack_example SuperStupidStack CORSIKAunits CORSIKAlogging) install (TARGETS stack_example DESTINATION share/examples) add_executable (staticsequence_example staticsequence_example.cc) -target_link_libraries (staticsequence_example CORSIKAstack CORSIKAprocesssequence CORSIKAunits CORSIKAlogging) +target_link_libraries (staticsequence_example SuperStupidStack CORSIKAprocesssequence CORSIKAunits CORSIKAlogging) install (TARGETS staticsequence_example DESTINATION share/examples) diff --git a/Documentation/Examples/stack_example.cc b/Documentation/Examples/stack_example.cc index 052965663..b38d07250 100644 --- a/Documentation/Examples/stack_example.cc +++ b/Documentation/Examples/stack_example.cc @@ -1,14 +1,13 @@ -#include <fwk/StackOne.h> -//#include <corsika/StackOne.h> +#include <stack/super_stupid/SuperStupidStack.h> #include <iomanip> #include <iostream> using namespace std; -//using namespace fwk; +// using namespace fwk; -void fill(stack::StackOne& s) { +void fill(stack::super_stupid::SuperStupidStack& s) { for (int i = 0; i < 11; ++i) { auto p = s.NewParticle(); p.SetId(i); @@ -16,7 +15,7 @@ void fill(stack::StackOne& s) { } } -void read(stack::StackOne& s) { +void read(stack::super_stupid::SuperStupidStack& s) { cout << "found Stack with " << s.GetSize() << " particles. " << endl; double Etot = 0; for (auto p : s) { Etot += p.GetEnergy(); } @@ -24,7 +23,7 @@ void read(stack::StackOne& s) { } int main() { - stack::StackOne s; + stack::super_stupid::SuperStupidStack s; fill(s); read(s); return 0; diff --git a/Framework/CMakeLists.txt b/Framework/CMakeLists.txt index 9de69dc03..2fdb7c85a 100644 --- a/Framework/CMakeLists.txt +++ b/Framework/CMakeLists.txt @@ -4,5 +4,4 @@ add_subdirectory (Geometry) add_subdirectory (Particles) add_subdirectory (Logging) add_subdirectory (StackInterface) -add_subdirectory (ParticleStack) add_subdirectory (ProcessSequence) diff --git a/Framework/ParticleStack/CMakeLists.txt b/Framework/ParticleStack/CMakeLists.txt deleted file mode 100644 index 6b9547ec2..000000000 --- a/Framework/ParticleStack/CMakeLists.txt +++ /dev/null @@ -1,40 +0,0 @@ - -set (CORSIKAstack_HEADERS StackOne.h) -set (CORSIKAstack_NAMESPACE fwk) - -add_library (CORSIKAstack INTERFACE) - -CORSIKA_COPY_HEADERS_TO_NAMESPACE (CORSIKAstack ${CORSIKAstack_NAMESPACE} ${CORSIKAstack_HEADERS}) - -#set_target_properties (CORSIKAstack PROPERTIES VERSION ${PROJECT_VERSION}) -#set_target_properties (CORSIKAstack PROPERTIES SOVERSION 1) - -#set_target_properties (CORSIKAstack PROPERTIES PUBLIC_HEADER "${STACK_HEADERS}") - -target_link_libraries ( - CORSIKAstack - INTERFACE - CORSIKAstackint - CORSIKAunits - ) - -#target_include_directories (CORSIKAstack PRIVATE ${EIGEN3_INCLUDE_DIR}) -target_include_directories ( - CORSIKAstack - INTERFACE - $<BUILD_INTERFACE:${PROJECT_BINARY_DIR}/include> - $<INSTALL_INTERFACE:include> - ) - -#add_custom_command ( -# CORSIKAstack -# PRE_BUILD -# COMMAND ${CMAKE_COMMAND} -E copy_if_different ${CORSIKAstack_HEADERS} ${PROJECT_BINARY_DIR}/include/corsika}) -# ) - -install ( - FILES - StackOne.h - DESTINATION - include/${CORSIKAstack_NAMESPACE} - ) diff --git a/Framework/ParticleStack/StackIterator.h b/Framework/ParticleStack/StackIterator.h deleted file mode 100644 index 616ee53b8..000000000 --- a/Framework/ParticleStack/StackIterator.h +++ /dev/null @@ -1,70 +0,0 @@ -#ifndef _include_StackIterator_h__ -#define _include_StackIterator_h__ - -#include <iostream> -#include <iomanip> - -namespace stack { - - template<class Stack, class Particle> class StackIteratorInfo; - - /** - The main interface to iterator over objects on a stack. - */ - - template<typename Stack, typename Particle> - class StackIterator : public Particle - { - friend Stack; - friend Particle; - friend StackIteratorInfo<Stack,Particle>; - - private: - int fIndex; - - //#warning stacks should not be copied because of this: - Stack* fData; - - public: - StackIterator() : fData(0), fIndex(0) { } - StackIterator(Stack& data, const int index) : fData(&data), fIndex(index) { } - StackIterator(const StackIterator& mit) : fData(mit.fData), fIndex(mit.fIndex) { } - - StackIterator& operator++() { ++fIndex; return *this; } - StackIterator operator++(int) { StackIterator tmp(*this); ++fIndex; return tmp; } - bool operator==(const StackIterator& rhs) { return fIndex == rhs.fIndex; } - bool operator!=(const StackIterator& rhs) { return fIndex != rhs.fIndex; } - - StackIterator& operator*() { return *this; } - const StackIterator& operator*() const { return *this; } - - protected: - int GetIndex() const { return fIndex; } - Stack& GetStack() { return *fData; } - const Stack& GetStack() const { return *fData; } - - inline StackIterator<Stack,Particle>& base_ref() { return static_cast<StackIterator<Stack, Particle>&>(*this); } - inline const StackIterator<Stack,Particle>& base_ref() const { return static_cast<const StackIterator<Stack, Particle>&>(*this); } - }; - - - /** - Internal helper class for StackIterator - */ - - template<class _Stack, class Particle> - class StackIteratorInfo { - - friend Particle; - private: - StackIteratorInfo() {} - - protected: - inline _Stack& Stack() { return static_cast<StackIterator<_Stack, Particle>*>(this)->GetStack(); } - inline int Index() const { return static_cast<const StackIterator<_Stack, Particle>*>(this)->GetIndex(); } - inline const _Stack& Stack() const { return static_cast<const StackIterator<_Stack, Particle>*>(this)->GetStack(); } - }; - -} // end namespace stack - -#endif diff --git a/Framework/ParticleStack/StackOne.h b/Framework/ParticleStack/StackOne.h deleted file mode 100644 index e7d4285f7..000000000 --- a/Framework/ParticleStack/StackOne.h +++ /dev/null @@ -1,80 +0,0 @@ -#ifndef _include_stackone_h_ -#define _include_stackone_h_ - -#include <string> -#include <vector> - -#include <fwk/Stack.h> - -namespace stack { - - /** - Example of a particle object on the stack. - */ - - template <typename _Stack> - class ParticleReadOne : public StackIteratorInfo<_Stack, ParticleReadOne<_Stack> > { - using StackIteratorInfo<_Stack, ParticleReadOne>::GetIndex; - using StackIteratorInfo<_Stack, ParticleReadOne>::GetStack; - - public: - void SetId(const int id) { GetStack().SetId(GetIndex(), id); } - void SetEnergy(const double e) { GetStack().SetEnergy(GetIndex(), e); } - - int GetId() const { return GetStack().GetId(GetIndex()); } - double GetEnergy() const { return GetStack().GetEnergy(GetIndex()); } - - double GetPDG() const { return 0; } // ConvertToPDG(GetId()); } - void SetPDG(double v) { GetStack().SetId(0, 0); } // fIndex, ConvertFromPDG(v)); } - }; - - /** - Memory implementation of the most simple particle stack object. - */ - - class StackOneImpl { - private: - /// the actual memory to store particle data - - std::vector<int> fId; - std::vector<double> fData; - - public: - void Clear() { fData.clear(); } - - int GetSize() const { return fData.size(); } - int GetCapacity() const { return fData.size(); } - - void SetId(const int i, const int id) { fId[i] = id; } - void SetEnergy(const int i, const double e) { fData[i] = e; } - - const int GetId(const int i) const { return fId[i]; } - const double GetEnergy(const int i) const { return fData[i]; } - - /** - Function to copy particle at location i2 in stack to i1 - */ - void Copy(const int i1, const int i2) { - fData[i2] = fData[i1]; - fId[i2] = fId[i1]; - } - - protected: - void IncrementSize() { - fData.push_back(0.); - fId.push_back(0.); - } - void DecrementSize() { - if (fData.size() > 0) { - fData.pop_back(); - fId.pop_back(); - } - } - }; - - typedef StackIterator<StackOneImpl, ParticleReadOne<StackOneImpl> > ParticleOne; - typedef Stack<StackOneImpl, ParticleOne> StackOne; - -} // namespace stack - -#endif diff --git a/Framework/StackInterface/CMakeLists.txt b/Framework/StackInterface/CMakeLists.txt index ba9ef212f..5388bb051 100644 --- a/Framework/StackInterface/CMakeLists.txt +++ b/Framework/StackInterface/CMakeLists.txt @@ -1,23 +1,23 @@ set ( - CORSIKAstackint_HEADERS + CORSIKAstackinterface_HEADERS Stack.h StackIterator.h ) set ( - CORSIKAstackint_NAMESPACE + CORSIKAstackinterface_NAMESPACE fwk ) add_library ( - CORSIKAstackint + CORSIKAstackinterface INTERFACE ) -CORSIKA_COPY_HEADERS_TO_NAMESPACE (CORSIKAstackint ${CORSIKAstackint_NAMESPACE} ${CORSIKAstackint_HEADERS}) +CORSIKA_COPY_HEADERS_TO_NAMESPACE (CORSIKAstackinterface ${CORSIKAstackinterface_NAMESPACE} ${CORSIKAstackinterface_HEADERS}) target_include_directories ( - CORSIKAstackint + CORSIKAstackinterface INTERFACE $<BUILD_INTERFACE:${PROJECT_BINARY_DIR}/include> $<INSTALL_INTERFACE:include> @@ -25,14 +25,14 @@ target_include_directories ( #add_custom_command ( # TARGET -# CORSIKAstackinterface +# CORSIKAstackinterfaceerface # PRE_BUILD -# COMMAND ${CMAKE_COMMAND} -E copy_if_different ${CORSIKAstackinterface_HEADERS} ${PROJECT_BINARY_DIR}/include/corsika +# COMMAND ${CMAKE_COMMAND} -E copy_if_different ${CORSIKAstackinterfaceerface_HEADERS} ${PROJECT_BINARY_DIR}/include/corsika # ) install ( FILES - ${CORSIKAstackint_HEADERS} + ${CORSIKAstackinterface_HEADERS} DESTINATION - include/${CORSIKAstackint_NAMESPACE} + include/${CORSIKAstackinterface_NAMESPACE} ) -- GitLab