Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:58:33

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 /*
0027  * G4ITTrackHolder.hh
0028  *
0029  *  Created on: 17 sept. 2014
0030  *      Author: kara
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   // to merge with fpMainList
0117   G4TrackList* fpWaitingList;
0118   // Waiting queue of currentList
0119 };
0120 
0121 class G4ITTrackHolder : public G4VITTrackHolder
0122 {
0123   /* UR:
0124    * Push on time
0125    * Push delayed
0126    * Exception when going back
0127    * Get all tracks
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   //----- typedefs -----
0138   using Key = int; //TODO
0139   using MapOfPriorityLists = std::map<Key, PriorityList*>;
0140   using MapOfDelayedLists = std::map<double, std::map<Key, G4TrackList*> >;
0141 
0142   //----- Access singletons + constructors/destructors-----
0143 
0144   static G4ITTrackHolder* Instance();
0145   static G4ITTrackHolder* MasterInstance();
0146 
0147   G4ITTrackHolder();
0148   
0149   ~G4ITTrackHolder() override;
0150 
0151   //----- Time of the next set of tracks -----
0152   inline double GetNextTime()
0153   {
0154     if (fDelayedList.empty()) return DBL_MAX;
0155     return fDelayedList.begin()->first;
0156   }
0157 
0158   //----- Add new tracks to the list -----
0159   void Push(G4Track*) override;
0160   static void PushToMaster(G4Track*);
0161 
0162   //----- Operations between lists -----
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   // ----- To call at the end of the step -----
0179   void KillTracks();
0180   void Clear();
0181 
0182   // ----- Add a watcher to a specific track list -----
0183   // comment: to stop watching, just call StopWatching from your watcher class
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   // ----- Access track lists -----
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   // ----- Check track lists are NOT empty -----
0214   // comment: checking NOT empty faster than checking IS empty
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   //  double fPreActivityGlobalTime ;
0256 
0257   G4TrackManyList fAllMainList;
0258   G4TrackManyList fAllSecondariesList;
0259 };
0260 
0261 #endif /* G4MIMOLECULARTRACKS_HH_ */