IAP GITLAB

Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • AirShowerPhysics/corsika
  • rulrich/corsika
  • AAAlvesJr/corsika
  • Andre/corsika
  • arrabito/corsika
  • Nikos/corsika
  • olheiser73/corsika
  • AirShowerPhysics/papers/corsika
  • pranav/corsika
9 results
Show changes
Commits on Source (2)
Showing
with 278 additions and 273 deletions
/* /*
* (c) Copyright 2019 CORSIKA Project, corsika-project@lists.kit.edu * (c) Copyright 2018 CORSIKA Project, corsika-project@lists.kit.edu
* *
* See file AUTHORS for a list of contributors. * See file AUTHORS for a list of contributors.
* *
......
/* /*
* (c) Copyright 2019 CORSIKA Project, corsika-project@lists.kit.edu * (c) Copyright 2018 CORSIKA Project, corsika-project@lists.kit.edu
* *
* See file AUTHORS for a list of contributors. * See file AUTHORS for a list of contributors.
* *
......
...@@ -22,43 +22,43 @@ namespace corsika::logging { ...@@ -22,43 +22,43 @@ namespace corsika::logging {
protected: protected:
std::string Message() { return "\n"; } std::string Message() { return "\n"; }
template <typename First, typename... Strings> template <typename TFirst, typename... TStrings>
std::string Message(const First& arg, const Strings&... rest) { std::string Message(const TFirst& arg, const TStrings&... rest) {
std::ostringstream ss; std::ostringstream ss;
ss << arg << Message(rest...); ss << arg << Message(rest...);
return ss.str(); return ss.str();
} }
template <typename... Strings> template <typename... TStrings>
std::string Message(const int& arg, const Strings&... rest) { std::string Message(const int& arg, const TStrings&... rest) {
return std::to_string(arg) + Message(rest...); return std::to_string(arg) + Message(rest...);
} }
template <typename... Strings> template <typename... TStrings>
std::string Message(const double& arg, const Strings&... rest) { std::string Message(const double& arg, const TStrings&... rest) {
return std::to_string(arg) + Message(rest...); return std::to_string(arg) + Message(rest...);
} }
template <typename... Strings> template <typename... TStrings>
std::string Message(char const* arg, const Strings&... rest) { std::string Message(char const* arg, const TStrings&... rest) {
return std::string(arg) + Message(rest...); return std::string(arg) + Message(rest...);
} }
template <typename... Strings> template <typename... TStrings>
std::string Message(const std::string& arg, const Strings&... rest) { std::string Message(const std::string& arg, const TStrings&... rest) {
return arg + Message(rest...); return arg + Message(rest...);
} }
// ---------------------- // ----------------------
// boost format // boost format
template <typename... Strings> template <typename... TStrings>
std::string Message(const boost::format& fmt, const Strings&... rest) { std::string Message(const boost::format& fmt, const TStrings&... rest) {
boost::format FMT(fmt); boost::format FMT(fmt);
return bformat(FMT, rest...); return bformat(FMT, rest...);
} }
template <typename Arg, typename... Strings> template <typename Arg, typename... TStrings>
std::string bformat(boost::format& fmt, const Arg& arg, const Strings&... rest) { std::string bformat(boost::format& fmt, const Arg& arg, const TStrings&... rest) {
fmt % arg; fmt % arg;
return bformat(fmt, rest...); return bformat(fmt, rest...);
} }
......
...@@ -14,19 +14,19 @@ ...@@ -14,19 +14,19 @@
namespace corsika::particles { namespace corsika::particles {
std::ostream& operator<<(std::ostream& stream, corsika::particles::Code const p) { std::ostream& operator<<(std::ostream& stream, corsika::particles::Code const vP) {
return stream << corsika::particles::GetName(p); return stream << corsika::particles::GetName(vP);
} }
Code ConvertFromPDG(PDGCode p) { Code ConvertFromPDG(PDGCode vP) {
static_assert(detail::conversionArray.size() % 2 == 1); static_assert(detail::conversionArray.size() % 2 == 1);
// this will fail, for the strange case where the maxPDG is negative... // this will fail, for the strange case where the maxPDG is negative...
unsigned int constexpr maxPDG{(detail::conversionArray.size() - 1) >> 1}; unsigned int constexpr maxPDG{(detail::conversionArray.size() - 1) >> 1};
auto k = static_cast<PDGCodeType>(p); auto k = static_cast<PDGCodeType>(vP);
if ((unsigned int)abs(k) <= maxPDG) { if ((unsigned int)abs(k) <= maxPDG) {
return detail::conversionArray[k + maxPDG]; return detail::conversionArray[k + maxPDG];
} else { } else {
return detail::conversionMap.at(p); return detail::conversionMap.at(vP);
} }
} }
......
...@@ -60,64 +60,64 @@ namespace corsika::particles { ...@@ -60,64 +60,64 @@ namespace corsika::particles {
/*! /*!
* returns mass of particle in natural units * returns mass of particle in natural units
*/ */
corsika::units::si::HEPMassType constexpr GetMass(Code const p) { corsika::units::si::HEPMassType constexpr GetMass(Code const vP) {
if (p == Code::Nucleus) if (vP == Code::Nucleus)
throw std::runtime_error("Cannot GetMass() of particle::Nucleus -> unspecified"); throw std::runtime_error("Cannot GetMass() of particle::Nucleus -> unspecified");
return detail::masses[static_cast<CodeIntType>(p)]; return detail::masses[static_cast<CodeIntType>(vP)];
} }
/*! /*!
* returns PDG id * returns PDG id
*/ */
PDGCode constexpr GetPDG(Code const p) { PDGCode constexpr GetPDG(Code const vP) {
return detail::pdg_codes[static_cast<CodeIntType>(p)]; return detail::pdg_codes[static_cast<CodeIntType>(vP)];
} }
/*! /*!
* returns electric charge number of particle return 1 for a proton. * returns electric charge number of particle return 1 for a proton.
*/ */
int16_t constexpr GetChargeNumber(Code const p) { int16_t constexpr GetChargeNumber(Code const vP) {
if (p == Code::Nucleus) if (vP == Code::Nucleus)
throw std::runtime_error( throw std::runtime_error(
"Cannot GetChargeNumber() of particle::Nucleus -> unspecified"); "Cannot GetChargeNumber() of particle::Nucleus -> unspecified");
// electric_charges stores charges in units of (e/3), e.g. 3 for a proton // electric_charges stores charges in units of (e/3), e.g. 3 for a proton
return detail::electric_charges[static_cast<CodeIntType>(p)] / 3; return detail::electric_charges[static_cast<CodeIntType>(vP)] / 3;
} }
/*! /*!
* returns electric charge of particle, e.g. return 1.602e-19_C for a proton. * returns electric charge of particle, e.g. return 1.602e-19_C for a proton.
*/ */
corsika::units::si::ElectricChargeType constexpr GetCharge(Code const p) { corsika::units::si::ElectricChargeType constexpr GetCharge(Code const vP) {
if (p == Code::Nucleus) if (vP == Code::Nucleus)
throw std::runtime_error("Cannot GetCharge() of particle::Nucleus -> unspecified"); throw std::runtime_error("Cannot GetCharge() of particle::Nucleus -> unspecified");
return GetChargeNumber(p) * (corsika::units::constants::e); return GetChargeNumber(vP) * (corsika::units::constants::e);
} }
constexpr std::string const& GetName(Code const p) { constexpr std::string const& GetName(Code const vP) {
return detail::names[static_cast<CodeIntType>(p)]; return detail::names[static_cast<CodeIntType>(vP)];
} }
corsika::units::si::TimeType constexpr GetLifetime(Code const p) { corsika::units::si::TimeType constexpr GetLifetime(Code const vP) {
return detail::lifetime[static_cast<CodeIntType>(p)] * corsika::units::si::second; return detail::lifetime[static_cast<CodeIntType>(vP)] * corsika::units::si::second;
} }
bool constexpr IsNucleus(Code const p) { bool constexpr IsNucleus(Code const vP) {
return detail::isNucleus[static_cast<CodeIntType>(p)]; return detail::isNucleus[static_cast<CodeIntType>(vP)];
} }
int constexpr GetNucleusA(Code const p) { int constexpr GetNucleusA(Code const vP) {
return detail::nucleusA[static_cast<CodeIntType>(p)]; return detail::nucleusA[static_cast<CodeIntType>(vP)];
} }
int constexpr GetNucleusZ(Code const p) { int constexpr GetNucleusZ(Code const vP) {
return detail::nucleusZ[static_cast<CodeIntType>(p)]; return detail::nucleusZ[static_cast<CodeIntType>(vP)];
} }
/** /**
* the output operator for particles * the output operator for particles
**/ **/
std::ostream& operator<<(std::ostream& stream, corsika::particles::Code const p); std::ostream& operator<<(std::ostream& stream, corsika::particles::Code const vP);
Code ConvertFromPDG(PDGCode); Code ConvertFromPDG(PDGCode);
......
...@@ -26,15 +26,15 @@ namespace corsika::process { ...@@ -26,15 +26,15 @@ namespace corsika::process {
*/ */
template <typename Derived> template <typename TDerived>
struct BaseProcess { struct BaseProcess {
private: private:
BaseProcess() {} BaseProcess() {}
friend Derived; friend TDerived;
public: public:
Derived& GetRef() { return static_cast<Derived&>(*this); } TDerived& GetRef() { return static_cast<TDerived&>(*this); }
const Derived& GetRef() const { return static_cast<const Derived&>(*this); } const TDerived& GetRef() const { return static_cast<const TDerived&>(*this); }
}; };
// overwrite the default trait class, to mark BaseProcess<T> as useful process // overwrite the default trait class, to mark BaseProcess<T> as useful process
......
...@@ -25,7 +25,7 @@ namespace corsika::process { ...@@ -25,7 +25,7 @@ namespace corsika::process {
* \p from and \p to. * \p from and \p to.
*/ */
template <typename Particle, typename VTNType> template <typename Particle, typename VTNType>
EProcessReturn DoBoundaryCrossing(Particle&, VTNType const& from, VTNType const& to); EProcessReturn DoBoundaryCrossing(Particle&, VTNType const&, VTNType const&);
}; };
template <class T> template <class T>
......
...@@ -26,19 +26,19 @@ namespace corsika::process { ...@@ -26,19 +26,19 @@ namespace corsika::process {
*/ */
template <typename derived> template <typename TDerived>
struct ContinuousProcess { struct ContinuousProcess {
derived& GetRef() { return static_cast<derived&>(*this); } TDerived& GetRef() { return static_cast<TDerived&>(*this); }
const derived& GetRef() const { return static_cast<const derived&>(*this); } const TDerived& GetRef() const { return static_cast<const TDerived&>(*this); }
// here starts the interface part // here starts the interface part
// -> enforce derived to implement DoContinuous... // -> enforce TDerived to implement DoContinuous...
template <typename Particle, typename Track> template <typename TParticle, typename TTrack>
EProcessReturn DoContinuous(Particle&, Track const&) const; EProcessReturn DoContinuous(TParticle&, TTrack const&) const;
// -> enforce derived to implement MaxStepLength... // -> enforce TDerived to implement MaxStepLength...
template <typename Particle, typename Track> template <typename TParticle, typename TTrack>
units::si::LengthType MaxStepLength(Particle const& p, Track const& track) const; units::si::LengthType MaxStepLength(TParticle const&, TTrack const&) const;
}; };
// overwrite the default trait class, to mark BaseProcess<T> as useful process // overwrite the default trait class, to mark BaseProcess<T> as useful process
......
...@@ -27,21 +27,21 @@ namespace corsika::process { ...@@ -27,21 +27,21 @@ namespace corsika::process {
*/ */
template <typename derived> template <typename TDerived>
struct DecayProcess { struct DecayProcess {
derived& GetRef() { return static_cast<derived&>(*this); } TDerived& GetRef() { return static_cast<TDerived&>(*this); }
const derived& GetRef() const { return static_cast<const derived&>(*this); } const TDerived& GetRef() const { return static_cast<const TDerived&>(*this); }
/// here starts the interface-definition part /// here starts the interface-definition part
// -> enforce derived to implement DoDecay... // -> enforce TDerived to implement DoDecay...
template <typename Particle> template <typename TParticle>
EProcessReturn DoDecay(Particle&); EProcessReturn DoDecay(TParticle&);
template <typename Particle> template <typename TParticle>
corsika::units::si::TimeType GetLifetime(Particle& p); corsika::units::si::TimeType GetLifetime(TParticle&);
template <typename Particle> template <typename TParticle>
corsika::units::si::InverseTimeType GetInverseLifetime(Particle& vP) { corsika::units::si::InverseTimeType GetInverseLifetime(TParticle& vP) {
return 1. / GetRef().GetLifetime(vP); return 1. / GetRef().GetLifetime(vP);
} }
}; };
......
...@@ -27,24 +27,24 @@ namespace corsika::process { ...@@ -27,24 +27,24 @@ namespace corsika::process {
*/ */
template <typename derived> template <typename TDerived>
struct InteractionProcess { struct InteractionProcess {
derived& GetRef() { return static_cast<derived&>(*this); } TDerived& GetRef() { return static_cast<TDerived&>(*this); }
const derived& GetRef() const { return static_cast<const derived&>(*this); } const TDerived& GetRef() const { return static_cast<const TDerived&>(*this); }
/// here starts the interface-definition part /// here starts the interface-definition part
// -> enforce derived to implement DoInteraction... // -> enforce TDerived to implement DoInteraction...
template <typename Particle> template <typename TParticle>
EProcessReturn DoInteraction(Particle&); EProcessReturn DoInteraction(TParticle&);
template <typename Particle, typename Track> template <typename TParticle, typename TTrack>
corsika::units::si::GrammageType GetInteractionLength(Particle& p, Track& t); corsika::units::si::GrammageType GetInteractionLength(TParticle&, TTrack&);
template <typename Particle, typename Track> template <typename TParticle, typename TTrack>
corsika::units::si::InverseGrammageType GetInverseInteractionLength(Particle& p, corsika::units::si::InverseGrammageType GetInverseInteractionLength(TParticle& vP,
Track& t) { TTrack& vT) {
return 1. / GetRef().GetInteractionLength(p, t); return 1. / GetRef().GetInteractionLength(vP, vT);
} }
}; };
......
...@@ -73,19 +73,19 @@ namespace corsika::process { ...@@ -73,19 +73,19 @@ namespace corsika::process {
// example for a trait-based call: // example for a trait-based call:
// void Hello() const { detail::CallHello<T1,T2>::Call(A, B); } // void Hello() const { detail::CallHello<T1,T2>::Call(A, B); }
template <typename Particle, typename VTNType> template <typename TParticle, typename VTNType>
EProcessReturn DoBoundaryCrossing(Particle& p, VTNType const& from, EProcessReturn DoBoundaryCrossing(TParticle& vP, VTNType const& vFrom,
VTNType const& to) { VTNType const& vTo) {
EProcessReturn ret = EProcessReturn::eOk; EProcessReturn ret = EProcessReturn::eOk;
if constexpr (std::is_base_of<BoundaryCrossingProcess<T1type>, T1type>::value || if constexpr (std::is_base_of<BoundaryCrossingProcess<T1type>, T1type>::value ||
is_process_sequence<T1>::value) { is_process_sequence<T1>::value) {
ret |= A.DoBoundaryCrossing(p, from, to); ret |= A.DoBoundaryCrossing(vP, vFrom, vTo);
} }
if constexpr (std::is_base_of<BoundaryCrossingProcess<T2type>, T2type>::value || if constexpr (std::is_base_of<BoundaryCrossingProcess<T2type>, T2type>::value ||
is_process_sequence<T2>::value) { is_process_sequence<T2>::value) {
ret |= B.DoBoundaryCrossing(p, from, to); ret |= B.DoBoundaryCrossing(vP, vFrom, vTo);
} }
return ret; return ret;
...@@ -198,20 +198,20 @@ namespace corsika::process { ...@@ -198,20 +198,20 @@ namespace corsika::process {
template <typename TParticle, typename TSecondaries, typename TTrack> template <typename TParticle, typename TSecondaries, typename TTrack>
EProcessReturn SelectInteraction( EProcessReturn SelectInteraction(
TParticle& vP, TSecondaries& vS, TTrack& vT, TParticle& vP, TSecondaries& vS, TTrack& vT,
[[maybe_unused]] corsika::units::si::InverseGrammageType lambda_select, [[maybe_unused]] corsika::units::si::InverseGrammageType vLambda_select,
corsika::units::si::InverseGrammageType& lambda_inv_count) { corsika::units::si::InverseGrammageType& vLambda_inv_count) {
if constexpr (is_process_sequence<T1type>::value) { if constexpr (is_process_sequence<T1type>::value) {
// if A is a process sequence --> check inside // if A is a process sequence --> check inside
const EProcessReturn ret = const EProcessReturn ret =
A.SelectInteraction(vP, vS, vT, lambda_select, lambda_inv_count); A.SelectInteraction(vP, vS, vT, vLambda_select, vLambda_inv_count);
// if A did succeed, stop routine // if A did succeed, stop routine
if (ret != EProcessReturn::eOk) { return ret; } if (ret != EProcessReturn::eOk) { return ret; }
} else if constexpr (std::is_base_of<InteractionProcess<T1type>, T1type>::value) { } else if constexpr (std::is_base_of<InteractionProcess<T1type>, T1type>::value) {
// if this is not a ContinuousProcess --> evaluate probability // if this is not a ContinuousProcess --> evaluate probability
lambda_inv_count += A.GetInverseInteractionLength(vP, vT); vLambda_inv_count += A.GetInverseInteractionLength(vP, vT);
// check if we should execute THIS process and then EXIT // check if we should execute THIS process and then EXIT
if (lambda_select < lambda_inv_count) { if (vLambda_select < vLambda_inv_count) {
A.DoInteraction(vS); A.DoInteraction(vS);
return EProcessReturn::eInteracted; return EProcessReturn::eInteracted;
} }
...@@ -220,14 +220,14 @@ namespace corsika::process { ...@@ -220,14 +220,14 @@ namespace corsika::process {
if constexpr (is_process_sequence<T2>::value) { if constexpr (is_process_sequence<T2>::value) {
// if A is a process sequence --> check inside // if A is a process sequence --> check inside
const EProcessReturn ret = const EProcessReturn ret =
B.SelectInteraction(vP, vS, vT, lambda_select, lambda_inv_count); B.SelectInteraction(vP, vS, vT, vLambda_select, vLambda_inv_count);
// if A did succeed, stop routine // if A did succeed, stop routine
if (ret != EProcessReturn::eOk) { return ret; } if (ret != EProcessReturn::eOk) { return ret; }
} else if constexpr (std::is_base_of<InteractionProcess<T2type>, T2type>::value) { } else if constexpr (std::is_base_of<InteractionProcess<T2type>, T2type>::value) {
// if this is not a ContinuousProcess --> evaluate probability // if this is not a ContinuousProcess --> evaluate probability
lambda_inv_count += B.GetInverseInteractionLength(vP, vT); vLambda_inv_count += B.GetInverseInteractionLength(vP, vT);
// check if we should execute THIS process and then EXIT // check if we should execute THIS process and then EXIT
if (lambda_select < lambda_inv_count) { if (vLambda_select < vLambda_inv_count) {
B.DoInteraction(vS); B.DoInteraction(vS);
return EProcessReturn::eInteracted; return EProcessReturn::eInteracted;
} }
...@@ -236,28 +236,28 @@ namespace corsika::process { ...@@ -236,28 +236,28 @@ namespace corsika::process {
} }
template <typename TParticle> template <typename TParticle>
corsika::units::si::TimeType GetTotalLifetime(TParticle& p) { corsika::units::si::TimeType GetTotalLifetime(TParticle& vP) {
return 1. / GetInverseLifetime(p); return 1. / GetInverseLifetime(vP);
} }
template <typename TParticle> template <typename TParticle>
corsika::units::si::InverseTimeType GetTotalInverseLifetime(TParticle& p) { corsika::units::si::InverseTimeType GetTotalInverseLifetime(TParticle& vP) {
return GetInverseLifetime(p); return GetInverseLifetime(vP);
} }
template <typename TParticle> template <typename TParticle>
corsika::units::si::InverseTimeType GetInverseLifetime(TParticle& p) { corsika::units::si::InverseTimeType GetInverseLifetime(TParticle& vP) {
using namespace corsika::units::si; using namespace corsika::units::si;
corsika::units::si::InverseTimeType tot = 0 / second; corsika::units::si::InverseTimeType tot = 0 / second;
if constexpr (std::is_base_of<DecayProcess<T1type>, T1type>::value || if constexpr (std::is_base_of<DecayProcess<T1type>, T1type>::value ||
is_process_sequence<T1>::value) { is_process_sequence<T1>::value) {
tot += A.GetInverseLifetime(p); tot += A.GetInverseLifetime(vP);
} }
if constexpr (std::is_base_of<DecayProcess<T2type>, T2type>::value || if constexpr (std::is_base_of<DecayProcess<T2type>, T2type>::value ||
is_process_sequence<T2>::value) { is_process_sequence<T2>::value) {
tot += B.GetInverseLifetime(p); tot += B.GetInverseLifetime(vP);
} }
return tot; return tot;
} }
...@@ -266,19 +266,19 @@ namespace corsika::process { ...@@ -266,19 +266,19 @@ namespace corsika::process {
template <typename TParticle, typename TSecondaries> template <typename TParticle, typename TSecondaries>
EProcessReturn SelectDecay( EProcessReturn SelectDecay(
TParticle& vP, TSecondaries& vS, TParticle& vP, TSecondaries& vS,
[[maybe_unused]] corsika::units::si::InverseTimeType decay_select, [[maybe_unused]] corsika::units::si::InverseTimeType vDecay_select,
corsika::units::si::InverseTimeType& decay_inv_count) { corsika::units::si::InverseTimeType& vDecay_inv_count) {
if constexpr (is_process_sequence<T1>::value) { if constexpr (is_process_sequence<T1>::value) {
// if A is a process sequence --> check inside // if A is a process sequence --> check inside
const EProcessReturn ret = A.SelectDecay(vP, vS, decay_select, decay_inv_count); const EProcessReturn ret = A.SelectDecay(vP, vS, vDecay_select, vDecay_inv_count);
// if A did succeed, stop routine // if A did succeed, stop routine
if (ret != EProcessReturn::eOk) { return ret; } if (ret != EProcessReturn::eOk) { return ret; }
} else if constexpr (std::is_base_of<DecayProcess<T1type>, T1type>::value) { } else if constexpr (std::is_base_of<DecayProcess<T1type>, T1type>::value) {
// if this is not a ContinuousProcess --> evaluate probability // if this is not a ContinuousProcess --> evaluate probability
decay_inv_count += A.GetInverseLifetime(vP); vDecay_inv_count += A.GetInverseLifetime(vP);
// check if we should execute THIS process and then EXIT // check if we should execute THIS process and then EXIT
if (decay_select < decay_inv_count) { // more pedagogical: rndm_select < if (vDecay_select < vDecay_inv_count) { // more pedagogical: rndm_select <
// decay_inv_count / decay_inv_tot // vDecay_inv_count / vDecay_inv_tot
A.DoDecay(vS); A.DoDecay(vS);
return EProcessReturn::eDecayed; return EProcessReturn::eDecayed;
} }
...@@ -286,14 +286,14 @@ namespace corsika::process { ...@@ -286,14 +286,14 @@ namespace corsika::process {
if constexpr (is_process_sequence<T2>::value) { if constexpr (is_process_sequence<T2>::value) {
// if A is a process sequence --> check inside // if A is a process sequence --> check inside
const EProcessReturn ret = B.SelectDecay(vP, vS, decay_select, decay_inv_count); const EProcessReturn ret = B.SelectDecay(vP, vS, vDecay_select, vDecay_inv_count);
// if A did succeed, stop routine // if A did succeed, stop routine
if (ret != EProcessReturn::eOk) { return ret; } if (ret != EProcessReturn::eOk) { return ret; }
} else if constexpr (std::is_base_of<DecayProcess<T2type>, T2type>::value) { } else if constexpr (std::is_base_of<DecayProcess<T2type>, T2type>::value) {
// if this is not a ContinuousProcess --> evaluate probability // if this is not a ContinuousProcess --> evaluate probability
decay_inv_count += B.GetInverseLifetime(vP); vDecay_inv_count += B.GetInverseLifetime(vP);
// check if we should execute THIS process and then EXIT // check if we should execute THIS process and then EXIT
if (decay_select < decay_inv_count) { if (vDecay_select < vDecay_inv_count) {
B.DoDecay(vS); B.DoDecay(vS);
return EProcessReturn::eDecayed; return EProcessReturn::eDecayed;
} }
......
...@@ -27,14 +27,14 @@ namespace corsika::process { ...@@ -27,14 +27,14 @@ namespace corsika::process {
*/ */
template <typename derived> template <typename TDerived>
struct SecondariesProcess { struct SecondariesProcess {
derived& GetRef() { return static_cast<derived&>(*this); } TDerived& GetRef() { return static_cast<TDerived&>(*this); }
const derived& GetRef() const { return static_cast<const derived&>(*this); } const TDerived& GetRef() const { return static_cast<const TDerived&>(*this); }
/// here starts the interface-definition part /// here starts the interface-definition part
// -> enforce derived to implement DoSecondaries... // -> enforce TDerived to implement DoSecondaries...
template <typename TSecondaries> template <typename TSecondaries>
inline EProcessReturn DoSecondaries(TSecondaries&); inline EProcessReturn DoSecondaries(TSecondaries&);
}; };
......
...@@ -27,7 +27,7 @@ namespace corsika::process { ...@@ -27,7 +27,7 @@ namespace corsika::process {
*/ */
template <typename derived> template <typename TDerived>
class StackProcess { class StackProcess {
public: public:
...@@ -35,11 +35,11 @@ namespace corsika::process { ...@@ -35,11 +35,11 @@ namespace corsika::process {
StackProcess(const unsigned int nStep) StackProcess(const unsigned int nStep)
: fNStep(nStep) {} : fNStep(nStep) {}
derived& GetRef() { return static_cast<derived&>(*this); } TDerived& GetRef() { return static_cast<TDerived&>(*this); }
const derived& GetRef() const { return static_cast<const derived&>(*this); } const TDerived& GetRef() const { return static_cast<const TDerived&>(*this); }
/// here starts the interface-definition part /// here starts the interface-definition part
// -> enforce derived to implement DoStack... // -> enforce TDerived to implement DoStack...
template <typename TStack> template <typename TStack>
inline EProcessReturn DoStack(TStack&); inline EProcessReturn DoStack(TStack&);
......
...@@ -36,19 +36,15 @@ namespace corsika::stack { ...@@ -36,19 +36,15 @@ namespace corsika::stack {
* ParticleInterface classes. * ParticleInterface classes.
* *
*/ */
template <template <typename> typename ParticleInterfaceA, template <template <typename> typename TParticleInterfaceA,
template <typename> typename ParticleInterfaceB, typename StackIterator> template <typename> typename TParticleInterfaceB, typename TStackIterator>
class CombinedParticleInterface class CombinedParticleInterface
: public ParticleInterfaceB<ParticleInterfaceA<StackIterator>> { : public TParticleInterfaceB<TParticleInterfaceA<TStackIterator>> {
// template<template <typename> typename _PI> using PI_C = CombinedParticleInterface<TParticleInterfaceA, TParticleInterfaceB,
// template <typename StackDataType, template <typename> typename ParticleInterface> TStackIterator>;
// template<typename T1, template <typename> typename T2> friend class Stack<T1, T2>; using PI_A = TParticleInterfaceA<TStackIterator>;
using PI_B = TParticleInterfaceB<TParticleInterfaceA<TStackIterator>>;
using PI_C =
CombinedParticleInterface<ParticleInterfaceA, ParticleInterfaceB, StackIterator>;
using PI_A = ParticleInterfaceA<StackIterator>;
using PI_B = ParticleInterfaceB<ParticleInterfaceA<StackIterator>>;
protected: protected:
using PI_B::GetIndex; // choose B, A would also work using PI_B::GetIndex; // choose B, A would also work
...@@ -65,34 +61,34 @@ namespace corsika::stack { ...@@ -65,34 +61,34 @@ namespace corsika::stack {
* *
* There is one implicit assumption here: if only one data tuple * There is one implicit assumption here: if only one data tuple
* is provided for SetParticleData, the data is passed on to * is provided for SetParticleData, the data is passed on to
* ParticleInterfaceA and the ParticleInterfaceB is * TParticleInterfaceA and the TParticleInterfaceB is
* default-initialized. There are many occasions where this is the * default-initialized. There are many occasions where this is the
* desired behaviour, e.g. for thinning etc. * desired behaviour, e.g. for thinning etc.
* *
*/ */
template <typename... Args1> template <typename... TArgs1>
void SetParticleData(const std::tuple<Args1...> vA) { void SetParticleData(const std::tuple<TArgs1...> vA) {
PI_A::SetParticleData(vA); PI_A::SetParticleData(vA);
PI_B::SetParticleData(); PI_B::SetParticleData();
} }
template <typename... Args1, typename... Args2> template <typename... TArgs1, typename... TArgs2>
void SetParticleData(const std::tuple<Args1...> vA, const std::tuple<Args2...> vB) { void SetParticleData(const std::tuple<TArgs1...> vA, const std::tuple<TArgs2...> vB) {
PI_A::SetParticleData(vA); PI_A::SetParticleData(vA);
PI_B::SetParticleData(vB); PI_B::SetParticleData(vB);
} }
template <typename... Args1> template <typename... TArgs1>
void SetParticleData(PI_C& p, const std::tuple<Args1...> vA) { void SetParticleData(PI_C& vP, const std::tuple<TArgs1...> vA) {
// static_assert(MT<I>::has_not, "error"); // static_assert(MT<I>::has_not, "error");
PI_A::SetParticleData(static_cast<PI_A&>(p), vA); // original stack PI_A::SetParticleData(static_cast<PI_A&>(vP), vA); // original stack
PI_B::SetParticleData(static_cast<PI_B&>(p)); // addon stack PI_B::SetParticleData(static_cast<PI_B&>(vP)); // addon stack
} }
template <typename... Args1, typename... Args2> template <typename... TArgs1, typename... TArgs2>
void SetParticleData(PI_C& p, const std::tuple<Args1...> vA, void SetParticleData(PI_C& vP, const std::tuple<TArgs1...> vA,
const std::tuple<Args2...> vB) { const std::tuple<TArgs2...> vB) {
PI_A::SetParticleData(static_cast<PI_A&>(p), vA); PI_A::SetParticleData(static_cast<PI_A&>(vP), vA);
PI_B::SetParticleData(static_cast<PI_B&>(p), vB); PI_B::SetParticleData(static_cast<PI_B&>(vP), vB);
} }
///@} ///@}
}; };
...@@ -106,57 +102,57 @@ namespace corsika::stack { ...@@ -106,57 +102,57 @@ namespace corsika::stack {
* merged into one consistent Stack container object providing * merged into one consistent Stack container object providing
* access to the combined number of data entries. * access to the combined number of data entries.
*/ */
template <typename Stack1Impl, typename Stack2Impl> template <typename TStack1Impl, typename TStack2Impl>
class CombinedStackImpl : public Stack1Impl, public Stack2Impl { class CombinedStackImpl : public TStack1Impl, public TStack2Impl {
public: public:
void Init() { void Init() {
Stack1Impl::Init(); TStack1Impl::Init();
Stack2Impl::Init(); TStack2Impl::Init();
} }
void Clear() { void Clear() {
Stack1Impl::Clear(); TStack1Impl::Clear();
Stack2Impl::Clear(); TStack2Impl::Clear();
} }
unsigned int GetSize() const { return Stack1Impl::GetSize(); } unsigned int GetSize() const { return TStack1Impl::GetSize(); }
unsigned int GetCapacity() const { return Stack1Impl::GetCapacity(); } unsigned int GetCapacity() const { return TStack1Impl::GetCapacity(); }
/** /**
* Function to copy particle at location i1 in stack to i2 * Function to copy particle at location i1 in stack to i2
*/ */
void Copy(const unsigned int i1, const unsigned int i2) { void Copy(const unsigned int vi1, const unsigned int vi2) {
if (i1 >= GetSize() || i2 >= GetSize()) { if (vi1 >= GetSize() || vi2 >= GetSize()) {
std::ostringstream err; std::ostringstream err;
err << "CombinedStack: trying to access data beyond size of stack!"; err << "CombinedStack: trying to access data beyond size of stack!";
throw std::runtime_error(err.str()); throw std::runtime_error(err.str());
} }
Stack1Impl::Copy(i1, i2); TStack1Impl::Copy(vi1, vi2);
Stack2Impl::Copy(i1, i2); TStack2Impl::Copy(vi1, vi2);
} }
/** /**
* Function to copy particle at location i2 in stack to i1 * Function to copy particle at location vi2 in stack to vi1
*/ */
void Swap(const unsigned int i1, const unsigned int i2) { void Swap(const unsigned int vi1, const unsigned int vi2) {
if (i1 >= GetSize() || i2 >= GetSize()) { if (vi1 >= GetSize() || vi2 >= GetSize()) {
std::ostringstream err; std::ostringstream err;
err << "CombinedStack: trying to access data beyond size of stack!"; err << "CombinedStack: trying to access data beyond size of stack!";
throw std::runtime_error(err.str()); throw std::runtime_error(err.str());
} }
Stack1Impl::Swap(i1, i2); TStack1Impl::Swap(vi1, vi2);
Stack2Impl::Swap(i1, i2); TStack2Impl::Swap(vi1, vi2);
} }
void IncrementSize() { void IncrementSize() {
Stack1Impl::IncrementSize(); TStack1Impl::IncrementSize();
Stack2Impl::IncrementSize(); TStack2Impl::IncrementSize();
} }
void DecrementSize() { void DecrementSize() {
Stack1Impl::DecrementSize(); TStack1Impl::DecrementSize();
Stack2Impl::DecrementSize(); TStack2Impl::DecrementSize();
} }
}; // end class CombinedStackImpl }; // end class CombinedStackImpl
...@@ -170,8 +166,8 @@ namespace corsika::stack { ...@@ -170,8 +166,8 @@ namespace corsika::stack {
* initialization are forwarded to Stack1Impl (first). * initialization are forwarded to Stack1Impl (first).
*/ */
template <typename Stack1Impl, typename Stack2Impl, template <typename> typename _PI> template <typename TStack1Impl, typename TStack2Impl, template <typename> typename TPI>
using CombinedStack = Stack<CombinedStackImpl<Stack1Impl, Stack2Impl>, _PI>; using CombinedStack = Stack<CombinedStackImpl<TStack1Impl, TStack2Impl>, TPI>;
} // namespace corsika::stack } // namespace corsika::stack
......
...@@ -57,55 +57,57 @@ namespace corsika::stack { ...@@ -57,55 +57,57 @@ namespace corsika::stack {
GetIndexFromIterator. GetIndexFromIterator.
*/ */
template <typename StackDataType, template <typename> typename ParticleInterface> template <typename TStackDataType, template <typename> typename TParticleInterface>
class SecondaryView : public Stack<StackDataType&, ParticleInterface> { class SecondaryView : public Stack<TStackDataType&, TParticleInterface> {
using ViewType = SecondaryView<StackDataType, ParticleInterface>; using ViewType = SecondaryView<TStackDataType, TParticleInterface>;
private: private:
/** /**
* Helper type for inside this class * Helper type for inside this class
*/ */
using InnerStackType = Stack<StackDataType&, ParticleInterface>; using InnerStackType = Stack<TStackDataType&, TParticleInterface>;
/** /**
* @name We need this "special" types with non-reference StackData for * @name We need this "special" types with non-reference StackData for
* the constructor of the SecondaryView class * the constructor of the SecondaryView class
* @{ * @{
*/ */
using InnerStackTypeValue = Stack<StackDataType, ParticleInterface>; using InnerStackTypeValue = Stack<TStackDataType, TParticleInterface>;
using StackIteratorValue = using StackIteratorValue =
StackIteratorInterface<typename std::remove_reference<StackDataType>::type, StackIteratorInterface<typename std::remove_reference<TStackDataType>::type,
ParticleInterface, InnerStackTypeValue>; TParticleInterface, InnerStackTypeValue>;
/// @} /// @}
public: public:
using StackIterator = using StackIterator =
StackIteratorInterface<typename std::remove_reference<StackDataType>::type, StackIteratorInterface<typename std::remove_reference<TStackDataType>::type,
ParticleInterface, ViewType>; TParticleInterface, ViewType>;
using ConstStackIterator = using ConstStackIterator =
ConstStackIteratorInterface<typename std::remove_reference<StackDataType>::type, ConstStackIteratorInterface<typename std::remove_reference<TStackDataType>::type,
ParticleInterface, ViewType>; TParticleInterface, ViewType>;
/** /**
* this is the full type of the declared ParticleInterface: typedef typename * this is the full type of the declared TParticleInterface: typedef typename
*/ */
using ParticleType = StackIterator; using ParticleType = StackIterator;
using ParticleInterfaceType = typename StackIterator::ParticleInterfaceType; using ParticleInterfaceType = typename StackIterator::ParticleInterfaceType;
friend class StackIteratorInterface< friend class StackIteratorInterface<
typename std::remove_reference<StackDataType>::type, ParticleInterface, ViewType>; typename std::remove_reference<TStackDataType>::type, TParticleInterface,
ViewType>;
friend class ConstStackIteratorInterface< friend class ConstStackIteratorInterface<
typename std::remove_reference<StackDataType>::type, ParticleInterface, ViewType>; typename std::remove_reference<TStackDataType>::type, TParticleInterface,
ViewType>;
private: private:
/** /**
* This is not accessible, since we don't want to allow creating a * This is not accessible, since we don't want to allow creating a
* new stack. * new stack.
*/ */
template <typename... Args> template <typename... TArgs>
SecondaryView(Args... args) = delete; SecondaryView(TArgs... vArgs) = delete;
public: public:
/** /**
...@@ -113,7 +115,7 @@ namespace corsika::stack { ...@@ -113,7 +115,7 @@ namespace corsika::stack {
StackIterator to another Stack object StackIterator to another Stack object
**/ **/
SecondaryView(StackIteratorValue& vI) SecondaryView(StackIteratorValue& vI)
: Stack<StackDataType&, ParticleInterface>(vI.GetStackData()) : Stack<TStackDataType&, TParticleInterface>(vI.GetStackData())
, fProjectileIndex(vI.GetIndex()) {} , fProjectileIndex(vI.GetIndex()) {}
StackIterator GetProjectile() { StackIterator GetProjectile() {
...@@ -121,14 +123,14 @@ namespace corsika::stack { ...@@ -121,14 +123,14 @@ namespace corsika::stack {
return StackIterator(*this, 0); return StackIterator(*this, 0);
} }
template <typename... Args> template <typename... TArgs>
auto AddSecondary(const Args... v) { auto AddSecondary(const TArgs... v) {
StackIterator proj = GetProjectile(); StackIterator proj = GetProjectile();
return AddSecondary(proj, v...); return AddSecondary(proj, v...);
} }
template <typename... Args> template <typename... TArgs>
auto AddSecondary(StackIterator& proj, const Args... v) { auto AddSecondary(StackIterator& vProj, const TArgs... vV) {
// make space on stack // make space on stack
InnerStackType::GetStackData().IncrementSize(); InnerStackType::GetStackData().IncrementSize();
// get current number of secondaries on stack // get current number of secondaries on stack
...@@ -138,7 +140,7 @@ namespace corsika::stack { ...@@ -138,7 +140,7 @@ namespace corsika::stack {
fIndices.push_back(index); fIndices.push_back(index);
// NOTE: "+1" is since "0" is special marker here for PROJECTILE, see // NOTE: "+1" is since "0" is special marker here for PROJECTILE, see
// GetIndexFromIterator // GetIndexFromIterator
return StackIterator(*this, idSec + 1, proj, v...); return StackIterator(*this, idSec + 1, vProj, vV...);
} }
/** /**
...@@ -179,22 +181,22 @@ namespace corsika::stack { ...@@ -179,22 +181,22 @@ namespace corsika::stack {
* remove the last particle. * remove the last particle.
* *
*/ */
void Delete(StackIterator p) { void Delete(StackIterator vP) {
if (IsEmpty()) { /* error */ if (IsEmpty()) { /* error */
throw std::runtime_error("Stack, cannot delete entry since size is zero"); throw std::runtime_error("Stack, cannot delete entry since size is zero");
} }
const int innerSize = InnerStackType::GetSize(); const int innerSize = InnerStackType::GetSize();
const int innerIndex = GetIndexFromIterator(p.GetIndex()); const int innerIndex = GetIndexFromIterator(vP.GetIndex());
if (innerIndex < innerSize - 1) if (innerIndex < innerSize - 1)
InnerStackType::GetStackData().Copy(innerSize - 1, InnerStackType::GetStackData().Copy(innerSize - 1,
GetIndexFromIterator(p.GetIndex())); GetIndexFromIterator(vP.GetIndex()));
DeleteLast(); DeleteLast();
} }
/** /**
* need overwrite Stack::Delete, since we want to call SecondaryView::DeleteLast * need overwrite Stack::Delete, since we want to call SecondaryView::DeleteLast
*/ */
void Delete(ParticleInterfaceType p) { Delete(p.GetIterator()); } void Delete(ParticleInterfaceType vP) { Delete(vP.GetIterator()); }
/** /**
* delete last particle on stack by decrementing stack size * delete last particle on stack by decrementing stack size
......
...@@ -26,17 +26,6 @@ ...@@ -26,17 +26,6 @@
namespace corsika::stack { namespace corsika::stack {
/**
This is just a forward declatation for the user-defined
ParticleInterface, which is one of the essential template
parameters for the Stack.
<b>Important:</b> ParticleInterface must inherit from ParticleBase !
*/
template <typename>
class ParticleInterface;
/** /**
The Stack class provides (and connects) the main particle data storage machinery. The Stack class provides (and connects) the main particle data storage machinery.
...@@ -45,7 +34,7 @@ namespace corsika::stack { ...@@ -45,7 +34,7 @@ namespace corsika::stack {
(fortran common block), to a combination of different and (fortran common block), to a combination of different and
distributed data sources. distributed data sources.
The user-provided ParticleInterface template type is the base The user-provided TParticleInterface template type is the base
class type of the StackIteratorInterface class (CRTP) and must class type of the StackIteratorInterface class (CRTP) and must
provide all functions to read single particle data from the provide all functions to read single particle data from the
StackDataType, given an 'unsigned int' index. StackDataType, given an 'unsigned int' index.
...@@ -55,11 +44,11 @@ namespace corsika::stack { ...@@ -55,11 +44,11 @@ namespace corsika::stack {
loops, ranges, etc. loops, ranges, etc.
*/ */
template <typename StackDataType, template <typename> typename ParticleInterface> template <typename TStackDataType, template <typename> typename TParticleInterface>
class Stack { class Stack {
using StackDataValueType = std::remove_reference_t<StackDataType>; using StackDataValueType = std::remove_reference_t<TStackDataType>;
StackDataType fData; ///< this in general holds all the data and can be quite big TStackDataType fData; ///< this in general holds all the data and can be quite big
private: private:
Stack(Stack&) = delete; ///< since Stack can be very big, we don't want to copy it Stack(Stack&) = delete; ///< since Stack can be very big, we don't want to copy it
...@@ -67,51 +56,50 @@ namespace corsika::stack { ...@@ -67,51 +56,50 @@ namespace corsika::stack {
delete; ///< since Stack can be very big, we don't want to copy it delete; ///< since Stack can be very big, we don't want to copy it
public: public:
// Stack() { Init(); }
/** /**
* if StackDataType is a reference member we *HAVE* to initialize * if TStackDataType is a reference member we *HAVE* to initialize
* it in the constructor, this is typically needed for SecondaryView * it in the constructor, this is typically needed for SecondaryView
*/ */
template <typename _ = StackDataType, typename = utl::enable_if<std::is_reference<_>>> template <typename _ = TStackDataType,
Stack(StackDataType vD) typename = utl::enable_if<std::is_reference<_>>>
Stack(TStackDataType vD)
: fData(vD) {} : fData(vD) {}
/** /**
* This constructor takes any argument and passes it on to the * This constructor takes any argument and passes it on to the
* StackDataType user class. If the user did not provide a suited * TStackDataType user class. If the user did not provide a suited
* constructor this will fail with an error message. * constructor this will fail with an error message.
* *
* Furthermore, this is disabled with enable_if for SecondaryView * Furthermore, this is disabled with enable_if for SecondaryView
* stacks, where the inner data container is always a reference * stacks, where the inner data container is always a reference
* and cannot be initialized here. * and cannot be initialized here.
*/ */
template <typename... Args, typename _ = StackDataType, template <typename... Args, typename _ = TStackDataType,
typename = utl::disable_if<std::is_reference<_>>> typename = utl::disable_if<std::is_reference<_>>>
Stack(Args... args) Stack(Args... args)
: fData(args...) {} : fData(args...) {}
public: public:
typedef StackDataType typedef TStackDataType
StackImpl; ///< this is the type of the user-provided data structure StackImpl; ///< this is the type of the user-provided data structure
template <typename SI> template <typename SI>
using PIType = ParticleInterface<SI>; using PIType = TParticleInterface<SI>;
/** /**
* Via the StackIteratorInterface and ConstStackIteratorInterface * Via the StackIteratorInterface and ConstStackIteratorInterface
* specialization, the type of the StackIterator * specialization, the type of the StackIterator
* template class is declared for a particular stack data * template class is declared for a particular stack data
* object. Using CRTP, this also determines the type of * object. Using CRTP, this also determines the type of
* ParticleInterface template class simultaneously. * TParticleInterface template class simultaneously.
*/ */
using StackIterator = using StackIterator =
StackIteratorInterface<StackDataValueType, ParticleInterface, Stack>; StackIteratorInterface<StackDataValueType, TParticleInterface, Stack>;
using ConstStackIterator = using ConstStackIterator =
ConstStackIteratorInterface<StackDataValueType, ParticleInterface, Stack>; ConstStackIteratorInterface<StackDataValueType, TParticleInterface, Stack>;
/** /**
* this is the full type of the user-declared ParticleInterface * this is the full type of the user-declared TParticleInterface
*/ */
using ParticleInterfaceType = typename StackIterator::ParticleInterfaceType; using ParticleInterfaceType = typename StackIterator::ParticleInterfaceType;
/** /**
...@@ -121,13 +109,13 @@ namespace corsika::stack { ...@@ -121,13 +109,13 @@ namespace corsika::stack {
using ParticleType = StackIterator; using ParticleType = StackIterator;
// friends are needed since they need access to protected members // friends are needed since they need access to protected members
friend class StackIteratorInterface<StackDataValueType, ParticleInterface, Stack>; friend class StackIteratorInterface<StackDataValueType, TParticleInterface, Stack>;
friend class ConstStackIteratorInterface<StackDataValueType, ParticleInterface, friend class ConstStackIteratorInterface<StackDataValueType, TParticleInterface,
Stack>; Stack>;
public: public:
/** /**
* @name Most generic proxy methods for StackDataType fData * @name Most generic proxy methods for TStackDataType fData
* @{ * @{
*/ */
unsigned int GetCapacity() const { return fData.GetCapacity(); } unsigned int GetCapacity() const { return fData.GetCapacity(); }
...@@ -163,8 +151,8 @@ namespace corsika::stack { ...@@ -163,8 +151,8 @@ namespace corsika::stack {
/** /**
* increase stack size, create new particle at end of stack * increase stack size, create new particle at end of stack
*/ */
template <typename... Args> template <typename... TArgs>
StackIterator AddParticle(const Args... v) { StackIterator AddParticle(const TArgs... v) {
fData.IncrementSize(); fData.IncrementSize();
return StackIterator(*this, GetSize() - 1, v...); return StackIterator(*this, GetSize() - 1, v...);
} }
...@@ -173,8 +161,8 @@ namespace corsika::stack { ...@@ -173,8 +161,8 @@ namespace corsika::stack {
* increase stack size, create new particle at end of stack, related to parent * increase stack size, create new particle at end of stack, related to parent
* particle/projectile * particle/projectile
*/ */
template <typename... Args> template <typename... TArgs>
StackIterator AddSecondary(StackIterator& parent, const Args... v) { StackIterator AddSecondary(StackIterator& parent, const TArgs... v) {
fData.IncrementSize(); fData.IncrementSize();
return StackIterator(*this, GetSize() - 1, parent, v...); return StackIterator(*this, GetSize() - 1, parent, v...);
} }
...@@ -226,13 +214,13 @@ namespace corsika::stack { ...@@ -226,13 +214,13 @@ namespace corsika::stack {
/** /**
* Function to perform eventual transformation from * Function to perform eventual transformation from
* StackIterator::GetIndex() to index in data stored in * StackIterator::GetIndex() to index in data stored in
* StackDataType fData. By default (and in almost all cases) this * TStackDataType fData. By default (and in almost all cases) this
* should just be identiy. See class SecondaryView for an alternative implementation. * should just be identiy. See class SecondaryView for an alternative implementation.
*/ */
unsigned int GetIndexFromIterator(const unsigned int vI) const { return vI; } unsigned int GetIndexFromIterator(const unsigned int vI) const { return vI; }
/** /**
* @name Return reference to StackDataType object fData for data access * @name Return reference to TStackDataType object fData for data access
* @{ * @{
*/ */
StackDataValueType& GetStackData() { return fData; } StackDataValueType& GetStackData() { return fData; }
......
...@@ -16,10 +16,10 @@ ...@@ -16,10 +16,10 @@
namespace corsika::stack { namespace corsika::stack {
template <typename StackDataType, template <typename> typename ParticleInterface> template <typename TStackDataType, template <typename> typename TParticleInterface>
class Stack; // forward decl class Stack; // forward decl
template <typename StackDataType, template <typename> typename ParticleInterface> template <typename TStackDataType, template <typename> typename TParticleInterface>
class SecondaryView; // forward decl class SecondaryView; // forward decl
/** /**
...@@ -40,50 +40,51 @@ namespace corsika::stack { ...@@ -40,50 +40,51 @@ namespace corsika::stack {
the StackIteratorInterface. In addition to Stack the iterator only knows the StackIteratorInterface. In addition to Stack the iterator only knows
the index fIndex in the Stack data. the index fIndex in the Stack data.
The template argument `ParticleInterface` acts as a policy to provide The template argument `TParticleInterface` acts as a policy to provide
readout function of Particle data from the stack. The ParticleInterface readout function of Particle data from the stack. The TParticleInterface
class must know how to retrieve information from the Stack data class must know how to retrieve information from the Stack data
for a particle entry at any index fIndex. for a particle entry at any index fIndex.
The ParticleInterface class must be written and provided by the The TParticleInterface class must be written and provided by the
user, it contains methods like <code> auto GetData() const { user, it contains methods like <code> auto GetData() const {
return GetStackData().GetData(GetIndex()); }</code>, where return GetStackData().GetData(GetIndex()); }</code>, where
StackIteratorInterface::GetStackData() return a reference to the StackIteratorInterface::GetStackData() return a reference to the
object storing the particle data of type StackDataType. And object storing the particle data of type TStackDataType. And
StackIteratorInterface::GetIndex() provides the iterator index to StackIteratorInterface::GetIndex() provides the iterator index to
be readout. The StackDataType is another user-provided class to be readout. The TStackDataType is another user-provided class to
store data and must implement functions compatible with store data and must implement functions compatible with
ParticleInterface, in this example StackDataType::GetData(const unsigned int TParticleInterface, in this example TStackDataType::GetData(const unsigned int
vIndex). vIndex).
For two examples see stack_example.cc, or the For two examples see stack_example.cc, or the
corsika::processes::sibyll::SibStack class corsika::processes::sibyll::SibStack class
*/ */
template <typename StackDataType, template <typename> typename ParticleInterface, template <typename TStackDataType, template <typename> typename TParticleInterface,
typename StackType = Stack<StackDataType, ParticleInterface>> typename TStackType = Stack<TStackDataType, TParticleInterface>>
class StackIteratorInterface class StackIteratorInterface
: public ParticleInterface< : public TParticleInterface<
StackIteratorInterface<StackDataType, ParticleInterface, StackType>> { StackIteratorInterface<TStackDataType, TParticleInterface, TStackType>> {
public: public:
using ParticleInterfaceType = using ParticleInterfaceType =
ParticleInterface<corsika::stack::StackIteratorInterface< TParticleInterface<corsika::stack::StackIteratorInterface<
StackDataType, ParticleInterface, StackType>>; TStackDataType, TParticleInterface, TStackType>>;
// friends are needed for access to protected methods // friends are needed for access to protected methods
friend class Stack<StackDataType, friend class Stack<TStackDataType,
ParticleInterface>; // for access to GetIndex for Stack TParticleInterface>; // for access to GetIndex for Stack
friend class Stack<StackDataType&, ParticleInterface>; // for access to GetIndex friend class Stack<TStackDataType&,
// SecondaryView : public Stack TParticleInterface>; // for access to GetIndex
// SecondaryView : public Stack
friend class ParticleBase<StackIteratorInterface>; // for access to GetStackDataType friend class ParticleBase<StackIteratorInterface>; // for access to GetStackDataType
friend class SecondaryView<StackDataType, friend class SecondaryView<TStackDataType,
ParticleInterface>; // access for SecondaryView TParticleInterface>; // access for SecondaryView
private: private:
unsigned int fIndex = 0; unsigned int fIndex = 0;
StackType* fData = 0; // info: Particles and StackIterators become invalid when parent TStackType* fData = 0; // info: Particles and StackIterators become invalid when
// Stack is copied or deleted! // parent Stack is copied or deleted!
// it is not allowed to create a "dangling" stack iterator // it is not allowed to create a "dangling" stack iterator
StackIteratorInterface() = delete; StackIteratorInterface() = delete;
...@@ -103,7 +104,7 @@ namespace corsika::stack { ...@@ -103,7 +104,7 @@ namespace corsika::stack {
@param data reference to the stack [rw] @param data reference to the stack [rw]
@param index index on stack @param index index on stack
*/ */
StackIteratorInterface(StackType& data, const unsigned int index) StackIteratorInterface(TStackType& data, const unsigned int index)
: fIndex(index) : fIndex(index)
, fData(&data) {} , fData(&data) {}
...@@ -114,8 +115,9 @@ namespace corsika::stack { ...@@ -114,8 +115,9 @@ namespace corsika::stack {
consistent with the definition of the user-provided consistent with the definition of the user-provided
ParticleInterfaceType::SetParticleData(...) function ParticleInterfaceType::SetParticleData(...) function
*/ */
template <typename... Args> template <typename... TArgs>
StackIteratorInterface(StackType& data, const unsigned int index, const Args... args) StackIteratorInterface(TStackType& data, const unsigned int index,
const TArgs... args)
: fIndex(index) : fIndex(index)
, fData(&data) { , fData(&data) {
(**this).SetParticleData(args...); (**this).SetParticleData(args...);
...@@ -131,9 +133,9 @@ namespace corsika::stack { ...@@ -131,9 +133,9 @@ namespace corsika::stack {
consistent with the definition of the user-provided consistent with the definition of the user-provided
ParticleInterfaceType::SetParticleData(...) function ParticleInterfaceType::SetParticleData(...) function
*/ */
template <typename... Args> template <typename... TArgs>
StackIteratorInterface(StackType& data, const unsigned int index, StackIteratorInterface(TStackType& data, const unsigned int index,
StackIteratorInterface& parent, const Args... args) StackIteratorInterface& parent, const TArgs... args)
: fIndex(index) : fIndex(index)
, fData(&data) { , fData(&data) {
(**this).SetParticleData(*parent, args...); (**this).SetParticleData(*parent, args...);
...@@ -182,13 +184,13 @@ namespace corsika::stack { ...@@ -182,13 +184,13 @@ namespace corsika::stack {
/// Get current particle index /// Get current particle index
inline unsigned int GetIndex() const { return fIndex; } inline unsigned int GetIndex() const { return fIndex; }
/// Get current particle Stack object /// Get current particle Stack object
inline StackType& GetStack() { return *fData; } inline TStackType& GetStack() { return *fData; }
/// Get current particle const Stack object /// Get current particle const Stack object
inline const StackType& GetStack() const { return *fData; } inline const TStackType& GetStack() const { return *fData; }
/// Get current user particle StackDataType object /// Get current user particle TStackDataType object
inline StackDataType& GetStackData() { return fData->GetStackData(); } inline TStackDataType& GetStackData() { return fData->GetStackData(); }
/// Get current const user particle StackDataType object /// Get current const user particle TStackDataType object
inline const StackDataType& GetStackData() const { return fData->GetStackData(); } inline const TStackDataType& GetStackData() const { return fData->GetStackData(); }
/// Get data index as mapped in Stack class /// Get data index as mapped in Stack class
inline unsigned int GetIndexFromIterator() const { inline unsigned int GetIndexFromIterator() const {
return fData->GetIndexFromIterator(fIndex); return fData->GetIndexFromIterator(fIndex);
...@@ -202,31 +204,31 @@ namespace corsika::stack { ...@@ -202,31 +204,31 @@ namespace corsika::stack {
This is the iterator class for const-access to stack data This is the iterator class for const-access to stack data
*/ */
template <typename StackDataType, template <typename> typename ParticleInterface, template <typename TStackDataType, template <typename> typename TParticleInterface,
typename StackType = Stack<StackDataType, ParticleInterface>> typename TStackType = Stack<TStackDataType, TParticleInterface>>
class ConstStackIteratorInterface class ConstStackIteratorInterface
: public ParticleInterface< : public TParticleInterface<
ConstStackIteratorInterface<StackDataType, ParticleInterface, StackType>> { ConstStackIteratorInterface<TStackDataType, TParticleInterface, TStackType>> {
public: public:
typedef ParticleInterface< typedef TParticleInterface<
ConstStackIteratorInterface<StackDataType, ParticleInterface, StackType>> ConstStackIteratorInterface<TStackDataType, TParticleInterface, TStackType>>
ParticleInterfaceType; ParticleInterfaceType;
friend class Stack<StackDataType, ParticleInterface>; // for access to GetIndex friend class Stack<TStackDataType, TParticleInterface>; // for access to GetIndex
friend class ParticleBase<ConstStackIteratorInterface>; // for access to friend class ParticleBase<ConstStackIteratorInterface>; // for access to
// GetStackDataType // GetStackDataType
private: private:
unsigned int fIndex = 0; unsigned int fIndex = 0;
const StackType* fData = 0; // info: Particles and StackIterators become invalid when const TStackType* fData = 0; // info: Particles and StackIterators become invalid when
// parent Stack is copied or deleted! // parent Stack is copied or deleted!
// we don't want to allow dangling iterators to exist // we don't want to allow dangling iterators to exist
ConstStackIteratorInterface() = delete; ConstStackIteratorInterface() = delete;
public: public:
ConstStackIteratorInterface(const StackType& data, const unsigned int index) ConstStackIteratorInterface(const TStackType& data, const unsigned int index)
: fIndex(index) : fIndex(index)
, fData(&data) {} , fData(&data) {}
...@@ -277,8 +279,8 @@ namespace corsika::stack { ...@@ -277,8 +279,8 @@ namespace corsika::stack {
*/ */
///@{ ///@{
inline unsigned int GetIndex() const { return fIndex; } inline unsigned int GetIndex() const { return fIndex; }
inline const StackType& GetStack() const { return *fData; } inline const TStackType& GetStack() const { return *fData; }
inline const StackDataType& GetStackData() const { return fData->GetStackData(); } inline const TStackDataType& GetStackData() const { return fData->GetStackData(); }
/// Get data index as mapped in Stack class /// Get data index as mapped in Stack class
inline unsigned int GetIndexFromIterator() const { inline unsigned int GetIndexFromIterator() const {
return fData->GetIndexFromIterator(fIndex); return fData->GetIndexFromIterator(fIndex);
......
/*
* (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.
*/
#ifndef _utilities_sgn_h #ifndef _utilities_sgn_h
#define _utilities_sgn_h #define _utilities_sgn_h
......
...@@ -8,3 +8,5 @@ ...@@ -8,3 +8,5 @@
* Licence version 3 (GPL Version 3). See file LICENSE for a full version of * Licence version 3 (GPL Version 3). See file LICENSE for a full version of
* the license. * the license.
*/ */
...@@ -8,3 +8,5 @@ ...@@ -8,3 +8,5 @@
* Licence version 3 (GPL Version 3). See file LICENSE for a full version of * Licence version 3 (GPL Version 3). See file LICENSE for a full version of
* the license. * the license.
*/ */