ECCE @ EIC Software
Reference for
ECCE @ EIC
simulation and reconstruction software on GitHub
Home page
Related Pages
Modules
Namespaces
Classes
Files
External Links
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Groups
Pages
StaticRandomStates.cc
Go to the documentation of this file.
Or view
the newest version in sPHENIX GitHub for file StaticRandomStates.cc
1
// -*- C++ -*-
2
//
3
// -----------------------------------------------------------------------
4
// HEP Random
5
// --- StaticRandomStates ---
6
// class implementation file
7
// -----------------------------------------------------------------------
8
//
9
// =======================================================================
10
// Mark Fischler - Created: Dec. 21, 2004
11
// Mark Fischler - Modified restore() to utilize anonymous engine input
12
// to create anonymous restore of the static distributions
13
//
14
// =======================================================================
15
16
#include "
CLHEP/Random/StaticRandomStates.h
"
17
#include "
CLHEP/Random/RandGauss.h
"
18
#include "
CLHEP/Random/RandFlat.h
"
19
#include <string>
20
#include <sstream>
21
22
//======================//
23
// //
24
// Maintenance warning: //
25
// //
26
//======================//
27
//
28
// Currently, only two distributions (RandFlat and RandGauss) have cached
29
// distribution state. All such distributions must be saved below, so if
30
// another such distribution is added, this implementation file must be
31
// modified to reflect that.
32
33
namespace
CLHEP {
34
35
36
std::ostream &
StaticRandomStates::save
(std::ostream & os){
37
RandGauss::saveFullState
(os);
38
RandFlat::saveDistState
(os);
39
return
os;
40
}
41
42
#ifdef NOTYET
43
std::istream &
StaticRandomStates::restore
(std::istream & is) {
44
RandGauss::restoreFullState
(is);
45
RandFlat::restoreDistState
(is);
46
return
is;
47
}
48
#endif
49
50
std::istream &
StaticRandomStates::restore
(std::istream & is) {
51
HepRandomEngine
*
e
=
HepRandom::getTheEngine
();
52
HepRandomEngine
*ne =
HepRandomEngine::newEngine
(is);
53
if
( !is )
return
is;
54
if
( !ne )
return
is;
55
if
(ne->
name
() == e->
name
()) {
56
// Because e has const data members, cannot simply do *e = *ne
57
std::ostringstream os;
58
os << *ne;
59
std::istringstream istst(os.str());
60
istst >> *
e
;
61
if
(!istst) {
62
std::cerr <<
"???? Unexpected behavior in StaticRandomStates::restore:\n"
63
<<
"The new engine, which had been input successfully from istream\n"
64
<<
"has encountered a problem when used to set state of theEngine\n"
;
65
is.clear(std::ios::badbit | is.rdstate());
66
return
is;
67
}
68
}
else
{
69
HepRandom::setTheEngine
(ne);
70
}
71
RandGauss::restoreDistState
(is);
72
RandFlat::restoreDistState
(is);
73
return
is;
74
}
75
76
}
// namespace CLHEP
geant4
tree
geant4-10.6-release
source
externals
clhep
src
StaticRandomStates.cc
Built by
Jin Huang
. updated:
Wed Jun 29 2022 17:25:15
using
1.8.2 with
ECCE GitHub integration