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 // G4TrackStack class implementation << 27 // 26 // 28 // Author: Makoto Asai (SLAC) << 27 // $Id: G4TrackStack.cc,v 1.6 2006/06/29 18:10:26 gunter Exp $ 29 // ------------------------------------------- << 28 // GEANT4 tag $Name: geant4-08-03-patch-01 $ >> 29 // 30 30 31 #include "G4TrackStack.hh" 31 #include "G4TrackStack.hh" 32 #include "G4SmartTrackStack.hh" << 33 #include "G4VTrajectory.hh" 32 #include "G4VTrajectory.hh" 34 #include "G4Track.hh" << 33 >> 34 G4TrackStack::G4TrackStack() >> 35 :n_stackedTrack(0),firstStackedTrack(0),lastStackedTrack(0) >> 36 {;} 35 37 36 G4TrackStack::~G4TrackStack() 38 G4TrackStack::~G4TrackStack() 37 { 39 { 38 clearAndDestroy(); << 40 if( n_stackedTrack != 0 ) >> 41 { >> 42 G4StackedTrack * aStackedTrack = firstStackedTrack; >> 43 G4StackedTrack * nextStackedTrack; >> 44 >> 45 // delete tracks in the stack >> 46 while( aStackedTrack != 0 ) >> 47 { >> 48 nextStackedTrack = aStackedTrack->GetNext(); >> 49 delete aStackedTrack->GetTrack(); >> 50 delete aStackedTrack->GetTrajectory(); >> 51 delete aStackedTrack; >> 52 aStackedTrack = nextStackedTrack; >> 53 } >> 54 } >> 55 } >> 56 >> 57 const G4TrackStack & G4TrackStack::operator=(const G4TrackStack &right) >> 58 { >> 59 n_stackedTrack = right.n_stackedTrack; >> 60 firstStackedTrack = right.firstStackedTrack; >> 61 lastStackedTrack = right.lastStackedTrack; >> 62 return *this; 39 } 63 } 40 64 41 void G4TrackStack::clearAndDestroy() << 65 int G4TrackStack::operator==(const G4TrackStack &right) const >> 66 { return (firstStackedTrack==right.firstStackedTrack); } >> 67 int G4TrackStack::operator!=(const G4TrackStack &right) const >> 68 { return (firstStackedTrack!=right.firstStackedTrack); } >> 69 >> 70 void G4TrackStack::TransferTo(G4TrackStack * aStack) 42 { 71 { 43 for(auto & i : *this) << 72 if(n_stackedTrack==0) return; >> 73 >> 74 if(aStack->n_stackedTrack == 0) >> 75 { >> 76 *aStack = *this; >> 77 } >> 78 else 44 { 79 { 45 delete i.GetTrack(); << 80 aStack->lastStackedTrack->SetNext( firstStackedTrack ); 46 delete i.GetTrajectory(); << 81 firstStackedTrack->SetPrevious( aStack->lastStackedTrack ); >> 82 aStack->lastStackedTrack = lastStackedTrack; >> 83 aStack->n_stackedTrack += n_stackedTrack; 47 } 84 } 48 clear(); << 85 >> 86 n_stackedTrack = 0; >> 87 firstStackedTrack = 0; >> 88 lastStackedTrack = 0; >> 89 } >> 90 >> 91 G4StackedTrack * G4TrackStack::PopFromStack() >> 92 { >> 93 if( n_stackedTrack == 0 ) return 0; >> 94 G4StackedTrack * aStackedTrack = lastStackedTrack; >> 95 GrabFromStack( aStackedTrack ); >> 96 return aStackedTrack; 49 } 97 } 50 98 51 void G4TrackStack::TransferTo(G4TrackStack* aS << 99 void G4TrackStack::PushToStack( G4StackedTrack * aStackedTrack ) 52 { 100 { 53 for(auto & i : *this) << 101 if( n_stackedTrack == 0 ) >> 102 { >> 103 aStackedTrack->SetPrevious( 0 ); >> 104 firstStackedTrack = aStackedTrack; >> 105 } >> 106 else 54 { 107 { 55 aStack->push_back(i); << 108 lastStackedTrack->SetNext( aStackedTrack ); >> 109 aStackedTrack->SetPrevious( lastStackedTrack ); 56 } 110 } 57 clear(); << 111 lastStackedTrack = aStackedTrack; >> 112 n_stackedTrack++; 58 } 113 } 59 114 60 void G4TrackStack::TransferTo(G4SmartTrackStac << 115 void G4TrackStack::GrabFromStack( G4StackedTrack * aStackedTrack ) 61 { 116 { 62 while (!this->empty()) << 117 if( n_stackedTrack == 1 ) 63 { 118 { 64 aStack->PushToStack(PopFromStack()); << 119 firstStackedTrack = 0; >> 120 lastStackedTrack = 0; 65 } 121 } >> 122 else >> 123 { >> 124 if( aStackedTrack == firstStackedTrack ) >> 125 { >> 126 firstStackedTrack = aStackedTrack->GetNext(); >> 127 firstStackedTrack->SetPrevious( 0 ); >> 128 } >> 129 else >> 130 { >> 131 if( aStackedTrack == lastStackedTrack ) >> 132 { >> 133 lastStackedTrack = aStackedTrack->GetPrevious(); >> 134 lastStackedTrack->SetNext( 0 ); >> 135 } >> 136 else >> 137 { >> 138 aStackedTrack->GetPrevious() >> 139 ->SetNext( aStackedTrack->GetNext() ); >> 140 aStackedTrack->GetNext() >> 141 ->SetPrevious( aStackedTrack->GetPrevious() ); >> 142 } >> 143 } >> 144 } >> 145 n_stackedTrack--; 66 } 146 } 67 147 68 G4double G4TrackStack::getTotalEnergy() const << 148 void G4TrackStack::clear() 69 { 149 { 70 G4double totalEnergy = 0.0; << 150 G4StackedTrack * aStackedTrack = firstStackedTrack; 71 for (const auto & i : *this) << 151 G4StackedTrack * nextStackedTrack; >> 152 >> 153 if ( n_stackedTrack == 0 ) return; >> 154 >> 155 // delete tracks in the stack >> 156 while( aStackedTrack != 0 ) 72 { 157 { 73 totalEnergy += i.GetTrack()->GetDynamicPar << 158 nextStackedTrack = aStackedTrack->GetNext(); >> 159 delete aStackedTrack->GetTrack(); >> 160 delete aStackedTrack->GetTrajectory(); >> 161 delete aStackedTrack; >> 162 aStackedTrack = nextStackedTrack; 74 } 163 } 75 return totalEnergy; << 164 n_stackedTrack = 0; >> 165 firstStackedTrack = 0; >> 166 lastStackedTrack = 0; 76 } 167 } >> 168 >> 169 77 170