Geant4 9.6.0
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
G4TrackList.hh
Go to the documentation of this file.
1//
2// ********************************************************************
3// * License and Disclaimer *
4// * *
5// * The Geant4 software is copyright of the Copyright Holders of *
6// * the Geant4 Collaboration. It is provided under the terms and *
7// * conditions of the Geant4 Software License, included in the file *
8// * LICENSE and available at http://cern.ch/geant4/license . These *
9// * include a list of copyright holders. *
10// * *
11// * Neither the authors of this software system, nor their employing *
12// * institutes,nor the agencies providing financial support for this *
13// * work make any representation or warranty, express or implied, *
14// * regarding this software system or assume any liability for its *
15// * use. Please see the license in the file LICENSE and URL above *
16// * for the full disclaimer and the limitation of liability. *
17// * *
18// * This code implementation is the result of the scientific and *
19// * technical work of the GEANT4 collaboration. *
20// * By using, copying, modifying or distributing the software (or *
21// * any work based on the software) you agree to acknowledge its *
22// * use in resulting scientific publications, and indicate your *
23// * acceptance of all terms of the Geant4 Software license. *
24// ********************************************************************
25//
26// $Id: G4TrackList.hh 64057 2012-10-30 15:04:49Z gcosmo $
27//
28// Author: Mathieu Karamitros (kara (AT) cenbg . in2p3 . fr)
29//
30// WARNING : This class is released as a prototype.
31// It might strongly evolve or even disapear in the next releases.
32//
33// History:
34// -----------
35// 10 Oct 2011 M.Karamitros created
36//
37// -------------------------------------------------------------------
38
39#ifndef G4TRACKLIST_H
40#define G4TRACKLIST_H
41
42#include "globals.hh"
44
45class G4Track;
46class G4TrackList;
47class G4TrackList_Boundary;
48
49/** Comments :
50* - A track cannot belong to two different track lists
51* - Erase a given track is constant complexity
52* - This development was thought to be used together with G4IT
53*/
54
56{
57 friend class G4TrackList ;
58protected :
59 inline _ListRef(G4TrackList* __list) :fpTrackList(__list)
60 {;}
61
63};
64
65/**
66 * G4TrackListNode is the entity actually stored
67 * by the G4TrackList. A G4TrackListNode should
68 * belong only to one list. Also, a track
69 * should belong only to one list.
70 */
71
73{
74 friend class G4TrackList;
75
76public :
77 G4Track* GetTrack() { return fpTrack; }
80 bool IsAttached() { return fAttachedToList;}
81
82protected:
83 /** Default constructor */
84 G4TrackListNode(G4Track* track= 0);
85 /** Default destructor */
87 void SetNext(G4TrackListNode* node) { fpNext = node;}
88 void SetPrevious(G4TrackListNode* node) { fpPrevious = node;}
89 void SetAttachedToList(bool flag) { fAttachedToList = flag;}
90
96};
97
99
100/**
101 * G4TrackList is used by G4ITStepManager to save
102 * G4IT tracks only. Its advantage lies to a fast
103 * search of a track in this list.
104 */
105
107{
108private :
109 G4int fNbTracks;
110 G4TrackListNode * fpStart;
111 G4TrackListNode * fpFinish;
113
114 G4TrackListNode fBoundary;
115 // Must be empty and link to the last non-empty node of the list
116 // and to the first non-empty node of the list (begin())
117 // The iterator returned by end() is linked to this empty node
118
119public:
121
122 G4TrackList();
123 ~G4TrackList();
124
125 inline G4Track* back()
126 {
127 if(fNbTracks != 0)
128 return fpFinish->GetTrack();
129 else return 0 ;
130 }
131 inline G4int size() const
132 {
133 return fNbTracks;
134 }
135 inline bool empty() const;
136 iterator insert(iterator /*position*/, G4Track*);
137 inline iterator begin();
138 inline iterator end();
139 /**
140 * return an iterator that contains an empty node
141 * use for boundary checking only
142 */
143
144 bool Holds(const G4Track*) const;
145
146 inline void push_front(G4Track* __track);
147 inline void push_back(G4Track* __track);
148 G4Track* pop_back();
149
150 void remove(G4Track*);
151
153 iterator pop(iterator __first, iterator __last);
155 /**
156 * Complexity = constant
157 * By storing the node inside the object, we avoid
158 * searching through all the container.
159 */
160
161 iterator erase(iterator __first, iterator __last);
162 /**
163 * Complexity = linear in size between __first and __last
164 */
165 void transferTo(G4TrackList*);
166 /**
167 * Complexity = constant
168 */
169
170protected:
175 void DeleteTrack(G4Track*);
176
177 void Hook(G4TrackListNode* /*position*/, G4TrackListNode* /*toHook*/);
178 void Unhook(G4TrackListNode*);
180
181private:
182 G4TrackList(const G4TrackList& other);
183 G4TrackList & operator=
184 (const G4TrackList &right);
185 G4int operator==(const G4TrackList &right) const;
186 G4int operator!=(const G4TrackList &right) const;
187};
188
189/**
190 * G4TrackList_iterator enables to go through
191 * the tracks contained by a list.
192 */
193
195{
196 friend class G4TrackList;
199
201 : fpNode() { }
202
203 explicit
205 : fpNode(__x) { }
206
208 { return fpNode; }
209
210 G4Track*
211 operator*();
212
213 const G4Track*
214 operator*() const;
215
216 G4Track*
217 operator->() ;
218
219 const G4Track*
220 operator->() const;
221
222 _Self&
224 {
225 fpNode = fpNode->GetNext();
226 return *this;
227 }
228
229 _Self
231 {
232 _Self __tmp = *this;
233 fpNode = fpNode->GetNext();
234 return __tmp;
235 }
236
237 _Self&
239 {
240 fpNode = fpNode->GetPrevious();
241 return *this;
242 }
243
244 _Self
246 {
247 _Self __tmp = *this;
248 fpNode = fpNode->GetPrevious();
249 return __tmp;
250 }
251
252 bool
253 operator==(const _Self& __x) const
254 { return (fpNode == __x.fpNode); }
255
256 bool
257 operator!=(const _Self& __x) const
258 {
259 return (fpNode != __x.fpNode);
260 }
261
262private:
263 // The only member points to the G4TrackList_iterator element.
264 _Node* fpNode;
265};
266
267inline bool G4TrackList::empty() const
268{ return (fNbTracks == 0); }
269
270
272{ return iterator(fpStart); }
273
275{ return iterator( &(fBoundary) ); }
276// return an iterator that contains an empty node
277// use for boundary checking only
278
280{
281 insert(begin(), track);
282}
283
285{
286 insert(end(), track);
287}
288
289#endif // G4TRACKLIST_H
int G4int
Definition: G4Types.hh:66
void SetNext(G4TrackListNode *node)
Definition: G4TrackList.hh:87
G4TrackListNode * fpNext
Definition: G4TrackList.hh:95
void SetPrevious(G4TrackListNode *node)
Definition: G4TrackList.hh:88
G4ReferenceCountedHandle< _ListRef > fListRef
Definition: G4TrackList.hh:92
G4TrackListNode * GetPrevious()
Definition: G4TrackList.hh:79
void SetAttachedToList(bool flag)
Definition: G4TrackList.hh:89
G4Track * GetTrack()
Definition: G4TrackList.hh:77
G4Track * fpTrack
Definition: G4TrackList.hh:93
G4TrackListNode * fpPrevious
Definition: G4TrackList.hh:94
G4TrackListNode * GetNext()
Definition: G4TrackList.hh:78
G4Track * pop_back()
Definition: G4TrackList.cc:308
G4TrackListNode * CreateNode(G4Track *)
Definition: G4TrackList.cc:170
void Unhook(G4TrackListNode *)
Definition: G4TrackList.cc:225
void CheckFlag(G4TrackListNode *)
Definition: G4TrackList.cc:269
void push_back(G4Track *__track)
Definition: G4TrackList.hh:284
bool Holds(const G4Track *) const
Definition: G4TrackList.cc:137
void transferTo(G4TrackList *)
Definition: G4TrackList.cc:389
void Hook(G4TrackListNode *, G4TrackListNode *)
Definition: G4TrackList.cc:176
iterator pop(G4Track *)
Definition: G4TrackList.cc:317
iterator insert(iterator, G4Track *)
Definition: G4TrackList.cc:258
G4Track * back()
Definition: G4TrackList.hh:125
bool empty() const
Definition: G4TrackList.hh:267
G4int size() const
Definition: G4TrackList.hh:131
G4TrackList_iterator iterator
Definition: G4TrackList.hh:120
void remove(G4Track *)
Definition: G4TrackList.cc:357
iterator end()
Definition: G4TrackList.hh:274
iterator begin()
Definition: G4TrackList.hh:271
void DeleteTrack(G4Track *)
Definition: G4TrackList.cc:335
G4TrackListNode * Flag(G4Track *)
Definition: G4TrackList.cc:142
G4TrackListNode * EraseTrackListNode(G4Track *)
Definition: G4TrackList.cc:325
void push_front(G4Track *__track)
Definition: G4TrackList.hh:279
iterator erase(G4Track *)
Definition: G4TrackList.cc:346
G4TrackListNode * Unflag(G4Track *)
Definition: G4TrackList.cc:288
G4TrackList_iterator(_Node *__x)
Definition: G4TrackList.hh:204
G4Track * operator*()
Definition: G4TrackList.cc:45
bool operator!=(const _Self &__x) const
Definition: G4TrackList.hh:257
G4TrackList_iterator _Self
Definition: G4TrackList.hh:197
G4Track * operator->()
Definition: G4TrackList.cc:49
bool operator==(const _Self &__x) const
Definition: G4TrackList.hh:253
G4TrackListNode _Node
Definition: G4TrackList.hh:198
_ListRef(G4TrackList *__list)
Definition: G4TrackList.hh:59
G4TrackList * fpTrackList
Definition: G4TrackList.hh:62