Geant4  10.03
G4TouchableHistory.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: G4TouchableHistory.icc 86527 2014-11-13 15:06:24Z gcosmo $
28 //
29 //
30 // class G4TouchableHistory inline implementation
31 // ----------------------------------------------------------------------
32 
33 extern G4GEOM_DLL G4ThreadLocal G4Allocator<G4TouchableHistory> *aTouchableHistoryAllocator;
34 
35 inline
36 void G4TouchableHistory::UpdateYourself( G4VPhysicalVolume* pPhysVol,
37  const G4NavigationHistory* pHistory )
38 {
39  fhistory = *pHistory;
40  G4AffineTransform tf(fhistory.GetTopTransform().Inverse());
41  if( pPhysVol == 0 )
42  {
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.
46  //
47  fhistory.SetFirstEntry(pPhysVol);
48  }
49  ftlate = tf.NetTranslation();
50  frot = tf.NetRotation();
51 }
52 
53 inline
54 G4int G4TouchableHistory::CalculateHistoryIndex( G4int stackDepth ) const
55 {
56  return (fhistory.GetDepth()-stackDepth); // was -1
57 }
58 
59 inline
60 G4VPhysicalVolume* G4TouchableHistory::GetVolume( G4int depth ) const
61 {
62  return fhistory.GetVolume(CalculateHistoryIndex(depth));
63 }
64 
65 inline
66 G4VSolid* G4TouchableHistory::GetSolid( G4int depth ) const
67 {
68  return fhistory.GetVolume(CalculateHistoryIndex(depth))
69  ->GetLogicalVolume()->GetSolid();
70 }
71 
72 inline
73 G4int G4TouchableHistory::GetReplicaNumber( G4int depth ) const
74 {
75  return fhistory.GetReplicaNo(CalculateHistoryIndex(depth));
76 }
77 
78 inline
79 G4int G4TouchableHistory::GetHistoryDepth() const
80 {
81  return fhistory.GetDepth();
82 }
83 
84 inline
85 G4int G4TouchableHistory::MoveUpHistory( G4int num_levels )
86 {
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
91  // fCurrentDepth;
92  if( num_levels > maxLevelsMove )
93  {
94  num_levels = maxLevelsMove;
95  }
96  else if( num_levels < minLevelsMove )
97  {
98  num_levels = minLevelsMove;
99  }
100  fhistory.BackLevel( num_levels );
101 
102  return num_levels;
103 }
104 
105 inline
106 const G4NavigationHistory* G4TouchableHistory::GetHistory() const
107 {
108  return &fhistory;
109 }
110 
111 // There is no provision in case this class is subclassed.
112 // If it is subclassed, this will fail and may not give errors!
113 //
114 inline
115 void* G4TouchableHistory::operator new(size_t)
116 {
117  // Once the Navigator calls InitializeAllocator,
118  // the if block below can be removed.
119  //
120  if (!aTouchableHistoryAllocator)
121  {
122  aTouchableHistoryAllocator = new G4Allocator<G4TouchableHistory>;
123  }
124  return (void *) aTouchableHistoryAllocator->MallocSingle();
125 }
126 
127 inline
128 void G4TouchableHistory::operator delete(void *aTH)
129 {
130  aTouchableHistoryAllocator->FreeSingle((G4TouchableHistory *) aTH);
131 }
132