IAP GITLAB

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

dummy particle stack

parent b2727df5
No related branches found
No related tags found
No related merge requests found
add_executable (geometry_example geometry_example.cc)
target_link_libraries (geometry_example CORSIKAgeometry CORSIKAunits)
install (TARGETS geometry_example DESTINATION share/examples)
add_executable (logger_example logger_example.cc)
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)
install (TARGETS stack_example DESTINATION share/examples)
#include <ParticleStack/StackOne.h>
#include <iostream>
#include <iomanip>
using namespace std;
void fill(stack::StackOne& s)
{
for (int i=0; i<11; ++i) {
auto p = s.NewParticle();
p.SetId(i);
p.SetEnergy(1.5*i);
}
}
void
read(stack::StackOne& s)
{
cout << "found Stack with " << s.GetSize() << " particles. " << endl;
double Etot = 0;
for (auto p : s) {
Etot += p.GetEnergy();
}
cout << "Etot=" << Etot << endl;
}
int
main()
{
stack::StackOne s;
fill(s);
read(s);
return 0;
}
......@@ -3,3 +3,4 @@ add_subdirectory (Units)
add_subdirectory (Geometry)
add_subdirectory (Logging)
add_subdirectory (StackInterface)
add_subdirectory (Stack)
set (STACK_HEADERS StackOne.h)
add_library (CORSIKAstack INTERFACE)
#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 (CORSIKAstackinterface CORSIKAunits)
#target_include_directories (CORSIKAstack PRIVATE ${EIGEN3_INCLUDE_DIR})
target_include_directories (CORSIKAstack INTERFACE $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/Framework>
$<INSTALL_INTERFACE:include/Framework>
)
install (FILES StackOne.h DESTINATION include/Stack)
#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 <vector>
#include <string>
#include <StackInterface/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>::Index;
using StackIteratorInfo<_Stack, ParticleReadOne>::Stack;
public:
void SetId(const int id) { Stack().SetId(Index(), id); }
void SetEnergy(const double e) { Stack().SetEnergy(Index(), e); }
int GetId() const { Stack().GetId(Index()); }
double GetEnergy() const { Stack().GetEnergy(Index()); }
double GetPDG() const { return 0; } // ConvertToPDG(GetId()); }
void SetPDG(double v) { Stack().SetId(0, 0); } //fIndex, ConvertFromPDG(v)); }
};
/**
Definition of one most simple particle stack object.
*/
class StackOneImpl
{
private:
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]; }
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;
} // end namespace
#endif
#ifndef _include_Stack_h__
#define _include_Stack_h__
#include <StackIterator.h> // to help application programmres
#include <StackInterface/StackIterator.h> // to help application programmres
namespace stack {
......@@ -13,8 +13,8 @@ namespace stack {
class Stack : public DataImpl {
public:
using DataImpl::Capacity;
using DataImpl::Size;
using DataImpl::GetCapacity;
using DataImpl::GetSize;
using DataImpl::Clear;
using DataImpl::Copy;
......@@ -26,15 +26,15 @@ namespace stack {
typedef Particle iterator;
typedef const Particle const_iterator;
iterator Begin() { return iterator(*this, 0); }
iterator End() { return iterator(*this, Size()); }
iterator Last() { return iterator(*this, Size()-1); }
iterator begin() { return iterator(*this, 0); }
iterator end() { return iterator(*this, GetSize()); }
iterator last() { return iterator(*this, GetSize()-1); }
const_iterator CBegin() const { return const_iterator(*this, 0); }
const_iterator CEnd() const { return const_iterator(*this, Size()); }
const_iterator CLast() const { return const_iterator(*this, Size()-1); }
const_iterator cbegin() const { return const_iterator(*this, 0); }
const_iterator cend() const { return const_iterator(*this, GetSize()); }
const_iterator clast() const { return const_iterator(*this, GetSize()-1); }
iterator NewParticle() { IncrementSize(); return iterator(*this, Size()-1); }
iterator NewParticle() { IncrementSize(); return iterator(*this, GetSize()-1); }
void DeleteLast() { DecrementSize(); }
};
......
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