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 G4TouchableHistory inline implementation
28// Created: Paul Kent, August 1996
29// ----------------------------------------------------------------------
31extern G4GEOM_DLL G4Allocator<G4TouchableHistory>*& aTouchableHistoryAllocator();
34void G4TouchableHistory::UpdateYourself( G4VPhysicalVolume* pPhysVol,
35 const G4NavigationHistory* pHistory )
38 const G4AffineTransform& tf = fhistory.GetTopTransform();
39 if( pPhysVol == nullptr )
41 // This means that the track has left the World Volume.
42 // Since the Navigation History does not already reflect this,
43 // we must correct this problem here.
45 fhistory.SetFirstEntry(pPhysVol);
47 ftlate = tf.InverseNetTranslation();
48 frot = tf.InverseNetRotation();
52G4int G4TouchableHistory::CalculateHistoryIndex( G4int stackDepth ) const
54 return G4int(fhistory.GetDepth()-stackDepth); // was -1
58G4VPhysicalVolume* G4TouchableHistory::GetVolume( G4int depth ) const
60 return fhistory.GetVolume(CalculateHistoryIndex(depth));
64G4VSolid* G4TouchableHistory::GetSolid( G4int depth ) const
66 return fhistory.GetVolume(CalculateHistoryIndex(depth))
67 ->GetLogicalVolume()->GetSolid();
71G4int G4TouchableHistory::GetReplicaNumber( G4int depth ) const
73 return fhistory.GetReplicaNo(CalculateHistoryIndex(depth));
77G4int G4TouchableHistory::GetHistoryDepth() const
79 return G4int(fhistory.GetDepth());
83G4int G4TouchableHistory::MoveUpHistory( G4int num_levels )
85 G4int maxLevelsMove = G4int(fhistory.GetDepth());
86 G4int minLevelsMove = 0; // Cannot redescend today!
87 // Soon it will be possible
88 // by adding a data member here
90 if( num_levels > maxLevelsMove )
92 num_levels = maxLevelsMove;
94 else if( num_levels < minLevelsMove )
96 num_levels = minLevelsMove;
98 fhistory.BackLevel( num_levels );
104const G4NavigationHistory* G4TouchableHistory::GetHistory() const
109// There is no provision in case this class is subclassed.
110// If it is subclassed, this will fail and may not give errors!
113void* G4TouchableHistory::operator new(size_t)
115 // Once the Navigator calls InitializeAllocator,
116 // the if block below can be removed.
118 if (aTouchableHistoryAllocator() == nullptr)
120 aTouchableHistoryAllocator() = new G4Allocator<G4TouchableHistory>;
122 return (void *) aTouchableHistoryAllocator()->MallocSingle();
126void G4TouchableHistory::operator delete(void* aTH)
128 aTouchableHistoryAllocator()->FreeSingle((G4TouchableHistory *) aTH);