| [816] | 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 | //
|
|---|
| [1196] | 27 | // $Id: G4StackManager.hh,v 1.13 2009/08/15 15:45:50 asaim Exp $
|
|---|
| 28 | // GEANT4 tag $Name: geant4-09-03-cand-01 $
|
|---|
| [816] | 29 | //
|
|---|
| 30 | //
|
|---|
| 31 |
|
|---|
| 32 |
|
|---|
| 33 | #ifndef G4StackManager_h
|
|---|
| 34 | #define G4StackManager_h 1
|
|---|
| 35 |
|
|---|
| 36 | #include "G4UserStackingAction.hh"
|
|---|
| 37 | #include "G4StackedTrack.hh"
|
|---|
| 38 | #include "G4TrackStack.hh"
|
|---|
| [1196] | 39 | #include "G4SmartTrackStack.hh"
|
|---|
| [816] | 40 | #include "G4ClassificationOfNewTrack.hh"
|
|---|
| 41 | #include "G4Track.hh"
|
|---|
| 42 | #include "G4TrackStatus.hh"
|
|---|
| 43 | #include "globals.hh"
|
|---|
| [1196] | 44 | #include "evmandefs.hh"
|
|---|
| [816] | 45 | class G4StackingMessenger;
|
|---|
| 46 | class G4VTrajectory;
|
|---|
| 47 |
|
|---|
| 48 | // class description:
|
|---|
| 49 | //
|
|---|
| 50 | // This is the manager class of handling stacks of G4Track objects.
|
|---|
| 51 | // This class must be a singleton and be constructed by G4EventManager.
|
|---|
| 52 | // Almost all methods must be invoked exclusively by G4EventManager.
|
|---|
| 53 | // Especially, some Clear() methods MUST NOT be invoked by the user.
|
|---|
| 54 | // Event abortion is handled by G4EventManager.
|
|---|
| 55 | //
|
|---|
| 56 | // This G4StackingManager has three stacks, the urgent stack, the
|
|---|
| 57 | // waiting stack, and the postpone to next event stack. The meanings
|
|---|
| 58 | // of each stack is descrived in the Geant4 user's manual.
|
|---|
| 59 | //
|
|---|
| 60 |
|
|---|
| 61 |
|
|---|
| 62 | class G4StackManager
|
|---|
| 63 | {
|
|---|
| 64 | public:
|
|---|
| 65 | G4StackManager();
|
|---|
| 66 | ~G4StackManager();
|
|---|
| 67 |
|
|---|
| 68 | private:
|
|---|
| 69 | const G4StackManager & operator=
|
|---|
| 70 | (const G4StackManager &right);
|
|---|
| 71 | G4int operator==(const G4StackManager &right) const;
|
|---|
| 72 | G4int operator!=(const G4StackManager &right) const;
|
|---|
| 73 |
|
|---|
| 74 | public:
|
|---|
| 75 | G4int PushOneTrack(G4Track *newTrack, G4VTrajectory *newTrajectory = 0);
|
|---|
| 76 | G4Track * PopNextTrack(G4VTrajectory**newTrajectory);
|
|---|
| 77 | G4int PrepareNewEvent();
|
|---|
| 78 |
|
|---|
| 79 | public: // with description
|
|---|
| 80 | void ReClassify();
|
|---|
| 81 | // Send all tracks stored in the Urgent stack one by one to
|
|---|
| 82 | // the user's concrete ClassifyNewTrack() method. This method
|
|---|
| 83 | // can be invoked from the user's G4UserStackingAction concrete
|
|---|
| 84 | // class, especially fron its NewStage() method. Be aware that
|
|---|
| 85 | // when the urgent stack becomes empty, all tracks in the waiting
|
|---|
| 86 | // stack are send to the urgent stack and then the user's NewStage()
|
|---|
| 87 | // method is invoked.
|
|---|
| 88 |
|
|---|
| 89 | void SetNumberOfAdditionalWaitingStacks(G4int iAdd);
|
|---|
| 90 | // Set the number of additional (optional) waiting stacks.
|
|---|
| 91 | // This method must be invoked at PreInit, Init or Idle states.
|
|---|
| 92 | // Once the user set the number of additional waiting stacks,
|
|---|
| 93 | // he/she can use the corresponding ENUM in G4ClassificationOfNewTrack.
|
|---|
| 94 | // The user should invoke G4RunManager::SetNumberOfAdditionalWaitingStacks
|
|---|
| 95 | // method, which invokes this method.
|
|---|
| 96 |
|
|---|
| 97 | void TransferStackedTracks(G4ClassificationOfNewTrack origin, G4ClassificationOfNewTrack destination);
|
|---|
| 98 | // Transfter all stacked tracks from the origin stack to the destination stack.
|
|---|
| 99 | // The destination stack needs not be empty.
|
|---|
| 100 | // If the destination is fKill, tracks are deleted.
|
|---|
| 101 | // If the origin is fKill, nothing happen.
|
|---|
| 102 |
|
|---|
| 103 | void TransferOneStackedTrack(G4ClassificationOfNewTrack origin, G4ClassificationOfNewTrack destination);
|
|---|
| 104 | // Transfter one stacked track from the origin stack to the destination stack.
|
|---|
| 105 | // The transfered track is the one which came last to the origin stack.
|
|---|
| 106 | // The destination stack needs not be empty.
|
|---|
| 107 | // If the destination is fKill, the track is deleted.
|
|---|
| 108 | // If the origin is fKill, nothing happen.
|
|---|
| 109 |
|
|---|
| 110 | private:
|
|---|
| 111 | G4UserStackingAction * userStackingAction;
|
|---|
| 112 | G4int verboseLevel;
|
|---|
| [1196] | 113 | #ifdef G4_USESMARTSTACK
|
|---|
| 114 | G4SmartTrackStack * urgentStack;
|
|---|
| 115 | #else
|
|---|
| [816] | 116 | G4TrackStack * urgentStack;
|
|---|
| [1196] | 117 | #endif
|
|---|
| [816] | 118 | G4TrackStack * waitingStack;
|
|---|
| 119 | G4TrackStack * postponeStack;
|
|---|
| 120 | G4StackingMessenger* theMessenger;
|
|---|
| 121 | std::vector<G4TrackStack*> additionalWaitingStacks;
|
|---|
| 122 | G4int numberOfAdditionalWaitingStacks;
|
|---|
| 123 |
|
|---|
| 124 | public:
|
|---|
| 125 | inline void clear()
|
|---|
| 126 | {
|
|---|
| 127 | ClearUrgentStack();
|
|---|
| 128 | ClearWaitingStack();
|
|---|
| 129 | for(int i=1;i<=numberOfAdditionalWaitingStacks;i++) {ClearWaitingStack(i);}
|
|---|
| 130 | }
|
|---|
| 131 | inline void ClearUrgentStack()
|
|---|
| 132 | { urgentStack->clear(); }
|
|---|
| 133 | inline void ClearWaitingStack(int i=0)
|
|---|
| 134 | {
|
|---|
| 135 | if(i==0) {
|
|---|
| 136 | waitingStack->clear();
|
|---|
| 137 | } else {
|
|---|
| 138 | if(i<=numberOfAdditionalWaitingStacks) additionalWaitingStacks[i-1]->clear();
|
|---|
| 139 | }
|
|---|
| 140 | }
|
|---|
| 141 | inline void ClearPostponeStack()
|
|---|
| 142 | { postponeStack->clear(); }
|
|---|
| 143 | inline G4int GetNTotalTrack() const
|
|---|
| 144 | { int n = urgentStack->GetNTrack() + waitingStack->GetNTrack() + postponeStack->GetNTrack();
|
|---|
| 145 | for(int i=1;i<=numberOfAdditionalWaitingStacks;i++) {n += additionalWaitingStacks[i-1]->GetNTrack();}
|
|---|
| 146 | return n;
|
|---|
| 147 | }
|
|---|
| 148 | inline G4int GetNUrgentTrack() const
|
|---|
| 149 | { return urgentStack->GetNTrack(); }
|
|---|
| 150 | inline G4int GetNWaitingTrack(int i=0) const
|
|---|
| 151 | { if(i==0) { return waitingStack->GetNTrack(); }
|
|---|
| 152 | else {
|
|---|
| 153 | if(i<=numberOfAdditionalWaitingStacks) { return additionalWaitingStacks[i-1]->GetNTrack();}
|
|---|
| 154 | }
|
|---|
| 155 | return 0;
|
|---|
| 156 | }
|
|---|
| 157 | inline G4int GetNPostponedTrack() const
|
|---|
| 158 | { return postponeStack->GetNTrack(); }
|
|---|
| 159 | inline void SetVerboseLevel( G4int const value )
|
|---|
| 160 | { verboseLevel = value; }
|
|---|
| 161 | inline void SetUserStackingAction(G4UserStackingAction* value)
|
|---|
| 162 | {
|
|---|
| 163 | userStackingAction = value;
|
|---|
| 164 | if(userStackingAction) userStackingAction->SetStackManager(this);
|
|---|
| 165 | }
|
|---|
| 166 |
|
|---|
| 167 | private:
|
|---|
| 168 | inline G4ClassificationOfNewTrack
|
|---|
| 169 | DefaultClassification(G4Track *aTrack)
|
|---|
| 170 | {
|
|---|
| 171 | G4ClassificationOfNewTrack classification = fUrgent;
|
|---|
| 172 | if( aTrack->GetTrackStatus() == fPostponeToNextEvent )
|
|---|
| 173 | { classification = fPostpone; }
|
|---|
| 174 | return classification;
|
|---|
| 175 | }
|
|---|
| 176 | };
|
|---|
| 177 |
|
|---|
| 178 | #endif
|
|---|
| 179 |
|
|---|