Geant4  10.03
G4TrackList.cc
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.cc 93616 2015-10-27 08:59:17Z gcosmo $
27 //
28 // Author: Mathieu Karamitros (kara (AT) cenbg . in2p3 . fr)
29 //
30 // History:
31 // -----------
32 // 10 Oct 2011 M.Karamitros created
33 //
34 // -------------------------------------------------------------------
35 
36 /*
37  * G4FastList.cc
38  *
39  * Created on: 18 nov. 2014
40  * Author: kara
41  */
42 
43 #include "G4TrackList.hh"
44 
46 template<>
48 {
49  G4IT* __IT = GetIT(__track);
50  G4FastListNode<G4Track>* __trackListNode = __IT->GetListNode();
51  // TODO : complete the exception
52  if (__trackListNode == 0)
53  {
54  G4ExceptionDescription exceptionDescription;
55  exceptionDescription << "This track " << GetIT(__track)->GetName();
56  exceptionDescription << " was not connected to any trackList ";
57  G4Exception("G4FastList<OBJECT>::Unflag", "G4TrackList003", FatalErrorInArgument,
58  exceptionDescription);
59  return 0;
60  }
61  return __trackListNode;
62 }
63 
65 template<>
67 {
69 
70  G4Step* __step = const_cast<G4Step*>(__track->GetStep());
71  if (__step)
72  {
73  if (__step->GetfSecondary())
74  __step->DeleteSecondaryVector();
75  delete __step;
76  }
77  delete __track;
78 }
79 
80 
81 template<>
83  {
84  if(fpObject)
85  {
87  }
88  }
89 
90 
92 template<>
93 bool G4FastList<G4Track>::Holds(const G4Track* track) const
94 {
95  return (GetIT(track)->GetListNode()->fListRef->fpList == this);
96 }
97 
99 template<>
101 {
102  G4IT* __iTrack = GetIT(__track);
103  G4FastListNode<G4Track>* __trackListNode = __iTrack->GetListNode();
104 
105  if (__trackListNode != 0)
106  {
107  // Suggestion move the node to this list
108  if (__trackListNode->fAttachedToList)
109  {
110  G4ExceptionDescription exceptionDescription;
111  exceptionDescription << "This track " << __iTrack->GetName();
112  exceptionDescription << " is already attached to a TrackList ";
113  G4Exception("G4FastList<OBJECT>::Flag", "G4TrackList001",
115  exceptionDescription);
116  }
117  } else
118  {
119  __trackListNode = new G4FastListNode<G4Track>(__track);
120  __iTrack->SetListNode(__trackListNode);
121  }
122 
123  __trackListNode->fAttachedToList = true;
124  __trackListNode->fListRef = fListRef;
125  return __trackListNode;
126 }
127 
129 template<>
131 {
132  if (__trackListNode->fListRef->fpList != this)
133  {
134  G4Track* track = __trackListNode->GetObject();
135  G4ExceptionDescription exceptionDescription;
136  exceptionDescription << "The track " << GetIT(track)->GetName()
137  << " with trackID " << track->GetTrackID()
138  << " is not correctly linked to a TrackList."
139  << G4endl
140  << "You are probably trying to withdraw this track "
141  << "from the list but it probably does not belong to "
142  << "this track list." << G4endl;
143  G4Exception("G4FastList<OBJECT>::CheckFlag", "G4FastList002",
144  FatalErrorInArgument, exceptionDescription);
145  }
146 }
147 
149 template<>
151 {
152  G4FastListNode<G4Track>* __node = Unflag(__track);
153  G4FastListNode<G4Track>* __next = __node->GetNext();
154  Unhook(__node);
155  __node->DetachYourSelf();
156  delete __node;
157  return __next;
158 }
159 
160 
162 template<>
164 {
165  G4IT* __IT = GetIT(__track);
166  G4FastListNode<G4Track>* __trackListNode = __IT->GetListNode();
167  // TODO : complete the exception
168  if (__trackListNode == 0)
169  {
170  return 0;
171  }
172  return __trackListNode;
173 }
174 
176 template<>
178 {
179  G4IT* __IT = GetIT(__track);
180  G4FastListNode<G4Track>* __trackListNode = __IT->GetListNode();
181 
182  if(__trackListNode == 0) return 0;
183  if(__trackListNode->fListRef == nullptr) return 0;
184 
185  return __trackListNode->fListRef->fpList;
186 }
187 
G4FastListNode< OBJECT > * Unflag(OBJECT *)
G4FastListNode< OBJECT > * GetNext()
Definition: G4FastList.hh:164
void DeleteObject(OBJECT *)
std::ostringstream G4ExceptionDescription
Definition: globals.hh:76
G4TrackListNode * GetListNode()
Definition: G4IT.hh:145
void DeleteSecondaryVector()
static G4AllocatorList * GetAllocatorListIfExist()
OBJECT * fpObject
Definition: G4FastList.hh:208
OBJECT * GetObject()
Definition: G4FastList.hh:154
static G4FastList< OBJECT > * GetList(OBJECT *)
G4FastListNode< OBJECT > * EraseListNode(OBJECT *)
virtual const G4String & GetName() const =0
G4shared_ptr< _ListRef< G4FastList< OBJECT > > > fListRef
Definition: G4FastList.hh:207
const G4Step * GetStep() const
void SetListNode(G4TrackListNode *node)
Definition: G4IT.hh:149
void CheckFlag(G4FastListNode< OBJECT > *)
G4IT * GetIT(const G4Track *track)
Definition: G4IT.cc:49
bool Holds(const OBJECT *) const
return an iterator that contains an empty node use for boundary checking only
Definition: G4Step.hh:76
G4int GetTrackID() const
void DetachYourSelf()
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
Definition: G4Exception.cc:41
static G4FastListNode< OBJECT > * GetNode(OBJECT *)
Complexity = constant.
G4FastListNode< G4FastList< OBJECT > > * GetListNode()
Definition: G4FastList.hh:335
G4TrackVector * GetfSecondary()
bool fAttachedToList
Definition: G4FastList.hh:206
#define G4endl
Definition: G4ios.hh:61
G4FastListNode< OBJECT > * Flag(OBJECT *)
static G4FastListNode< OBJECT > * __GetNode(OBJECT *)
G4shared_ptr< _ListRef< G4FastList< OBJECT > > > fListRef
Definition: G4FastList.hh:226
{ Class description:
void Unhook(G4FastListNode< OBJECT > *)