IAP GITLAB

Skip to content
Snippets Groups Projects
Commit e1fb6e92 authored by ralfulrich's avatar ralfulrich
Browse files

move stack implementation to new subdirectory

parent 5cd9bce5
No related branches found
No related tags found
No related merge requests found
...@@ -40,8 +40,9 @@ find_package (Eigen3 REQUIRED) ...@@ -40,8 +40,9 @@ find_package (Eigen3 REQUIRED)
# order of subdirectories # order of subdirectories
add_subdirectory (ThirdParty) add_subdirectory (ThirdParty)
add_subdirectory (Documentation)
add_subdirectory (Framework) add_subdirectory (Framework)
add_subdirectory (Stack)
#add_subdirectory (Processes) #add_subdirectory (Processes)
add_subdirectory (Documentation)
add_subdirectory (Main) add_subdirectory (Main)
...@@ -11,10 +11,10 @@ target_link_libraries (logger_example CORSIKAunits CORSIKAlogging) ...@@ -11,10 +11,10 @@ target_link_libraries (logger_example CORSIKAunits CORSIKAlogging)
install (TARGETS logger_example DESTINATION share/examples) install (TARGETS logger_example DESTINATION share/examples)
add_executable (stack_example stack_example.cc) 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) install (TARGETS stack_example DESTINATION share/examples)
add_executable (staticsequence_example staticsequence_example.cc) 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) install (TARGETS staticsequence_example DESTINATION share/examples)
#include <fwk/StackOne.h> #include <stack/super_stupid/SuperStupidStack.h>
//#include <corsika/StackOne.h>
#include <iomanip> #include <iomanip>
#include <iostream> #include <iostream>
using namespace std; 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) { for (int i = 0; i < 11; ++i) {
auto p = s.NewParticle(); auto p = s.NewParticle();
p.SetId(i); p.SetId(i);
...@@ -16,7 +15,7 @@ void fill(stack::StackOne& s) { ...@@ -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; cout << "found Stack with " << s.GetSize() << " particles. " << endl;
double Etot = 0; double Etot = 0;
for (auto p : s) { Etot += p.GetEnergy(); } for (auto p : s) { Etot += p.GetEnergy(); }
...@@ -24,7 +23,7 @@ void read(stack::StackOne& s) { ...@@ -24,7 +23,7 @@ void read(stack::StackOne& s) {
} }
int main() { int main() {
stack::StackOne s; stack::super_stupid::SuperStupidStack s;
fill(s); fill(s);
read(s); read(s);
return 0; return 0;
......
...@@ -4,5 +4,4 @@ add_subdirectory (Geometry) ...@@ -4,5 +4,4 @@ add_subdirectory (Geometry)
add_subdirectory (Particles) add_subdirectory (Particles)
add_subdirectory (Logging) add_subdirectory (Logging)
add_subdirectory (StackInterface) add_subdirectory (StackInterface)
add_subdirectory (ParticleStack)
add_subdirectory (ProcessSequence) add_subdirectory (ProcessSequence)
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}
)
#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
#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
set ( set (
CORSIKAstackint_HEADERS CORSIKAstackinterface_HEADERS
Stack.h Stack.h
StackIterator.h StackIterator.h
) )
set ( set (
CORSIKAstackint_NAMESPACE CORSIKAstackinterface_NAMESPACE
fwk fwk
) )
add_library ( add_library (
CORSIKAstackint CORSIKAstackinterface
INTERFACE INTERFACE
) )
CORSIKA_COPY_HEADERS_TO_NAMESPACE (CORSIKAstackint ${CORSIKAstackint_NAMESPACE} ${CORSIKAstackint_HEADERS}) CORSIKA_COPY_HEADERS_TO_NAMESPACE (CORSIKAstackinterface ${CORSIKAstackinterface_NAMESPACE} ${CORSIKAstackinterface_HEADERS})
target_include_directories ( target_include_directories (
CORSIKAstackint CORSIKAstackinterface
INTERFACE INTERFACE
$<BUILD_INTERFACE:${PROJECT_BINARY_DIR}/include> $<BUILD_INTERFACE:${PROJECT_BINARY_DIR}/include>
$<INSTALL_INTERFACE:include> $<INSTALL_INTERFACE:include>
...@@ -25,14 +25,14 @@ target_include_directories ( ...@@ -25,14 +25,14 @@ target_include_directories (
#add_custom_command ( #add_custom_command (
# TARGET # TARGET
# CORSIKAstackinterface # CORSIKAstackinterfaceerface
# PRE_BUILD # 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 ( install (
FILES FILES
${CORSIKAstackint_HEADERS} ${CORSIKAstackinterface_HEADERS}
DESTINATION DESTINATION
include/${CORSIKAstackint_NAMESPACE} include/${CORSIKAstackinterface_NAMESPACE}
) )
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment