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