File indexing completed on 2025-01-18 09:58:33
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033 #ifndef G4ITTRACKHOLDER_HH
0034 #define G4ITTRACKHOLDER_HH
0035
0036 #include "G4TrackList.hh"
0037 #include "G4VITTrackHolder.hh"
0038 #include <iostream>
0039
0040 class PriorityList : public G4TrackList::Watcher
0041 {
0042 public:
0043 enum Type
0044 {
0045 MainList = 0,
0046 SecondariesList = 1,
0047 WaitingList = 2,
0048 Undefined = -1
0049 };
0050
0051 PriorityList();
0052 PriorityList(G4TrackManyList& allMainList);
0053 PriorityList(const PriorityList& right);
0054 ~PriorityList() override;
0055
0056 virtual void NotifyDeletingList(G4TrackList* __list);
0057
0058 void NewMainList(G4TrackList* __list, G4TrackManyList& allMainList);
0059
0060 G4TrackList* NewMainList(G4TrackManyList& allMainList);
0061
0062 void PushToMainList(G4Track* __track, G4TrackManyList& allMainList);
0063
0064 void TransferToMainList(G4TrackList*& __list, G4TrackManyList& allMainList);
0065
0066 void PushToListOfSecondaries(G4Track* __track,
0067 G4TrackManyList& listOfAllSecondaries);
0068
0069 void PushToWaitingList(G4Track* __track);
0070
0071 void TransferSecondariesToMainList();
0072
0073 void PushToMainList(G4Track* track);
0074
0075 void MergeWithMainList(G4TrackList* trackList);
0076
0077 inline G4TrackList* GetMainList()
0078 {
0079 return fpMainList;
0080 }
0081
0082 inline G4TrackList* GetSecondariesList()
0083 {
0084 return &fSecondaries;
0085 }
0086
0087 inline void SetWaitingList(G4TrackList* __list)
0088 {
0089 fpWaitingList = __list;
0090 }
0091
0092 inline G4TrackList* Get(Type type)
0093 {
0094 switch (type)
0095 {
0096 case MainList:
0097 return fpMainList;
0098 break;
0099 case SecondariesList:
0100 return &fSecondaries;
0101 break;
0102 case WaitingList:
0103 return fpWaitingList;
0104 break;
0105 case Undefined:
0106 return nullptr;
0107 }
0108 return nullptr;
0109 }
0110
0111 int GetNTracks();
0112
0113 private:
0114 G4TrackList* fpMainList;
0115 G4TrackList fSecondaries;
0116
0117 G4TrackList* fpWaitingList;
0118
0119 };
0120
0121 class G4ITTrackHolder : public G4VITTrackHolder
0122 {
0123
0124
0125
0126
0127
0128
0129
0130 static G4ThreadLocal G4ITTrackHolder* fgInstance;
0131 static G4ITTrackHolder* fgMasterInstance;
0132 friend class G4Scheduler;
0133 friend class G4ITStepProcessor;
0134 friend class G4ITModelProcessor;
0135
0136 public:
0137
0138 using Key = int;
0139 using MapOfPriorityLists = std::map<Key, PriorityList*>;
0140 using MapOfDelayedLists = std::map<double, std::map<Key, G4TrackList*> >;
0141
0142
0143
0144 static G4ITTrackHolder* Instance();
0145 static G4ITTrackHolder* MasterInstance();
0146
0147 G4ITTrackHolder();
0148
0149 ~G4ITTrackHolder() override;
0150
0151
0152 inline double GetNextTime()
0153 {
0154 if (fDelayedList.empty()) return DBL_MAX;
0155 return fDelayedList.begin()->first;
0156 }
0157
0158
0159 void Push(G4Track*) override;
0160 static void PushToMaster(G4Track*);
0161
0162
0163
0164 inline void PushToKill(G4Track* track)
0165 {
0166 G4TrackList::Pop(track);
0167 fToBeKilledList.push_back(track);
0168
0169 if(track->GetTrackStatus() != fKillTrackAndSecondaries){
0170 track->SetTrackStatus(fStopAndKill);
0171 }
0172 }
0173
0174 bool MergeNextTimeToMainList(double& time);
0175 void MergeSecondariesWithMainList();
0176 void MoveMainToWaitingList();
0177
0178
0179 void KillTracks();
0180 void Clear();
0181
0182
0183
0184 bool AddWatcher(int,
0185 G4TrackList::Watcher*,
0186 PriorityList::Type = PriorityList::MainList);
0187
0188 void AddWatcherForMainList(G4TrackList::Watcher*);
0189 void AddWatcherForKillList(G4TrackList::Watcher*);
0190
0191
0192 inline MapOfPriorityLists& GetLists()
0193 { return fLists;}
0194 PriorityList* GetPriorityList(Key);
0195 G4TrackList* GetMainList(Key);
0196 inline G4TrackManyList* GetMainList()
0197 {
0198 return &fAllMainList;
0199 }
0200
0201 inline G4TrackManyList* GetSecondariesList()
0202 {
0203 return &fAllSecondariesList;
0204 }
0205
0206 inline MapOfDelayedLists& GetDelayedLists()
0207 {
0208 return fDelayedList;
0209 }
0210
0211 size_t GetNTracks() override;
0212
0213
0214
0215 inline bool MainListsNOTEmpty()
0216 {
0217 return CheckMapIsNOTEmpty(fLists, PriorityList::MainList);
0218 }
0219
0220 inline bool SecondaryListsNOTEmpty()
0221 {
0222 return CheckMapIsNOTEmpty(fLists, PriorityList::SecondariesList);
0223 }
0224
0225 bool DelayListsNOTEmpty();
0226
0227 bool CheckMapIsNOTEmpty(MapOfPriorityLists& mapOfLists,
0228 PriorityList::Type type);
0229
0230 inline void SetVerbose(int verbose)
0231 {
0232 fVerbose = verbose;
0233 }
0234
0235 inline G4TrackList* GetKillList()
0236 {
0237 return &fToBeKilledList;
0238 }
0239
0240 protected:
0241 void AddTrackID(G4Track* track);
0242 void _PushTrack(G4Track* track);
0243 void PushTo(G4Track*, PriorityList::Type);
0244 void PushDelayed(G4Track* track);
0245
0246 protected:
0247 std::map<Key, PriorityList*> fLists;
0248 MapOfDelayedLists fDelayedList;
0249 G4TrackList fToBeKilledList;
0250 bool fMainListHaveBeenSet;
0251 int fVerbose;
0252 int fNbTracks;
0253
0254 double fPostActivityGlobalTime;
0255
0256
0257 G4TrackManyList fAllMainList;
0258 G4TrackManyList fAllSecondariesList;
0259 };
0260
0261 #endif