|
||||
File indexing completed on 2025-01-18 09:59:17
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 // 0028 // 0029 // ------------------------------------------------------------ 0030 // GEANT 4 class header file 0031 // ------------------------------------------------------------ 0032 // Class description: 0033 // 0034 // Class implementing a pool of random numbers filled according 0035 // to specified fixed size (default 1024). 0036 0037 // Author: A.Dotti (SLAC) 0038 // ------------------------------------------------------------ 0039 #ifndef G4UNIFORMRANDPOOL_HH 0040 #define G4UNIFORMRANDPOOL_HH 0041 0042 #include "G4Types.hh" 0043 #include "Randomize.hh" 0044 0045 #include <algorithm> 0046 #include <cassert> 0047 0048 #define G4UNIFORMRANDPOOL_DEFAULT_POOLSIZE 1024 0049 #define G4UNIFORMRANDPOOL_TINY_POOLSIZE 128 0050 #define G4UNIFORMRANDPOOL_SMALL_POOLSIZE 256 0051 #define G4UNIFORMRANDPOOL_MEDIUM_POOLSIZE 512 0052 #define G4UNIFORMRANDPOOL_LARGE_POOLSIZE 2048 0053 #define G4UNIFORMRANDPOOL_HUGE_POOLSIZE 8192 0054 0055 class G4UniformRandPool 0056 { 0057 public: 0058 G4UniformRandPool(); 0059 explicit G4UniformRandPool(G4int ps); 0060 ~G4UniformRandPool(); 0061 0062 void Resize(G4int newSize); 0063 void GetMany(G4double* rnds, G4int howMany); 0064 inline G4double GetOne(); 0065 inline G4int GetPoolSize() const; 0066 0067 // These two static methods are used to 0068 // simulate the calls of CLHEP::HepRandom 0069 // 0070 static G4double flat(); 0071 static void flatArray(G4int howmany, G4double* rnds); 0072 0073 private: 0074 void Fill(G4int howmany); 0075 0076 private: 0077 G4int size{G4UNIFORMRANDPOOL_DEFAULT_POOLSIZE}; 0078 G4double* buffer{nullptr}; 0079 G4int currentIdx{0}; 0080 }; 0081 0082 inline G4double G4UniformRandPool::GetOne() 0083 { 0084 // No more available numbers, re-fill 0085 // 0086 if(currentIdx >= /*(unsigned int)*/ size) 0087 { 0088 Fill(/*(unsigned int)*/ size); 0089 } 0090 0091 return buffer[currentIdx++]; 0092 } 0093 0094 inline G4int G4UniformRandPool::GetPoolSize() const 0095 { 0096 return size; 0097 } 0098 0099 #endif
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |