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 258 of file dSFMTEngine.cxx.

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

◆ 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 286 of file dSFMTEngine.cxx.

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

◆ get() [2/2]

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

Definition at line 240 of file dSFMTEngine.cxx.

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

◆ getState() [1/2]

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

Definition at line 295 of file dSFMTEngine.cxx.

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

◆ getState() [2/2]

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

Definition at line 262 of file dSFMTEngine.cxx.

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

◆ 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 200 of file dSFMTEngine.cxx.

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

◆ operator unsigned int()

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

Definition at line 204 of file dSFMTEngine.cxx.

204  {
205  return dsfmt_genrand_uint32(m_dsfmt);
206 }

◆ 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 227 of file dSFMTEngine.cxx.

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

◆ put() [2/2]

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

Definition at line 208 of file dSFMTEngine.cxx.

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

◆ restoreStatus()

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

Definition at line 169 of file dSFMTEngine.cxx.

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

◆ saveStatus()

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

Definition at line 157 of file dSFMTEngine.cxx.

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

◆ 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  int dum ATLAS_THREAD_SAFE [[maybe_unused]] = wrap_init_by_array(m_dsfmt,buf,i);
152  } else {
153  setSeed(1234567);
154  }
155 }

◆ 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 184 of file dSFMTEngine.cxx.

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

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:262
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