Geant4  10.03
G4NavigationHistory.icc
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 // $Id: G4NavigationHistory.icc 86527 2014-11-13 15:06:24Z gcosmo $
28 //
29 //
30 // class G4NavigationHistory Inline implementation
31 //
32 // ----------------------------------------------------------------------
33 
34 extern G4GEOM_DLL G4ThreadLocal
35 G4Allocator<G4NavigationHistory> *aNavigHistoryAllocator;
36 
37 // There is no provision that this class is subclassed.
38 // If it is subclassed & new data members are added then the
39 // following "new" & "delete" will fail and give errors.
40 //
41 inline
42 void* G4NavigationHistory::operator new(size_t)
43 {
44  if (!aNavigHistoryAllocator)
45  {
46  aNavigHistoryAllocator = new G4Allocator<G4NavigationHistory>;
47  }
48  return (void *) aNavigHistoryAllocator->MallocSingle();
49 }
50 
51 inline
52 void G4NavigationHistory::operator delete(void *aHistory)
53 {
54  aNavigHistoryAllocator->FreeSingle((G4NavigationHistory *) aHistory);
55 }
56 
57 inline
58 G4NavigationHistory&
59 G4NavigationHistory::operator=(const G4NavigationHistory &h)
60 {
61  if (&h == this) { return *this; }
62 
63  // *fNavHistory=*(h.fNavHistory); // This works, but is very slow.
64 
65  if( GetMaxDepth() != h.GetMaxDepth() )
66  {
67  fNavHistory->resize( h.GetMaxDepth() );
68  }
69 
70  for ( G4int ilev=h.fStackDepth; ilev>=0; --ilev )
71  {
72  (*fNavHistory)[ilev] = (*h.fNavHistory)[ilev];
73  }
74  fStackDepth=h.fStackDepth;
75 
76  return *this;
77 }
78 
79 inline
80 void G4NavigationHistory::Reset()
81 {
82  fStackDepth=0;
83 }
84 
85 inline
86 void G4NavigationHistory::Clear()
87 {
88  G4AffineTransform origin(G4ThreeVector(0.,0.,0.));
89  G4NavigationLevel tmpNavLevel = G4NavigationLevel(0, origin, kNormal, -1) ;
90 
91  Reset();
92  for (G4int ilev=fNavHistory->size()-1; ilev>=0; ilev--)
93  {
94  (*fNavHistory)[ilev] = tmpNavLevel;
95  }
96 }
97 
98 inline
99 void G4NavigationHistory::SetFirstEntry(G4VPhysicalVolume* pVol)
100 {
101  G4ThreeVector translation(0.,0.,0.);
102  G4int copyNo = -1;
103 
104  // Protection needed in case pVol=null
105  // so that a touchable-history can signal OutOfWorld
106  //
107  if( pVol!=0 )
108  {
109  translation = pVol->GetTranslation();
110  copyNo = pVol->GetCopyNo();
111  }
112  (*fNavHistory)[0] =
113  G4NavigationLevel( pVol, G4AffineTransform(translation), kNormal, copyNo );
114 }
115 
116 inline
117 const G4AffineTransform* G4NavigationHistory::GetPtrTopTransform() const
118 {
119  return (*fNavHistory)[fStackDepth].GetPtrTransform();
120 }
121 
122 inline
123 const G4AffineTransform& G4NavigationHistory::GetTopTransform() const
124 {
125  return (*fNavHistory)[fStackDepth].GetTransform();
126 }
127 
128 inline
129 G4int G4NavigationHistory::GetTopReplicaNo() const
130 {
131  return (*fNavHistory)[fStackDepth].GetReplicaNo();
132 }
133 
134 inline
135 EVolume G4NavigationHistory::GetTopVolumeType() const
136 {
137  return (*fNavHistory)[fStackDepth].GetVolumeType();
138 }
139 
140 inline
141 G4VPhysicalVolume* G4NavigationHistory::GetTopVolume() const
142 {
143  return (*fNavHistory)[fStackDepth].GetPhysicalVolume();
144 }
145 
146 inline
147 G4int G4NavigationHistory::GetDepth() const
148 {
149  return fStackDepth;
150 }
151 
152 inline
153 const G4AffineTransform&
154 G4NavigationHistory::GetTransform(G4int n) const
155 {
156  return (*fNavHistory)[n].GetTransform();
157 }
158 
159 inline
160 G4int G4NavigationHistory::GetReplicaNo(G4int n) const
161 {
162  return (*fNavHistory)[n].GetReplicaNo();
163 }
164 
165 inline
166 EVolume G4NavigationHistory::GetVolumeType(G4int n) const
167 {
168  return (*fNavHistory)[n].GetVolumeType();
169 }
170 
171 inline
172 G4VPhysicalVolume* G4NavigationHistory::GetVolume(G4int n) const
173 {
174  return (*fNavHistory)[n].GetPhysicalVolume();
175 }
176 
177 inline
178 G4int G4NavigationHistory::GetMaxDepth() const
179 {
180  return fNavHistory->size();
181 }
182 
183 inline
184 void G4NavigationHistory::BackLevel()
185 {
186  assert( fStackDepth>0 );
187 
188  // Tell the level that I am forgetting it
189  // delete (*fNavHistory)[fStackDepth];
190  //
191  fStackDepth--;
192 }
193 
194 inline
195 void G4NavigationHistory::BackLevel(G4int n)
196 {
197  assert( n<=fStackDepth );
198  fStackDepth-=n;
199 }
200 
201 inline
202 void G4NavigationHistory::EnlargeHistory()
203 {
204  G4int len = fNavHistory->size();
205  if ( len==fStackDepth )
206  {
207  // Note: Resize operation clears additional entries
208  //
209  G4int nlen = len+kHistoryStride;
210  fNavHistory->resize(nlen);
211  }
212 }
213 
214 
215 inline
216 void G4NavigationHistory::NewLevel( G4VPhysicalVolume *pNewMother,
217  EVolume vType,
218  G4int nReplica )
219 {
220  fStackDepth++;
221  EnlargeHistory(); // Enlarge if required
222  (*fNavHistory)[fStackDepth] =
223  G4NavigationLevel( pNewMother,
224  (*fNavHistory)[fStackDepth-1].GetTransform(),
225  G4AffineTransform(pNewMother->GetRotation(),
226  pNewMother->GetTranslation()),
227  vType,
228  nReplica );
229  // The constructor computes the new global->local transform
230 }