ATLAS Offline Software
Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes | Static Private Attributes | List of all members
CLHEP::dSFMTEngine Class Reference

#include <dSFMTEngine.h>

Inheritance diagram for CLHEP::dSFMTEngine:
Collaboration diagram for CLHEP::dSFMTEngine:

Public Member Functions

 dSFMTEngine ()
 
 dSFMTEngine (long seed)
 
 dSFMTEngine (const long *seeds)
 
virtual ~dSFMTEngine ()
 
 dSFMTEngine (const dSFMTEngine &p)
 
dSFMTEngineoperator= (const dSFMTEngine &p)
 
virtual double flat () override
 
virtual void flatArray (const int size, double *vect) override
 
virtual void setSeed (long seed, int k=0) override
 
void setSeeds (const uint32_t *seeds, int k=0)
 
virtual void setSeeds (const long *seeds, int k=0) override
 
virtual void saveStatus (const char filename[]="MTwist.conf") const override
 
virtual void restoreStatus (const char filename[]="MTwist.conf") override
 
virtual void showStatus () const override
 
virtual operator float () override
 
virtual operator unsigned int () override
 
virtual std::ostream & put (std::ostream &os) const override
 
virtual std::istream & get (std::istream &is) override
 
virtual std::istream & getState (std::istream &is) override
 
virtual std::string name () const override
 
virtual std::vector< unsigned long > put () const override
 
virtual bool get (const std::vector< unsigned long > &v) override
 
virtual bool getState (const std::vector< unsigned long > &v) override
 

Static Public Member Functions

static std::string beginTag ()
 
static std::string engineName ()
 

Private Member Functions

void init_dsfmt ()
 

Private Attributes

DSFMT_T * m_dsfmt
 

Static Private Attributes

static std::atomic< int > numEngines = 0
 
static constexpr int maxIndex = 215
 

Detailed Description

Author

Definition at line 31 of file dSFMTEngine.h.

Constructor & Destructor Documentation

◆ dSFMTEngine() [1/4]

CLHEP::dSFMTEngine::dSFMTEngine ( )

Definition at line 47 of file dSFMTEngine.cxx.

47  :m_dsfmt(0)
48 {
49  init_dsfmt();
50 
51  int engineNum = numEngines++;
52  int cycle = abs(int(engineNum/maxIndex));
53  int curIndex = abs(int(engineNum%maxIndex));
54  long mask = ((cycle & 0x007fffff) << 8);
55  long seedlist[2];
56  HepRandom::getTheTableSeeds( seedlist, curIndex );
57  seedlist[0] = (seedlist[0])^mask;
58  seedlist[1] = 0;
59  setSeeds( seedlist, engineNum );
60  for( int i=0; i < 2000; ++i ) dSFMTEngine::flat(); // Warm up just a bit
61 }

◆ dSFMTEngine() [2/4]

CLHEP::dSFMTEngine::dSFMTEngine ( long  seed)

Definition at line 63 of file dSFMTEngine.cxx.

63  :m_dsfmt(0)
64 {
65  init_dsfmt();
66 
67  dSFMTEngine::setSeed( seed , 0);
68  for( int i=0; i < 2000; ++i ) dSFMTEngine::flat(); // Warm up just a bit
69 }

◆ dSFMTEngine() [3/4]

CLHEP::dSFMTEngine::dSFMTEngine ( const long *  seeds)

Definition at line 71 of file dSFMTEngine.cxx.

71  :m_dsfmt(0)
72 {
73  init_dsfmt();
74 
75  dSFMTEngine::setSeeds( seeds, 0 );
76  for( int i=0; i < 2000; ++i ) dSFMTEngine::flat(); // Warm up just a bit
77 }

◆ ~dSFMTEngine()

CLHEP::dSFMTEngine::~dSFMTEngine ( )
virtual

Definition at line 90 of file dSFMTEngine.cxx.

91 {
92  if(m_dsfmt) {
93  free(m_dsfmt);
94  m_dsfmt=0;
95  }
96 }

◆ dSFMTEngine() [4/4]

CLHEP::dSFMTEngine::dSFMTEngine ( const dSFMTEngine p)

Definition at line 98 of file dSFMTEngine.cxx.

99 {
100  init_dsfmt();
101 
102  *this = p;
103 }

Member Function Documentation

◆ beginTag()

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

Definition at line 259 of file dSFMTEngine.cxx.

259  {
260  return "dSFMTEngine-begin";
261 }

◆ engineName()

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

Definition at line 80 of file dSFMTEngine.h.

80 {return "MTwistEngine";}

◆ flat()

double CLHEP::dSFMTEngine::flat ( )
overridevirtual

Definition at line 112 of file dSFMTEngine.cxx.

112  {
113  double ret ATLAS_THREAD_SAFE = dsfmt_genrand_close_open(m_dsfmt);
114  return ret;
115 }

◆ flatArray()

void CLHEP::dSFMTEngine::flatArray ( const int  size,
double *  vect 
)
overridevirtual

Definition at line 117 of file dSFMTEngine.cxx.

117  {
118  for( int i=0; i < size; ++i) vect[i] = flat();
119 }

◆ get() [1/2]

bool CLHEP::dSFMTEngine::get ( const std::vector< unsigned long > &  v)
overridevirtual

Definition at line 287 of file dSFMTEngine.cxx.

287  {
288  if ((v[0] & 0xffffffffUL) != engineIDulong<dSFMTEngine>()) {
289  std::cerr <<
290  "\ndSFMTEngine get:state vector has wrong ID word - state unchanged\n";
291  return false;
292  }
293  return getState(v);
294 }

◆ get() [2/2]

std::istream & CLHEP::dSFMTEngine::get ( std::istream &  is)
overridevirtual

Definition at line 241 of file dSFMTEngine.cxx.

242 {
243  char beginMarker [MarkerLen];
244  is >> std::ws;
245  is.width(MarkerLen); // causes the next read to the char* to be <=
246  // that many bytes, INCLUDING A TERMINATION \0
247  // (Stroustrup, section 21.3.2)
248  is >> beginMarker;
249  if (strcmp(beginMarker,"dSFMTEngine-begin")) {
250  is.clear(std::ios::badbit | is.rdstate());
251  std::cerr << "\nInput stream mispositioned or"
252  << "\ndSFMTEngine state description missing or"
253  << "\nwrong engine type found." << std::endl;
254  return is;
255  }
256  return getState(is);
257 }

◆ getState() [1/2]

bool CLHEP::dSFMTEngine::getState ( const std::vector< unsigned long > &  v)
overridevirtual

Definition at line 296 of file dSFMTEngine.cxx.

296  {
297  if (v.size() != VECTOR_STATE_SIZE ) {
298  std::cerr <<
299  "\ndSFMTEngine get:state vector has wrong length - state unchanged\n";
300  return false;
301  }
302 
303  m_dsfmt->idx=v[1];
304  for (int i=0; i<DSFMT_N + 1; ++i) {
305  m_dsfmt->status[i].u32[0]=v[2+i*4+0];
306  m_dsfmt->status[i].u32[1]=v[2+i*4+1];
307  m_dsfmt->status[i].u32[2]=v[2+i*4+2];
308  m_dsfmt->status[i].u32[3]=v[2+i*4+3];
309  }
310 
311  return true;
312 }

◆ getState() [2/2]

std::istream & CLHEP::dSFMTEngine::getState ( std::istream &  is)
overridevirtual

Definition at line 263 of file dSFMTEngine.cxx.

264 {
265  char endMarker [MarkerLen];
266  is >> m_dsfmt->idx;
267 
268  for (int i=0; i<DSFMT_N + 1; ++i) {
269  is >> m_dsfmt->status[i].u32[0] ;
270  is >> m_dsfmt->status[i].u32[1] ;
271  is >> m_dsfmt->status[i].u32[2] ;
272  is >> m_dsfmt->status[i].u32[3] ;
273  }
274 
275  is >> std::ws;
276  is.width(MarkerLen);
277  is >> endMarker;
278  if (strcmp(endMarker,"dSFMTEngine-end")) {
279  is.clear(std::ios::badbit | is.rdstate());
280  std::cerr << "\ndSFMTEngine state description incomplete."
281  << "\nInput stream is probably mispositioned now." << std::endl;
282  return is;
283  }
284  return is;
285 }

◆ init_dsfmt()

void CLHEP::dSFMTEngine::init_dsfmt ( )
private

Definition at line 79 of file dSFMTEngine.cxx.

80 {
81  int err=posix_memalign((void**)&m_dsfmt,16,sizeof(dsfmt_t));
82  if(err!=0) {
83  std::stringstream errstring;
84  errstring << "dSFMTEngine::init_dsfmt() : could not allocate memory for dsfmt data structure, error=" << err;
85  throw std::runtime_error(errstring.str());
86  }
87  //cout<<"dSFMTEngine::init_dsfmt() ptr="<<m_dsfmt<<endl;
88 }

◆ name()

std::string CLHEP::dSFMTEngine::name ( ) const
overridevirtual

Definition at line 41 of file dSFMTEngine.cxx.

41 {return "dSFMTEngine";}

◆ operator float()

CLHEP::dSFMTEngine::operator float ( )
overridevirtual

Definition at line 201 of file dSFMTEngine.cxx.

201  {
202  return (float)flat();
203 }

◆ operator unsigned int()

CLHEP::dSFMTEngine::operator unsigned int ( )
overridevirtual

Definition at line 205 of file dSFMTEngine.cxx.

205  {
206  return dsfmt_genrand_uint32(m_dsfmt);
207 }

◆ operator=()

dSFMTEngine & CLHEP::dSFMTEngine::operator= ( const dSFMTEngine p)

Definition at line 105 of file dSFMTEngine.cxx.

105  {
106  if( this != &p ) {
107  *m_dsfmt=*p.m_dsfmt;
108  }
109  return *this;
110 }

◆ put() [1/2]

std::vector< unsigned long > CLHEP::dSFMTEngine::put ( ) const
overridevirtual

Definition at line 228 of file dSFMTEngine.cxx.

228  {
229  std::vector<unsigned long> v;
230  v.push_back (engineIDulong<dSFMTEngine>());
231  v.push_back(m_dsfmt->idx);
232  for (int i=0; i<DSFMT_N + 1; ++i) {
233  v.push_back(static_cast<unsigned long>(m_dsfmt->status[i].u32[0]));
234  v.push_back(static_cast<unsigned long>(m_dsfmt->status[i].u32[1]));
235  v.push_back(static_cast<unsigned long>(m_dsfmt->status[i].u32[2]));
236  v.push_back(static_cast<unsigned long>(m_dsfmt->status[i].u32[3]));
237  }
238  return v;
239 }

◆ put() [2/2]

std::ostream & CLHEP::dSFMTEngine::put ( std::ostream &  os) const
overridevirtual

Definition at line 209 of file dSFMTEngine.cxx.

210 {
211  char beginMarker[] = "dSFMTEngine-begin";
212  char endMarker[] = "dSFMTEngine-end";
213 
214  int pr = os.precision(20);
215  os << " " << beginMarker << " ";
216  os << m_dsfmt->idx << " ";
217  for (int i=0; i<DSFMT_N + 1; ++i) {
218  os << m_dsfmt->status[i].u32[0] << "\n";
219  os << m_dsfmt->status[i].u32[1] << "\n";
220  os << m_dsfmt->status[i].u32[2] << "\n";
221  os << m_dsfmt->status[i].u32[3] << "\n";
222  }
223  os << endMarker << "\n";
224  os.precision(pr);
225  return os;
226 }

◆ restoreStatus()

void CLHEP::dSFMTEngine::restoreStatus ( const char  filename[] = "MTwist.conf")
overridevirtual

Definition at line 170 of file dSFMTEngine.cxx.

171 {
172  std::ifstream inFile( filename, std::ios::in);
173  if (!checkFile ( inFile, filename, engineName(), "restoreStatus" )) {
174  std::cerr << " -- Engine state remains unchanged\n";
175  return;
176  }
177 
178  if (!inFile.bad() && !inFile.eof()) {
179  inFile >> m_dsfmt->idx;
180  for (int i=0; i<DSFMT_N + 1; ++i) inFile >> m_dsfmt->status[i].u32[0] >> m_dsfmt->status[i].u32[1]
181  >> m_dsfmt->status[i].u32[2] >> m_dsfmt->status[i].u32[3];
182  }
183 }

◆ saveStatus()

void CLHEP::dSFMTEngine::saveStatus ( const char  filename[] = "MTwist.conf") const
overridevirtual

Definition at line 158 of file dSFMTEngine.cxx.

159 {
160  std::ofstream outFile( filename, std::ios::out ) ;
161  if (!outFile.bad()) {
162  outFile << m_dsfmt->idx << std::endl;
163  for (int i=0; i<DSFMT_N + 1; ++i) outFile <<std::setprecision(20)
164  << m_dsfmt->status[i].u32[0] << " " << m_dsfmt->status[i].u32[1] << " "
165  << m_dsfmt->status[i].u32[2] << " " << m_dsfmt->status[i].u32[3] << " ";
166  outFile << std::endl;
167  }
168 }

◆ setSeed()

void CLHEP::dSFMTEngine::setSeed ( long  seed,
int  k = 0 
)
overridevirtual

Definition at line 121 of file dSFMTEngine.cxx.

121  {
122  //std::cout<<"dSFMTEngine::setSeed seed="<<seed<<endl;
123  int dum ATLAS_THREAD_SAFE [[maybe_unused]] = wrap_init_gen_rand(m_dsfmt,seed);
124 }

◆ setSeeds() [1/2]

void CLHEP::dSFMTEngine::setSeeds ( const long *  seeds,
int  k = 0 
)
overridevirtual

Definition at line 141 of file dSFMTEngine.cxx.

141  {
142  //std::cout<<"dSFMTEngine::setSeeds"<<endl;
143  if (*seeds) {
144  int i = 0;
145  const int numBuff=DSFMT_N;
146  uint32_t buf[numBuff]{};
147  while (i < numBuff && seeds[i]) {
148  buf[i]=seeds[i];
149  ++i;
150  }
151  // cppcheck-suppress uninitvar; false positive
152  int dum ATLAS_THREAD_SAFE [[maybe_unused]] = wrap_init_by_array(m_dsfmt,buf,i);
153  } else {
154  setSeed(1234567);
155  }
156 }

◆ setSeeds() [2/2]

void CLHEP::dSFMTEngine::setSeeds ( const uint32_t *  seeds,
int  k = 0 
)

Definition at line 126 of file dSFMTEngine.cxx.

126  {
127  //std::cout<<"dSFMTEngine::setSeeds"<<endl;
128  if (*seeds) {
129  int i = 0;
130  const int numBuff=DSFMT_N;
131  while (i < numBuff && seeds[i]) {
132  //cout<<" seed "<<i<<" = "<<seeds[i]<<endl;
133  ++i;
134  }
135  int dum ATLAS_THREAD_SAFE [[maybe_unused]] = wrap_init_by_array(m_dsfmt,seeds,i);
136  } else {
137  setSeed(1234567);
138  }
139 }

◆ showStatus()

void CLHEP::dSFMTEngine::showStatus ( ) const
overridevirtual

Definition at line 185 of file dSFMTEngine.cxx.

186 {
187  std::cout << "\n";
188  std::cout << "--------- dSFMT engine status ---------\n";
189  int pr = std::cout.precision();
190  std::cout.precision(20);
191  std::cout << " Current index = " << m_dsfmt->idx << "\n";
192  std::cout << " Array status[] = \n";
193  for (int i=0; i<DSFMT_N + 1; ++i) {
194  std::cout << m_dsfmt->status[i].u32[0] << " " << m_dsfmt->status[i].u32[1] << " "
195  << m_dsfmt->status[i].u32[2] << " " << m_dsfmt->status[i].u32[3] << "\n";
196  }
197  std::cout << "----------------------------------------" << std::endl;
198  std::cout.precision(pr);
199 }

Member Data Documentation

◆ m_dsfmt

DSFMT_T* CLHEP::dSFMTEngine::m_dsfmt
private

Definition at line 87 of file dSFMTEngine.h.

◆ maxIndex

constexpr int CLHEP::dSFMTEngine::maxIndex = 215
staticconstexprprivate

Definition at line 91 of file dSFMTEngine.h.

◆ numEngines

std::atomic< int > CLHEP::dSFMTEngine::numEngines = 0
staticprivate

Definition at line 90 of file dSFMTEngine.h.


The documentation for this class was generated from the following files:
CLHEP::dSFMTEngine::engineName
static std::string engineName()
Definition: dSFMTEngine.h:80
xAOD::uint32_t
setEventNumber uint32_t
Definition: EventInfo_v1.cxx:127
makeTOC.inFile
string inFile
Definition: makeTOC.py:5
cycle
double cycle(double a, double b)
Definition: SiHitCollectionCnv_p2.cxx:38
python.AthDsoLogger.out
out
Definition: AthDsoLogger.py:71
CLHEP::dSFMTEngine::numEngines
static std::atomic< int > numEngines
Definition: dSFMTEngine.h:90
python.utils.AtlRunQueryLookup.mask
string mask
Definition: AtlRunQueryLookup.py:460
python.setupRTTAlg.size
int size
Definition: setupRTTAlg.py:39
CLHEP::dSFMTEngine::setSeeds
void setSeeds(const uint32_t *seeds, int k=0)
Definition: dSFMTEngine.cxx:126
python.utils.AtlRunQueryDQUtils.p
p
Definition: AtlRunQueryDQUtils.py:210
dqt_zlumi_pandas.err
err
Definition: dqt_zlumi_pandas.py:182
lumiFormat.i
int i
Definition: lumiFormat.py:85
python.DecayParser.buf
buf
print ("=> [%s]"cmd)
Definition: DecayParser.py:27
TileDCSDataPlotter.pr
pr
Definition: TileDCSDataPlotter.py:922
checkFile
Definition: checkFile.py:1
ReadFromCoolCompare.os
os
Definition: ReadFromCoolCompare.py:231
DQPostProcessTest.outFile
outFile
Comment Out Those You do not wish to run.
Definition: DQPostProcessTest.py:37
CLHEP::dSFMTEngine::setSeed
virtual void setSeed(long seed, int k=0) override
Definition: dSFMTEngine.cxx:121
CLHEP::dSFMTEngine::m_dsfmt
DSFMT_T * m_dsfmt
Definition: dSFMTEngine.h:87
CLHEP::VECTOR_STATE_SIZE
const unsigned int VECTOR_STATE_SIZE
Definition: dSFMTEngine.cxx:45
CLHEP::dSFMTEngine::init_dsfmt
void init_dsfmt()
Definition: dSFMTEngine.cxx:79
CLHEP::dSFMTEngine::maxIndex
static constexpr int maxIndex
Definition: dSFMTEngine.h:91
python.PyAthena.v
v
Definition: PyAthena.py:154
CLHEP::dSFMTEngine::getState
virtual std::istream & getState(std::istream &is) override
Definition: dSFMTEngine.cxx:263
CaloCellTimeCorrFiller.filename
filename
Definition: CaloCellTimeCorrFiller.py:24
ATLAS_THREAD_SAFE
#define ATLAS_THREAD_SAFE
Definition: checker_macros.h:211
CLHEP::dSFMTEngine::flat
virtual double flat() override
Definition: dSFMTEngine.cxx:112