CLHEP 2.4.6.4
C++ Class Library for High Energy Physics
Loading...
Searching...
No Matches
CLHEP::NonRandomEngine Class Reference

#include <NonRandomEngine.h>

+ Inheritance diagram for CLHEP::NonRandomEngine:

Public Member Functions

 NonRandomEngine ()
 
virtual ~NonRandomEngine ()
 
void setNextRandom (double r)
 
void setRandomSequence (double *s, int n)
 
void setRandomInterval (double x)
 
double flat ()
 
void flatArray (const int size, double *vect)
 
virtual std::ostream & put (std::ostream &os) const
 
virtual std::istream & get (std::istream &is)
 
virtual std::istream & getState (std::istream &is)
 
std::string name () const
 
std::vector< unsigned long > put () const
 
bool get (const std::vector< unsigned long > &v)
 
bool getState (const std::vector< unsigned long > &v)
 
- Public Member Functions inherited from CLHEP::HepRandomEngine
 HepRandomEngine ()
 
virtual ~HepRandomEngine ()
 
bool operator== (const HepRandomEngine &engine)
 
bool operator!= (const HepRandomEngine &engine)
 
virtual double flat ()=0
 
virtual void flatArray (const int size, double *vect)=0
 
virtual void setSeed (long seed, int)=0
 
virtual void setSeeds (const long *seeds, int)=0
 
virtual void saveStatus (const char filename[]="Config.conf") const =0
 
virtual void restoreStatus (const char filename[]="Config.conf")=0
 
virtual void showStatus () const =0
 
virtual std::string name () const =0
 
virtual std::ostream & put (std::ostream &os) const
 
virtual std::istream & get (std::istream &is)
 
virtual std::istream & getState (std::istream &is)
 
virtual std::vector< unsigned long > put () const
 
virtual bool get (const std::vector< unsigned long > &v)
 
virtual bool getState (const std::vector< unsigned long > &v)
 
long getSeed () const
 
const long * getSeeds () const
 
virtual operator double ()
 
virtual operator float ()
 
virtual operator unsigned int ()
 

Static Public Member Functions

static std::string beginTag ()
 
static std::string engineName ()
 
- Static Public Member Functions inherited from CLHEP::HepRandomEngine
static std::string beginTag ()
 
static HepRandomEnginenewEngine (std::istream &is)
 
static HepRandomEnginenewEngine (const std::vector< unsigned long > &v)
 

Additional Inherited Members

- Static Protected Member Functions inherited from CLHEP::HepRandomEngine
static double exponent_bit_32 ()
 
static double mantissa_bit_12 ()
 
static double mantissa_bit_24 ()
 
static double mantissa_bit_32 ()
 
static double twoToMinus_32 ()
 
static double twoToMinus_48 ()
 
static double twoToMinus_49 ()
 
static double twoToMinus_53 ()
 
static double nearlyTwoToMinus_54 ()
 
static bool checkFile (std::istream &file, const std::string &filename, const std::string &classname, const std::string &methodname)
 
- Protected Attributes inherited from CLHEP::HepRandomEngine
long theSeed
 
const long * theSeeds
 

Detailed Description

Author

Definition at line 40 of file NonRandomEngine.h.

Constructor & Destructor Documentation

◆ NonRandomEngine()

CLHEP::NonRandomEngine::NonRandomEngine ( )

Definition at line 37 of file NonRandomEngine.cc.

37 : nextHasBeenSet(false),
38 sequenceHasBeenSet(false),
39 intervalHasBeenSet(false) ,
40 nextRandom(0.05),
41 nInSeq(0),
42 randomInterval(0.1) { }

◆ ~NonRandomEngine()

CLHEP::NonRandomEngine::~NonRandomEngine ( )
virtual

Definition at line 44 of file NonRandomEngine.cc.

44{ }

Member Function Documentation

◆ beginTag()

std::string CLHEP::NonRandomEngine::beginTag ( )
static

Definition at line 161 of file NonRandomEngine.cc.

161 {
162 return "NonRandomEngine-begin";
163}

◆ engineName()

static std::string CLHEP::NonRandomEngine::engineName ( )
inlinestatic

Definition at line 72 of file NonRandomEngine.h.

72{return "NonRandomEngine";}

Referenced by anonymousRestore1< NonRandomEngine >(), vectorRestore1< NonRandomEngine >(), and vectorTest64< NonRandomEngine >().

◆ flat()

double CLHEP::NonRandomEngine::flat ( )
virtual

Implements CLHEP::HepRandomEngine.

Definition at line 69 of file NonRandomEngine.cc.

69 {
70
71 if (sequenceHasBeenSet) {
72 double v = sequence[nInSeq++];
73 if (nInSeq >= sequence.size() ) sequenceHasBeenSet = false;
74 return v;
75 }
76
77 if ( !nextHasBeenSet ) {
78 std::cout
79 << "Attempt to use NonRandomEngine without setting next random!\n";
80 exit(1);
81 }
82
83 double a = nextRandom;
84 nextHasBeenSet = false;
85
86 if (intervalHasBeenSet) {
87 nextRandom += randomInterval;
88 if ( nextRandom >= 1 ) nextRandom -= 1.0;
89 nextHasBeenSet = true;
90 }
91
92 return a;
93}
#define exit(x)

Referenced by anonymousRestore1< NonRandomEngine >(), flatArray(), vectorRestore1< NonRandomEngine >(), and vectorTest64< NonRandomEngine >().

◆ flatArray()

void CLHEP::NonRandomEngine::flatArray ( const int  size,
double vect 
)
virtual

Implements CLHEP::HepRandomEngine.

Definition at line 96 of file NonRandomEngine.cc.

96 {
97 for (int i = 0; i < size; ++i) {
98 vect[i] = flat();
99 }
100}

◆ get() [1/2]

bool CLHEP::NonRandomEngine::get ( const std::vector< unsigned long > &  v)
virtual

Reimplemented from CLHEP::HepRandomEngine.

Definition at line 231 of file NonRandomEngine.cc.

231 {
232 if ((v[0] & 0xffffffffUL) != engineIDulong<NonRandomEngine>()) {
233 std::cerr <<
234 "\nNonRandomEngine get:state vector has wrong ID word - state unchanged\n";
235 return false;
236 }
237 return getState(v);
238}
virtual std::istream & getState(std::istream &is)

◆ get() [2/2]

std::istream & CLHEP::NonRandomEngine::get ( std::istream &  is)
virtual

Reimplemented from CLHEP::HepRandomEngine.

Definition at line 148 of file NonRandomEngine.cc.

148 {
149 std::string beginMarker = "NonRandomEngine-begin";
150 is >> beginMarker;
151 if (beginMarker != "NonRandomEngine-begin") {
152 is.clear(std::ios::badbit | is.rdstate());
153 std::cerr << "\nInput mispositioned or"
154 << "\nNonRandomEngine state description missing or"
155 << "\nwrong engine type found.\n";
156 return is;
157 }
158 return getState(is);
159}

◆ getState() [1/2]

bool CLHEP::NonRandomEngine::getState ( const std::vector< unsigned long > &  v)
virtual

Reimplemented from CLHEP::HepRandomEngine.

Definition at line 240 of file NonRandomEngine.cc.

240 {
241 unsigned long seqSize = v[9];
242 if (v.size() != 2*seqSize + 10 ) {
243 std::cerr <<
244 "\nNonRandomEngine get:state vector has wrong length - state unchanged\n";
245 std::cerr << " (length = " << v.size()
246 << "; expected " << 2*seqSize + 10 << ")\n";
247 return false;
248 }
249 std::vector<unsigned long> t(2);
250 nextHasBeenSet = (v[1]!=0);
251 sequenceHasBeenSet = (v[2]!=0);
252 intervalHasBeenSet = (v[3]!=0);
253 t[0] = v[4]; t[1] = v[5]; nextRandom = DoubConv::longs2double(t);
254 nInSeq = (unsigned int)v[6];
255 t[0] = v[7]; t[1] = v[8]; randomInterval = DoubConv::longs2double(t);
256 sequence.clear();
257 for (unsigned long i=0; i<seqSize; ++i) {
258 t[0] = v[2*i+10]; t[1] = v[2*i+11];
259 sequence.push_back(DoubConv::longs2double(t));
260 }
261 return true;
262}
static double longs2double(const std::vector< unsigned long > &v)
Definition: DoubConv.cc:110

◆ getState() [2/2]

std::istream & CLHEP::NonRandomEngine::getState ( std::istream &  is)
virtual

Reimplemented from CLHEP::HepRandomEngine.

Definition at line 165 of file NonRandomEngine.cc.

165 {
166 if ( possibleKeywordInput ( is, "Uvec", nextHasBeenSet ) ) {
167 std::vector<unsigned long> v;
168 unsigned long uu = 99999;
169 unsigned long ssiz = 0;
170 //std::string temporary;
171 //is >> temporary;
172 //std::cout << "*** " << temporary << "\n";
173 for (unsigned int istart=0; istart < 10; ++istart) {
174 is >> uu;
175 if (!is) {
176 is.clear(std::ios::badbit | is.rdstate());
177 std::cout << "istart = " << istart << "\n";
178 std::cerr
179 << "\nNonRandomEngine state (vector) description has no sequence size."
180 << "\ngetState() has failed."
181 << "\nInput stream is probably mispositioned now." << std::endl;
182 return is;
183 }
184 v.push_back(uu);
185 #ifdef TRACE_IO
186 std::cout << "v[" << istart << "] = " << uu << "\n";
187 #endif
188 if (istart==9) ssiz = uu;
189 }
190 for (unsigned int ivec=0; ivec < 2*ssiz; ++ivec) {
191 is >> uu;
192 if (!is) {
193 is.clear(std::ios::badbit | is.rdstate());
194 std::cerr << "\nNonRandomEngine state (vector) description improper."
195 << "\ngetState() has failed."
196 << "\nInput stream is probably mispositioned now." << std::endl;
197 return is;
198 }
199 v.push_back(uu);
200 #ifdef TRACE_IO
201 std::cout << "v[" << v.size()-1 << "] = " << uu << "\n";
202 #endif
203 }
204 getState(v);
205 return (is);
206 }
207
208// is >> nextHasBeenSet; Removed, encompassed by possibleKeywordInput()
209
210 std::string endMarker = "NonRandomEngine-end";
211 is >> sequenceHasBeenSet >> intervalHasBeenSet;
212 is >> nextRandom >> nInSeq >> randomInterval;
213 unsigned int seqSize;
214 is >> seqSize;
215 sequence.clear();
216 double x;
217 for (unsigned int i = 0; i < seqSize; ++i) {
218 is >> x;
219 sequence.push_back(x);
220 }
221 is >> endMarker;
222 if (endMarker != "NonRandomEngine-end") {
223 is.clear(std::ios::badbit | is.rdstate());
224 std::cerr << "\n NonRandomEngine state description incomplete."
225 << "\nInput stream is probably mispositioned now." << std::endl;
226 return is;
227 }
228 return is;
229}
bool possibleKeywordInput(IS &is, const std::string &key, T &t)
Definition: RandomEngine.h:168

Referenced by get(), and getState().

◆ name()

std::string CLHEP::NonRandomEngine::name ( ) const
virtual

Implements CLHEP::HepRandomEngine.

Definition at line 35 of file NonRandomEngine.cc.

35{return "NonRandomEngine";}

◆ put() [1/2]

std::vector< unsigned long > CLHEP::NonRandomEngine::put ( ) const
virtual

Reimplemented from CLHEP::HepRandomEngine.

Definition at line 128 of file NonRandomEngine.cc.

128 {
129 std::vector<unsigned long> v;
130 v.push_back (engineIDulong<NonRandomEngine>());
131 std::vector<unsigned long> t;
132 v.push_back(static_cast<unsigned long>(nextHasBeenSet));
133 v.push_back(static_cast<unsigned long>(sequenceHasBeenSet));
134 v.push_back(static_cast<unsigned long>(intervalHasBeenSet));
135 t = DoubConv::dto2longs(nextRandom);
136 v.push_back(t[0]); v.push_back(t[1]);
137 v.push_back(static_cast<unsigned long>(nInSeq));
138 t = DoubConv::dto2longs(randomInterval);
139 v.push_back(t[0]); v.push_back(t[1]);
140 v.push_back(static_cast<unsigned long>(sequence.size()));
141 for (unsigned int i=0; i<sequence.size(); ++i) {
142 t = DoubConv::dto2longs(sequence[i]);
143 v.push_back(t[0]); v.push_back(t[1]);
144 }
145 return v;
146}
static std::vector< unsigned long > dto2longs(double d)
Definition: DoubConv.cc:94

Referenced by put().

◆ put() [2/2]

std::ostream & CLHEP::NonRandomEngine::put ( std::ostream &  os) const
virtual

Reimplemented from CLHEP::HepRandomEngine.

Definition at line 102 of file NonRandomEngine.cc.

102 {
103 std::string beginMarker = "NonRandomEngine-begin";
104 os << beginMarker << "\nUvec\n";
105 std::vector<unsigned long> v = put();
106 for (unsigned int i=0; i<v.size(); ++i) {
107 os << v[i] << "\n";
108 }
109 return os;
110#ifdef REMOVED
111 std::string endMarker = "NonRandomEngine-end";
112 long pr = os.precision(20);
113 os << " " << beginMarker << "\n";
114 os << nextHasBeenSet << " ";
115 os << sequenceHasBeenSet << " ";
116 os << intervalHasBeenSet << "\n";
117 os << nextRandom << " " << nInSeq << " " << randomInterval << "\n";
118 os << sequence.size() << "\n";
119 for (unsigned int i = 0; i < sequence.size(); ++i) {
120 os << sequence[i] << "\n";
121 }
122 os << endMarker << "\n ";
123 os.precision(pr);
124 return os;
125#endif
126}
std::vector< unsigned long > put() const

Referenced by vectorTest64< NonRandomEngine >().

◆ setNextRandom()

void CLHEP::NonRandomEngine::setNextRandom ( double  r)

Definition at line 47 of file NonRandomEngine.cc.

47 {
48 nextRandom = r;
49 nextHasBeenSet=true;
50 return;
51}

Referenced by main().

◆ setRandomInterval()

void CLHEP::NonRandomEngine::setRandomInterval ( double  x)

Definition at line 63 of file NonRandomEngine.cc.

63 {
64 randomInterval = x;
65 intervalHasBeenSet=true;
66 return;
67}

◆ setRandomSequence()

void CLHEP::NonRandomEngine::setRandomSequence ( double s,
int  n 
)

Definition at line 53 of file NonRandomEngine.cc.

53 {
54 sequence.clear();
55 for (int i=0; i<n; i++) sequence.push_back(*s++);
56 assert (sequence.size() == (unsigned int)n);
57 nInSeq = 0;
58 sequenceHasBeenSet=true;
59 nextHasBeenSet=false;
60 return;
61}

Referenced by anonymousRestore1< NonRandomEngine >(), main(), vectorRestore1< NonRandomEngine >(), and vectorTest64< NonRandomEngine >().


The documentation for this class was generated from the following files: