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] [ 10.5 ] [ 10.5.p1 ] [ 10.6 ] [ 10.6.p1 ] [ 10.6.p2 ] [ 10.6.p3 ] [ 10.7 ] [ 10.7.p1 ] [ 10.7.p2 ] [ 10.7.p3 ] [ 10.7.p4 ] [ 11.0 ] [ 11.0.p1 ] [ 11.0.p2 ] [ 11.0.p3, ] [ 11.0.p4 ] [ 11.1 ] [ 11.1.1 ] [ 11.1.2 ] [ 11.1.3 ] [ 11.2 ] [ 11.2.1 ] [ 11.2.2 ] [ 11.3.0 ]

  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 /*
 27  * G4ITTrackHolder.hh
 28  *
 29  *  Created on: 17 sept. 2014
 30  *      Author: kara
 31  */
 32 
 33 #ifndef G4ITTRACKHOLDER_HH
 34 #define G4ITTRACKHOLDER_HH
 35 
 36 #include "G4TrackList.hh"
 37 #include "G4VITTrackHolder.hh"
 38 #include <iostream>
 39 
 40 class PriorityList : public G4TrackList::Watcher
 41 {
 42 public:
 43   enum Type
 44   {
 45     MainList = 0,
 46     SecondariesList = 1,
 47     WaitingList = 2,
 48     Undefined = -1
 49   };
 50 
 51   PriorityList();
 52   PriorityList(G4TrackManyList& allMainList);
 53   PriorityList(const PriorityList& right);
 54   ~PriorityList() override;
 55 
 56   virtual void NotifyDeletingList(G4TrackList* __list);
 57 
 58   void NewMainList(G4TrackList* __list, G4TrackManyList& allMainList);
 59 
 60   G4TrackList* NewMainList(G4TrackManyList& allMainList);
 61 
 62   void PushToMainList(G4Track* __track, G4TrackManyList& allMainList);
 63 
 64   void TransferToMainList(G4TrackList*& __list, G4TrackManyList& allMainList);
 65 
 66   void PushToListOfSecondaries(G4Track* __track,
 67                                G4TrackManyList& listOfAllSecondaries);
 68 
 69   void PushToWaitingList(G4Track* __track);
 70 
 71   void TransferSecondariesToMainList();
 72 
 73   void PushToMainList(G4Track* track);
 74 
 75   void MergeWithMainList(G4TrackList* trackList);
 76 
 77   inline G4TrackList* GetMainList()
 78   {
 79     return fpMainList;
 80   }
 81 
 82   inline G4TrackList* GetSecondariesList()
 83   {
 84     return &fSecondaries;
 85   }
 86 
 87   inline void SetWaitingList(G4TrackList* __list)
 88   {
 89     fpWaitingList = __list;
 90   }
 91 
 92   inline G4TrackList* Get(Type type)
 93   {
 94     switch (type)
 95     {
 96       case MainList:
 97         return fpMainList;
 98         break;
 99       case SecondariesList:
100         return &fSecondaries;
101         break;
102       case WaitingList:
103         return fpWaitingList;
104         break;
105       case Undefined:
106         return nullptr;
107     }
108     return nullptr;
109   }
110 
111   int GetNTracks();
112 
113 private:
114   G4TrackList* fpMainList;
115   G4TrackList fSecondaries;
116   // to merge with fpMainList
117   G4TrackList* fpWaitingList;
118   // Waiting queue of currentList
119 };
120 
121 class G4ITTrackHolder : public G4VITTrackHolder
122 {
123   /* UR:
124    * Push on time
125    * Push delayed
126    * Exception when going back
127    * Get all tracks
128    */
129 
130   static G4ThreadLocal G4ITTrackHolder* fgInstance;
131   static G4ITTrackHolder* fgMasterInstance;
132   friend class G4Scheduler;
133   friend class G4ITStepProcessor;
134   friend class G4ITModelProcessor;
135 
136 public:
137   //----- typedefs -----
138   using Key = int; //TODO
139   using MapOfPriorityLists = std::map<Key, PriorityList*>;
140   using MapOfDelayedLists = std::map<double, std::map<Key, G4TrackList*> >;
141 
142   //----- Access singletons + constructors/destructors-----
143 
144   static G4ITTrackHolder* Instance();
145   static G4ITTrackHolder* MasterInstance();
146 
147   G4ITTrackHolder();
148   
149   ~G4ITTrackHolder() override;
150 
151   //----- Time of the next set of tracks -----
152   inline double GetNextTime()
153   {
154     if (fDelayedList.empty()) return DBL_MAX;
155     return fDelayedList.begin()->first;
156   }
157 
158   //----- Add new tracks to the list -----
159   void Push(G4Track*) override;
160   static void PushToMaster(G4Track*);
161 
162   //----- Operations between lists -----
163 
164   inline void PushToKill(G4Track* track)
165   {
166     G4TrackList::Pop(track);
167     fToBeKilledList.push_back(track);
168     
169     if(track->GetTrackStatus() != fKillTrackAndSecondaries){
170       track->SetTrackStatus(fStopAndKill);
171     }
172   }
173 
174   bool MergeNextTimeToMainList(double& time);
175   void MergeSecondariesWithMainList();
176   void MoveMainToWaitingList();
177 
178   // ----- To call at the end of the step -----
179   void KillTracks();
180   void Clear();
181 
182   // ----- Add a watcher to a specific track list -----
183   // comment: to stop watching, just call StopWatching from your watcher class
184   bool AddWatcher(int,
185       G4TrackList::Watcher*,
186       PriorityList::Type = PriorityList::MainList);
187 
188   void AddWatcherForMainList(G4TrackList::Watcher*);
189   void AddWatcherForKillList(G4TrackList::Watcher*);
190 
191   // ----- Access track lists -----
192   inline MapOfPriorityLists& GetLists()
193   { return fLists;}
194   PriorityList* GetPriorityList(Key);
195   G4TrackList* GetMainList(Key);
196   inline G4TrackManyList* GetMainList()
197   {
198     return &fAllMainList;
199   }
200 
201   inline G4TrackManyList* GetSecondariesList()
202   {
203     return &fAllSecondariesList;
204   }
205 
206   inline MapOfDelayedLists& GetDelayedLists()
207   {
208     return fDelayedList;
209   }
210 
211   size_t GetNTracks() override;
212 
213   // ----- Check track lists are NOT empty -----
214   // comment: checking NOT empty faster than checking IS empty
215   inline bool MainListsNOTEmpty()
216   {
217     return CheckMapIsNOTEmpty(fLists, PriorityList::MainList);
218   }
219 
220   inline bool SecondaryListsNOTEmpty()
221   {
222     return CheckMapIsNOTEmpty(fLists, PriorityList::SecondariesList);
223   }
224 
225   bool DelayListsNOTEmpty();
226 
227   bool CheckMapIsNOTEmpty(MapOfPriorityLists& mapOfLists,
228       PriorityList::Type type);
229 
230   inline void SetVerbose(int verbose)
231   {
232     fVerbose = verbose;
233   }
234 
235   inline G4TrackList* GetKillList()
236   {
237     return &fToBeKilledList;
238   }
239 
240 protected:
241   void AddTrackID(G4Track* track);
242   void _PushTrack(G4Track* track);
243   void PushTo(G4Track*, PriorityList::Type);
244   void PushDelayed(G4Track* track);
245 
246 protected:
247   std::map<Key, PriorityList*> fLists;
248   MapOfDelayedLists fDelayedList;
249   G4TrackList fToBeKilledList;
250   bool fMainListHaveBeenSet;
251   int fVerbose;
252   int fNbTracks;
253 
254   double fPostActivityGlobalTime;
255   //  double fPreActivityGlobalTime ;
256 
257   G4TrackManyList fAllMainList;
258   G4TrackManyList fAllSecondariesList;
259 };
260 
261 #endif /* G4MIMOLECULARTRACKS_HH_ */
262