IAP GITLAB

Skip to content
Snippets Groups Projects
staticsequence_example.cc 2.29 KiB
Newer Older
 * (c) Copyright 2018 CORSIKA Project, corsika-project@lists.kit.edu
 *
 * See file AUTHORS for a list of contributors.
 *
 * This software is distributed under the terms of the GNU General Public
 * Licence version 3 (GPL Version 3). See file LICENSE for a full version of
 * the license.
 */

#include <iomanip>
#include <iostream>
#include <corsika/process/ProcessSequence.h>
Ralf Ulrich's avatar
Ralf Ulrich committed
#include <corsika/geometry/Point.h>
#include <corsika/geometry/RootCoordinateSystem.h>
#include <corsika/geometry/Vector.h>
Ralf Ulrich's avatar
Ralf Ulrich committed
using namespace corsika;
using namespace corsika::units::si;
using namespace corsika::process;
Ralf Ulrich's avatar
Ralf Ulrich committed
using namespace std;

const int nData = 10;
class Process1 : public BaseProcess<Process1> {
public:
  Process1() {}
  template <typename D, typename T, typename S>
  EProcessReturn DoContinuous(D& d, T&, S&) const {
Ralf Ulrich's avatar
Ralf Ulrich committed
    for (int i = 0; i < nData; ++i) d.p[i] += 1;
ralfulrich's avatar
ralfulrich committed
    return EProcessReturn::eOk;
class Process2 : public BaseProcess<Process2> {
public:
  Process2() {}
  template <typename D, typename T, typename S>
ralfulrich's avatar
ralfulrich committed
  inline EProcessReturn DoContinuous(D& d, T&, S&) const {
Ralf Ulrich's avatar
Ralf Ulrich committed
    for (int i = 0; i < nData; ++i) d.p[i] -= 0.1 * i;
ralfulrich's avatar
ralfulrich committed
    return EProcessReturn::eOk;
class Process3 : public BaseProcess<Process3> {
public:
  Process3() {}
  template <typename D, typename T, typename S>
Ralf Ulrich's avatar
Ralf Ulrich committed
  inline EProcessReturn DoContinuous(D&, T&, S&) const {
ralfulrich's avatar
ralfulrich committed
    return EProcessReturn::eOk;
class Process4 : public BaseProcess<Process4> {
public:
Ralf Ulrich's avatar
Ralf Ulrich committed
  Process4(const double v)
      : fV(v) {}
  template <typename D, typename T, typename S>
Ralf Ulrich's avatar
Ralf Ulrich committed
  inline EProcessReturn DoContinuous(D& d, T&, S&) const {
    for (int i = 0; i < nData; ++i) d.p[i] *= fV;
ralfulrich's avatar
ralfulrich committed
    return EProcessReturn::eOk;
private:
Ralf Ulrich's avatar
Ralf Ulrich committed
  double fV;
struct DummyData {
Ralf Ulrich's avatar
Ralf Ulrich committed
  double p[nData] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
};
struct DummyStack {
  void clear() {}
Ralf Ulrich's avatar
Ralf Ulrich committed
struct DummyTrajectory {};
  Process1 m1;
  Process2 m2;
  Process3 m3;
Ralf Ulrich's avatar
Ralf Ulrich committed
  Process4 m4(0.9);
  auto sequence = m1 << m2 << m3 << m4;
Ralf Ulrich's avatar
Ralf Ulrich committed

  DummyData p;
  DummyStack s;
Ralf Ulrich's avatar
Ralf Ulrich committed
  DummyTrajectory t;
ralfulrich's avatar
ralfulrich committed
  const int n = 1000;
  for (int i = 0; i < n; ++i) { sequence.DoContinuous(p, t, s); }
Ralf Ulrich's avatar
Ralf Ulrich committed

  for (int i = 0; i < nData; ++i) {
    // cout << p.p[i] << endl;
    // assert(p.p[i] == n-i*100);
ralfulrich's avatar
ralfulrich committed
  }
Ralf Ulrich's avatar
Ralf Ulrich committed

  cout << " done (nothing...) " << endl;
  modular();
  return 0;
}