34#define INCLXX_IN_GEANT4_MODE 1
48 loadedStoppingTime(0.),
63 inside.insert(inside.end(), pL.begin(), pL.end());
68 avatarList.push_back(a);
71 for(
ParticleIter i=pList.begin(), e=pList.end(); i!=e; ++i) {
74 connectAvatarToParticle(a, *i);
79 for(
IAvatarIter a=al.begin(), e=al.end(); a!=e; ++a)
85 avatarList.push_back(a);
88 for(
ParticleIter i=pList.begin(), e=pList.end(); i!=e; ++i) {
90 connectAvatarToParticle(a, *i);
96 incoming.push_back(p);
99 void Store::connectAvatarToParticle(
IAvatar *
const a,
Particle *
const p) {
100 particleAvatarConnections.insert(PAPair(p,a));
103 void Store::disconnectAvatarFromParticle(IAvatar *
const a, Particle *
const p) {
104 PAIterPair iterPair = particleAvatarConnections.equal_range(p);
105 for(PAIter i=iterPair.first, last=iterPair.second; i!=last; ++i) {
107 particleAvatarConnections.erase(i);
111 INCL_WARN(
"Loop in Store::disconnectAvatarFromParticle fell through." << std::endl
112 <<
"This indicates an inconsistent state of the particleAvatarConnections map." << std::endl);
115 void Store::removeAvatar(IAvatar *
const avatar) {
117 ParticleList particlesRelatedToAvatar = avatar->getParticles();
118 for(
ParticleIter particleIter = particlesRelatedToAvatar.begin(), e = particlesRelatedToAvatar.end();
119 particleIter != e; ++particleIter) {
120 disconnectAvatarFromParticle(avatar, *particleIter);
124 avatarList.
remove(avatar);
128 PAIterPair iterPair = particleAvatarConnections.equal_range(particle);
129 for(PAIter i=iterPair.first, last=iterPair.second; i!=last; ++i) {
130 avatarsToBeRemoved.insert(i->second);
135 for(ASIter a=avatarsToBeRemoved.begin(), e=avatarsToBeRemoved.end(); a!=e; ++a) {
139 avatarsToBeRemoved.clear();
143 if(avatarList.empty())
return NULL;
145#ifdef INCL_AVATAR_SEARCH_FullSort
152 IAvatar *avatar = avatarList.front();
154#elif defined(INCL_AVATAR_SEARCH_MinElement)
157 IAvatar *avatar = *(std::min_element(avatarList.begin(), avatarList.end(),
161#error Unrecognized INCL_AVATAR_SEARCH. Allowed values are: FullSort, MinElement.
164 removeAvatar(avatar);
169 for(
ParticleIter particleIter = inside.begin(), particleEnd=inside.end();
170 particleIter != particleEnd; ++particleIter) {
171 (*particleIter)->propagate(step);
194 for(
IAvatarIter iter = avatarList.begin(), e = avatarList.end(); iter != e; ++iter) {
198 particleAvatarConnections.clear();
200 avatarsToBeRemoved.clear();
209 if( incoming.size() != 0 ) {
210 INCL_WARN(
"Incoming list is not empty when Store::clear() is called" <<
'\n');
217 for(
ParticleIter iter=inside.begin(), e=inside.end(); iter!=e; ++iter) {
224 for(
ParticleIter iter=outgoing.begin(), e=outgoing.end(); iter!=e; ++iter) {
225 if((*iter)->isCluster()) {
228#ifdef INCLXX_IN_GEANT4_MODE
241 G4int projectileA, projectileZ,
A, Z;
243 G4int ID, type, isParticipant;
247 std::ifstream in(filename.c_str());
248 in >> projectileA >> projectileZ >>
A >> Z >> stoppingTime >> cutNN;
251 loadedStoppingTime = stoppingTime;
254 in >> ID >> type >> isParticipant >> x >> y >> z >> px >> py >> pz >> E >> v;
255 if(!in.good())
break;
260 else if(type == -1) {
264 INCL_FATAL(
"Unrecognized particle type while loading particles; type=" << type <<
'\n');
271 if(isParticipant == 1) {
282 std::stringstream ss;
284 for(
ParticleIter i=inside.begin(), e=inside.end(); i!=e; ++i) {
285 if((*i)->getType() ==
Proton) {
289 if((*i)->getType() ==
Neutron) {
295 ss <<
"0 0 " <<
A <<
" " << Z <<
" "
299 for(
ParticleIter i=inside.begin(), e=inside.end(); i!=e; ++i) {
302 if((*i)->getType() ==
Proton) {
305 if((*i)->getType() ==
Neutron) {
309 G4int isParticipant = 0;
310 if((*i)->isParticipant()) {
314 G4double x = (*i)->getPosition().getX();
315 G4double y = (*i)->getPosition().getY();
316 G4double z = (*i)->getPosition().getZ();
318 G4double px = (*i)->getMomentum().getX();
319 G4double py = (*i)->getMomentum().getY();
320 G4double pz = (*i)->getMomentum().getZ();
321 G4double V = (*i)->getPotentialEnergy();
323 ss << ID <<
" " << type <<
" " << isParticipant <<
" "
324 << x <<
" " << y <<
" " << z <<
" "
325 << px <<
" " << py <<
" " << pz <<
" "
326 << E <<
" " << V <<
'\n';
333 std::ofstream out(filename.c_str());
339 std::stringstream ss;
340 for(
IAvatarIter i = avatarList.begin(), e = avatarList.end(); i != e; ++i) {
341 ss << (*i)->toString() <<
'\n';
347 for(
IAvatarIter i = avatarList.begin(), e = avatarList.end(); i != e; ++i)
void incrementCascading()
virtual ParticleList getParticles() const =0
void setPotentialEnergy(G4double v)
Set the particle potential energy.
virtual void makeParticipant()
void addParticleEntryAvatars(IAvatarList const &al)
Add one ParticleEntry avatar.
void timeStep(G4double step)
IAvatar * findSmallestTime()
Store(Config const *const config)
std::string printAvatars()
void addIncomingParticle(Particle *const p)
void particleHasBeenDestroyed(Particle *const)
void particleHasEntered(Particle *const particle)
Move a particle from incoming to inside.
void particleHasBeenUpdated(Particle *const)
Notify the Store about a particle update.
std::string printParticleConfiguration()
void removeScheduledAvatars()
Remove avatars that have been scheduled.
G4bool containsCollisions() const
void particleHasBeenEjected(Particle *const)
static G4bool avatarComparisonPredicate(IAvatar *lhs, IAvatar *rhs)
Comparison predicate for avatars.
void loadParticles(std::string const &filename)
void writeParticles(std::string const &filename)
void addParticleEntryAvatar(IAvatar *a)
Add one ParticleEntry avatar.
void removeFromIncoming(Particle *const p)
ParticleList::const_iterator ParticleIter
UnorderedVector< IAvatar * >::const_iterator IAvatarIter