IAP GITLAB

Skip to content
Snippets Groups Projects
Commit 0017f855 authored by Ralf Ulrich's avatar Ralf Ulrich
Browse files

Merge branch '126-add-nucleus-to-corsika-id-conversion' into 'master'

Resolve "add Nucleus to corsika id conversion"

Closes #126

See merge request !70
parents 09a4bb14 e1b483ac
No related branches found
No related tags found
1 merge request!70Resolve "add Nucleus to corsika id conversion"
Pipeline #277 canceled
Showing
with 219 additions and 26 deletions
......@@ -21,6 +21,7 @@
using namespace corsika::units::si;
using namespace corsika::stack;
using namespace corsika;
using namespace std;
void fill(corsika::stack::super_stupid::SuperStupidStack& s) {
......@@ -44,7 +45,6 @@ void read(corsika::stack::super_stupid::SuperStupidStack& s) {
assert(p.GetPID() == corsika::particles::Code::Electron);
assert(p.GetEnergy() == 1.5_GeV * (i++));
}
// assert(total_energy == 82.5_GeV);
}
int main() {
......
/*
* (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.
*/
/*
* (c) Copyright 2018 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.
*
* 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.
*/
/*
* (c) Copyright 2018 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.
*
* 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.
*/
/*
* (c) Copyright 2018 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.
*
* 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.
*/
/*
* (c) Copyright 2018 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.
*
* 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.
*/
/*
* (c) Copyright 2018 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.
*
* 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.
*/
/*
* (c) Copyright 2018 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.
*
* 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.
*/
/*
* (c) Copyright 2018 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.
*
* 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.
*/
/*
* (c) Copyright 2018 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.
*
* 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.
*/
/*
* (c) Copyright 2018 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.
*
* 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.
*/
/*
* (c) Copyright 2018 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.
*
* 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.
*/
/*
* (c) Copyright 2018 CORSIKA Project, corsika-project@lists.kit.edu
*
......
<chapter name="Nuclear Data">
<particle id="1000000000" name="nucleus" A="0" Z="0" >
</particle>
<particle id="1000010010" name="hydrogen" A="1" Z="1" >
</particle>
......
......@@ -4,7 +4,7 @@
<particle id="0" name="void" spinType="0" chargeType="0" colType="0"
m0="0.00000">
</particle>
<!--
<particle id="1" name="d" antiName="dbar" spinType="2" chargeType="-1" colType="1"
m0="0.33000">
......
/*
* (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.
*/
/*
* (c) Copyright 2018 CORSIKA Project, corsika-project@lists.kit.edu
*
......
......@@ -251,7 +251,7 @@ def read_nuclei_db(filename, particle_db, classnames):
}
return particle_db
......
......@@ -45,6 +45,8 @@ TEST_CASE("ParticleProperties", "[Particles]") {
SECTION("Names") {
REQUIRE(Electron::GetName() == "e-");
REQUIRE(PiMinus::GetName() == "pi-");
REQUIRE(Nucleus::GetName() == "nucleus");
REQUIRE(Iron::GetName() == "iron");
}
SECTION("PDG") {
......
......@@ -22,6 +22,26 @@ namespace corsika::stack {
The base class to define the readout of particle properties from a
particle stack. Every stack must implement this readout via the
ParticleBase class.
The StackIterator template argument is derived from StackIteratorInterface, which is of
type <code> template <typename StackData, template <typename> typename
ParticleInterface> class StackIteratorInterface : public
ParticleInterface<StackIteratorInterface<StackData, ParticleInterface>>
</code>
where StackData must refer to a Stack type, and
ParticleInterface<StackIteratorInterface> is the corresponding particle readout class.
Thus, StackIteratorInterface is a CRTP class, injecting the full StackIteratorInterface
machinery into the ParticleInterface (aka ParticleBase) type!
The declartion of a StackIteratorInterface type simultaneously declares the
corresponding ParticleInterface type.
Furthermore, the operator* of the StackIteratorInterface returns a
static_cast to the ParticleInterface type, allowing a direct
readout of the particle data from the iterator.
*/
template <typename StackIterator>
......@@ -31,6 +51,7 @@ namespace corsika::stack {
ParticleBase() = default;
private:
/*
// those copy constructors and assigments should never be implemented
ParticleBase(ParticleBase&) = delete;
ParticleBase operator=(ParticleBase&) = delete;
......@@ -38,10 +59,11 @@ namespace corsika::stack {
ParticleBase operator=(ParticleBase&&) = delete;
ParticleBase(const ParticleBase&) = delete;
ParticleBase operator=(const ParticleBase&) = delete;
*/
public:
/** delete this particle on the stack. The corresponding iterator
* will be invalidated by this operation
/**
* Delete this particle on the stack. The corresponding iterator
* will be invalidated by this operation
*/
void Delete() { GetIterator().GetStack().Delete(GetIterator()); }
......@@ -55,7 +77,7 @@ namespace corsika::stack {
return GetStack().AddSecondary(GetIterator(), args...);
}
// protected: // todo should [MAY]be proteced, but don't now how to 'friend Stack'
// protected: // todo should [MAY]be proteced, but don't now how to 'friend Stack'
// Function to provide CRTP access to inheriting class (type)
/**
* return the corresponding StackIterator for this particle
......@@ -66,7 +88,8 @@ namespace corsika::stack {
}
protected:
/** @name Access to underlying stack data
/**
@name Access to underlying stack data
@{
*/
auto& GetStackData() { return GetIterator().GetStackData(); }
......@@ -78,7 +101,7 @@ namespace corsika::stack {
/**
* return the index number of the underlying iterator object
*/
int GetIndex() const { return GetIterator().GetIndex(); }
unsigned int GetIndex() const { return GetIterator().GetIndex(); }
};
} // namespace corsika::stack
......
......@@ -27,36 +27,67 @@ namespace corsika::stack {
ParticleInterface, which is one of the essential template
parameters for the Stack.
Important: ParticleInterface must inherit from ParticleBase !
<b>Important:</b> ParticleInterface must inherit from ParticleBase !
*/
template <typename>
class ParticleInterface; // forward decl
/**
Interface definition of a Stack object. The Stack implements the
The Stack class provides (and connects) the main particle data storage machinery.
The StackData type is the user-provided bare data storage
object. This can be of any complexity, from a simple struct
(fortran common block), to a combination of different and
distributed data sources.
The user-provided ParticleInterface template type is the base
class type of the StackIteratorInterface class (CRTP) and must
provide all functions to read single particle data from the
StackData, given an 'unsigned int' index.
The Stack implements the
std-type begin/end function to allow integration in normal for
loops etc.
loops, ranges, etc.
*/
template <typename StackData, template <typename> typename ParticleInterface>
class Stack : public StackData {
public:
typedef Stack<StackData, ParticleInterface> StackType;
typedef StackData StackImpl; ///< this is the type of the user-provided data structure
template <typename SI>
using PIType = ParticleInterface<SI>;
// typedef ParticleInterface<StackIteratorInterface> StackParticleInterface; ///<
// this is the type of the user-provided ParticleInterface typedef Stack<StackData,
// ParticleInterface> StackType;
/**
* 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.
*/
typedef StackIteratorInterface<StackData, ParticleInterface> StackIterator;
typedef ConstStackIteratorInterface<StackData, ParticleInterface> ConstStackIterator;
// typedef const StackIterator ConstStackIterator;
/**
* this is the full type of the declared ParticleInterface: typedef typename
*/
typedef typename StackIterator::ParticleInterfaceType ParticleType;
friend class StackIteratorInterface<StackData, ParticleInterface>;
friend class ConstStackIteratorInterface<StackData, ParticleInterface>;
protected:
using StackData::Copy;
using StackData::Swap;
public:
using StackData::GetCapacity;
using StackData::GetSize;
using StackData::Clear;
using StackData::Copy;
using StackData::DecrementSize;
using StackData::IncrementSize;
......@@ -88,9 +119,14 @@ namespace corsika::stack {
IncrementSize();
return StackIterator(*this, GetSize() - 1, parent, v...);
}
void Copy(StackIterator& a, StackIterator& b) { Copy(a.GetIndex(), b.GetIndex()); }
void Swap(StackIterator a, StackIterator b) { Swap(a.GetIndex(), b.GetIndex()); }
void Swap(ConstStackIterator a, ConstStackIterator b) {
Swap(a.GetIndex(), b.GetIndex());
}
void Copy(StackIterator a, StackIterator b) { Copy(a.GetIndex(), b.GetIndex()); }
void Copy(ConstStackIterator a, StackIterator b) { Copy(a.GetIndex(), b.GetIndex()); }
/// delete this particle
void Delete(StackIterator& p) {
void Delete(StackIterator p) {
if (GetSize() == 0) { /*error*/
throw std::runtime_error("Stack, cannot delete entry since size is zero");
}
......@@ -98,7 +134,7 @@ namespace corsika::stack {
DeleteLast();
// p.SetInvalid();
}
void Delete(ParticleType& p) { Delete(p.GetIterator()); }
void Delete(ParticleType p) { Delete(p.GetIterator()); }
/// delete last particle on stack by decrementing stack size
void DeleteLast() { DecrementSize(); }
/// check if there are no further particles on stack
......
......@@ -51,11 +51,13 @@ namespace corsika::stack {
class StackIteratorInterface
: public ParticleInterface<StackIteratorInterface<StackData, ParticleInterface>> {
public:
typedef Stack<StackData, ParticleInterface> StackType;
/*typedef
typename std::conditional<std::is_const<StackData>::value,
const Stack<const StackData, ParticleInterface>&,
Stack<StackData, ParticleInterface>&>::type StackType;*/
typedef ParticleInterface<StackIteratorInterface<StackData, ParticleInterface>>
ParticleInterfaceType;
......@@ -63,7 +65,7 @@ namespace corsika::stack {
friend class ParticleBase<StackIteratorInterface>; // for access to GetStackData
private:
int fIndex = 0;
unsigned int fIndex = 0;
StackType* fData = 0; // info: Particles and StackIterators become invalid when parent
// Stack is copied or deleted!
......@@ -75,7 +77,7 @@ namespace corsika::stack {
@param data reference to the stack [rw]
@param index index on stack
*/
StackIteratorInterface(StackType& data, const int index)
StackIteratorInterface(StackType& data, const unsigned int index)
: fIndex(index)
, fData(&data) {}
......@@ -87,7 +89,7 @@ namespace corsika::stack {
ParticleInterfaceType::SetParticleData(...) function
*/
template <typename... Args>
StackIteratorInterface(StackType& data, const int index, const Args... args)
StackIteratorInterface(StackType& data, const unsigned int index, const Args... args)
: fIndex(index)
, fData(&data) {
(**this).SetParticleData(args...);
......@@ -104,7 +106,7 @@ namespace corsika::stack {
ParticleInterfaceType::SetParticleData(...) function
*/
template <typename... Args>
StackIteratorInterface(StackType& data, const int index,
StackIteratorInterface(StackType& data, const unsigned int index,
StackIteratorInterface& parent, const Args... args)
: fIndex(index)
, fData(&data) {
......@@ -124,6 +126,9 @@ namespace corsika::stack {
++fIndex;
return tmp;
}
StackIteratorInterface operator+(int delta) {
return StackIteratorInterface(*fData, fIndex + delta);
}
bool operator==(const StackIteratorInterface& rhs) { return fIndex == rhs.fIndex; }
bool operator!=(const StackIteratorInterface& rhs) { return fIndex != rhs.fIndex; }
/// Convert to value type
......@@ -141,7 +146,7 @@ namespace corsika::stack {
*/
///@{
/// Get current particle index
inline int GetIndex() const { return fIndex; }
inline unsigned int GetIndex() const { return fIndex; }
/// Get current particle Stack object
inline StackType& GetStack() { return *fData; }
/// Get current particle const Stack object
......@@ -164,6 +169,7 @@ namespace corsika::stack {
: public ParticleInterface<
ConstStackIteratorInterface<StackData, ParticleInterface>> {
public:
typedef Stack<StackData, ParticleInterface> StackType;
typedef ParticleInterface<ConstStackIteratorInterface<StackData, ParticleInterface>>
ParticleInterfaceType;
......@@ -172,7 +178,7 @@ namespace corsika::stack {
friend class ParticleBase<ConstStackIteratorInterface>; // for access to GetStackData
private:
int fIndex = 0;
unsigned int fIndex = 0;
const StackType* fData = 0; // info: Particles and StackIterators become invalid when
// parent Stack is copied or deleted!
......@@ -180,7 +186,7 @@ namespace corsika::stack {
ConstStackIteratorInterface() = delete;
public:
ConstStackIteratorInterface(const StackType& data, const int index)
ConstStackIteratorInterface(const StackType& data, const unsigned int index)
: fIndex(index)
, fData(&data) {}
......@@ -210,6 +216,9 @@ namespace corsika::stack {
++fIndex;
return tmp;
}
ConstStackIteratorInterface operator+(int delta) {
return ConstStackIteratorInterface(*fData, fIndex + delta);
}
bool operator==(const ConstStackIteratorInterface& rhs) {
return fIndex == rhs.fIndex;
}
......@@ -227,7 +236,7 @@ namespace corsika::stack {
Only the const versions for read-only access
*/
///@{
inline int GetIndex() const { return fIndex; }
inline unsigned int GetIndex() const { return fIndex; }
inline const StackType& GetStack() const { return *fData; }
inline const StackData& GetStackData() const { return fData->GetStackData(); }
///@}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment