// $Id: RandFlat.cc,v 1.14 2002/05/07 16:47:29 mf Exp $ // -*- C++ -*- // // ----------------------------------------------------------------------- // HEP Random // --- RandFlat --- // class implementation file // ----------------------------------------------------------------------- // This file is part of Geant4 (simulation toolkit for HEP). // ======================================================================= // Gabriele Cosmo - Created: 17th May 1995 // - Added methods to shoot arrays: 28th July 1997 // - Added operator(): 24th Jul 1997 // J.Marraffino - Added default arguments as attributes and // operator() with arguments: 16th Feb 1998 // M Fischler - Copy constructor should supply right engine to HepRandom: // 1/26/00. // M Fischler - Semi-fix to the saveEngineStatus misbehavior causing // non-reproducing shootBit() 3/1/00. // ======================================================================= #include "CLHEP/Random/RandFlat.h" #include const int RandFlat::MSBBits= 15; const unsigned long RandFlat::MSB= 1ul<flat(); } void RandFlat::shootArray(const int size, double* vect) { HepRandom::getTheEngine()->flatArray(size,vect); } void RandFlat::shootArray( const int size, double* vect, double lx, double dx ) { int i; for (i=0; isaveStatus( filename ); // Now append the cached random Int, and first unused bit: HepStd::ofstream outfile ( filename, HepStd::ios::app ); outfile << "RANDFLAT staticRandomInt: " << staticRandomInt << " staticFirstUnusedBit: " << staticFirstUnusedBit << "\n"; } // saveEngineStatus void RandFlat::restoreEngineStatus( const char filename[] ) { // First restore the engine status just like the base class would do: getTheEngine()->restoreStatus( filename ); // Now find the line describing the cached data: HepStd::ifstream infile ( filename, HepStd::ios::in ); char inputword[] = "NO_KEYWORD "; // leaves room for 14 characters plus \0 while (true) { infile.width(13); infile >> inputword; if (strcmp(inputword,"RANDFLAT")==0) break; if (infile.eof()) break; // If the file ends without the RANDFLAT line, that means this // was a file produced by an earlier version of RandFlat. We will // replicate the old behavior in that case: staticFirstUnusedBit // and staticRandomInt retain their existing values. } // Then read and use the caching info: if (strcmp(inputword,"RANDFLAT")==0) { char setword[40]; // the longest, staticFirstUnusedBit: has length 21 infile.width(39); infile >> setword; // setword should be staticRandomInt: infile >> staticRandomInt; infile.width(39); infile >> setword; // setword should be staticFirstUnusedBit: infile >> staticFirstUnusedBit; } } // restoreEngineStatus