Analysis Software
Documentation for
sPHENIX
simulation software
Home page
Related Pages
Modules
Namespaces
Classes
Files
Examples
External Links
File List
File Members
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
);
15
int
PHRandomSeed::verbose
(1);
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
{
33
iseed =
fDistribution
(
fRandomGenerator
);
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
48
void
PHRandomSeed::InitSeed
()
49
{
50
recoConsts
*rc =
recoConsts::instance
();
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
}
coresoftware
blob
master
offline
framework
phool
PHRandomSeed.cc
Built by
Jin Huang
. updated:
Sat Feb 17 2024 22:18:05
using
1.8.2 with
sPHENIX GitHub integration