Geant4 Cross Reference

Cross-Referencing   Geant4
Geant4/externals/clhep/src/RanecuEngine.cc

Version: [ ReleaseNotes ] [ 1.0 ] [ 1.1 ] [ 2.0 ] [ 3.0 ] [ 3.1 ] [ 3.2 ] [ 4.0 ] [ 4.0.p1 ] [ 4.0.p2 ] [ 4.1 ] [ 4.1.p1 ] [ 5.0 ] [ 5.0.p1 ] [ 5.1 ] [ 5.1.p1 ] [ 5.2 ] [ 5.2.p1 ] [ 5.2.p2 ] [ 6.0 ] [ 6.0.p1 ] [ 6.1 ] [ 6.2 ] [ 6.2.p1 ] [ 6.2.p2 ] [ 7.0 ] [ 7.0.p1 ] [ 7.1 ] [ 7.1.p1 ] [ 8.0 ] [ 8.0.p1 ] [ 8.1 ] [ 8.1.p1 ] [ 8.1.p2 ] [ 8.2 ] [ 8.2.p1 ] [ 8.3 ] [ 8.3.p1 ] [ 8.3.p2 ] [ 9.0 ] [ 9.0.p1 ] [ 9.0.p2 ] [ 9.1 ] [ 9.1.p1 ] [ 9.1.p2 ] [ 9.1.p3 ] [ 9.2 ] [ 9.2.p1 ] [ 9.2.p2 ] [ 9.2.p3 ] [ 9.2.p4 ] [ 9.3 ] [ 9.3.p1 ] [ 9.3.p2 ] [ 9.4 ] [ 9.4.p1 ] [ 9.4.p2 ] [ 9.4.p3 ] [ 9.4.p4 ] [ 9.5 ] [ 9.5.p1 ] [ 9.5.p2 ] [ 9.6 ] [ 9.6.p1 ] [ 9.6.p2 ] [ 9.6.p3 ] [ 9.6.p4 ] [ 10.0 ] [ 10.0.p1 ] [ 10.0.p2 ] [ 10.0.p3 ] [ 10.0.p4 ] [ 10.1 ] [ 10.1.p1 ] [ 10.1.p2 ] [ 10.1.p3 ] [ 10.2 ] [ 10.2.p1 ] [ 10.2.p2 ] [ 10.2.p3 ] [ 10.3 ] [ 10.3.p1 ] [ 10.3.p2 ] [ 10.3.p3 ] [ 10.4 ] [ 10.4.p1 ] [ 10.4.p2 ] [ 10.4.p3 ] [ 10.5 ] [ 10.5.p1 ] [ 10.6 ] [ 10.6.p1 ] [ 10.6.p2 ] [ 10.6.p3 ] [ 10.7 ] [ 10.7.p1 ] [ 10.7.p2 ] [ 10.7.p3 ] [ 10.7.p4 ] [ 11.0 ] [ 11.0.p1 ] [ 11.0.p2 ] [ 11.0.p3, ] [ 11.0.p4 ] [ 11.1 ] [ 11.1.1 ] [ 11.1.2 ] [ 11.1.3 ] [ 11.2 ] [ 11.2.1 ] [ 11.2.2 ] [ 11.3.0 ]

Diff markup

Differences between /externals/clhep/src/RanecuEngine.cc (Version 11.3.0) and /externals/clhep/src/RanecuEngine.cc (Version 10.1.p1)


                                                   >>   1 // $Id:$
  1 // -*- C++ -*-                                      2 // -*- C++ -*-
  2 //                                                  3 //
  3 // -------------------------------------------      4 // -----------------------------------------------------------------------
  4 //                             HEP Random           5 //                             HEP Random
  5 //                        --- RanecuEngine ---      6 //                        --- RanecuEngine ---
  6 //                      class implementation f      7 //                      class implementation file
  7 // -------------------------------------------      8 // -----------------------------------------------------------------------
  8 // This file is part of Geant4 (simulation too      9 // This file is part of Geant4 (simulation toolkit for HEP).
  9 //                                                 10 //
 10 // RANECU Random Engine - algorithm originally     11 // RANECU Random Engine - algorithm originally written in FORTRAN77
 11 //                        as part of the MATHL     12 //                        as part of the MATHLIB HEP library.
 12                                                    13 
 13 // ===========================================     14 // =======================================================================
 14 // Gabriele Cosmo - Created - 2nd February 199     15 // Gabriele Cosmo - Created - 2nd February 1996
 15 //                - Minor corrections: 31st Oc     16 //                - Minor corrections: 31st October 1996
 16 //                - Added methods for engine s     17 //                - Added methods for engine status: 19th November 1996
 17 //                - Added abs for setting seed     18 //                - Added abs for setting seed index: 11th July 1997
 18 //                - Modified setSeeds() to han     19 //                - Modified setSeeds() to handle default index: 16th Oct 1997
 19 //                - setSeed() now resets the e     20 //                - setSeed() now resets the engine status to the original
 20 //                  values in the static table     21 //                  values in the static table of HepRandom: 19th Mar 1998
 21 // J.Marraffino   - Added stream operators and     22 // J.Marraffino   - Added stream operators and related constructor.
 22 //                  Added automatic seed selec     23 //                  Added automatic seed selection from seed table and
 23 //                  engine counter: 16th Feb 1     24 //                  engine counter: 16th Feb 1998
 24 // Ken Smith      - Added conversion operators     25 // Ken Smith      - Added conversion operators:  6th Aug 1998
 25 // J. Marraffino  - Remove dependence on hepSt     26 // J. Marraffino  - Remove dependence on hepString class   13 May 1999
 26 // M. Fischler    - Add endl to the end of sav     27 // M. Fischler    - Add endl to the end of saveStatus      10 Apr 2001
 27 // M. Fischler    - In restore, checkFile for      28 // M. Fischler    - In restore, checkFile for file not found    03 Dec 2004
 28 // M. Fischler    - Methods for distrib. insta     29 // M. Fischler    - Methods for distrib. instance save/restore  12/8/04    
 29 // M. Fischler    - split get() into tag valid     30 // M. Fischler    - split get() into tag validation and 
 30 //                  getState() for anonymous r     31 //                  getState() for anonymous restores           12/27/04    
 31 // M. Fischler    - put/get for vectors of ulo     32 // M. Fischler    - put/get for vectors of ulongs   3/14/05
 32 // M. Fischler    - State-saving using only in     33 // M. Fischler    - State-saving using only ints, for portability 4/12/05
 33 // M. Fischler    - Modify ctor and setSeed to     34 // M. Fischler    - Modify ctor and setSeed to utilize all info provided
 34 //                  and avoid coincidence of s     35 //                  and avoid coincidence of same state from different
 35 //                  seeds                          36 //                  seeds                                       6/22/10
 36 //                                                 37 //        
 37 // ===========================================     38 // =======================================================================
 38                                                    39 
 39 #include "CLHEP/Random/Random.h"                   40 #include "CLHEP/Random/Random.h"
 40 #include "CLHEP/Random/RanecuEngine.h"             41 #include "CLHEP/Random/RanecuEngine.h"
 41 #include "CLHEP/Random/engineIDulong.h"            42 #include "CLHEP/Random/engineIDulong.h"
 42 #include "CLHEP/Utility/atomic_int.h"              43 #include "CLHEP/Utility/atomic_int.h"
 43                                                    44 
 44 #include <atomic>                              << 
 45 #include <cstdlib>                             << 
 46 #include <cmath>                               << 
 47 #include <iostream>                            << 
 48 #include <string>                              << 
 49 #include <string.h> // for strcmp                  45 #include <string.h> // for strcmp
 50 #include <vector>                              <<  46 #include <cmath>
                                                   >>  47 #include <cstdlib>
 51                                                    48 
 52 namespace CLHEP {                                  49 namespace CLHEP {
 53                                                    50 
 54 namespace {                                        51 namespace {
 55   // Number of instances with automatic seed s     52   // Number of instances with automatic seed selection
 56   CLHEP_ATOMIC_INT_TYPE numberOfEngines(0);        53   CLHEP_ATOMIC_INT_TYPE numberOfEngines(0);
 57 }                                                  54 }
 58                                                    55 
 59 static const int MarkerLen = 64; // Enough roo     56 static const int MarkerLen = 64; // Enough room to hold a begin or end marker. 
 60                                                    57 
 61 static const double prec = 4.6566128E-10;          58 static const double prec = 4.6566128E-10;
 62                                                    59 
 63 std::string RanecuEngine::name() const {return     60 std::string RanecuEngine::name() const {return "RanecuEngine";}
 64                                                    61 
 65 void RanecuEngine::further_randomize (int seq1     62 void RanecuEngine::further_randomize (int seq1, int col, int index, int modulus)
 66 {                                                  63 {
 67   table[seq1][col] -= (index&0x3FFFFFFF);          64   table[seq1][col] -= (index&0x3FFFFFFF);
 68   while (table[seq1][col] <= 0) table[seq1][co     65   while (table[seq1][col] <= 0) table[seq1][col] += (modulus-1);
 69 }  // mf 6/22/10                                   66 }  // mf 6/22/10
 70                                                    67 
 71 RanecuEngine::RanecuEngine()                       68 RanecuEngine::RanecuEngine()
 72 : HepRandomEngine()                                69 : HepRandomEngine()
 73 {                                                  70 {
 74   int numEngines = numberOfEngines++;              71   int numEngines = numberOfEngines++;
 75   int cycle = std::abs(int(numEngines/maxSeq))     72   int cycle = std::abs(int(numEngines/maxSeq));
 76   seq = std::abs(int(numEngines%maxSeq));          73   seq = std::abs(int(numEngines%maxSeq));
 77                                                    74 
 78   theSeed = seq;                                   75   theSeed = seq;
 79   long mask = ((cycle & 0x007fffff) << 8);         76   long mask = ((cycle & 0x007fffff) << 8);
 80   for (int i=0; i<2; ++i) {                        77   for (int i=0; i<2; ++i) {
 81     for (int j=0; j<maxSeq; ++j) {                 78     for (int j=0; j<maxSeq; ++j) {
 82       HepRandom::getTheTableSeeds(table[j],j);     79       HepRandom::getTheTableSeeds(table[j],j);
 83       table[j][i] ^= mask;                         80       table[j][i] ^= mask;
 84     }                                              81     }
 85   }                                                82   }
 86   theSeeds = &table[seq][0];                       83   theSeeds = &table[seq][0];
 87 }                                                  84 }
 88                                                    85 
 89 RanecuEngine::RanecuEngine(int index)              86 RanecuEngine::RanecuEngine(int index)
 90 : HepRandomEngine()                                87 : HepRandomEngine()
 91 {                                                  88 {
 92   int cycle = std::abs(int(index/maxSeq));         89   int cycle = std::abs(int(index/maxSeq));
 93   seq = std::abs(int(index%maxSeq));               90   seq = std::abs(int(index%maxSeq));
 94   theSeed = seq;                                   91   theSeed = seq;
 95   long mask = ((cycle & 0x000007ff) << 20);        92   long mask = ((cycle & 0x000007ff) << 20);
 96   for (int j=0; j<maxSeq; ++j) {                   93   for (int j=0; j<maxSeq; ++j) {
 97     HepRandom::getTheTableSeeds(table[j],j);       94     HepRandom::getTheTableSeeds(table[j],j);
 98     table[j][0] ^= mask;                           95     table[j][0] ^= mask;
 99     table[j][1] ^= mask;                           96     table[j][1] ^= mask;
100   }                                                97   }
101   theSeeds = &table[seq][0];                       98   theSeeds = &table[seq][0];
102   further_randomize (seq, 0, index, shift1);       99   further_randomize (seq, 0, index, shift1);     // mf 6/22/10
103 }                                                 100 }
104                                                   101 
105 RanecuEngine::RanecuEngine(std::istream& is)      102 RanecuEngine::RanecuEngine(std::istream& is)
106 : HepRandomEngine()                               103 : HepRandomEngine()
107 {                                                 104 {
108    is >> *this;                                   105    is >> *this;
109 }                                                 106 }
110                                                   107 
111 RanecuEngine::~RanecuEngine() {}                  108 RanecuEngine::~RanecuEngine() {}
112                                                   109 
113 void RanecuEngine::setSeed(long index, int dum    110 void RanecuEngine::setSeed(long index, int dum)
114 {                                                 111 {
115   seq = std::abs(int(index%maxSeq));              112   seq = std::abs(int(index%maxSeq));
116   theSeed = seq;                                  113   theSeed = seq;
117   HepRandom::getTheTableSeeds(table[seq],seq);    114   HepRandom::getTheTableSeeds(table[seq],seq);
118   theSeeds = &table[seq][0];                      115   theSeeds = &table[seq][0];
119   further_randomize (seq, 0, (int)index, shift << 116   further_randomize (seq, 0, index, shift1);     // mf 6/22/10
120   further_randomize (seq, 1, dum,   shift2);      117   further_randomize (seq, 1, dum,   shift2);     // mf 6/22/10
121 }                                                 118 }
122                                                   119 
123 void RanecuEngine::setSeeds(const long* seeds,    120 void RanecuEngine::setSeeds(const long* seeds, int pos)
124 {                                                 121 {
125   if (pos != -1) {                                122   if (pos != -1) {
126     seq = std::abs(int(pos%maxSeq));              123     seq = std::abs(int(pos%maxSeq));
127     theSeed = seq;                                124     theSeed = seq;
128   }                                               125   }
129   // only positive seeds are allowed              126   // only positive seeds are allowed
130   table[seq][0] = std::abs(seeds[0])%shift1;      127   table[seq][0] = std::abs(seeds[0])%shift1;
131   table[seq][1] = std::abs(seeds[1])%shift2;      128   table[seq][1] = std::abs(seeds[1])%shift2;
132   theSeeds = &table[seq][0];                      129   theSeeds = &table[seq][0];
133 }                                                 130 }
134                                                   131 
135 void RanecuEngine::setIndex(long index)           132 void RanecuEngine::setIndex(long index)
136 {                                                 133 {
137   seq = std::abs(int(index%maxSeq));              134   seq = std::abs(int(index%maxSeq));
138   theSeed = seq;                                  135   theSeed = seq;
139   theSeeds = &table[seq][0];                      136   theSeeds = &table[seq][0];
140 }                                                 137 }
141                                                   138 
142 void RanecuEngine::saveStatus( const char file    139 void RanecuEngine::saveStatus( const char filename[] ) const
143 {                                                 140 {
144    std::ofstream outFile( filename, std::ios::    141    std::ofstream outFile( filename, std::ios::out ) ;
145                                                   142 
146   if (!outFile.bad()) {                           143   if (!outFile.bad()) {
147     outFile << "Uvec\n";                          144     outFile << "Uvec\n";
148     std::vector<unsigned long> v = put();         145     std::vector<unsigned long> v = put();
149     for (unsigned int i=0; i<v.size(); ++i) {     146     for (unsigned int i=0; i<v.size(); ++i) {
150       outFile << v[i] << "\n";                    147       outFile << v[i] << "\n";
151     }                                             148     }
152   }                                               149   }
153 }                                                 150 }
154                                                   151 
155 void RanecuEngine::restoreStatus( const char f    152 void RanecuEngine::restoreStatus( const char filename[] )
156 {                                                 153 {
157   std::ifstream inFile( filename, std::ios::in    154   std::ifstream inFile( filename, std::ios::in);
158   if (!checkFile ( inFile, filename, engineNam    155   if (!checkFile ( inFile, filename, engineName(), "restoreStatus" )) {
159     std::cerr << "  -- Engine state remains un    156     std::cerr << "  -- Engine state remains unchanged\n";
160     return;                                       157     return;
161   }                                               158   }
162   if ( possibleKeywordInput ( inFile, "Uvec",     159   if ( possibleKeywordInput ( inFile, "Uvec", theSeed ) ) {
163     std::vector<unsigned long> v;                 160     std::vector<unsigned long> v;
164     unsigned long xin;                            161     unsigned long xin;
165     for (unsigned int ivec=0; ivec < VECTOR_ST    162     for (unsigned int ivec=0; ivec < VECTOR_STATE_SIZE; ++ivec) {
166       inFile >> xin;                              163       inFile >> xin;
167       if (!inFile) {                              164       if (!inFile) {
168         inFile.clear(std::ios::badbit | inFile    165         inFile.clear(std::ios::badbit | inFile.rdstate());
169         std::cerr << "\nJamesRandom state (vec    166         std::cerr << "\nJamesRandom state (vector) description improper."
170          << "\nrestoreStatus has failed."         167          << "\nrestoreStatus has failed."
171          << "\nInput stream is probably mispos    168          << "\nInput stream is probably mispositioned now." << std::endl;
172         return;                                   169         return;
173       }                                           170       }
174       v.push_back(xin);                           171       v.push_back(xin);
175     }                                             172     }
176     getState(v);                                  173     getState(v);
177     return;                                       174     return;
178   }                                               175   }
179                                                   176 
180   if (!inFile.bad() && !inFile.eof()) {           177   if (!inFile.bad() && !inFile.eof()) {
181 //     inFile >> theSeed;  removed -- encompas    178 //     inFile >> theSeed;  removed -- encompased by possibleKeywordInput
182      for (int i=0; i<2; ++i)                      179      for (int i=0; i<2; ++i)
183        inFile >> table[theSeed][i];               180        inFile >> table[theSeed][i];
184      seq = int(theSeed);                          181      seq = int(theSeed);
185   }                                               182   }
186 }                                                 183 }
187                                                   184 
188 void RanecuEngine::showStatus() const             185 void RanecuEngine::showStatus() const
189 {                                                 186 {
190    std::cout << std::endl;                        187    std::cout << std::endl;
191    std::cout << "--------- Ranecu engine statu    188    std::cout << "--------- Ranecu engine status ---------" << std::endl;
192    std::cout << " Initial seed (index) = " <<     189    std::cout << " Initial seed (index) = " << theSeed << std::endl;
193    std::cout << " Current couple of seeds = "     190    std::cout << " Current couple of seeds = "
194        << table[theSeed][0] << ", "               191        << table[theSeed][0] << ", "
195        << table[theSeed][1] << std::endl;         192        << table[theSeed][1] << std::endl;
196    std::cout << "-----------------------------    193    std::cout << "----------------------------------------" << std::endl;
197 }                                                 194 }
198                                                   195 
199 double RanecuEngine::flat()                       196 double RanecuEngine::flat()
200 {                                                 197 {
201    const int index = seq;                         198    const int index = seq;
202    long seed1 = table[index][0];                  199    long seed1 = table[index][0];
203    long seed2 = table[index][1];                  200    long seed2 = table[index][1];
204                                                   201 
205    int k1 = (int)(seed1/ecuyer_b);                202    int k1 = (int)(seed1/ecuyer_b);
206    int k2 = (int)(seed2/ecuyer_e);                203    int k2 = (int)(seed2/ecuyer_e);
207                                                   204 
208    seed1 = ecuyer_a*(seed1-k1*ecuyer_b)-k1*ecu    205    seed1 = ecuyer_a*(seed1-k1*ecuyer_b)-k1*ecuyer_c;
209    if (seed1 < 0) seed1 += shift1;                206    if (seed1 < 0) seed1 += shift1;
210    seed2 = ecuyer_d*(seed2-k2*ecuyer_e)-k2*ecu    207    seed2 = ecuyer_d*(seed2-k2*ecuyer_e)-k2*ecuyer_f;
211    if (seed2 < 0) seed2 += shift2;                208    if (seed2 < 0) seed2 += shift2;
212                                                   209 
213    table[index][0] = seed1;                       210    table[index][0] = seed1;
214    table[index][1] = seed2;                       211    table[index][1] = seed2;
215                                                   212 
216    long diff = seed1-seed2;                       213    long diff = seed1-seed2;
217                                                   214 
218    if (diff <= 0) diff += (shift1-1);             215    if (diff <= 0) diff += (shift1-1);
219    return (double)(diff*prec);                    216    return (double)(diff*prec);
220 }                                                 217 }
221                                                   218 
222 void RanecuEngine::flatArray(const int size, d    219 void RanecuEngine::flatArray(const int size, double* vect)
223 {                                                 220 {
224    const int index = seq;                         221    const int index = seq;
225    long seed1 = table[index][0];                  222    long seed1 = table[index][0];
226    long seed2 = table[index][1];                  223    long seed2 = table[index][1];
227    int k1, k2;                                    224    int k1, k2;
228    int i;                                         225    int i;
229                                                   226 
230    for (i=0; i<size; ++i)                         227    for (i=0; i<size; ++i)
231    {                                              228    {
232      k1 = (int)(seed1/ecuyer_b);                  229      k1 = (int)(seed1/ecuyer_b);
233      k2 = (int)(seed2/ecuyer_e);                  230      k2 = (int)(seed2/ecuyer_e);
234                                                   231 
235      seed1 = ecuyer_a*(seed1-k1*ecuyer_b)-k1*e    232      seed1 = ecuyer_a*(seed1-k1*ecuyer_b)-k1*ecuyer_c;
236      if (seed1 < 0) seed1 += shift1;              233      if (seed1 < 0) seed1 += shift1;
237      seed2 = ecuyer_d*(seed2-k2*ecuyer_e)-k2*e    234      seed2 = ecuyer_d*(seed2-k2*ecuyer_e)-k2*ecuyer_f;
238      if (seed2 < 0) seed2 += shift2;              235      if (seed2 < 0) seed2 += shift2;
239                                                   236 
240      long diff = seed1-seed2;                     237      long diff = seed1-seed2;
241      if (diff <= 0) diff += (shift1-1);           238      if (diff <= 0) diff += (shift1-1);
242                                                   239 
243      vect[i] = (double)(diff*prec);               240      vect[i] = (double)(diff*prec);
244    }                                              241    }
245    table[index][0] = seed1;                       242    table[index][0] = seed1;
246    table[index][1] = seed2;                       243    table[index][1] = seed2;
247 }                                              << 
248                                                << 
249 RanecuEngine::operator double() {              << 
250   return flat();                               << 
251 }                                              << 
252                                                << 
253 RanecuEngine::operator float() {               << 
254   return float( flat() );                      << 
255 }                                                 244 }
256                                                   245 
257 RanecuEngine::operator unsigned int() {           246 RanecuEngine::operator unsigned int() {
258    const int index = seq;                         247    const int index = seq;
259    long seed1 = table[index][0];                  248    long seed1 = table[index][0];
260    long seed2 = table[index][1];                  249    long seed2 = table[index][1];
261                                                   250 
262    int k1 = (int)(seed1/ecuyer_b);                251    int k1 = (int)(seed1/ecuyer_b);
263    int k2 = (int)(seed2/ecuyer_e);                252    int k2 = (int)(seed2/ecuyer_e);
264                                                   253 
265    seed1 = ecuyer_a*(seed1-k1*ecuyer_b)-k1*ecu    254    seed1 = ecuyer_a*(seed1-k1*ecuyer_b)-k1*ecuyer_c;
266    if (seed1 < 0) seed1 += shift1;                255    if (seed1 < 0) seed1 += shift1;
267    seed2 = ecuyer_d*(seed2-k2*ecuyer_e)-k2*ecu    256    seed2 = ecuyer_d*(seed2-k2*ecuyer_e)-k2*ecuyer_f;
268    if (seed2 < 0) seed2 += shift2;                257    if (seed2 < 0) seed2 += shift2;
269                                                   258 
270    table[index][0] = seed1;                       259    table[index][0] = seed1;
271    table[index][1] = seed2;                       260    table[index][1] = seed2;
272    long diff = seed1-seed2;                       261    long diff = seed1-seed2;
273    if( diff <= 0 ) diff += (shift1-1);            262    if( diff <= 0 ) diff += (shift1-1);
274                                                   263 
275    return ((diff << 1) | (seed1&1))& 0xfffffff    264    return ((diff << 1) | (seed1&1))& 0xffffffff;
276 }                                                 265 }
277                                                   266 
278 std::ostream & RanecuEngine::put( std::ostream    267 std::ostream & RanecuEngine::put( std::ostream& os ) const
279 {                                                 268 {
280    char beginMarker[] = "RanecuEngine-begin";     269    char beginMarker[] = "RanecuEngine-begin";
281   os << beginMarker << "\nUvec\n";                270   os << beginMarker << "\nUvec\n";
282   std::vector<unsigned long> v = put();           271   std::vector<unsigned long> v = put();
283   for (unsigned int i=0; i<v.size(); ++i) {       272   for (unsigned int i=0; i<v.size(); ++i) {
284      os <<  v[i] <<  "\n";                        273      os <<  v[i] <<  "\n";
285   }                                               274   }
286   return os;                                      275   return os;  
287 }                                                 276 }
288                                                   277 
289 std::vector<unsigned long> RanecuEngine::put (    278 std::vector<unsigned long> RanecuEngine::put () const {
290   std::vector<unsigned long> v;                   279   std::vector<unsigned long> v;
291   v.push_back (engineIDulong<RanecuEngine>());    280   v.push_back (engineIDulong<RanecuEngine>());
292   v.push_back(static_cast<unsigned long>(theSe    281   v.push_back(static_cast<unsigned long>(theSeed));
293   v.push_back(static_cast<unsigned long>(table    282   v.push_back(static_cast<unsigned long>(table[theSeed][0]));
294   v.push_back(static_cast<unsigned long>(table    283   v.push_back(static_cast<unsigned long>(table[theSeed][1]));
295   return v;                                       284   return v;
296 }                                                 285 }
297                                                   286 
298 std::istream & RanecuEngine::get ( std::istrea    287 std::istream & RanecuEngine::get ( std::istream& is )
299 {                                                 288 {
300   char beginMarker [MarkerLen];                   289   char beginMarker [MarkerLen];
301                                                   290 
302   is >> std::ws;                                  291   is >> std::ws;
303   is.width(MarkerLen);  // causes the next rea    292   is.width(MarkerLen);  // causes the next read to the char* to be <=
304       // that many bytes, INCLUDING A TERMINAT    293       // that many bytes, INCLUDING A TERMINATION \0 
305       // (Stroustrup, section 21.3.2)             294       // (Stroustrup, section 21.3.2)
306   is >> beginMarker;                              295   is >> beginMarker;
307   if (strcmp(beginMarker,"RanecuEngine-begin")    296   if (strcmp(beginMarker,"RanecuEngine-begin")) {
308      is.clear(std::ios::badbit | is.rdstate())    297      is.clear(std::ios::badbit | is.rdstate());
309      std::cerr << "\nInput stream mispositione    298      std::cerr << "\nInput stream mispositioned or"
310          << "\nRanecuEngine state description     299          << "\nRanecuEngine state description missing or"
311          << "\nwrong engine type found." << st    300          << "\nwrong engine type found." << std::endl;
312      return is;                                   301      return is;
313    }                                              302    }
314   return getState(is);                            303   return getState(is);
315 }                                                 304 }
316                                                   305 
317 std::string RanecuEngine::beginTag ( )  {         306 std::string RanecuEngine::beginTag ( )  { 
318   return "RanecuEngine-begin";                    307   return "RanecuEngine-begin"; 
319 }                                                 308 }
320                                                   309 
321 std::istream & RanecuEngine::getState ( std::i    310 std::istream & RanecuEngine::getState ( std::istream& is )
322 {                                                 311 {
323   if ( possibleKeywordInput ( is, "Uvec", theS    312   if ( possibleKeywordInput ( is, "Uvec", theSeed ) ) {
324     std::vector<unsigned long> v;                 313     std::vector<unsigned long> v;
325     unsigned long uu;                             314     unsigned long uu;
326     for (unsigned int ivec=0; ivec < VECTOR_ST    315     for (unsigned int ivec=0; ivec < VECTOR_STATE_SIZE; ++ivec) {
327       is >> uu;                                   316       is >> uu;
328       if (!is) {                                  317       if (!is) {
329         is.clear(std::ios::badbit | is.rdstate    318         is.clear(std::ios::badbit | is.rdstate());
330         std::cerr << "\nRanecuEngine state (ve    319         std::cerr << "\nRanecuEngine state (vector) description improper."
331     << "\ngetState() has failed."                 320     << "\ngetState() has failed."
332          << "\nInput stream is probably mispos    321          << "\nInput stream is probably mispositioned now." << std::endl;
333         return is;                                322         return is;
334       }                                           323       }
335       v.push_back(uu);                            324       v.push_back(uu);
336     }                                             325     }
337     getState(v);                                  326     getState(v);
338     return (is);                                  327     return (is);
339   }                                               328   }
340                                                   329 
341 //  is >> theSeed;  Removed, encompassed by po    330 //  is >> theSeed;  Removed, encompassed by possibleKeywordInput()
342   char endMarker   [MarkerLen];                   331   char endMarker   [MarkerLen];
343    for (int i=0; i<2; ++i) {                      332    for (int i=0; i<2; ++i) {
344      is >> table[theSeed][i];                     333      is >> table[theSeed][i];
345    }                                              334    }
346   is >> std::ws;                                  335   is >> std::ws;
347   is.width(MarkerLen);                            336   is.width(MarkerLen);  
348   is >> endMarker;                                337   is >> endMarker;
349   if (strcmp(endMarker,"RanecuEngine-end")) {     338   if (strcmp(endMarker,"RanecuEngine-end")) {
350      is.clear(std::ios::badbit | is.rdstate())    339      is.clear(std::ios::badbit | is.rdstate());
351      std::cerr << "\nRanecuEngine state descri    340      std::cerr << "\nRanecuEngine state description incomplete."
352          << "\nInput stream is probably mispos    341          << "\nInput stream is probably mispositioned now." << std::endl;
353      return is;                                   342      return is;
354    }                                              343    }
355                                                   344 
356    seq = int(theSeed);                            345    seq = int(theSeed);
357    return is;                                     346    return is;
358 }                                                 347 }
359                                                   348 
360 bool RanecuEngine::get (const std::vector<unsi    349 bool RanecuEngine::get (const std::vector<unsigned long> & v) {
361   if ((v[0] & 0xffffffffUL) != engineIDulong<R    350   if ((v[0] & 0xffffffffUL) != engineIDulong<RanecuEngine>()) {
362     std::cerr <<                                  351     std::cerr << 
363       "\nRanecuEngine get:state vector has wro    352       "\nRanecuEngine get:state vector has wrong ID word - state unchanged\n";
364     return false;                                 353     return false;
365   }                                               354   }
366   return getState(v);                             355   return getState(v);
367 }                                                 356 }
368                                                   357 
369 bool RanecuEngine::getState (const std::vector    358 bool RanecuEngine::getState (const std::vector<unsigned long> & v) {
370   if (v.size() != VECTOR_STATE_SIZE ) {           359   if (v.size() != VECTOR_STATE_SIZE ) {
371     std::cerr <<                                  360     std::cerr << 
372       "\nRanecuEngine get:state vector has wro    361       "\nRanecuEngine get:state vector has wrong length - state unchanged\n";
373     return false;                                 362     return false;
374   }                                               363   }
375   theSeed           = v[1];                       364   theSeed           = v[1];
376   table[theSeed][0] = v[2];                       365   table[theSeed][0] = v[2];
377   table[theSeed][1] = v[3];                       366   table[theSeed][1] = v[3];
378   seq = int(theSeed);                             367   seq = int(theSeed);
379   return true;                                    368   return true;
380 }                                                 369 }
381                                                   370 
382                                                   371 
383 }  // namespace CLHEP                             372 }  // namespace CLHEP
384                                                   373