Geant4 Cross Reference

Cross-Referencing   Geant4
Geant4/externals/clhep/src/RanshiEngine.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/RanshiEngine.cc (Version 11.3.0) and /externals/clhep/src/RanshiEngine.cc (Version 10.6.p1)


  1 // -*- C++ -*-                                      1 // -*- C++ -*-
  2 //                                                  2 //
  3 // -------------------------------------------      3 // -----------------------------------------------------------------------
  4 //                           HEP Random             4 //                           HEP Random
  5 //                      --- RanshiEngine ---        5 //                      --- RanshiEngine ---
  6 //                    class implementation fil      6 //                    class implementation file
  7 // -------------------------------------------      7 // -----------------------------------------------------------------------
  8 //                                                  8 //
  9 // This algorithm implements the random number      9 // This algorithm implements the random number generator as proposed by 
 10 // "F. Gutbrod, Comp. Phys. Comm. 87 (1995) 29     10 // "F. Gutbrod, Comp. Phys. Comm. 87 (1995) 291-306". 
 11 //                                                 11 //
 12 // ===========================================     12 // =======================================================================
 13 // Ken Smith      - Created:                       13 // Ken Smith      - Created:                                 9th June 1998
 14 //                - Removed std::pow() from fl     14 //                - Removed std::pow() from flat method:     21st Jul 1998
 15 //                - Added conversion operators     15 //                - Added conversion operators:               6th Aug 1998
 16 // J. Marraffino  - Added some explicit casts      16 // J. Marraffino  - Added some explicit casts to deal with
 17 //                  machines where sizeof(int)     17 //                  machines where sizeof(int) != sizeof(long) 22 Aug 1998
 18 // M. Fischler    - Modified constructors taki     18 // M. Fischler    - Modified constructors taking seeds to not
 19 //                  depend on numEngines (same     19 //                  depend on numEngines (same seeds should
 20 //                  produce same sequences).       20 //                  produce same sequences).  Default still
 21 //                  depends on numEngines.         21 //                  depends on numEngines.                      16 Sep 1998
 22 //                - Modified use of the variou     22 //                - Modified use of the various exponents of 2
 23 //                  to avoid per-instance spac     23 //                  to avoid per-instance space overhead and
 24 //                  correct the rounding proce     24 //                  correct the rounding procedure              16 Sep 1998
 25 // J. Marraffino  - Remove dependence on hepSt     25 // J. Marraffino  - Remove dependence on hepString class        13 May 1999
 26 // M. Fischler    - In restore, checkFile for      26 // M. Fischler    - In restore, checkFile for file not found    03 Dec 2004
 27 // M. Fischler    - Methods for instance save/     27 // M. Fischler    - Methods for instance save/restore            12/8/04    
 28 // M. Fischler    - split get() into tag valid     28 // M. Fischler    - split get() into tag validation and 
 29 //                  getState() for anonymous r     29 //                  getState() for anonymous restores           12/27/04    
 30 // M. Fischler    - State-saving using only in     30 // M. Fischler    - State-saving using only ints, for portability 4/12/05
 31 // L. Garren      - use explicit 32bit mask to     31 // L. Garren      - use explicit 32bit mask to avoid compiler warnings  6/6/2014  
 32 // L. Garren      - adding pragma for 32bit gc     32 // L. Garren      - adding pragma for 32bit gcc 4.9 11/20/2014  
 33 //                                                 33 //
 34 // ===========================================     34 // =======================================================================
 35                                                    35 
 36 #include "CLHEP/Random/RanshiEngine.h"             36 #include "CLHEP/Random/RanshiEngine.h"
 37 #include "CLHEP/Random/engineIDulong.h"            37 #include "CLHEP/Random/engineIDulong.h"
 38 #include "CLHEP/Utility/atomic_int.h"              38 #include "CLHEP/Utility/atomic_int.h"
 39                                                    39 
 40 #include <atomic>                              << 
 41 #include <string.h> // for strcmp                  40 #include <string.h> // for strcmp
 42 #include <iostream>                                41 #include <iostream>
 43 #include <string>                              << 
 44 #include <vector>                              << 
 45                                                    42 
 46 // don't generate warnings about agressive loo     43 // don't generate warnings about agressive loop optimization
 47 #if defined __GNUC__                               44 #if defined __GNUC__ 
 48   #if __GNUC__ > 3 && __GNUC_MINOR__ > 8           45   #if __GNUC__ > 3 && __GNUC_MINOR__ > 8
 49     #pragma GCC diagnostic push                    46     #pragma GCC diagnostic push
 50     #pragma GCC diagnostic ignored "-Waggressi     47     #pragma GCC diagnostic ignored "-Waggressive-loop-optimizations"
 51   #endif                                           48   #endif
 52 #endif                                             49 #endif
 53                                                    50 
 54 namespace CLHEP {                                  51 namespace CLHEP {
 55                                                    52 
 56 namespace {                                        53 namespace {
 57   // Number of instances with automatic seed s     54   // Number of instances with automatic seed selection
 58   CLHEP_ATOMIC_INT_TYPE numberOfEngines(0);        55   CLHEP_ATOMIC_INT_TYPE numberOfEngines(0);
 59 }                                                  56 }
 60                                                    57 
 61 static const int MarkerLen = 64; // Enough roo     58 static const int MarkerLen = 64; // Enough room to hold a begin or end marker. 
 62                                                    59 
 63 std::string RanshiEngine::name() const {return     60 std::string RanshiEngine::name() const {return "RanshiEngine";}
 64                                                    61 
 65 RanshiEngine::RanshiEngine()                       62 RanshiEngine::RanshiEngine()
 66 : HepRandomEngine(),                               63 : HepRandomEngine(),
 67   halfBuff(0), numFlats(0)                         64   halfBuff(0), numFlats(0) 
 68 {                                                  65 {
 69   int numEngines = numberOfEngines++;              66   int numEngines = numberOfEngines++;
 70   int i = 0;                                       67   int i = 0;
 71   while (i < numBuff) {                            68   while (i < numBuff) {    
 72     buffer[i] = (unsigned int)((numEngines+197     69     buffer[i] = (unsigned int)((numEngines+19780503L*(i+1))& 0xffffffff);
 73     ++i;                                           70     ++i;
 74   }                                                71   }
 75   theSeed = numEngines+19780503L*++i;              72   theSeed = numEngines+19780503L*++i;
 76   redSpin = (unsigned int)(theSeed & 0xfffffff     73   redSpin = (unsigned int)(theSeed & 0xffffffff);
 77                                                    74 
 78   for( i = 0; i < 10000; ++i) flat();  // Warm     75   for( i = 0; i < 10000; ++i) flat();  // Warm-up by running thorugh 10000 nums
 79 }                                                  76 }
 80                                                    77 
 81 RanshiEngine::RanshiEngine(std::istream& is)       78 RanshiEngine::RanshiEngine(std::istream& is)
 82 : HepRandomEngine(),                               79 : HepRandomEngine(),
 83   halfBuff(0), numFlats(0)                         80   halfBuff(0), numFlats(0) 
 84 {                                                  81 {
 85   is >> *this;                                     82   is >> *this;
 86 }                                                  83 }
 87                                                    84 
 88 RanshiEngine::RanshiEngine(long seed)              85 RanshiEngine::RanshiEngine(long seed)
 89 : HepRandomEngine(),                               86 : HepRandomEngine(),
 90   halfBuff(0), numFlats(0)                         87   halfBuff(0), numFlats(0) 
 91 {                                                  88 {
 92   for (int i = 0; i < numBuff; ++i) {              89   for (int i = 0; i < numBuff; ++i) {
 93     buffer[i] = (unsigned int)seed&0xffffffff;     90     buffer[i] = (unsigned int)seed&0xffffffff;
 94   }                                                91   }
 95   theSeed = seed;                                  92   theSeed = seed;
 96   redSpin = (unsigned int)(theSeed & 0xfffffff     93   redSpin = (unsigned int)(theSeed & 0xffffffff);
 97   int j;                                           94   int j;
 98   for (j = 0; j < numBuff*20; ++j) {      // "     95   for (j = 0; j < numBuff*20; ++j) {      // "warm-up" for engine to hit
 99     flat();                               //       96     flat();                               //  every ball on average 20X.
100   }                                                97   }
101 }                                                  98 }
102                                                    99 
103 RanshiEngine::RanshiEngine(int rowIndex, int c    100 RanshiEngine::RanshiEngine(int rowIndex, int colIndex)
104 : HepRandomEngine(),                              101 : HepRandomEngine(),
105   halfBuff(0), numFlats(0)                        102   halfBuff(0), numFlats(0) 
106 {                                                 103 {
107   int i = 0;                                      104   int i = 0;
108   while( i < numBuff ) {                          105   while( i < numBuff ) {
109     buffer[i] = (unsigned int)((rowIndex + (i+    106     buffer[i] = (unsigned int)((rowIndex + (i+1)*(colIndex+8))&0xffffffff);
110     ++i;                                          107     ++i;
111   }                                               108   }
112   theSeed = rowIndex;                             109   theSeed = rowIndex;
113   redSpin = colIndex & 0xffffffff;                110   redSpin = colIndex & 0xffffffff;
114   for( i = 0; i < 100; ++i) flat();    // Warm    111   for( i = 0; i < 100; ++i) flat();    // Warm-up by running thorugh 100 nums
115 }                                                 112 }
116                                                   113 
117 RanshiEngine::~RanshiEngine() { }                 114 RanshiEngine::~RanshiEngine() { }
118                                                   115 
119 double RanshiEngine::flat() {                     116 double RanshiEngine::flat() {
120   unsigned int redAngle = (((numBuff/2) - 1) &    117   unsigned int redAngle = (((numBuff/2) - 1) & redSpin) + halfBuff;
121   unsigned int blkSpin     = buffer[redAngle]     118   unsigned int blkSpin     = buffer[redAngle] & 0xffffffff;
122   unsigned int boostResult = blkSpin ^ redSpin    119   unsigned int boostResult = blkSpin ^ redSpin;
123                                                   120 
124   buffer[redAngle] = ((blkSpin << 17) | (blkSp    121   buffer[redAngle] = ((blkSpin << 17) | (blkSpin >> (32-17))) ^ redSpin;
125                                                   122   
126   redSpin  = (blkSpin + numFlats++) & 0xffffff    123   redSpin  = (blkSpin + numFlats++) & 0xffffffff;
127   halfBuff = numBuff/2 - halfBuff;                124   halfBuff = numBuff/2 - halfBuff;
128                                                   125   
129   return ( blkSpin * twoToMinus_32() +            126   return ( blkSpin * twoToMinus_32() +            // most significant part
130      (boostResult>>11) * twoToMinus_53() +  //    127      (boostResult>>11) * twoToMinus_53() +  // fill in remaining bits
131      nearlyTwoToMinus_54());      // non-zero     128      nearlyTwoToMinus_54());      // non-zero
132 }                                                 129 }
133                                                   130 
134 void RanshiEngine::flatArray(const int size, d    131 void RanshiEngine::flatArray(const int size, double* vect) {
135   for (int i = 0; i < size; ++i) {                132   for (int i = 0; i < size; ++i) {
136     vect[i] = flat();                             133     vect[i] = flat();
137   }                                               134   }
138 }                                                 135 }
139                                                   136 
140 void RanshiEngine::setSeed(long seed, int) {      137 void RanshiEngine::setSeed(long seed, int) {
141   *this = RanshiEngine(seed);                     138   *this = RanshiEngine(seed); 
142 }                                                 139 }
143                                                   140 
144 void RanshiEngine::setSeeds(const long* seeds,    141 void RanshiEngine::setSeeds(const long* seeds, int) {
145   if (*seeds) {                                   142   if (*seeds) {
146     int i = 0;                                    143     int i = 0;
147     while (seeds[i] && i < numBuff) {             144     while (seeds[i] && i < numBuff) {
148       buffer[i] = (unsigned int)seeds[i];         145       buffer[i] = (unsigned int)seeds[i];
149       ++i;                                        146       ++i;
150     }                                             147     }
151     while (i < numBuff) {                         148     while (i < numBuff) {
152       buffer[i] = buffer[i-1];                    149       buffer[i] = buffer[i-1];
153       ++i;                                        150       ++i;
154     }                                             151     }
155     theSeed = seeds[0];                           152     theSeed = seeds[0];
156     redSpin = (unsigned int)theSeed;              153     redSpin = (unsigned int)theSeed;
157   }                                               154   }
158   theSeeds = seeds;                               155   theSeeds = seeds;
159 }                                                 156 }
160                                                   157      
161 void RanshiEngine::saveStatus(const char filen    158 void RanshiEngine::saveStatus(const char filename[]) const {
162   std::ofstream outFile(filename, std::ios::ou    159   std::ofstream outFile(filename, std::ios::out);
163   if (!outFile.bad()) {                           160   if (!outFile.bad()) {
164     outFile << "Uvec\n";                          161     outFile << "Uvec\n";
165     std::vector<unsigned long> v = put();         162     std::vector<unsigned long> v = put();
166     for (unsigned int i=0; i<v.size(); ++i) {     163     for (unsigned int i=0; i<v.size(); ++i) {
167       outFile << v[i] << "\n";                    164       outFile << v[i] << "\n";
168     }                                             165     }
169   }                                               166   }
170 }                                                 167 }
171                                                   168 
172 void RanshiEngine::restoreStatus(const char fi    169 void RanshiEngine::restoreStatus(const char filename[]) {
173   std::ifstream inFile(filename, std::ios::in)    170   std::ifstream inFile(filename, std::ios::in);
174   if (!checkFile ( inFile, filename, engineNam    171   if (!checkFile ( inFile, filename, engineName(), "restoreStatus" )) {
175     std::cerr << "  -- Engine state remains un    172     std::cerr << "  -- Engine state remains unchanged\n";
176     return;                                       173     return;
177   }                                               174   }
178   if ( possibleKeywordInput ( inFile, "Uvec",     175   if ( possibleKeywordInput ( inFile, "Uvec", theSeed ) ) {
179     std::vector<unsigned long> v;                 176     std::vector<unsigned long> v;
180     unsigned long xin;                            177     unsigned long xin;
181     for (unsigned int ivec=0; ivec < VECTOR_ST    178     for (unsigned int ivec=0; ivec < VECTOR_STATE_SIZE; ++ivec) {
182       inFile >> xin;                              179       inFile >> xin;
183       if (!inFile) {                              180       if (!inFile) {
184         inFile.clear(std::ios::badbit | inFile    181         inFile.clear(std::ios::badbit | inFile.rdstate());
185         std::cerr << "\nRanshiEngine state (ve    182         std::cerr << "\nRanshiEngine state (vector) description improper."
186          << "\nrestoreStatus has failed."         183          << "\nrestoreStatus has failed."
187          << "\nInput stream is probably mispos    184          << "\nInput stream is probably mispositioned now." << std::endl;
188         return;                                   185         return;
189       }                                           186       }
190       v.push_back(xin);                           187       v.push_back(xin);
191     }                                             188     }
192     getState(v);                                  189     getState(v);
193     return;                                       190     return;
194   }                                               191   }
195                                                   192 
196   if (!inFile.bad()) {                            193   if (!inFile.bad()) {
197 //     inFile >> theSeed;  removed -- encompas    194 //     inFile >> theSeed;  removed -- encompased by possibleKeywordInput
198     for (int i = 0; i < numBuff; ++i) {           195     for (int i = 0; i < numBuff; ++i) {
199       inFile >> buffer[i];                        196       inFile >> buffer[i];
200     }                                             197     }
201     inFile >> redSpin >> numFlats >> halfBuff;    198     inFile >> redSpin >> numFlats >> halfBuff;
202   }                                               199   }
203 }                                                 200 }
204                                                   201 
205 void RanshiEngine::showStatus() const {           202 void RanshiEngine::showStatus() const {
206   std::cout << std::setprecision(20) << std::e    203   std::cout << std::setprecision(20) << std::endl;
207   std::cout << "----------- Ranshi engine stat    204   std::cout << "----------- Ranshi engine status ----------" << std::endl;
208   std::cout << "Initial seed      = " << theSe    205   std::cout << "Initial seed      = " << theSeed << std::endl;
209   std::cout << "Current red spin  = " << redSp    206   std::cout << "Current red spin  = " << redSpin << std::endl;
210   std::cout << "Values produced   = " << numFl    207   std::cout << "Values produced   = " << numFlats << std::endl;
211   std::cout << "Side of buffer    = " << (half    208   std::cout << "Side of buffer    = " << (halfBuff ? "upper" : "lower")
212       << std::endl;                               209       << std::endl;
213   std::cout << "Current buffer    = " << std::    210   std::cout << "Current buffer    = " << std::endl;
214   for (int i = 0; i < numBuff; i+=4) {            211   for (int i = 0; i < numBuff; i+=4) {
215     std::cout << std::setw(10) << std::setiosf    212     std::cout << std::setw(10) << std::setiosflags(std::ios::right)
216         << buffer[i]     << std::setw(11) << b    213         << buffer[i]     << std::setw(11) << buffer[i+1] << std::setw(11)
217         << buffer[i+2]   << std::setw(11) << b    214         << buffer[i+2]   << std::setw(11) << buffer[i+3] << std::endl;
218   }                                               215   }
219   std::cout << "------------------------------    216   std::cout << "-------------------------------------------" << std::endl;
220 }                                                 217 }
221                                                   218 
222 RanshiEngine::operator double() {                 219 RanshiEngine::operator double() {
223   return flat();                                  220   return flat();
224 }                                                 221 }
225                                                   222 
226 RanshiEngine::operator float() {                  223 RanshiEngine::operator float() {
227   unsigned int redAngle = (((numBuff/2) - 1) &    224   unsigned int redAngle = (((numBuff/2) - 1) & redSpin) + halfBuff;
228   unsigned int blkSpin  = buffer[redAngle] & 0    225   unsigned int blkSpin  = buffer[redAngle] & 0xffffffff;
229                                                   226   
230   buffer[redAngle] = ((blkSpin << 17) | (blkSp    227   buffer[redAngle] = ((blkSpin << 17) | (blkSpin >> (32-17))) ^ redSpin;
231                                                   228   
232   redSpin  = (blkSpin + numFlats++) & 0xffffff    229   redSpin  = (blkSpin + numFlats++) & 0xffffffff;
233   halfBuff = numBuff/2 - halfBuff;                230   halfBuff = numBuff/2 - halfBuff;
234                                                   231   
235   return float(blkSpin * twoToMinus_32());        232   return float(blkSpin * twoToMinus_32());
236 }                                                 233 }
237                                                   234 
238 RanshiEngine::operator unsigned int() {           235 RanshiEngine::operator unsigned int() {
239   unsigned int redAngle = (((numBuff/2) - 1) &    236   unsigned int redAngle = (((numBuff/2) - 1) & redSpin) + halfBuff;
240   unsigned int blkSpin  = buffer[redAngle] & 0    237   unsigned int blkSpin  = buffer[redAngle] & 0xffffffff;
241                                                   238   
242   buffer[redAngle] = ((blkSpin << 17) | (blkSp    239   buffer[redAngle] = ((blkSpin << 17) | (blkSpin >> (32-17))) ^ redSpin;
243                                                   240   
244   redSpin  = (blkSpin + numFlats++) & 0xffffff    241   redSpin  = (blkSpin + numFlats++) & 0xffffffff;
245   halfBuff = numBuff/2 - halfBuff;                242   halfBuff = numBuff/2 - halfBuff;
246                                                   243   
247   return blkSpin;                                 244   return blkSpin;
248 }                                                 245 }
249                                                   246 
250 std::ostream& RanshiEngine::put (std::ostream&    247 std::ostream& RanshiEngine::put (std::ostream& os ) const {
251   char beginMarker[] = "RanshiEngine-begin";      248   char beginMarker[] = "RanshiEngine-begin";
252   os << beginMarker << "\nUvec\n";                249   os << beginMarker << "\nUvec\n";
253   std::vector<unsigned long> v = put();           250   std::vector<unsigned long> v = put();
254   for (unsigned int i=0; i<v.size(); ++i) {       251   for (unsigned int i=0; i<v.size(); ++i) {
255      os <<  v[i] <<  "\n";                        252      os <<  v[i] <<  "\n";
256   }                                               253   }
257   return os;                                      254   return os;  
258 }                                                 255 }
259                                                   256 
260 std::vector<unsigned long> RanshiEngine::put (    257 std::vector<unsigned long> RanshiEngine::put () const {
261   std::vector<unsigned long> v;                   258   std::vector<unsigned long> v;
262   v.push_back (engineIDulong<RanshiEngine>());    259   v.push_back (engineIDulong<RanshiEngine>());
263   for (int i = 0; i < numBuff; ++i) {             260   for (int i = 0; i < numBuff; ++i) {
264     v.push_back(static_cast<unsigned long>(buf    261     v.push_back(static_cast<unsigned long>(buffer[i]));
265   }                                               262   }
266   v.push_back(static_cast<unsigned long>(redSp    263   v.push_back(static_cast<unsigned long>(redSpin));
267   v.push_back(static_cast<unsigned long>(numFl    264   v.push_back(static_cast<unsigned long>(numFlats));
268   v.push_back(static_cast<unsigned long>(halfB    265   v.push_back(static_cast<unsigned long>(halfBuff));  
269   return v;                                       266   return v;
270 }                                                 267 }
271                                                   268 
272 std::istream& RanshiEngine::get (std::istream&    269 std::istream& RanshiEngine::get (std::istream& is) {
273   char beginMarker [MarkerLen];                   270   char beginMarker [MarkerLen];
274   is >> std::ws;                                  271   is >> std::ws;
275   is.width(MarkerLen);  // causes the next rea    272   is.width(MarkerLen);  // causes the next read to the char* to be <=
276       // that many bytes, INCLUDING A TERMINAT    273       // that many bytes, INCLUDING A TERMINATION \0 
277       // (Stroustrup, section 21.3.2)             274       // (Stroustrup, section 21.3.2)
278   is >> beginMarker;                              275   is >> beginMarker;
279   if (strcmp(beginMarker,"RanshiEngine-begin")    276   if (strcmp(beginMarker,"RanshiEngine-begin")) {
280     is.clear(std::ios::badbit | is.rdstate());    277     is.clear(std::ios::badbit | is.rdstate());
281     std::cerr << "\nInput mispositioned or"       278     std::cerr << "\nInput mispositioned or"
282         << "\nRanshiEngine state description m    279         << "\nRanshiEngine state description missing or"
283         << "\nwrong engine type found." << std    280         << "\nwrong engine type found." << std::endl;
284     return is;                                    281     return is;
285   }                                               282   }
286   return getState(is);                            283   return getState(is);
287 }                                                 284 }
288                                                   285 
289 std::string RanshiEngine::beginTag ( )  {         286 std::string RanshiEngine::beginTag ( )  { 
290   return "RanshiEngine-begin";                    287   return "RanshiEngine-begin"; 
291 }                                                 288 }
292                                                   289   
293 std::istream& RanshiEngine::getState (std::ist    290 std::istream& RanshiEngine::getState (std::istream& is) {
294   if ( possibleKeywordInput ( is, "Uvec", theS    291   if ( possibleKeywordInput ( is, "Uvec", theSeed ) ) {
295     std::vector<unsigned long> v;                 292     std::vector<unsigned long> v;
296     unsigned long uu;                             293     unsigned long uu;
297     for (unsigned int ivec=0; ivec < VECTOR_ST    294     for (unsigned int ivec=0; ivec < VECTOR_STATE_SIZE; ++ivec) {
298       is >> uu;                                   295       is >> uu;
299       if (!is) {                                  296       if (!is) {
300         is.clear(std::ios::badbit | is.rdstate    297         is.clear(std::ios::badbit | is.rdstate());
301         std::cerr << "\nRanshiEngine state (ve    298         std::cerr << "\nRanshiEngine state (vector) description improper."
302     << "\ngetState() has failed."                 299     << "\ngetState() has failed."
303          << "\nInput stream is probably mispos    300          << "\nInput stream is probably mispositioned now." << std::endl;
304         return is;                                301         return is;
305       }                                           302       }
306       v.push_back(uu);                            303       v.push_back(uu);
307     }                                             304     }
308     getState(v);                                  305     getState(v);
309     return (is);                                  306     return (is);
310   }                                               307   }
311                                                   308 
312 //  is >> theSeed;  Removed, encompassed by po    309 //  is >> theSeed;  Removed, encompassed by possibleKeywordInput()
313                                                   310 
314   char endMarker   [MarkerLen];                   311   char endMarker   [MarkerLen];
315   for (int i = 0; i < numBuff; ++i) {             312   for (int i = 0; i < numBuff; ++i) {
316     is >> buffer[i];                              313     is >> buffer[i];
317   }                                               314   }
318   is >> redSpin >> numFlats >> halfBuff;          315   is >> redSpin >> numFlats >> halfBuff;
319   is >> std::ws;                                  316   is >> std::ws;
320   is.width(MarkerLen);                            317   is.width(MarkerLen);  
321   is >> endMarker;                                318   is >> endMarker;
322   if (strcmp(endMarker,"RanshiEngine-end")) {     319   if (strcmp(endMarker,"RanshiEngine-end")) {
323     is.clear(std::ios::badbit | is.rdstate());    320     is.clear(std::ios::badbit | is.rdstate());
324     std::cerr << "\nRanshiEngine state descrip    321     std::cerr << "\nRanshiEngine state description incomplete."
325         << "\nInput stream is probably misposi    322         << "\nInput stream is probably mispositioned now." << std::endl;
326     return is;                                    323     return is;
327   }                                               324   }
328   return is;                                      325   return is;
329 }                                                 326 }
330                                                   327 
331 bool RanshiEngine::get (const std::vector<unsi    328 bool RanshiEngine::get (const std::vector<unsigned long> & v) {
332   if ((v[0] & 0xffffffffUL) != engineIDulong<R    329   if ((v[0] & 0xffffffffUL) != engineIDulong<RanshiEngine>()) {
333     std::cerr <<                                  330     std::cerr << 
334       "\nRanshiEngine get:state vector has wro    331       "\nRanshiEngine get:state vector has wrong ID word - state unchanged\n";
335     return false;                                 332     return false;
336   }                                               333   }
337   return getState(v);                             334   return getState(v);
338 }                                                 335 }
339                                                   336 
340 bool RanshiEngine::getState (const std::vector    337 bool RanshiEngine::getState (const std::vector<unsigned long> & v) {
341   if (v.size() != VECTOR_STATE_SIZE ) {           338   if (v.size() != VECTOR_STATE_SIZE ) {
342     std::cerr <<                                  339     std::cerr << 
343       "\nRanshiEngine get:state vector has wro    340       "\nRanshiEngine get:state vector has wrong length - state unchanged\n";
344     return false;                                 341     return false;
345   }                                               342   }
346   for (int i = 0; i < numBuff; ++i) {             343   for (int i = 0; i < numBuff; ++i) {
347     buffer[i] = (unsigned int)v[i+1];          << 344     buffer[i] = v[i+1];
348   }                                               345   }
349   redSpin  = (unsigned int)v[numBuff+1];       << 346   redSpin  = v[numBuff+1];
350   numFlats = (unsigned int)v[numBuff+2];       << 347   numFlats = v[numBuff+2]; 
351   halfBuff = (unsigned int)v[numBuff+3];       << 348   halfBuff = v[numBuff+3];
352   return true;                                    349   return true;
353 }                                                 350 }
354                                                   351 
355 }  // namespace CLHEP                             352 }  // namespace CLHEP
356                                                   353 
357 #if defined __GNUC__                              354 #if defined __GNUC__ 
358   #if __GNUC__ > 3 && __GNUC_MINOR__ > 8          355   #if __GNUC__ > 3 && __GNUC_MINOR__ > 8
359     #pragma GCC diagnostic pop                    356     #pragma GCC diagnostic pop
360   #endif                                          357   #endif
361 #endif                                            358 #endif
362                                                   359