Warning, file /include/Geant4/G4RNGHelper.hh was not indexed
or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
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
0034
0035
0036
0037
0038
0039
0040
0041
0042 #ifndef G4TemplateRNGHelper_hh
0043 #define G4TemplateRNGHelper_hh 1
0044
0045 #include "globals.hh"
0046
0047 #include <queue>
0048 #include <vector>
0049
0050 template<class T>
0051 class G4TemplateRNGHelper
0052 {
0053 public:
0054 using SeedsQueue = std::vector<T>;
0055 using SeedsQueueSize_type = typename SeedsQueue::size_type;
0056
0057 public:
0058
0059 static G4TemplateRNGHelper<T>* GetInstance();
0060 static G4TemplateRNGHelper<T>* GetInstanceIfExist();
0061 virtual ~G4TemplateRNGHelper();
0062
0063
0064 virtual const T GetSeed(const G4int& sdId)
0065 {
0066 G4int seedId = sdId - 2 * offset;
0067 if (seedId < static_cast<G4int>(seeds.size())) {
0068 T& seed = seeds[seedId];
0069 return seed;
0070 }
0071 G4ExceptionDescription msg;
0072 msg << "No seed number " << seedId << "(" << seeds.size() << " available)\n"
0073 << " Original seed number " << sdId << " filled so far " << offset;
0074 G4Exception("G4RNGHelper::GetSeed", "Run0115", FatalException, msg);
0075 return T();
0076 }
0077
0078
0079 void AddOneSeed(const T& seed) { seeds.push_back(seed); }
0080
0081
0082 void Fill(G4double* dbl, G4int nev, G4int nev_tot, G4int nrpe)
0083 {
0084 seeds.clear();
0085 for (G4int i = 0; i < nrpe * nev; ++i) {
0086 seeds.push_back((G4long)(100000000L * dbl[i]));
0087 }
0088 offset = 0;
0089 nev_filled = nev;
0090 nev_total = nev_tot;
0091 nRandParEvent = nrpe;
0092 }
0093
0094 void Refill(G4double* dbl, G4int nev)
0095 {
0096 if (nev == 0) return;
0097 seeds.clear();
0098 for (G4int i = 0; i < nRandParEvent * nev; ++i) {
0099 seeds.push_back((G4long)(100000000L * dbl[i]));
0100 }
0101 offset += nev_filled;
0102 nev_filled = nev;
0103 }
0104
0105
0106 const SeedsQueueSize_type GetNumberSeeds() const { return seeds.size(); }
0107
0108
0109 virtual void Clear() { seeds.clear(); }
0110
0111 protected:
0112 SeedsQueue seeds;
0113
0114
0115 G4int offset = 0;
0116 G4int nev_filled = 0;
0117 G4int nev_total = 0;
0118 G4int nRandParEvent = 0;
0119
0120 private:
0121 G4TemplateRNGHelper() = default;
0122
0123 private:
0124 static G4TemplateRNGHelper<T>* instance;
0125 };
0126
0127 using G4RNGHelper = G4TemplateRNGHelper<G4long>;
0128 using G4StringRNGHelper = G4TemplateRNGHelper<G4String>;
0129 using G4SeedsQueue = std::queue<G4long>;
0130
0131 #endif