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 // ********************************************************************
27 // $Id: G4TouchableHistory.icc 86527 2014-11-13 15:06:24Z gcosmo $
30 // class G4TouchableHistory inline implementation
31 // ----------------------------------------------------------------------
33 extern G4GEOM_DLL G4ThreadLocal G4Allocator<G4TouchableHistory> *aTouchableHistoryAllocator;
36 void G4TouchableHistory::UpdateYourself( G4VPhysicalVolume* pPhysVol,
37 const G4NavigationHistory* pHistory )
40 G4AffineTransform tf(fhistory.GetTopTransform().Inverse());
43 // This means that the track has left the World Volume.
44 // Since the Navigation History does not already reflect this,
45 // we must correct this problem here.
47 fhistory.SetFirstEntry(pPhysVol);
49 ftlate = tf.NetTranslation();
50 frot = tf.NetRotation();
54 G4int G4TouchableHistory::CalculateHistoryIndex( G4int stackDepth ) const
56 return (fhistory.GetDepth()-stackDepth); // was -1
60 G4VPhysicalVolume* G4TouchableHistory::GetVolume( G4int depth ) const
62 return fhistory.GetVolume(CalculateHistoryIndex(depth));
66 G4VSolid* G4TouchableHistory::GetSolid( G4int depth ) const
68 return fhistory.GetVolume(CalculateHistoryIndex(depth))
69 ->GetLogicalVolume()->GetSolid();
73 G4int G4TouchableHistory::GetReplicaNumber( G4int depth ) const
75 return fhistory.GetReplicaNo(CalculateHistoryIndex(depth));
79 G4int G4TouchableHistory::GetHistoryDepth() const
81 return fhistory.GetDepth();
85 G4int G4TouchableHistory::MoveUpHistory( G4int num_levels )
87 G4int maxLevelsMove = fhistory.GetDepth();
88 G4int minLevelsMove = 0; // Cannot redescend today!
89 // Soon it will be possible
90 // by adding a data member here
92 if( num_levels > maxLevelsMove )
94 num_levels = maxLevelsMove;
96 else if( num_levels < minLevelsMove )
98 num_levels = minLevelsMove;
100 fhistory.BackLevel( num_levels );
106 const G4NavigationHistory* G4TouchableHistory::GetHistory() const
111 // There is no provision in case this class is subclassed.
112 // If it is subclassed, this will fail and may not give errors!
115 void* G4TouchableHistory::operator new(size_t)
117 // Once the Navigator calls InitializeAllocator,
118 // the if block below can be removed.
120 if (!aTouchableHistoryAllocator)
122 aTouchableHistoryAllocator = new G4Allocator<G4TouchableHistory>;
124 return (void *) aTouchableHistoryAllocator->MallocSingle();
128 void G4TouchableHistory::operator delete(void *aTH)
130 aTouchableHistoryAllocator->FreeSingle((G4TouchableHistory *) aTH);