Geant4 Cross Reference |
1 // 1 // 2 // ******************************************* 2 // ******************************************************************** 3 // * License and Disclaimer 3 // * License and Disclaimer * 4 // * 4 // * * 5 // * The Geant4 software is copyright of th 5 // * The Geant4 software is copyright of the Copyright Holders of * 6 // * the Geant4 Collaboration. It is provided 6 // * the Geant4 Collaboration. It is provided under the terms and * 7 // * conditions of the Geant4 Software License 7 // * conditions of the Geant4 Software License, included in the file * 8 // * LICENSE and available at http://cern.ch/ 8 // * LICENSE and available at http://cern.ch/geant4/license . These * 9 // * include a list of copyright holders. 9 // * include a list of copyright holders. * 10 // * 10 // * * 11 // * Neither the authors of this software syst 11 // * Neither the authors of this software system, nor their employing * 12 // * institutes,nor the agencies providing fin 12 // * institutes,nor the agencies providing financial support for this * 13 // * work make any representation or warran 13 // * work make any representation or warranty, express or implied, * 14 // * regarding this software system or assum 14 // * regarding this software system or assume any liability for its * 15 // * use. Please see the license in the file 15 // * use. Please see the license in the file LICENSE and URL above * 16 // * for the full disclaimer and the limitatio 16 // * for the full disclaimer and the limitation of liability. * 17 // * 17 // * * 18 // * This code implementation is the result 18 // * This code implementation is the result of the scientific and * 19 // * technical work of the GEANT4 collaboratio 19 // * technical work of the GEANT4 collaboration. * 20 // * By using, copying, modifying or distri 20 // * By using, copying, modifying or distributing the software (or * 21 // * any work based on the software) you ag 21 // * any work based on the software) you agree to acknowledge its * 22 // * use in resulting scientific publicati 22 // * use in resulting scientific publications, and indicate your * 23 // * acceptance of all terms of the Geant4 Sof 23 // * acceptance of all terms of the Geant4 Software license. * 24 // ******************************************* 24 // ******************************************************************** 25 // 25 // 26 // class G4NavigationHistory Inline implementa 26 // class G4NavigationHistory Inline implementation 27 // 27 // 28 // ------------------------------------------- 28 // ---------------------------------------------------------------------- 29 29 30 extern G4GEOM_DLL G4Allocator<G4NavigationHist 30 extern G4GEOM_DLL G4Allocator<G4NavigationHistory>*& aNavigHistoryAllocator(); 31 31 32 // There is no provision that this class is su 32 // There is no provision that this class is subclassed. 33 // If it is subclassed & new data members are 33 // If it is subclassed & new data members are added then the 34 // following "new" & "delete" will fail and gi 34 // following "new" & "delete" will fail and give errors. 35 // 35 // 36 inline 36 inline 37 void* G4NavigationHistory::operator new(std::s 37 void* G4NavigationHistory::operator new(std::size_t) 38 { 38 { 39 if (aNavigHistoryAllocator() == nullptr) 39 if (aNavigHistoryAllocator() == nullptr) 40 { 40 { 41 aNavigHistoryAllocator() = new G4Allocator 41 aNavigHistoryAllocator() = new G4Allocator<G4NavigationHistory>; 42 } 42 } 43 return (void *) aNavigHistoryAllocator()->Ma 43 return (void *) aNavigHistoryAllocator()->MallocSingle(); 44 } 44 } 45 45 46 inline 46 inline 47 void G4NavigationHistory::operator delete(void 47 void G4NavigationHistory::operator delete(void *aHistory) 48 { 48 { 49 aNavigHistoryAllocator()->FreeSingle((G4Navi 49 aNavigHistoryAllocator()->FreeSingle((G4NavigationHistory *) aHistory); 50 } 50 } 51 51 52 inline 52 inline 53 G4NavigationHistory& 53 G4NavigationHistory& 54 G4NavigationHistory::operator=(const G4Navigat 54 G4NavigationHistory::operator=(const G4NavigationHistory &h) 55 { 55 { 56 if (&h == this) { return *this; } 56 if (&h == this) { return *this; } 57 57 58 // *fNavHistory=*(h.fNavHistory); // This 58 // *fNavHistory=*(h.fNavHistory); // This works, but is very slow. 59 59 60 if( GetMaxDepth() != h.GetMaxDepth() ) 60 if( GetMaxDepth() != h.GetMaxDepth() ) 61 { 61 { 62 fNavHistory->resize( h.GetMaxDepth() ); 62 fNavHistory->resize( h.GetMaxDepth() ); 63 } 63 } 64 64 65 for ( auto ilev=G4int(h.fStackDepth); ilev> 65 for ( auto ilev=G4int(h.fStackDepth); ilev>=0; --ilev ) 66 { 66 { 67 (*fNavHistory)[ilev] = (*h.fNavHistory)[il 67 (*fNavHistory)[ilev] = (*h.fNavHistory)[ilev]; 68 } 68 } 69 fStackDepth = h.fStackDepth; 69 fStackDepth = h.fStackDepth; 70 70 71 return *this; 71 return *this; 72 } 72 } 73 73 74 inline 74 inline 75 void G4NavigationHistory::Reset() 75 void G4NavigationHistory::Reset() 76 { 76 { 77 fStackDepth=0; 77 fStackDepth=0; 78 } 78 } 79 79 80 inline 80 inline 81 void G4NavigationHistory::Clear() 81 void G4NavigationHistory::Clear() 82 { 82 { 83 G4AffineTransform origin(G4ThreeVector(0.,0. 83 G4AffineTransform origin(G4ThreeVector(0.,0.,0.)); 84 G4NavigationLevel tmpNavLevel = G4Navigation 84 G4NavigationLevel tmpNavLevel = G4NavigationLevel(nullptr, origin, kNormal, -1) ; 85 85 86 Reset(); 86 Reset(); 87 for (auto ilev=G4long(fNavHistory->size()-1 87 for (auto ilev=G4long(fNavHistory->size()-1); ilev>=0; --ilev) 88 { 88 { 89 (*fNavHistory)[ilev] = tmpNavLevel; 89 (*fNavHistory)[ilev] = tmpNavLevel; 90 } 90 } 91 } 91 } 92 92 93 inline 93 inline 94 void G4NavigationHistory::SetFirstEntry(G4VPhy 94 void G4NavigationHistory::SetFirstEntry(G4VPhysicalVolume* pVol) 95 { 95 { 96 G4ThreeVector translation(0.,0.,0.); 96 G4ThreeVector translation(0.,0.,0.); 97 G4int copyNo = -1; 97 G4int copyNo = -1; 98 98 99 // Protection needed in case pVol=null 99 // Protection needed in case pVol=null 100 // so that a touchable-history can signal Ou 100 // so that a touchable-history can signal OutOfWorld 101 // 101 // 102 if( pVol != nullptr ) 102 if( pVol != nullptr ) 103 { 103 { 104 translation = pVol->GetTranslation(); 104 translation = pVol->GetTranslation(); 105 copyNo = pVol->GetCopyNo(); 105 copyNo = pVol->GetCopyNo(); 106 } 106 } 107 (*fNavHistory)[0] = 107 (*fNavHistory)[0] = 108 G4NavigationLevel( pVol, G4AffineTransform 108 G4NavigationLevel( pVol, G4AffineTransform(translation), kNormal, copyNo ); 109 } 109 } 110 110 111 inline 111 inline 112 const G4AffineTransform* G4NavigationHistory:: 112 const G4AffineTransform* G4NavigationHistory::GetPtrTopTransform() const 113 { 113 { 114 return (*fNavHistory)[fStackDepth].GetPtrTra 114 return (*fNavHistory)[fStackDepth].GetPtrTransform(); 115 } 115 } 116 116 117 inline 117 inline 118 const G4AffineTransform& G4NavigationHistory:: 118 const G4AffineTransform& G4NavigationHistory::GetTopTransform() const 119 { 119 { 120 return (*fNavHistory)[fStackDepth].GetTransf 120 return (*fNavHistory)[fStackDepth].GetTransform(); 121 } 121 } 122 122 123 inline 123 inline 124 G4int G4NavigationHistory::GetTopReplicaNo() c 124 G4int G4NavigationHistory::GetTopReplicaNo() const 125 { 125 { 126 return (*fNavHistory)[fStackDepth].GetReplic 126 return (*fNavHistory)[fStackDepth].GetReplicaNo(); 127 } 127 } 128 128 129 inline 129 inline 130 EVolume G4NavigationHistory::GetTopVolumeType( 130 EVolume G4NavigationHistory::GetTopVolumeType() const 131 { 131 { 132 return (*fNavHistory)[fStackDepth].GetVolume 132 return (*fNavHistory)[fStackDepth].GetVolumeType(); 133 } 133 } 134 134 135 inline 135 inline 136 G4VPhysicalVolume* G4NavigationHistory::GetTop 136 G4VPhysicalVolume* G4NavigationHistory::GetTopVolume() const 137 { 137 { 138 return (*fNavHistory)[fStackDepth].GetPhysic 138 return (*fNavHistory)[fStackDepth].GetPhysicalVolume(); 139 } 139 } 140 140 141 inline 141 inline 142 std::size_t G4NavigationHistory::GetDepth() co 142 std::size_t G4NavigationHistory::GetDepth() const 143 { 143 { 144 return fStackDepth; 144 return fStackDepth; 145 } 145 } 146 146 147 inline 147 inline 148 const G4AffineTransform& 148 const G4AffineTransform& 149 G4NavigationHistory::GetTransform(G4int n) con 149 G4NavigationHistory::GetTransform(G4int n) const 150 { 150 { 151 return (*fNavHistory)[n].GetTransform(); 151 return (*fNavHistory)[n].GetTransform(); 152 } 152 } 153 153 154 inline 154 inline 155 G4int G4NavigationHistory::GetReplicaNo(G4int 155 G4int G4NavigationHistory::GetReplicaNo(G4int n) const 156 { 156 { 157 return (*fNavHistory)[n].GetReplicaNo(); 157 return (*fNavHistory)[n].GetReplicaNo(); 158 } 158 } 159 159 160 inline 160 inline 161 EVolume G4NavigationHistory::GetVolumeType(G4i 161 EVolume G4NavigationHistory::GetVolumeType(G4int n) const 162 { 162 { 163 return (*fNavHistory)[n].GetVolumeType(); 163 return (*fNavHistory)[n].GetVolumeType(); 164 } 164 } 165 165 166 inline 166 inline 167 G4VPhysicalVolume* G4NavigationHistory::GetVol 167 G4VPhysicalVolume* G4NavigationHistory::GetVolume(G4int n) const 168 { 168 { 169 return (*fNavHistory)[n].GetPhysicalVolume() 169 return (*fNavHistory)[n].GetPhysicalVolume(); 170 } 170 } 171 171 172 inline 172 inline 173 std::size_t G4NavigationHistory::GetMaxDepth() 173 std::size_t G4NavigationHistory::GetMaxDepth() const 174 { 174 { 175 return fNavHistory->size(); 175 return fNavHistory->size(); 176 } 176 } 177 177 178 inline 178 inline 179 void G4NavigationHistory::BackLevel() 179 void G4NavigationHistory::BackLevel() 180 { 180 { 181 assert( fStackDepth>0 ); 181 assert( fStackDepth>0 ); 182 182 183 // Tell the level that I am forgetting it 183 // Tell the level that I am forgetting it 184 // delete (*fNavHistory)[fStackDepth]; 184 // delete (*fNavHistory)[fStackDepth]; 185 // 185 // 186 --fStackDepth; 186 --fStackDepth; 187 } 187 } 188 188 189 inline 189 inline 190 void G4NavigationHistory::BackLevel(G4int n) 190 void G4NavigationHistory::BackLevel(G4int n) 191 { 191 { 192 assert( n<=G4int(fStackDepth) ); 192 assert( n<=G4int(fStackDepth) ); 193 fStackDepth-=n; 193 fStackDepth-=n; 194 } 194 } 195 195 196 inline 196 inline 197 void G4NavigationHistory::EnlargeHistory() 197 void G4NavigationHistory::EnlargeHistory() 198 { 198 { 199 std::size_t len = fNavHistory->size(); 199 std::size_t len = fNavHistory->size(); 200 if ( len == fStackDepth ) 200 if ( len == fStackDepth ) 201 { 201 { 202 // Note: Resize operation clears additiona 202 // Note: Resize operation clears additional entries 203 // 203 // 204 std::size_t nlen = len+kHistoryStride; 204 std::size_t nlen = len+kHistoryStride; 205 fNavHistory->resize(nlen); 205 fNavHistory->resize(nlen); 206 } 206 } 207 } 207 } 208 208 209 209 210 inline 210 inline 211 void G4NavigationHistory::NewLevel( G4VPhysica 211 void G4NavigationHistory::NewLevel( G4VPhysicalVolume* pNewMother, 212 EVolume vT 212 EVolume vType, 213 G4int nRep 213 G4int nReplica ) 214 { 214 { 215 ++fStackDepth; 215 ++fStackDepth; 216 EnlargeHistory(); // Enlarge if required 216 EnlargeHistory(); // Enlarge if required 217 (*fNavHistory)[fStackDepth] = 217 (*fNavHistory)[fStackDepth] = 218 G4NavigationLevel( pNewMother, 218 G4NavigationLevel( pNewMother, 219 (*fNavHistory)[fStackDe 219 (*fNavHistory)[fStackDepth-1].GetTransform(), 220 G4AffineTransform(pNewM 220 G4AffineTransform(pNewMother->GetRotation(), 221 pNewMother->GetTranslat 221 pNewMother->GetTranslation()), 222 vType, 222 vType, 223 nReplica ); 223 nReplica ); 224 // The constructor computes the new global-> 224 // The constructor computes the new global->local transform 225 } 225 } 226 226