Geant4  v4-10.4-release
 모두 클래스 네임스페이스들 파일들 함수 변수 타입정의 열거형 타입 열거형 멤버 Friends 매크로 그룹들 페이지들
G4RNGHelper.hh
이 파일의 문서화 페이지로 가기
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 // Helper class for RNG Engine seeds.
28 // Used in MT builds to guarantee reproducibility.
29 // The function of this class is to return a RNG Engine seed
30 // given its index. It is a simple templated container that
31 // Allows to add seeds (AddOneSeed) and retrieve a seed (GetSeed)
32 // by index.
33 //
34 // The normal use is with G4RNGHelper where each element of th econtainer
35 // represents a seed. To enforce strong-reproducibility the variant with
36 // the RNG Engine status file names is avilable
37 
38 #ifndef G4RNGHELPER_HH
39 #define G4RNGHELPER_HH
40 
41 #include <vector>
42 #include <queue>
43 #include "globals.hh"
44 
45 template <class T>
47 {
48  public:
49  // The container is modeled as a (shared) singleton
52  typedef std::vector<T> SeedsQueue;
53  typedef typename SeedsQueue::size_type SeedsQueueSize_type;
54 
55  virtual ~G4TemplateRNGHelper();
56 
57  //Returns seed given id
58  virtual const T GetSeed(const G4int& sdId )
59  {
60  G4int seedId = sdId - 2*offset;
61  if ( seedId < static_cast<G4int>(seeds.size()) )
62  {
63  T& seed = seeds[seedId];
64  return seed;
65  }
67  msg << "No seed number "<<seedId<<"("<<seeds.size()<<" available)\n"
68  << " Original seed number "<<sdId<<" filled so far "<<offset;
69  G4Exception("G4RNGHelper::GetSeed","Run0115", FatalException,msg);
70  return T();
71  }
72 
73  //Adds one seed to the collection
74  void AddOneSeed( const T& seed ) { seeds.push_back(seed); }
75 
76  //Fills N primary seed pairs
77  void Fill(G4double* dbl,G4int nev,G4int nev_tot,G4int nrpe)
78  {
79  seeds.clear();
80  for(G4int i=0;i<nrpe*nev;i++)
81  { seeds.push_back((G4long)(100000000L*dbl[i])); }
82  offset = 0;
83  nev_filled = nev;
84  nev_total = nev_tot;
85  nRandParEvent = nrpe;
86  }
87 
88  void Refill(G4double* dbl, G4int nev)
89  {
90  if(nev==0) return;
91  seeds.clear();
92  for(G4int i=0;i<nRandParEvent*nev;i++)
93  { seeds.push_back((G4long)(100000000L*dbl[i])); }
94  offset += nev_filled;
95  nev_filled = nev;
96  }
97 
98  //Number of available seeds
99  const SeedsQueueSize_type GetNumberSeeds() const { return seeds.size(); }
100 
101  //Empty the seeds container
102  virtual void Clear() { seeds.clear(); }
103 
104  protected:
106  // Note: following numbers are number of events.
107  // seeds are generated for nRandParEvent times n_event
112 
113  private:
115  {
116  offset=0;
117  nev_filled=0;
118  nev_total=0;
119  nRandParEvent=0;
120  }
121 
122  private:
124 };
125 
128 typedef std::queue<G4long> G4SeedsQueue;
129 
130 #endif
static constexpr double L
Definition: G4SIunits.hh:124
void AddOneSeed(const T &seed)
Definition: G4RNGHelper.hh:74
std::ostringstream G4ExceptionDescription
Definition: G4Exception.hh:45
const SeedsQueueSize_type GetNumberSeeds() const
Definition: G4RNGHelper.hh:99
void Fill(G4double *dbl, G4int nev, G4int nev_tot, G4int nrpe)
Definition: G4RNGHelper.hh:77
virtual const T GetSeed(const G4int &sdId)
Definition: G4RNGHelper.hh:58
G4TemplateRNGHelper< G4long > G4RNGHelper
Definition: G4RNGHelper.hh:126
static G4TemplateRNGHelper< T > * instance
Definition: G4RNGHelper.hh:123
double G4double
Definition: G4Types.hh:76
virtual ~G4TemplateRNGHelper()
Definition: G4RNGHelper.cc:82
virtual void Clear()
Definition: G4RNGHelper.hh:102
long G4long
Definition: G4Types.hh:80
long seed
Definition: chem4.cc:68
static G4TemplateRNGHelper< T > * GetInstanceIfExist()
Definition: G4RNGHelper.cc:46
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
Definition: G4Exception.hh:65
std::vector< T > SeedsQueue
Definition: G4RNGHelper.hh:52
int G4int
Definition: G4Types.hh:78
SeedsQueue::size_type SeedsQueueSize_type
Definition: G4RNGHelper.hh:53
std::queue< G4long > G4SeedsQueue
Definition: G4RNGHelper.hh:128
static G4TemplateRNGHelper< T > * GetInstance()
Definition: G4RNGHelper.cc:37
void Refill(G4double *dbl, G4int nev)
Definition: G4RNGHelper.hh:88
G4TemplateRNGHelper< G4String > G4StringRNGHelper
Definition: G4RNGHelper.hh:127