diff --git a/Documentation/Examples/staticsequence_example.cc b/Documentation/Examples/staticsequence_example.cc index 26d27d10bb1633838d4950f065b0e81cfba369a2..473a75761d939cde34fc3799f76311dbbded20a0 100644 --- a/Documentation/Examples/staticsequence_example.cc +++ b/Documentation/Examples/staticsequence_example.cc @@ -10,7 +10,7 @@ class Process1 : public processes::Base <Process1> { public: Process1() {} - template<typename D> void Call(D& d) const { + template<typename D> void DoContinuous(D& d) const { for (int i=0; i<10; ++i) d.p[i] += 1; } }; @@ -20,7 +20,7 @@ class Process2 : public processes::Base <Process2> public: Process2() {} - template<typename D> inline void Call(D& d) const { + template<typename D> inline void DoContinuous(D& d) const { //for (int i=0; i<10; ++i) d.p[i] *= 2; } }; @@ -30,11 +30,11 @@ class Process3 : public processes::Base <Process3> public: //Process3(const int v) :fV(v) {} Process3() {} - - template<typename D> inline void Call(D& d) const { + + template<typename D> inline void DoContinuous(D& d) const { //for (int i=0; i<10; ++i) d.p[i] += fV; } - + private: //int fV; }; @@ -44,10 +44,10 @@ class Process4 : public processes::Base <Process4> public: //Process4(const int v) : fV(v) {} Process4() {} - template<typename D> inline void Call(D& d) const { + template<typename D> inline void DoContinuous(D& d) const { //for (int i=0; i<10; ++i) d.p[i] /= fV; } - + private: //int fV; }; @@ -65,7 +65,7 @@ void modular() { data d0; - + Process1 m1; Process2 m2; Process3 m3; @@ -75,14 +75,14 @@ modular() const int n = 100000000; for (int i=0; i<n; ++i) { - sequence.Call(d0); + sequence.DoContinuous(d0); } - + double s = 0; for (int i=0; i<10; ++i) { s += d0.p[i]; } - + cout << scientific << " v=" << s << " n=" << n << endl; } diff --git a/Framework/Cascade/Cascade.cc b/Framework/Cascade/Cascade.cc new file mode 100644 index 0000000000000000000000000000000000000000..68cde099e063784978b34b820f3a5d8f66e3b689 --- /dev/null +++ b/Framework/Cascade/Cascade.cc @@ -0,0 +1,26 @@ + + +namespace cascade; + + +void +Cascade::Process() +{ + Stack s; + if (!s.IsEmpty()) { + + s + + } + +} + +void +Cascade::Step(auto& sequence, Particle& particle) +{ + double nextStep = sequence.MinStepLength(particle); + Trajectory trajectory = sequence.Transport(particle, nextStep); + sequence.DoContinuous(particle, trajectory); + sequence.DoDiscrete(particle); +} + diff --git a/Framework/Cascade/Step.cc b/Framework/Cascade/Step.cc new file mode 100644 index 0000000000000000000000000000000000000000..5a04f06a60b25f0a35ec27e93ba917f478fac104 --- /dev/null +++ b/Framework/Cascade/Step.cc @@ -0,0 +1,14 @@ + + +namespace cascade; + + +void +Cascade::Step(auto& sequence, Particle& particle) +{ + double nextStep = sequence.MinStepLength(particle); + Trajectory trajectory = sequence.Transport(particle, nextStep); + sequence.DoContinuous(particle, trajectory); + sequence.DoDiscrete(particle); +} + diff --git a/Framework/ParticleStack/StackIterator.h b/Framework/ParticleStack/StackIterator.h index 87ce66d401c4e74192cf3ffb8f69814ca8931c9d..616ee53b89be6f786278e39ba38236c2c6ac9324 100644 --- a/Framework/ParticleStack/StackIterator.h +++ b/Framework/ParticleStack/StackIterator.h @@ -46,7 +46,7 @@ namespace stack { 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 diff --git a/Framework/ProcessSequence/ProcessSequence.h b/Framework/ProcessSequence/ProcessSequence.h index bae3be1f8ae10fed79c303f4b67f182de55f4668..5a8a7c268de87d62d88c26ad4fcced056d34b3ab 100644 --- a/Framework/ProcessSequence/ProcessSequence.h +++ b/Framework/ProcessSequence/ProcessSequence.h @@ -7,6 +7,15 @@ using namespace std; namespace processes { + /** + /class Base + + The structural base type of a process object in a + ProcessSequence. Both, the ProcessSequence and all its elements + are of type Base<T> + + */ + template <typename derived> struct Base { @@ -16,7 +25,15 @@ namespace processes { } }; + /** + \class ProcessSequence + A compile time static list of processes. The compiler will + generate a new type based on template logic containing all the + elements. + + \comment Using CRTP pattern, https://en.wikipedia.org/wiki/Curiously_recurring_template_pattern + */ template <typename T1, typename T2> class ProcessSequence : public Base <ProcessSequence<T1,T2> > @@ -31,7 +48,16 @@ namespace processes { { } template<typename D> - inline void Call(D& d) const { A.Call(d); B.Call(d); } + inline void DoContinuous(D& d) const { A.DoContinuous(d); B.DoContinuous(d); } + + template<typename D> + inline double MinStepLength(D& d) const { return min(A.MinStepLength(d), B.MinStepLength(d)); } + + //template<typename D> + //inline Trajectory Transport(D& d, double& length) const { A.Transport(d, length); B.Transport(d, length); } + + template<typename D> + inline void DoDiscrete(D& d) const { A.DoDiscrete(d); B.DoDiscrete(d); } }; diff --git a/Framework/ProcessSequence/StaticSequence.h b/Framework/ProcessSequence/StaticSequence.h deleted file mode 100644 index 093612cbf54b16d697beca4ae3febaef868acf3f..0000000000000000000000000000000000000000 --- a/Framework/ProcessSequence/StaticSequence.h +++ /dev/null @@ -1,128 +0,0 @@ -#ifndef _include_ProcessSequence_h_ -#define _include_ProcessSequence_h_ - -#include <iostream> -#include <typeinfo> -using namespace std; - -namespace processes { - - template <typename derived> - struct Base - { - const derived& GetRef() const - { - return static_cast<const derived&>(*this); - } - }; - - - - template <typename T1, typename T2> - class ProcessSequence : public Base <Sequence<T1,T2>> - { - public: - const T1& A; - const T2& B; - - ProcessSequence(const T1& in_A, const T2& in_B) - : A(in_A) - , B(in_B) - { } - - template<class D> - inline void Call(D& d) const { A.Call<D>(d); B.Call<D>(d); } - - }; - - - - template <typename T1, typename T2> - inline - const ProcessSequence<T1,T2> - operator+ (const Base<T1>& A, const Base<T2>& B) - { - return ProcessSequence<T1,T2>( A.GetRef(), B.GetRef() ); - } - - - /* - template <typename T1> - struct depth_lhs - { - static const int num = 0; - }; - - - - // terminating condition - template <typename T1, typename T2> - struct depth_lhs< Sequence<T1,T2> > - { - // try to expand the left node (T1) which might be a Sequence type - static const int num = 1 + depth_lhs<T1>::num; - }; - */ - - - - - /* - template <typename T1> - struct mat_ptrs - { - static const int num = 0; - - inline static void - get_ptrs(const Process** ptrs, const T1& X) - { - ptrs[0] = reinterpret_cast<const Process*>(&X); - } - }; - - - template <typename T1, typename T2> - struct mat_ptrs< Sequence<T1,T2> > - { - static const int num = 1 + mat_ptrs<T1>::num; - - inline static void - get_ptrs(const Process** in_ptrs, const Sequence<T1,T2>& X) - { - // traverse the left node - mat_ptrs<T1>::get_ptrs(in_ptrs, X.A); - // get address of the matrix on the right node - in_ptrs[num] = reinterpret_cast<const Process*>(&X.B); - } - }; - */ - - /* - template<typename T1, typename T2> - const Process& - Process::operator=(const Sequence<T1,T2>& X) - { - int N = 1 + depth_lhs< Sequence<T1,T2> >::num; - const Process* ptrs[N]; - mat_ptrs< Sequence<T1,T2> >::get_ptrs(ptrs, X); - int r = ptrs[0]->rows; - int c = ptrs[0]->cols; - // ... check that all matrices have the same size ... - set_size(r, c); - for(int j=0; j<r*c; ++j) - { - double sum = ptrs[0]->data[j]; - for(int i=1; i<N; ++i) - { - sum += ptrs[i]->data[j]; - } - data[j] = sum; - } - return *this; - } - */ - -} // end namespace - -#endif - diff --git a/Framework/StackInterface/Stack.h b/Framework/StackInterface/Stack.h index 6fa19e2d4fb3819a86e0419d1665b6a055688e48..570603c11d072861f705b8ee60a9076aed4e924b 100644 --- a/Framework/StackInterface/Stack.h +++ b/Framework/StackInterface/Stack.h @@ -25,11 +25,13 @@ namespace stack { public: typedef Particle iterator; typedef const Particle const_iterator; - + + /// these are functions required by std containers and std loops iterator begin() { return iterator(*this, 0); } iterator end() { return iterator(*this, GetSize()); } iterator last() { return iterator(*this, GetSize()-1); } + /// these are functions required by std containers and std loops 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); } diff --git a/Framework/StackInterface/StackIterator.h b/Framework/StackInterface/StackIterator.h index 3070ae68a9ee96f11cde620a0d1de324c86e5afa..2fac50999e67df73fca85f65738a3b24f0c08b6a 100644 --- a/Framework/StackInterface/StackIterator.h +++ b/Framework/StackInterface/StackIterator.h @@ -6,11 +6,26 @@ namespace stack { + // forward decl. template<class Stack, class Particle> class StackIteratorInfo; /** - The main interface to iterator over objects on a stack. - */ + \class StackIterator + + The StackIterator is the main interface to iterator over + particles on a stack. At the same time StackIterator is a + Particle object by itself, thus there is no difference between + type and ref_type for convenience of the physicist. + + This allows to write code like + \verbatim + for (auto p : theStack) { p.SetEnergy(newEnergy); } + \endverbatim + + It might be interesting to investigate whether auto or auto& is + better in the loop here... + + */ template<typename Stack, typename Particle> class StackIterator : public Particle @@ -42,14 +57,18 @@ namespace stack { 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); } + + // this is probably not needed rigth now: + //inline StackIterator<Stack,Particle>& BaseRef() { return static_cast<StackIterator<Stack, Particle>&>(*this); } + //inline const StackIterator<Stack,Particle>& BaseRef() const { return static_cast<const StackIterator<Stack, Particle>&>(*this); } }; + /** - Internal helper class for StackIterator + \class StackIteratorInfo + + Internal helper class for StackIterator. Document better... */ template<class _Stack, class Particle>