2// ********************************************************************
3// * License and Disclaimer *
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. *
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. *
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// ********************************************************************
26// class G4NavigationHistory Inline implementation
28// ----------------------------------------------------------------------
30extern G4GEOM_DLL G4Allocator<G4NavigationHistory>*& aNavigHistoryAllocator();
32// There is no provision that this class is subclassed.
33// If it is subclassed & new data members are added then the
34// following "new" & "delete" will fail and give errors.
37void* G4NavigationHistory::operator new(size_t)
39 if (aNavigHistoryAllocator() == nullptr)
41 aNavigHistoryAllocator() = new G4Allocator<G4NavigationHistory>;
43 return (void *) aNavigHistoryAllocator()->MallocSingle();
47void G4NavigationHistory::operator delete(void *aHistory)
49 aNavigHistoryAllocator()->FreeSingle((G4NavigationHistory *) aHistory);
54G4NavigationHistory::operator=(const G4NavigationHistory &h)
56 if (&h == this) { return *this; }
58 // *fNavHistory=*(h.fNavHistory); // This works, but is very slow.
60 if( GetMaxDepth() != h.GetMaxDepth() )
62 fNavHistory->resize( h.GetMaxDepth() );
65 for ( G4int ilev=G4int(h.fStackDepth); ilev>=0; --ilev )
67 (*fNavHistory)[ilev] = (*h.fNavHistory)[ilev];
69 fStackDepth = h.fStackDepth;
75void G4NavigationHistory::Reset()
81void G4NavigationHistory::Clear()
83 G4AffineTransform origin(G4ThreeVector(0.,0.,0.));
84 G4NavigationLevel tmpNavLevel = G4NavigationLevel(0, origin, kNormal, -1) ;
87 for (G4long ilev=G4long(fNavHistory->size()-1); ilev>=0; --ilev)
89 (*fNavHistory)[ilev] = tmpNavLevel;
94void G4NavigationHistory::SetFirstEntry(G4VPhysicalVolume* pVol)
96 G4ThreeVector translation(0.,0.,0.);
99 // Protection needed in case pVol=null
100 // so that a touchable-history can signal OutOfWorld
102 if( pVol != nullptr )
104 translation = pVol->GetTranslation();
105 copyNo = pVol->GetCopyNo();
108 G4NavigationLevel( pVol, G4AffineTransform(translation), kNormal, copyNo );
112const G4AffineTransform* G4NavigationHistory::GetPtrTopTransform() const
114 return (*fNavHistory)[fStackDepth].GetPtrTransform();
118const G4AffineTransform& G4NavigationHistory::GetTopTransform() const
120 return (*fNavHistory)[fStackDepth].GetTransform();
124G4int G4NavigationHistory::GetTopReplicaNo() const
126 return (*fNavHistory)[fStackDepth].GetReplicaNo();
130EVolume G4NavigationHistory::GetTopVolumeType() const
132 return (*fNavHistory)[fStackDepth].GetVolumeType();
136G4VPhysicalVolume* G4NavigationHistory::GetTopVolume() const
138 return (*fNavHistory)[fStackDepth].GetPhysicalVolume();
142size_t G4NavigationHistory::GetDepth() const
148const G4AffineTransform&
149G4NavigationHistory::GetTransform(G4int n) const
151 return (*fNavHistory)[n].GetTransform();
155G4int G4NavigationHistory::GetReplicaNo(G4int n) const
157 return (*fNavHistory)[n].GetReplicaNo();
161EVolume G4NavigationHistory::GetVolumeType(G4int n) const
163 return (*fNavHistory)[n].GetVolumeType();
167G4VPhysicalVolume* G4NavigationHistory::GetVolume(G4int n) const
169 return (*fNavHistory)[n].GetPhysicalVolume();
173size_t G4NavigationHistory::GetMaxDepth() const
175 return fNavHistory->size();
179void G4NavigationHistory::BackLevel()
181 assert( fStackDepth>0 );
183 // Tell the level that I am forgetting it
184 // delete (*fNavHistory)[fStackDepth];
190void G4NavigationHistory::BackLevel(G4int n)
192 assert( n<=G4int(fStackDepth) );
197void G4NavigationHistory::EnlargeHistory()
199 size_t len = fNavHistory->size();
200 if ( len == fStackDepth )
202 // Note: Resize operation clears additional entries
204 size_t nlen = len+kHistoryStride;
205 fNavHistory->resize(nlen);
211void G4NavigationHistory::NewLevel( G4VPhysicalVolume* pNewMother,
216 EnlargeHistory(); // Enlarge if required
217 (*fNavHistory)[fStackDepth] =
218 G4NavigationLevel( pNewMother,
219 (*fNavHistory)[fStackDepth-1].GetTransform(),
220 G4AffineTransform(pNewMother->GetRotation(),
221 pNewMother->GetTranslation()),
224 // The constructor computes the new global->local transform