36 new_memory[i] =
data_[i];
39 new_memory[i].index_ = i;
41 std::swap(
data_, new_memory);
58 const auto offset =
dirty_.back();
61 data_[offset].hole_ =
false;
68 while (number && !
dirty_.empty()) {
69 const auto offset =
dirty_.back();
74 data_[offset].hole_ =
false;
83 ptr->type_ = pd.
type_;
97 const auto offset =
dirty_.back();
110 const unsigned index =
p.index_;
114 data_[index].set_id(-1);
115 data_[index].hole_ =
true;
122 for (; i < std::min(to_remove.size(), to_add.size()); ++i) {
124 const auto index = to_remove[i].index_;
126 to_add[i].id_ =
data_[index].id_;
127 to_add[i].index_ = index;
129 for (; i < to_remove.size(); ++i) {
132 for (; i < to_add.size(); ++i) {
134 to_add[i].id_ =
p.id_;
135 to_add[i].index_ =
p.index_;
142 for (
auto index :
dirty_) {
143 data_[index].hole_ =
false;
149 out << particles.
size() <<
" Particles:\n";
150 for (
unsigned i = 0; i < particles.
data_size_; ++i) {
151 const auto &
p = particles.
data_[i];
155 out << std::setw(5) << std::setprecision(3) <<
p.momentum().abs3()
ParticleData contains the dynamic information of a certain particle.
int32_t id_
Each particle has a unique identifier.
bool hole_
If true, the object is an entry in Particles::data_ and does not hold valid particle data.
void copy_to(ParticleData &dst) const
Copies some information of the particle to the given particle dst.
ParticleTypePtr type_
A reference to the ParticleType object for this particle (this contains all the static information).
static const ParticleType & find(PdgCode pdgcode)
Returns the ParticleType object for the given pdgcode.
The Particles class abstracts the storage and manipulation of particles.
std::unique_ptr< ParticleData[]> data_
Points to a dynamically allocated array of ParticleData objects.
void reset()
Reset the state of the Particles object to an empty list and a new id counter.
bool is_valid(const ParticleData ©) const
Check whether the ParticleData copy is still a valid copy of the one stored in the Particles object.
std::vector< unsigned > dirty_
Stores the indexes in data_ that do not hold valid particle data and should be reused when new partic...
void copy_in(ParticleData &to, const ParticleData &from)
int id_max_
Highest id of a given particle.
void ensure_capacity(unsigned to_add)
Particles()
Creates a new (empty) Particles object.
void replace(const ParticleList &to_remove, ParticleList &to_add)
Replace the particles in to_remove with the particles in to_add in the list of current particles.
const ParticleData & insert(const ParticleData &p)
Inserts the particle into the list of particles.
void create(size_t n, PdgCode pdg)
Add n particles of the same type (pdg) to the list.
void increase_capacity(unsigned new_capacity)
void remove(const ParticleData &p)
Remove the given particle p from the list.
PdgCode stores a Particle Data Group Particle Numbering Scheme particle type number.
std::ostream & operator<<(std::ostream &out, const ActionPtr &action)
Convenience: dereferences the ActionPtr to Action.
#define likely(x)
Tell the branch predictor that this expression is likely true.