Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
PHRandomSeed.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file PHRandomSeed.cc
1 #include "PHRandomSeed.h"
2 #include "recoConsts.h"
3 
4 #include <iostream>
5 #include <memory> // for allocator
6 #include <queue>
7 #include <random>
8 
9 static std::queue<unsigned int> seedqueue;
10 static std::mt19937 fRandomGenerator;
11 static std::uniform_int_distribution<unsigned int> fDistribution;
12 
13 bool PHRandomSeed::fInitialized(false);
14 bool PHRandomSeed::fFixed(false);
16 
17 unsigned int PHRandomSeed::GetSeed()
18 {
19  unsigned int iseed;
20  if (!seedqueue.empty())
21  {
22  iseed = seedqueue.front();
23  seedqueue.pop();
24  }
25  else
26  {
27  if (!fInitialized)
28  {
29  InitSeed();
30  }
31  if (fFixed)
32  {
34  }
35  else
36  {
37  std::random_device rdev;
38  iseed = rdev();
39  }
40  }
41  if (verbose)
42  {
43  std::cout << "PHRandomSeed::GetSeed() seed: " << iseed << std::endl;
44  }
45  return iseed;
46 }
47 
49 {
51  if (rc->FlagExist("RANDOMSEED"))
52  {
53  // fixed init seed
54  const unsigned int seed = rc->get_IntFlag("RANDOMSEED");
55  std::cout << "PHRandomSeed: using fixed seed " << seed << std::endl;
56  fRandomGenerator.seed(seed);
57  fFixed = true;
58  fInitialized = true;
59  }
60 }
61 
62 void PHRandomSeed::LoadSeed(const unsigned int iseed)
63 {
64  seedqueue.push(iseed);
65 }
66 
67 void PHRandomSeed::Verbosity(const int iverb)
68 {
69  verbose = iverb;
70 }