Geant4 9.6.0
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
G4TrackList Class Reference

#include <G4TrackList.hh>

Public Types

typedef G4TrackList_iterator iterator
 

Public Member Functions

 G4TrackList ()
 
 ~G4TrackList ()
 
G4Trackback ()
 
G4int size () const
 
bool empty () const
 
iterator insert (iterator, G4Track *)
 
iterator begin ()
 
iterator end ()
 
bool Holds (const G4Track *) const
 
void push_front (G4Track *__track)
 
void push_back (G4Track *__track)
 
G4Trackpop_back ()
 
void remove (G4Track *)
 
iterator pop (G4Track *)
 
iterator pop (iterator __first, iterator __last)
 
iterator erase (G4Track *)
 
iterator erase (iterator __first, iterator __last)
 
void transferTo (G4TrackList *)
 

Protected Member Functions

G4TrackListNodeCreateNode (G4Track *)
 
G4TrackListNodeFlag (G4Track *)
 
G4TrackListNodeUnflag (G4Track *)
 
void CheckFlag (G4TrackListNode *)
 
void DeleteTrack (G4Track *)
 
void Hook (G4TrackListNode *, G4TrackListNode *)
 
void Unhook (G4TrackListNode *)
 
G4TrackListNodeEraseTrackListNode (G4Track *)
 

Detailed Description

G4TrackList is used by G4ITStepManager to save G4IT tracks only. Its advantage lies to a fast search of a track in this list.

Definition at line 106 of file G4TrackList.hh.

Member Typedef Documentation

◆ iterator

Definition at line 120 of file G4TrackList.hh.

Constructor & Destructor Documentation

◆ G4TrackList()

G4TrackList::G4TrackList ( )

Definition at line 77 of file G4TrackList.cc.

77 : fBoundary()
78{
79 fListRef = new _ListRef(this);
80 fpStart = 0;
81 fpFinish = 0;
82 fNbTracks = 0 ;
83 fBoundary.SetPrevious(&fBoundary);
84 fBoundary.SetNext(&fBoundary);
85 fBoundary.fAttachedToList = true;
86}
void SetNext(G4TrackListNode *node)
Definition: G4TrackList.hh:87
void SetPrevious(G4TrackListNode *node)
Definition: G4TrackList.hh:88

◆ ~G4TrackList()

G4TrackList::~G4TrackList ( )

Definition at line 107 of file G4TrackList.cc.

108{
109 if( fNbTracks != 0 )
110 {
111 G4TrackListNode * __stackedTrack = fpStart;
112 G4TrackListNode * __nextStackedTrack;
113
114 // delete tracks in the stack
115 while( __stackedTrack && __stackedTrack != &(fBoundary) )
116 {
117 __nextStackedTrack = __stackedTrack->GetNext();
118 G4Track* __track = __stackedTrack->GetTrack();
119
120 delete __stackedTrack;
121 __stackedTrack = 0;
122
123 if(__track)
124 {
125 //////////////
126 DeleteTrack(__track);
127 __track = 0;
128 //////////////
129 }
130
131 __stackedTrack = __nextStackedTrack;
132 }
133 }
134 fNbTracks = 0;
135}
G4Track * GetTrack()
Definition: G4TrackList.hh:77
G4TrackListNode * GetNext()
Definition: G4TrackList.hh:78
void DeleteTrack(G4Track *)
Definition: G4TrackList.cc:335

Member Function Documentation

◆ back()

G4Track * G4TrackList::back ( )
inline

Definition at line 125 of file G4TrackList.hh.

126 {
127 if(fNbTracks != 0)
128 return fpFinish->GetTrack();
129 else return 0 ;
130 }

◆ begin()

G4TrackList::iterator G4TrackList::begin ( )
inline

Definition at line 271 of file G4TrackList.hh.

272{ return iterator(fpStart); }
G4TrackList_iterator iterator
Definition: G4TrackList.hh:120

Referenced by push_front().

◆ CheckFlag()

void G4TrackList::CheckFlag ( G4TrackListNode __trackListNode)
protected

Definition at line 269 of file G4TrackList.cc.

270{
271 if(__trackListNode -> fListRef->fpTrackList != this)
272 {
273 G4Track* track = __trackListNode->GetTrack();
274 G4ExceptionDescription exceptionDescription ;
275 exceptionDescription
276 << "The track "<< GetIT(track)->GetName()
277 << " with trackID " << track->GetTrackID()
278 << " is not correctly linked to a TrackList."
279 << G4endl
280 << "You are probably trying to withdraw this track "
281 << "from the list but it probably does not belong to "
282 << "this track list." << G4endl;
283 G4Exception("G4TrackList::CheckFlag","G4TrackList002",
284 FatalErrorInArgument,exceptionDescription);
285 }
286}
@ FatalErrorInArgument
G4IT * GetIT(const G4Track *track)
Definition: G4IT.cc:48
#define G4endl
Definition: G4ios.hh:52
virtual const G4String & GetName() const =0
G4int GetTrackID() const
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
Definition: G4Exception.cc:41
std::ostringstream G4ExceptionDescription
Definition: globals.hh:76
G4TrackList * fpTrackList
Definition: G4TrackList.hh:62

Referenced by Unflag().

◆ CreateNode()

G4TrackListNode * G4TrackList::CreateNode ( G4Track __track)
protected

Complexity = constant

Definition at line 170 of file G4TrackList.cc.

171{
172 G4TrackListNode* __trackListNode = Flag(__track);
173 return __trackListNode;
174}
G4TrackListNode * Flag(G4Track *)
Definition: G4TrackList.cc:142

Referenced by insert().

◆ DeleteTrack()

void G4TrackList::DeleteTrack ( G4Track __track)
protected

Definition at line 335 of file G4TrackList.cc.

336{
337 G4Step* __step = const_cast<G4Step*>(__track->GetStep());
338 if(__step)
339 {
340 if(__step->GetfSecondary()) __step->DeleteSecondaryVector();
341 delete __step;
342 }
343 delete __track;
344}
Definition: G4Step.hh:78
void DeleteSecondaryVector()
G4TrackVector * GetfSecondary()
const G4Step * GetStep() const

Referenced by erase(), and ~G4TrackList().

◆ empty()

bool G4TrackList::empty ( ) const
inline

Definition at line 267 of file G4TrackList.hh.

268{ return (fNbTracks == 0); }

◆ end()

G4TrackList::iterator G4TrackList::end ( )
inline

Definition at line 274 of file G4TrackList.hh.

275{ return iterator( &(fBoundary) ); }

Referenced by push_back().

◆ erase() [1/2]

G4TrackList::iterator G4TrackList::erase ( G4Track __track)

Definition at line 346 of file G4TrackList.cc.

347{
348 G4TrackListNode* __next_node = EraseTrackListNode(__track);
349 //////////////////
350 DeleteTrack(__track);
351 __track = 0;
352 //////////////////
353 iterator __next(__next_node);
354 return __next;
355}
G4TrackListNode * EraseTrackListNode(G4Track *)
Definition: G4TrackList.cc:325

Referenced by erase(), and remove().

◆ erase() [2/2]

G4TrackList::iterator G4TrackList::erase ( iterator  __first,
iterator  __last 
)

Complexity = constant By storing the node inside the object, we avoid searching through all the container.

Definition at line 377 of file G4TrackList.cc.

378{
379 if(fNbTracks == 0) return iterator(&fBoundary);
380
381 while (__first != __last)
382 {
383 if(__first . fpNode)
384 __first = erase(*__first);
385 }
386 return __last;
387}
iterator erase(G4Track *)
Definition: G4TrackList.cc:346

◆ EraseTrackListNode()

G4TrackListNode * G4TrackList::EraseTrackListNode ( G4Track __track)
protected

Definition at line 325 of file G4TrackList.cc.

326{
327 G4TrackListNode* __node = Unflag(__track);
328 GetIT(__track)->SetTrackListNode(0);
329 G4TrackListNode* __next = __node->GetNext();
330 Unhook(__node);
331 delete __node;
332 return __next;
333}
void SetTrackListNode(G4TrackListNode *node)
Definition: G4IT.hh:137
void Unhook(G4TrackListNode *)
Definition: G4TrackList.cc:225
G4TrackListNode * Unflag(G4Track *)
Definition: G4TrackList.cc:288

Referenced by erase().

◆ Flag()

G4TrackListNode * G4TrackList::Flag ( G4Track __track)
protected

Definition at line 142 of file G4TrackList.cc.

143{
144 G4IT* __iTrack = GetIT(__track);
145 G4TrackListNode* __trackListNode = __iTrack->GetTrackListNode();
146
147 if(__trackListNode != 0)
148 {
149 // Suggestion move the node to this list
150 if(__trackListNode->fAttachedToList)
151 {
152 G4ExceptionDescription exceptionDescription ;
153 exceptionDescription << "This track "<< __iTrack->GetName() ;
154 exceptionDescription << " is already attached to a TrackList ";
155 G4Exception("G4TrackList::Flag","G4TrackList001",
156 FatalErrorInArgument,exceptionDescription);
157 }
158 }
159 else
160 {
161 __trackListNode = new G4TrackListNode(__track);
162 __iTrack->SetTrackListNode(__trackListNode);
163 }
164
165 __trackListNode->fAttachedToList = true;
166 __trackListNode->fListRef = fListRef;
167 return __trackListNode;
168}
Definition: G4IT.hh:83
G4TrackListNode * GetTrackListNode()
Definition: G4IT.hh:136
G4ReferenceCountedHandle< _ListRef > fListRef
Definition: G4TrackList.hh:92

Referenced by CreateNode().

◆ Holds()

bool G4TrackList::Holds ( const G4Track track) const

return an iterator that contains an empty node use for boundary checking only

Definition at line 137 of file G4TrackList.cc.

138{
139 return (GetIT(track)->GetTrackListNode()->fListRef->fpTrackList == this) ;
140}

◆ Hook()

void G4TrackList::Hook ( G4TrackListNode __position,
G4TrackListNode __toHook 
)
protected

Definition at line 176 of file G4TrackList.cc.

177{
178 if(fNbTracks == 0)
179 {
180 // DEBUG
181 // G4cout << "fNbTracks == 0" << G4endl;
182 fpStart = __toHook;
183 fpFinish = __toHook;
184 __toHook->SetNext(&fBoundary);
185 __toHook->SetPrevious(&fBoundary);
186 fBoundary.SetNext(__toHook);
187 fBoundary.SetPrevious(__toHook);
188 }
189 else if( __position == &fBoundary)
190 {
191 // DEBUG
192 // G4cout << "__position == &fBoundary" << G4endl;
193 fpFinish->SetNext( __toHook );
194 __toHook->SetPrevious( fpFinish );
195
196 __toHook->SetNext(&fBoundary);
197 fBoundary.SetPrevious( __toHook );
198
199 fpFinish = __toHook;
200 }
201 else if( __position == fpStart )
202 {
203 // DEBUG
204 // G4cout << "__position == fStart" << G4endl;
205 __toHook->SetPrevious( &fBoundary );
206 fBoundary.SetNext(__toHook);
207 __toHook->SetNext(fpStart);
208 fpStart->SetPrevious(__toHook);
209 fpStart = __toHook;
210 }
211 else
212 {
213 // DEBUG
214 // G4cout << "else" << G4endl;
215 G4TrackListNode* __previous = __position->GetPrevious();
216 __toHook->SetPrevious(__previous);
217 __toHook->SetNext(__position);
218 __position->SetPrevious(__toHook);
219 __previous->SetNext(__toHook);
220 }
221
222 fNbTracks++;
223}
G4TrackListNode * GetPrevious()
Definition: G4TrackList.hh:79

Referenced by insert().

◆ insert()

G4TrackList::iterator G4TrackList::insert ( G4TrackList::iterator  __position,
G4Track __track 
)

Definition at line 258 of file G4TrackList.cc.

259{
260 G4TrackListNode* __node = CreateNode(__track);
261 Hook(__position.fpNode, __node);
262 return iterator(__node);
263}
G4TrackListNode * CreateNode(G4Track *)
Definition: G4TrackList.cc:170
void Hook(G4TrackListNode *, G4TrackListNode *)
Definition: G4TrackList.cc:176

Referenced by push_back(), and push_front().

◆ pop() [1/2]

G4TrackList::iterator G4TrackList::pop ( G4Track __track)

Definition at line 317 of file G4TrackList.cc.

318{
319 G4TrackListNode* __node = Unflag(__track);
320 iterator __next(__node->GetNext());
321 Unhook(__node);
322 return __next;
323}

Referenced by pop().

◆ pop() [2/2]

G4TrackList::iterator G4TrackList::pop ( iterator  __first,
iterator  __last 
)

Definition at line 363 of file G4TrackList.cc.

364{
365 if(fNbTracks == 0) return iterator(&fBoundary);
366
367 while (__first != __last)
368 {
369 if(__first . fpNode)
370 __first = pop(*__first);
371 }
372 return __last;
373}
iterator pop(G4Track *)
Definition: G4TrackList.cc:317

◆ pop_back()

G4Track * G4TrackList::pop_back ( )

Definition at line 308 of file G4TrackList.cc.

309{
310 if( fNbTracks == 0 ) return 0;
311 G4TrackListNode * __aStackedTrack = fpFinish;
312 Unhook( __aStackedTrack );
313 Unflag( __aStackedTrack->GetTrack() );
314 return __aStackedTrack->GetTrack();
315}

◆ push_back()

void G4TrackList::push_back ( G4Track __track)
inline

Definition at line 284 of file G4TrackList.hh.

285{
286 insert(end(), track);
287}
iterator insert(iterator, G4Track *)
Definition: G4TrackList.cc:258
iterator end()
Definition: G4TrackList.hh:274

◆ push_front()

void G4TrackList::push_front ( G4Track __track)
inline

Definition at line 279 of file G4TrackList.hh.

280{
281 insert(begin(), track);
282}
iterator begin()
Definition: G4TrackList.hh:271

◆ remove()

void G4TrackList::remove ( G4Track __track)

Definition at line 357 of file G4TrackList.cc.

358{
359 this->erase(__track);
360}

◆ size()

G4int G4TrackList::size ( ) const
inline

Definition at line 131 of file G4TrackList.hh.

132 {
133 return fNbTracks;
134 }

◆ transferTo()

void G4TrackList::transferTo ( G4TrackList __destination)

Complexity = linear in size between __first and __last

Definition at line 389 of file G4TrackList.cc.

390{
391 if(fNbTracks==0) return;
392
393 if(__destination->fNbTracks == 0)
394 {
395 __destination->fpStart = this->fpStart ;
396 __destination->fpFinish = this->fpFinish ;
397 __destination->fNbTracks = this->fNbTracks;
398
399 __destination->fBoundary.SetNext(fpStart);
400 __destination->fBoundary.SetPrevious(fpFinish);
401
402 __destination->fpFinish->SetNext(&__destination->fBoundary);
403 __destination->fpStart->SetPrevious(&__destination->fBoundary);
404 }
405 else
406 {
407 this->fpStart->SetPrevious(__destination->fpFinish);
408 __destination->fpFinish->SetNext(this->fpStart);
409 __destination->fBoundary.SetPrevious(this->fpFinish);
410 this->fpFinish->SetNext(&__destination->fBoundary);
411
412 __destination->fpFinish = this->fpFinish;
413 __destination->fNbTracks += this->fNbTracks;
414 }
415
416 fNbTracks = 0;
417 fpStart = 0;
418 fpFinish = 0;
419 this->fBoundary.SetPrevious(&this->fBoundary);
420 this->fBoundary.SetNext(&this->fBoundary);
421
422 fListRef->fpTrackList = __destination;
423}

◆ Unflag()

G4TrackListNode * G4TrackList::Unflag ( G4Track __track)
protected

Definition at line 288 of file G4TrackList.cc.

289{
290 G4IT* __IT = GetIT(__track);
291 G4TrackListNode* __trackListNode = __IT->GetTrackListNode();
292 // TODO : complete the exception
293 if(__trackListNode == 0)
294 {
295 G4ExceptionDescription exceptionDescription ;
296 exceptionDescription << "This track "<< GetIT(__track)->GetName() ;
297 exceptionDescription << " was not connected to any trackList ";
298 G4Exception("G4TrackList::Unflag","G4TrackList003",
299 FatalErrorInArgument,exceptionDescription);
300 return 0;
301 }
302 CheckFlag(__trackListNode);
303 __trackListNode->fAttachedToList = false;
304 __trackListNode->fListRef = 0;
305 return __trackListNode;
306}
void CheckFlag(G4TrackListNode *)
Definition: G4TrackList.cc:269

Referenced by EraseTrackListNode(), pop(), and pop_back().

◆ Unhook()

void G4TrackList::Unhook ( G4TrackListNode __toUnHook)
protected

Definition at line 225 of file G4TrackList.cc.

226{
227 G4TrackListNode* __previous = __toUnHook->GetPrevious();
228 G4TrackListNode* __next = __toUnHook->GetNext();
229
230 __toUnHook->SetPrevious(0);
231 __toUnHook->SetNext(0);
232
233 if( fNbTracks == 1 )
234 {
235 fpStart = 0;
236 fpFinish = 0;
237 }
238 else
239 {
240 if(__toUnHook == fpFinish)
241 {
242 fpFinish = __previous;
243 }
244 if(__toUnHook == fpStart)
245 {
246 fpStart = __next;
247 }
248 }
249
250 // There should be always a __next and a __previous
251 // because it is a circle link
252 __next->SetPrevious(__previous);
253 __previous->SetNext(__next);
254
255 fNbTracks--;
256}

Referenced by EraseTrackListNode(), pop(), and pop_back().


The documentation for this class was generated from the following files: