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