00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #include "CLHEP/Random/StaticRandomStates.h"
00018 #include "CLHEP/Random/RandGauss.h"
00019 #include "CLHEP/Random/RandFlat.h"
00020 #include <string>
00021 #include <sstream>
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034 namespace CLHEP {
00035
00036
00037 std::ostream & StaticRandomStates::save(std::ostream & os){
00038 RandGauss::saveFullState(os);
00039 RandFlat::saveDistState(os);
00040 return os;
00041 }
00042
00043 #ifdef NOTYET
00044 std::istream & StaticRandomStates::restore(std::istream & is) {
00045 RandGauss::restoreFullState(is);
00046 RandFlat::restoreDistState(is);
00047 return is;
00048 }
00049 #endif
00050
00051 std::istream & StaticRandomStates::restore(std::istream & is) {
00052 HepRandomEngine * e = HepRandom::getTheEngine();
00053 HepRandomEngine *ne = HepRandomEngine::newEngine(is);
00054 if ( !is ) return is;
00055 if ( !ne ) return is;
00056 if (ne->name() == e->name()) {
00057
00058 std::ostringstream os;
00059 os << *ne;
00060 std::istringstream istst(os.str());
00061 istst >> *e;
00062 if (!istst) {
00063 std::cerr << "???? Unexpected behavior in StaticRandomStates::restore:\n"
00064 << "The new engine, which had been input successfully from istream\n"
00065 << "has encountered a problem when used to set state of theEngine\n";
00066 is.clear(std::ios::badbit | is.rdstate());
00067 return is;
00068 }
00069 } else {
00070 HepRandom::setTheEngine(ne);
00071 }
00072 RandGauss::restoreDistState(is);
00073 RandFlat::restoreDistState(is);
00074 return is;
00075 }
00076
00077 }