CLHEP 2.4.6.4
C++ Class Library for High Energy Physics
Loading...
Searching...
No Matches
StaticRandomStates.cc
Go to the documentation of this file.
1// $Id:
2// -*- C++ -*-
3//
4// -----------------------------------------------------------------------
5// HEP Random
6// --- StaticRandomStates ---
7// class implementation file
8// -----------------------------------------------------------------------
9//
10// =======================================================================
11// Mark Fischler - Created: Dec. 21, 2004
12// Mark Fischler - Modified restore() to utilize anonymous engine input
13// to create anonymous restore of the static distributions
14//
15// =======================================================================
16
17#include "CLHEP/Random/StaticRandomStates.h"
18#include "CLHEP/Random/RandGauss.h"
19#include "CLHEP/Random/RandFlat.h"
20#include <iostream>
21#include <string>
22#include <sstream>
23
24//======================//
25// //
26// Maintenance warning: //
27// //
28//======================//
29//
30// Currently, only two distributions (RandFlat and RandGauss) have cached
31// distribution state. All such distributions must be saved below, so if
32// another such distribution is added, this implementation file must be
33// modified to reflect that.
34
35namespace CLHEP {
36
37
38std::ostream & StaticRandomStates::save(std::ostream & os){
41 return os;
42}
43
44#ifdef NOTYET
45std::istream & StaticRandomStates::restore(std::istream & is) {
48 return is;
49}
50#endif
51
52std::istream & StaticRandomStates::restore(std::istream & is) {
55 if ( !is ) return is;
56 if ( !ne ) return is;
57 if (ne->name() == e->name()) {
58 // Because e has const data members, cannot simply do *e = *ne
59 std::ostringstream os;
60 os << *ne;
61 std::istringstream istst(os.str());
62 istst >> *e;
63 if (!istst) {
64 std::cerr << "???? Unexpected behavior in StaticRandomStates::restore:\n"
65 << "The new engine, which had been input successfully from istream\n"
66 << "has encountered a problem when used to set state of theEngine\n";
67 is.clear(std::ios::badbit | is.rdstate());
68 return is;
69 }
70 } else {
72 }
75 return is;
76}
77
78} // namespace CLHEP
virtual std::string name() const =0
static HepRandomEngine * newEngine(std::istream &is)
Definition: RandomEngine.cc:93
static HepRandomEngine * getTheEngine()
Definition: Random.cc:270
static void setTheEngine(HepRandomEngine *theNewEngine)
Definition: Random.cc:275
static std::ostream & saveDistState(std::ostream &os)
Definition: RandFlat.cc:228
static std::istream & restoreDistState(std::istream &is)
Definition: RandFlat.cc:237
static std::istream & restoreFullState(std::istream &is)
Definition: RandGauss.cc:411
static std::ostream & saveFullState(std::ostream &os)
Definition: RandGauss.cc:405
static std::istream & restoreDistState(std::istream &is)
Definition: RandGauss.cc:361
static std::istream & restore(std::istream &is)
static std::ostream & save(std::ostream &os)