Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-09-21 09:10:45

0001 //
0002 // ********************************************************************
0003 // * License and Disclaimer                                           *
0004 // *                                                                  *
0005 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
0006 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
0007 // * conditions of the Geant4 Software License,  included in the file *
0008 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
0009 // * include a list of copyright holders.                             *
0010 // *                                                                  *
0011 // * Neither the authors of this software system, nor their employing *
0012 // * institutes,nor the agencies providing financial support for this *
0013 // * work  make  any representation or  warranty, express or implied, *
0014 // * regarding  this  software system or assume any liability for its *
0015 // * use.  Please see the license in the file  LICENSE  and URL above *
0016 // * for the full disclaimer and the limitation of liability.         *
0017 // *                                                                  *
0018 // * This  code  implementation is the result of  the  scientific and *
0019 // * technical work of the GEANT4 collaboration.                      *
0020 // * By using,  copying,  modifying or  distributing the software (or *
0021 // * any work based  on the software)  you  agree  to acknowledge its *
0022 // * use  in  resulting  scientific  publications,  and indicate your *
0023 // * acceptance of all terms of the Geant4 Software license.          *
0024 // ********************************************************************
0025 //
0026 // G4NavigationHistory Inline implementation
0027 //
0028 // Author: Paul Kent (CERN), 25.07.1996 - Initial version.
0029 // ----------------------------------------------------------------------
0030 
0031 extern G4GEOM_DLL G4Allocator<G4NavigationHistory>*& aNavigHistoryAllocator();
0032 
0033 // There is no provision that this class is subclassed.
0034 // If it is subclassed & new data members are added then the
0035 // following "new" & "delete" will fail and give errors. 
0036 //
0037 inline
0038 void* G4NavigationHistory::operator new(std::size_t)
0039 {
0040   if (aNavigHistoryAllocator() == nullptr)
0041   {
0042     aNavigHistoryAllocator() = new G4Allocator<G4NavigationHistory>;
0043   }
0044   return (void *) aNavigHistoryAllocator()->MallocSingle();
0045 }
0046 
0047 inline
0048 void G4NavigationHistory::operator delete(void *aHistory)
0049 {
0050   aNavigHistoryAllocator()->FreeSingle((G4NavigationHistory *) aHistory);
0051 }
0052 
0053 inline
0054 G4NavigationHistory&
0055 G4NavigationHistory::operator=(const G4NavigationHistory &h)
0056 {
0057   if (&h == this)  { return *this; }
0058 
0059   // *fNavHistory=*(h.fNavHistory);   // This works, but is very slow.
0060 
0061   if( GetMaxDepth() != h.GetMaxDepth() )
0062   {
0063     fNavHistory->resize( h.GetMaxDepth() );
0064   }
0065 
0066   for ( auto  ilev=G4int(h.fStackDepth); ilev>=0; --ilev )
0067   { 
0068     (*fNavHistory)[ilev] = (*h.fNavHistory)[ilev];
0069   }
0070   fStackDepth = h.fStackDepth;
0071 
0072   return *this;
0073 }
0074 
0075 inline
0076 void G4NavigationHistory::Reset()
0077 {
0078   fStackDepth=0;
0079 }
0080 
0081 inline
0082 void G4NavigationHistory::Clear()
0083 {
0084   G4AffineTransform origin(G4ThreeVector(0.,0.,0.));
0085   G4NavigationLevel tmpNavLevel = G4NavigationLevel(nullptr, origin, kNormal, -1) ;
0086 
0087   Reset();
0088   for (auto  ilev=G4long(fNavHistory->size()-1); ilev>=0; --ilev)
0089   {
0090      (*fNavHistory)[ilev] = tmpNavLevel;
0091   }
0092 }
0093 
0094 inline
0095 void G4NavigationHistory::SetFirstEntry(G4VPhysicalVolume* pVol)
0096 {
0097   G4ThreeVector translation(0.,0.,0.);
0098   G4int copyNo = -1;
0099 
0100   // Protection needed in case pVol=null 
0101   // so that a touchable-history can signal OutOfWorld 
0102   //
0103   if( pVol != nullptr )
0104   {
0105     translation = pVol->GetTranslation();
0106     copyNo = pVol->GetCopyNo();
0107   }
0108   (*fNavHistory)[0] =
0109     G4NavigationLevel( pVol, G4AffineTransform(translation), kNormal, copyNo );
0110 }
0111 
0112 inline
0113 const G4AffineTransform* G4NavigationHistory::GetPtrTopTransform() const
0114 {
0115   return (*fNavHistory)[fStackDepth].GetPtrTransform();
0116 }
0117 
0118 inline
0119 const G4AffineTransform& G4NavigationHistory::GetTopTransform() const
0120 {
0121   return (*fNavHistory)[fStackDepth].GetTransform();
0122 }
0123 
0124 inline
0125 G4int G4NavigationHistory::GetTopReplicaNo() const
0126 {
0127   return (*fNavHistory)[fStackDepth].GetReplicaNo();
0128 }
0129 
0130 inline
0131 EVolume G4NavigationHistory::GetTopVolumeType() const
0132 {
0133   return (*fNavHistory)[fStackDepth].GetVolumeType();
0134 }
0135 
0136 inline
0137 G4VPhysicalVolume* G4NavigationHistory::GetTopVolume() const
0138 {
0139   return (*fNavHistory)[fStackDepth].GetPhysicalVolume();
0140 }
0141 
0142 inline
0143 std::size_t G4NavigationHistory::GetDepth() const
0144 {
0145   return fStackDepth;
0146 }
0147 
0148 inline
0149 const G4AffineTransform&
0150 G4NavigationHistory::GetTransform(G4int n) const
0151 {
0152   return (*fNavHistory)[n].GetTransform();
0153 }
0154 
0155 inline
0156 G4int G4NavigationHistory::GetReplicaNo(G4int n) const
0157 {
0158   return (*fNavHistory)[n].GetReplicaNo();
0159 }
0160 
0161 inline
0162 EVolume G4NavigationHistory::GetVolumeType(G4int n) const
0163 {
0164   return (*fNavHistory)[n].GetVolumeType();
0165 }
0166 
0167 inline
0168 G4VPhysicalVolume* G4NavigationHistory::GetVolume(G4int n) const
0169 {
0170   return (*fNavHistory)[n].GetPhysicalVolume();
0171 }
0172 
0173 inline
0174 std::size_t G4NavigationHistory::GetMaxDepth() const
0175 {
0176   return fNavHistory->size();
0177 }
0178 
0179 inline
0180 void G4NavigationHistory::BackLevel()
0181 {
0182   assert( fStackDepth>0 );
0183 
0184   // Tell  the  level  that I am forgetting it
0185   // delete (*fNavHistory)[fStackDepth];
0186   //
0187   --fStackDepth;
0188 }
0189 
0190 inline
0191 void G4NavigationHistory::BackLevel(G4int n)
0192 {
0193   assert( n<=G4int(fStackDepth) );
0194   fStackDepth-=n;
0195 }
0196 
0197 inline
0198 void G4NavigationHistory::EnlargeHistory()
0199 {
0200   std::size_t len = fNavHistory->size();
0201   if ( len == fStackDepth )
0202   {
0203     // Note: Resize operation clears additional entries
0204     //
0205     std::size_t nlen = len+kHistoryStride;
0206     fNavHistory->resize(nlen);
0207   }  
0208 }
0209 
0210 
0211 inline
0212 void G4NavigationHistory::NewLevel( G4VPhysicalVolume* pNewMother,
0213                                     EVolume vType,
0214                                     G4int nReplica )
0215 {
0216   ++fStackDepth;
0217   EnlargeHistory();  // Enlarge if required
0218   (*fNavHistory)[fStackDepth] =
0219     G4NavigationLevel( pNewMother, 
0220                        (*fNavHistory)[fStackDepth-1].GetTransform(),
0221                        G4AffineTransform(pNewMother->GetRotation(),
0222                        pNewMother->GetTranslation()),
0223                        vType,
0224                        nReplica ); 
0225   // The constructor computes the new global->local transform
0226 }