Commit 1c80a6bd authored by Lynn Garren's avatar Lynn Garren
Browse files

Merging Mark's changes into the 2.0 branch

parent 90fae7cc
2005-04-14 Mark Fischler <mf@fnal.gov>
* RandFlat.cc RandGauss.cc RandBinomial.cc ... all the distributions
Express states of all distributions which ave private double
members as sequences of ordinary unsigned ints,
to avoid precision issues and avoid issues of non-portability of hex
input manipulators.
2005-04-13 Mark Fischler <mf@fnal.gov>
* DRand48Engine.cc DualRand.cc Hurd160Engine.cc
Hurd288Engine.cc JamesRandom.cc MTwistEngine.cc RandFlat.cc
RandGauss.cc RandomEngine.cc RandomEngine.cc RanecuEngine.cc
Ranlux64Engine.cc RanluxEngine.cc TripleRand.cc
(and tiny change in corresponding .h files)
Express states of all engines as sequences of ordinary unsigned ints,
to avoid precision issues and avoid issues of non-portability of hex
input manipulators.
* testAnonymousEngineRestore.cc testInstanceRestore.cc
testSaveEngineStatus.cc testSaveSharedEngines.cc
testStaticStreamSave.cc testVectorSave.cc
* test/Makefile.am
Break up the very lengthy validation of engine saves and restores.
Compilation time grows worse than linearly on some systems; this
split should make the check target go faster.
2005-04-11 Mark Fischler <mf@fnal.gov>
* JamesRandom.cc ranRestoreTest.cc NonRandomEngine.h
Express state of this engine in hex form rather than as doubles, to
avoid precision issues.
2005-04-07 Lynn Garren <garren@fnal.gov>
* configure.in: set AR and ARFLAGS
......
// $Id: DRand48Engine.h,v 1.3.4.1 2005/03/18 22:26:48 garren Exp $
// $Id: DRand48Engine.h,v 1.3.4.2 2005/04/15 16:32:52 garren Exp $
// -*- C++ -*-
//
// -----------------------------------------------------------------------
......@@ -99,6 +99,8 @@ public:
std::vector<unsigned long> put () const;
bool get (const std::vector<unsigned long> & v);
bool getState (const std::vector<unsigned long> & v);
static const unsigned int VECTOR_STATE_SIZE = 4;
private:
......
// $Id: DualRand.h,v 1.3.4.1 2005/03/18 22:26:48 garren Exp $
// $Id: DualRand.h,v 1.3.4.2 2005/04/15 16:32:52 garren Exp $
// -*- C++ -*-
//
// -----------------------------------------------------------------------
......@@ -99,6 +99,8 @@ public:
bool get (const std::vector<unsigned long> & v);
bool getState (const std::vector<unsigned long> & v);
static const unsigned int VECTOR_STATE_SIZE = 9;
private:
static int numEngines;
......
// $Id: Hurd160Engine.h,v 1.3.4.1 2005/03/18 22:26:48 garren Exp $
// $Id: Hurd160Engine.h,v 1.3.4.2 2005/04/15 16:32:52 garren Exp $
// -*- C++ -*-
//
// -----------------------------------------------------------------------
......@@ -91,6 +91,8 @@ public:
bool get (const std::vector<unsigned long> & v);
bool getState (const std::vector<unsigned long> & v);
static const unsigned int VECTOR_STATE_SIZE = 7;
private:
static int numEngines;
static int maxIndex;
......
// $Id: Hurd288Engine.h,v 1.3.4.1 2005/03/18 22:26:48 garren Exp $
// $Id: Hurd288Engine.h,v 1.3.4.2 2005/04/15 16:32:52 garren Exp $
// -*- C++ -*-
//
// -----------------------------------------------------------------------
......@@ -89,6 +89,8 @@ public:
std::vector<unsigned long> put () const;
bool get (const std::vector<unsigned long> & v);
bool getState (const std::vector<unsigned long> & v);
static const unsigned int VECTOR_STATE_SIZE = 11;
private:
static int numEngines;
......
// $Id: JamesRandom.h,v 1.3.4.1 2005/03/18 22:26:48 garren Exp $
// $Id: JamesRandom.h,v 1.3.4.2 2005/04/15 16:32:52 garren Exp $
// -*- C++ -*-
//
// -----------------------------------------------------------------------
......@@ -98,6 +98,8 @@ public:
bool get (const std::vector<unsigned long> & v);
bool getState (const std::vector<unsigned long> & v);
static const unsigned int VECTOR_STATE_SIZE = 202;
private:
// Members defining the current status of the generator.
......
// $Id: MTwistEngine.h,v 1.3.4.1 2005/03/18 22:26:48 garren Exp $
// $Id: MTwistEngine.h,v 1.3.4.2 2005/04/15 16:32:52 garren Exp $
// -*- C++ -*-
//
// -----------------------------------------------------------------------
......@@ -84,6 +84,8 @@ public:
std::vector<unsigned long> put () const;
bool get (const std::vector<unsigned long> & v);
bool getState (const std::vector<unsigned long> & v);
static const unsigned int VECTOR_STATE_SIZE = 626;
private:
......
// $Id: RandEngine.h,v 1.3.4.2 2005/03/18 22:26:48 garren Exp $
// $Id: RandEngine.h,v 1.3.4.3 2005/04/15 16:32:52 garren Exp $
// -*- C++ -*-
//
// -----------------------------------------------------------------------
......@@ -101,6 +101,8 @@ public:
bool get (const std::vector<unsigned long> & v);
bool getState (const std::vector<unsigned long> & v);
static const unsigned int VECTOR_STATE_SIZE = 3;
private:
RandEngine(const RandEngine &p);
......
// $Id: RandomEngine.h,v 1.3.4.1 2005/03/18 22:26:48 garren Exp $
// $Id: RandomEngine.h,v 1.3.4.2 2005/04/15 16:32:52 garren Exp $
// -*- C++ -*-
//
// -----------------------------------------------------------------------
......@@ -42,6 +42,7 @@
#include <fstream>
#include <iomanip>
#include <string>
#include <sstream>
#include <vector>
#include "CLHEP/Random/defs.h"
......@@ -155,6 +156,16 @@ protected:
std::ostream & operator<< (std::ostream & os, const HepRandomEngine & e);
std::istream & operator>> (std::istream & is, HepRandomEngine & e);
template <class IS, class T>
bool possibleKeywordInput (IS & is, const std::string & key, T & t) {
std::string firstWord;
is >> firstWord;
if (firstWord == key) return true;
std::istringstream reread(firstWord);
reread >> t;
return false;
}
} // namespace CLHEP
#ifdef ENABLE_BACKWARDS_COMPATIBILITY
......
// $Id: RanecuEngine.h,v 1.3.4.1 2005/03/18 22:26:48 garren Exp $
// $Id: RanecuEngine.h,v 1.3.4.2 2005/04/15 16:32:52 garren Exp $
// -*- C++ -*-
//
// -----------------------------------------------------------------------
......@@ -114,6 +114,8 @@ protected:
const int shift1, shift2;
const double prec;
static const unsigned int VECTOR_STATE_SIZE = 4;
private:
// Members defining the current state of the generator.
......
// $Id: Ranlux64Engine.h,v 1.3.4.1 2005/03/18 22:26:48 garren Exp $
// $Id: Ranlux64Engine.h,v 1.3.4.2 2005/04/15 16:32:52 garren Exp $
// -*- C++ -*-
//
// -----------------------------------------------------------------------
......@@ -102,6 +102,8 @@ public:
bool get (const std::vector<unsigned long> & v);
bool getState (const std::vector<unsigned long> & v);
static const unsigned int VECTOR_STATE_SIZE = 30;
private:
void update();
......
// $Id: RanluxEngine.h,v 1.3.4.1 2005/03/18 22:26:48 garren Exp $
// $Id: RanluxEngine.h,v 1.3.4.2 2005/04/15 16:32:53 garren Exp $
// -*- C++ -*-
//
// -----------------------------------------------------------------------
......@@ -112,6 +112,8 @@ public:
bool get (const std::vector<unsigned long> & v);
bool getState (const std::vector<unsigned long> & v);
static const unsigned int VECTOR_STATE_SIZE = 31;
private:
int nskip, luxury;
......
// $Id: RanshiEngine.h,v 1.3.4.1 2005/03/18 22:26:48 garren Exp $
// $Id: RanshiEngine.h,v 1.3.4.2 2005/04/15 16:32:53 garren Exp $
// -*- C++ -*-
//
// -----------------------------------------------------------------------
......@@ -116,6 +116,8 @@ private:
unsigned int buffer[numBuff];
unsigned int redSpin;
static const unsigned int VECTOR_STATE_SIZE = numBuff + 4;
}; // RanshiEngine
} // namespace CLHEP
......
// $Id: TripleRand.h,v 1.3.4.1 2005/03/18 22:26:48 garren Exp $
// $Id: TripleRand.h,v 1.3.4.2 2005/04/15 16:32:53 garren Exp $
// -*- C++ -*-
//
// -----------------------------------------------------------------------
......@@ -102,6 +102,8 @@ public:
bool get (const std::vector<unsigned long> & v);
bool getState (const std::vector<unsigned long> & v);
static const unsigned int VECTOR_STATE_SIZE = 20;
private:
static int numEngines;
......
// -*- C++ -*-
// $Id: DRand48Engine.cc,v 1.4.4.1 2005/03/18 22:26:48 garren Exp $
// $Id: DRand48Engine.cc,v 1.4.4.2 2005/04/15 16:32:53 garren Exp $
// -----------------------------------------------------------------------
// HEP Random
// --- DRand48Engine ---
......@@ -26,6 +26,7 @@
// M. Fischler - split get() into tag validation and
// getState() for anonymous restores 12/27/04
// M. Fischler - put/get for vectors of ulongs 3/8/05
// M. Fischler - State-saving using only ints, for portability 4/12/05
//
// =======================================================================
......@@ -36,6 +37,8 @@
#include "CLHEP/Random/engineIDulong.h"
#include <string.h>
//#define TRACE_IO
namespace CLHEP {
static const int MarkerLen = 64; // Enough room to hold a begin or end marker.
......@@ -130,9 +133,27 @@ void DRand48Engine::saveStatus( const char filename[] ) const
{
std::ofstream outFile( filename, std::ios::out ) ;
if (!outFile.bad()) {
outFile << "Uvec\n";
std::vector<unsigned long> v = put();
#ifdef TRACE_IO
std::cout << "Result of v = put() is:\n";
#endif
for (unsigned int i=0; i<v.size(); ++i) {
outFile << v[i] << "\n";
#ifdef TRACE_IO
std::cout << v[i] << " ";
if (i%6==0) std::cout << "\n";
#endif
}
#ifdef TRACE_IO
std::cout << "\n";
#endif
}
#ifdef REMOVED
unsigned short dummy[] = { 0, 0, 0 };
unsigned short* cseed = seed48(dummy);
if (!outFile.bad()) {
outFile << theSeed << std::endl;
for (int i=0; i<3; ++i) {
......@@ -141,6 +162,7 @@ void DRand48Engine::saveStatus( const char filename[] ) const
}
seed48(dummy);
}
#endif
}
void DRand48Engine::restoreStatus( const char filename[] )
......@@ -152,10 +174,32 @@ void DRand48Engine::restoreStatus( const char filename[] )
std::cerr << " -- Engine state remains unchanged\n";
return;
}
if ( possibleKeywordInput ( inFile, "Uvec", theSeed ) ) {
std::vector<unsigned long> v;
unsigned long xin;
for (unsigned int ivec=0; ivec < VECTOR_STATE_SIZE; ++ivec) {
inFile >> xin;
#ifdef TRACE_IO
std::cout << "ivec = " << ivec << " xin = " << xin << " ";
if (ivec%3 == 0) std::cout << "\n";
#endif
if (!inFile) {
inFile.clear(std::ios::badbit | inFile.rdstate());
std::cerr << "\nDRand48Engine state (vector) description improper."
<< "\nrestoreStatus has failed."
<< "\nInput stream is probably mispositioned now." << std::endl;
return;
}
v.push_back(xin);
}
getState(v);
return;
}
if (!inFile.bad() && !inFile.eof()) {
inFile >> theSeed;
for (int i=0; i<3; ++i)
inFile >> cseed[i];
// inFile >> theSeed; removed -- encompased by possibleKeywordInput
seed48(cseed);
}
}
......@@ -195,11 +239,18 @@ void DRand48Engine::flatArray(const int size, double* vect)
std::ostream & DRand48Engine::put ( std::ostream& os ) const
{
char beginMarker[] = "DRand48Engine-begin";
os << beginMarker << "\nUvec\n";
std::vector<unsigned long> v = put();
for (unsigned int i=0; i<v.size(); ++i) {
os << v[i] << "\n";
}
return os;
#ifdef REMOVED
unsigned short dummy[] = { 0, 0, 0 };
unsigned short* cseed = seed48(dummy);
char beginMarker[] = "DRand48Engine-begin";
char endMarker[] = "DRand48Engine-end";
os << " " << beginMarker << " ";
os << theSeed << " ";
for (int i=0; i<3; ++i) {
......@@ -209,6 +260,7 @@ std::ostream & DRand48Engine::put ( std::ostream& os ) const
os << endMarker << " ";
seed48(dummy);
return os;
#endif
}
std::vector<unsigned long> DRand48Engine::put () const {
......@@ -246,12 +298,40 @@ std::string DRand48Engine::beginTag ( ) {
return "DRand48Engine-begin";
}
std::istream & DRand48Engine::getState ( std::istream& is )
std::istream & DRand48Engine::getState ( std::istream& is )
{
char endMarker [MarkerLen];
unsigned short cseed[3];
if ( possibleKeywordInput ( is, "Uvec", cseed[0] ) ) {
std::vector<unsigned long> v;
unsigned long uu;
#ifdef TRACE_IO
std::cout << "DRand48Engine::getState detected Uvec keyword\n";
uu = 999999;
#endif
for (unsigned int ivec=0; ivec < VECTOR_STATE_SIZE; ++ivec) {
uu = 999999;
is >> uu;
#ifdef TRACE_IO
std::cout << "ivec = " << ivec << " uu = " << uu << "\n";
#endif
if (!is) {
is.clear(std::ios::badbit | is.rdstate());
std::cerr << "\nDRand48Engine state (vector) description improper."
<< "\ngetState() has failed."
<< "\nInput stream is probably mispositioned now." << std::endl;
return is;
}
v.push_back(uu);
}
getState(v);
return (is);
}
// is >> cseed[0] was removed from loop, encompassed by possibleKeywordInput()
char endMarker [MarkerLen];
is >> theSeed;
for (int i=0; i<3; ++i) {
for (int i=1; i<3; ++i) {
is >> cseed[i];
}
is >> std::ws;
......@@ -277,9 +357,9 @@ bool DRand48Engine::get (const std::vector<unsigned long> & v) {
}
bool DRand48Engine::getState (const std::vector<unsigned long> & v) {
if (v.size() != 4 ) {
if (v.size() != VECTOR_STATE_SIZE ) {
std::cerr <<
"\nDRand48Engine get:state vector has wrong length - state unchanged\n";
"\nDRand48Engine getState:state vector has wrong length - state unchanged\n";
return false;
}
unsigned short cseed[3];
......
// $Id: DualRand.cc,v 1.3.4.1 2005/03/18 22:26:48 garren Exp $
// $Id: DualRand.cc,v 1.3.4.2 2005/04/15 16:32:53 garren Exp $
// -*- C++ -*-
//
// -----------------------------------------------------------------------
......@@ -47,6 +47,8 @@
// M. Fischler - split get() into tag validation and
// getState() for anonymous restores 12/27/04
// Mark Fischler - methods for vector save/restore 3/7/05
// M. Fischler - State-saving using only ints, for portability 4/12/05
//
//=========================================================================
#include "CLHEP/Random/DualRand.h"
......@@ -155,13 +157,30 @@ void DualRand::setSeeds(const long * seeds, int) {
void DualRand::saveStatus(const char filename[]) const {
std::ofstream outFile(filename, std::ios::out);
if (!outFile.bad()) {
outFile << "Uvec\n";
std::vector<unsigned long> v = put();
#ifdef TRACE_IO
std::cout << "Result of v = put() is:\n";
#endif
for (unsigned int i=0; i<v.size(); ++i) {
outFile << v[i] << "\n";
#ifdef TRACE_IO
std::cout << v[i] << " ";
if (i%6==0) std::cout << "\n";
#endif
}
#ifdef TRACE_IO
std::cout << "\n";
#endif
}
#ifdef REMOVED
int pr=outFile.precision(20);
outFile << theSeed << std::endl;
tausworthe.put(outFile);
integerCong.put(outFile);
outFile << std::endl; // This is superfluous but harmless
outFile.precision(pr);
}
#endif
}
void DualRand::restoreStatus(const char filename[]) {
......@@ -170,8 +189,30 @@ void DualRand::restoreStatus(const char filename[]) {
std::cerr << " -- Engine state remains unchanged\n";
return;
}
if ( possibleKeywordInput ( inFile, "Uvec", theSeed ) ) {
std::vector<unsigned long> v;
unsigned long xin;
for (unsigned int ivec=0; ivec < VECTOR_STATE_SIZE; ++ivec) {
inFile >> xin;
#ifdef TRACE_IO
std::cout << "ivec = " << ivec << " xin = " << xin << " ";
if (ivec%3 == 0) std::cout << "\n";
#endif
if (!inFile) {
inFile.clear(std::ios::badbit | inFile.rdstate());
std::cerr << "\nDualRand state (vector) description improper."
<< "\nrestoreStatus has failed."
<< "\nInput stream is probably mispositioned now." << std::endl;
return;
}
v.push_back(xin);
}
getState(v);
return;
}
if (!inFile.bad()) {
inFile >> theSeed;
// inFile >> theSeed; removed -- encompased by possibleKeywordInput
tausworthe.get(inFile);
integerCong.get(inFile);
}
......@@ -204,6 +245,13 @@ DualRand::operator unsigned int() {
std::ostream & DualRand::put(std::ostream & os) const {
char beginMarker[] = "DualRand-begin";
os << beginMarker << "\nUvec\n";
std::vector<unsigned long> v = put();
for (unsigned int i=0; i<v.size(); ++i) {
os << v[i] << "\n";
}
return os;
#ifdef REMOVED
char endMarker[] = "DualRand-end";
int pr=os.precision(20);
os << " " << beginMarker << " ";
......@@ -213,6 +261,7 @@ std::ostream & DualRand::put(std::ostream & os) const {
os << " " << endMarker << "\n";
os.precision(pr);
return os;
#endif
}
std::vector<unsigned long> DualRand::put () const {
......@@ -245,8 +294,27 @@ std::string DualRand::beginTag ( ) {
}
std::istream & DualRand::getState ( std::istream & is ) {
if ( possibleKeywordInput ( is, "Uvec", theSeed ) ) {
std::vector<unsigned long> v;
unsigned long uu;
for (unsigned int ivec=0; ivec < VECTOR_STATE_SIZE; ++ivec) {
is >> uu;
if (!is) {
is.clear(std::ios::badbit | is.rdstate());
std::cerr << "\nDualRand state (vector) description improper."
<< "\ngetState() has failed."
<< "\nInput stream is probably mispositioned now." << std::endl;
return is;
}
v.push_back(uu);
}
getState(v);
return (is);
}
// is >> theSeed; Removed, encompassed by possibleKeywordInput()
char endMarker [MarkerLen];
is >> theSeed;
tausworthe.get(is);
integerCong.get(is);
is >> std::ws;
......@@ -267,7 +335,7 @@ bool DualRand::get(const std::vector<unsigned long> & v) {
"\nDualRand get:state vector has wrong ID word - state unchanged\n";
return false;
}
if (v.size() != 9) {
if (v.size() != VECTOR_STATE_SIZE) {
std::cerr << "\nDualRand get:state vector has wrong size: "
<< v.size() << " - state unchanged\n";
return false;
......
// $Id: Hurd160Engine.cc,v 1.4.4.1 2005/03/18 22:26:48 garren Exp $
// $Id: Hurd160Engine.cc,v 1.4.4.2 2005/04/15 16:32:53 garren Exp $
// -*- C++ -*-
//
// -----------------------------------------------------------------------
......@@ -24,6 +24,7 @@
// M. Fischler - split get() into tag validation and
// getState() for anonymous restores 12/27/04
// M. Fischler - put/get for vectors of ulongs 3/14/05
// M. Fischler - State-saving using only ints, for portability 4/12/05
//
// =======================================================================
......@@ -180,13 +181,30 @@ void Hurd160Engine::setSeeds( const long* seeds, int ) {
void Hurd160Engine::saveStatus( const char filename[] ) const {
std::ofstream outFile(filename, std::ios::out);
if( !outFile.bad() ) {
outFile << "Uvec\n";
std::vector<unsigned long> v = put();
#ifdef TRACE_IO
std::cout << "Result of v = put() is:\n";
#endif
for (unsigned int i=0; i<v.size(); ++i) {
outFile << v[i] << "\n";
#ifdef TRACE_IO
std::cout << v[i] << " ";
if (i%6==0) std::cout << "\n";
#endif
}
#ifdef TRACE_IO
std::cout << "\n";
#endif
}
#ifdef REMOVED
outFile << std::setprecision(20) << theSeed << " ";
outFile << wordIndex << " ";
for( int i = 0; i < 5; ++i ) {
outFile << words[i] << " ";
}
outFile << std::endl;
}
#endif
}
void Hurd160Engine::restoreStatus( const char filename[] ) {
......@@ -195,8 +213,30 @@ void Hurd160Engine::restoreStatus( const char filename[] ) {
std::cerr << " -- Engine state remains unchanged\n";
return;
}
if ( possibleKeywordInput ( inFile, "Uvec", theSeed ) ) {
std::vector<unsigned long> v;
unsigned long xin;
for (unsigned int ivec=0; ivec < VECTOR_STATE_SIZE; ++ivec) {
inFile >> xin;