Files
geant4/source/geometry/management/include/G4NavigationHistory.icc
T
2025-12-05 08:54:02 +01:00

227 lines
6.1 KiB
Plaintext

//
// ********************************************************************
// * License and Disclaimer *
// * *
// * The Geant4 software is copyright of the Copyright Holders of *
// * the Geant4 Collaboration. It is provided under the terms and *
// * conditions of the Geant4 Software License, included in the file *
// * LICENSE and available at http://cern.ch/geant4/license . These *
// * include a list of copyright holders. *
// * *
// * Neither the authors of this software system, nor their employing *
// * institutes,nor the agencies providing financial support for this *
// * work make any representation or warranty, express or implied, *
// * regarding this software system or assume any liability for its *
// * use. Please see the license in the file LICENSE and URL above *
// * for the full disclaimer and the limitation of liability. *
// * *
// * This code implementation is the result of the scientific and *
// * technical work of the GEANT4 collaboration. *
// * By using, copying, modifying or distributing the software (or *
// * any work based on the software) you agree to acknowledge its *
// * use in resulting scientific publications, and indicate your *
// * acceptance of all terms of the Geant4 Software license. *
// ********************************************************************
//
// G4NavigationHistory Inline implementation
//
// Author: Paul Kent (CERN), 25.07.1996 - Initial version.
// ----------------------------------------------------------------------
extern G4GEOM_DLL G4Allocator<G4NavigationHistory>*& aNavigHistoryAllocator();
// There is no provision that this class is subclassed.
// If it is subclassed & new data members are added then the
// following "new" & "delete" will fail and give errors.
//
inline
void* G4NavigationHistory::operator new(std::size_t)
{
if (aNavigHistoryAllocator() == nullptr)
{
aNavigHistoryAllocator() = new G4Allocator<G4NavigationHistory>;
}
return (void *) aNavigHistoryAllocator()->MallocSingle();
}
inline
void G4NavigationHistory::operator delete(void *aHistory)
{
aNavigHistoryAllocator()->FreeSingle((G4NavigationHistory *) aHistory);
}
inline
G4NavigationHistory&
G4NavigationHistory::operator=(const G4NavigationHistory &h)
{
if (&h == this) { return *this; }
// *fNavHistory=*(h.fNavHistory); // This works, but is very slow.
if( GetMaxDepth() != h.GetMaxDepth() )
{
fNavHistory->resize( h.GetMaxDepth() );
}
for ( auto ilev=G4int(h.fStackDepth); ilev>=0; --ilev )
{
(*fNavHistory)[ilev] = (*h.fNavHistory)[ilev];
}
fStackDepth = h.fStackDepth;
return *this;
}
inline
void G4NavigationHistory::Reset()
{
fStackDepth=0;
}
inline
void G4NavigationHistory::Clear()
{
G4AffineTransform origin(G4ThreeVector(0.,0.,0.));
G4NavigationLevel tmpNavLevel = G4NavigationLevel(nullptr, origin, kNormal, -1) ;
Reset();
for (auto ilev=G4long(fNavHistory->size()-1); ilev>=0; --ilev)
{
(*fNavHistory)[ilev] = tmpNavLevel;
}
}
inline
void G4NavigationHistory::SetFirstEntry(G4VPhysicalVolume* pVol)
{
G4ThreeVector translation(0.,0.,0.);
G4int copyNo = -1;
// Protection needed in case pVol=null
// so that a touchable-history can signal OutOfWorld
//
if( pVol != nullptr )
{
translation = pVol->GetTranslation();
copyNo = pVol->GetCopyNo();
}
(*fNavHistory)[0] =
G4NavigationLevel( pVol, G4AffineTransform(translation), kNormal, copyNo );
}
inline
const G4AffineTransform* G4NavigationHistory::GetPtrTopTransform() const
{
return (*fNavHistory)[fStackDepth].GetPtrTransform();
}
inline
const G4AffineTransform& G4NavigationHistory::GetTopTransform() const
{
return (*fNavHistory)[fStackDepth].GetTransform();
}
inline
G4int G4NavigationHistory::GetTopReplicaNo() const
{
return (*fNavHistory)[fStackDepth].GetReplicaNo();
}
inline
EVolume G4NavigationHistory::GetTopVolumeType() const
{
return (*fNavHistory)[fStackDepth].GetVolumeType();
}
inline
G4VPhysicalVolume* G4NavigationHistory::GetTopVolume() const
{
return (*fNavHistory)[fStackDepth].GetPhysicalVolume();
}
inline
std::size_t G4NavigationHistory::GetDepth() const
{
return fStackDepth;
}
inline
const G4AffineTransform&
G4NavigationHistory::GetTransform(G4int n) const
{
return (*fNavHistory)[n].GetTransform();
}
inline
G4int G4NavigationHistory::GetReplicaNo(G4int n) const
{
return (*fNavHistory)[n].GetReplicaNo();
}
inline
EVolume G4NavigationHistory::GetVolumeType(G4int n) const
{
return (*fNavHistory)[n].GetVolumeType();
}
inline
G4VPhysicalVolume* G4NavigationHistory::GetVolume(G4int n) const
{
return (*fNavHistory)[n].GetPhysicalVolume();
}
inline
std::size_t G4NavigationHistory::GetMaxDepth() const
{
return fNavHistory->size();
}
inline
void G4NavigationHistory::BackLevel()
{
assert( fStackDepth>0 );
// Tell the level that I am forgetting it
// delete (*fNavHistory)[fStackDepth];
//
--fStackDepth;
}
inline
void G4NavigationHistory::BackLevel(G4int n)
{
assert( n<=G4int(fStackDepth) );
fStackDepth-=n;
}
inline
void G4NavigationHistory::EnlargeHistory()
{
std::size_t len = fNavHistory->size();
if ( len == fStackDepth )
{
// Note: Resize operation clears additional entries
//
std::size_t nlen = len+kHistoryStride;
fNavHistory->resize(nlen);
}
}
inline
void G4NavigationHistory::NewLevel( G4VPhysicalVolume* pNewMother,
EVolume vType,
G4int nReplica )
{
++fStackDepth;
EnlargeHistory(); // Enlarge if required
(*fNavHistory)[fStackDepth] =
G4NavigationLevel( pNewMother,
(*fNavHistory)[fStackDepth-1].GetTransform(),
G4AffineTransform(pNewMother->GetRotation(),
pNewMother->GetTranslation()),
vType,
nReplica );
// The constructor computes the new global->local transform
}