ECCE @ EIC Software
 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 
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){
39  return os;
40 }
41 
42 #ifdef NOTYET
43 std::istream & StaticRandomStates::restore(std::istream & is) {
46  return is;
47 }
48 #endif
49 
50 std::istream & StaticRandomStates::restore(std::istream & 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 {
70  }
73  return is;
74 }
75 
76 } // namespace CLHEP