All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Public Member Functions | Private Member Functions | Static Private Member Functions | Private Attributes | List of all members
util::NonRandomCounter Class Reference

Fast random engine which returns sequential numbers. More...

#include <NonRandomCounter.h>

Inheritance diagram for util::NonRandomCounter:

Public Member Functions

 NonRandomCounter ()=default
 
 NonRandomCounter (long seed)
 
 NonRandomCounter (std::istream &is)
 
virtual double flat () override
 
virtual void flatArray (const int size, double *vect) override
 
virtual void setSeed (long seed, int) override
 
virtual void setSeeds (long const *seeds, int _) override
 
virtual void saveStatus (const char filename[]="NonRandomCounter.conf") const override
 
virtual void restoreStatus (const char filename[]="NonRandomCounter.conf") override
 
virtual void showStatus () const override
 
virtual std::string name () const override
 

Private Member Functions

double doFlat ()
 

Static Private Member Functions

static long readLong (std::istream &is)
 

Private Attributes

unsigned long count = 0U
 

Detailed Description

Fast random engine which returns sequential numbers.

This generator does not produce pseudorandom numbers. It is used only as a replacement of a real engine for profiling purposes.

The range of values spans [ 0, 1 [.

Definition at line 33 of file NonRandomCounter.h.

Constructor & Destructor Documentation

util::NonRandomCounter::NonRandomCounter ( )
default
util::NonRandomCounter::NonRandomCounter ( long  seed)
inline

Definition at line 39 of file NonRandomCounter.h.

39 : count(seed) {}
unsigned int seed
util::NonRandomCounter::NonRandomCounter ( std::istream &  is)
inline

Definition at line 41 of file NonRandomCounter.h.

41 : NonRandomCounter(readLong(is)) {}
static long readLong(std::istream &is)

Member Function Documentation

double util::NonRandomCounter::doFlat ( )
inlineprivate

Definition at line 68 of file NonRandomCounter.h.

69  {
70  return static_cast<double>(++count)
71  / std::numeric_limits<unsigned long>::max();
72  }
virtual double util::NonRandomCounter::flat ( )
inlineoverridevirtual

Definition at line 43 of file NonRandomCounter.h.

43 { return doFlat(); }
virtual void util::NonRandomCounter::flatArray ( const int  size,
double *  vect 
)
inlineoverridevirtual

Definition at line 45 of file NonRandomCounter.h.

46  { double* end = vect + size; while (vect != end) *(vect++) = doFlat(); }
decltype(auto) constexpr end(T &&obj)
ADL-aware version of std::end.
Definition: StdUtils.h:77
decltype(auto) constexpr size(T &&obj)
ADL-aware version of std::size.
Definition: StdUtils.h:92
virtual std::string util::NonRandomCounter::name ( ) const
inlineoverridevirtual

Definition at line 62 of file NonRandomCounter.h.

62 { return "NonRandomCounter"; }
static long util::NonRandomCounter::readLong ( std::istream &  is)
inlinestaticprivate

Definition at line 75 of file NonRandomCounter.h.

75 { unsigned long l; is >> l; return l; }
void util::NonRandomCounter::restoreStatus ( const char  filename[] = "NonRandomCounter.conf")
overridevirtual

Definition at line 32 of file NonRandomCounter.cxx.

33 {
34  std::ifstream f { filename };
35  if (!f) return; // shouldn't we complain? HepJamesRandom does not
36 
37  f >> count;
38 
39 } // util::NonRandomCounter::restoreStatus()
BEGIN_PROLOG could also be dds filename
void util::NonRandomCounter::saveStatus ( const char  filename[] = "NonRandomCounter.conf") const
overridevirtual

Definition at line 20 of file NonRandomCounter.cxx.

21 {
22  std::ofstream f { filename };
23  if (!f) return; // shouldn't we complain? HepJamesRandom does not
24 
25  f << count;
26 
27 } // util::NonRandomCounter::saveStatus()
BEGIN_PROLOG could also be dds filename
virtual void util::NonRandomCounter::setSeed ( long  seed,
int   
)
inlineoverridevirtual

Definition at line 48 of file NonRandomCounter.h.

49  { count = static_cast<unsigned long>(seed); }
unsigned int seed
virtual void util::NonRandomCounter::setSeeds ( long const *  seeds,
int  _ 
)
inlineoverridevirtual

Definition at line 51 of file NonRandomCounter.h.

52  { setSeed(*seeds, _); }
std::vector< TrajPoint > seeds
Definition: DataStructs.cxx:14
virtual void setSeed(long seed, int) override
void util::NonRandomCounter::showStatus ( ) const
overridevirtual

Definition at line 43 of file NonRandomCounter.cxx.

43  {
44  std::cout << "Counter: " << count << std::endl;
45 }
BEGIN_PROLOG could also be cout

Member Data Documentation

unsigned long util::NonRandomCounter::count = 0U
private

Definition at line 66 of file NonRandomCounter.h.


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