npstat is hosted by Hepforge, IPPP Durham
NPStat  5.10.0
RandomSequenceRepeater.hh
Go to the documentation of this file.
1 #ifndef NPSTAT_RANDOMSEQUENCEREPEATER_HH_
2 #define NPSTAT_RANDOMSEQUENCEREPEATER_HH_
3 
4 /*!
5 // \file RandomSequenceRepeater.hh
6 //
7 // \brief Repeat a random sequence produced by another generator
8 //
9 // Author: I. Volobouev
10 //
11 // May 2010
12 */
13 
14 #include <vector>
15 
17 
18 namespace npstat {
19  /**
20  // This class remembers and repeats a random sequence.
21  //
22  // Use method "repeat()" to rewind to the beginning of the sequence.
23  //
24  // Use method "skip(...)" to skip an arbitrary number of sequence points.
25  //
26  // Use method "run(..)", as usual, to get the points. The class will
27  // either call an underlying generator (when the number of "run" calls
28  // exceeds the length of stored sequence) or, after at least one rewind,
29  // will return a member of the stored sequence, as appropriate.
30  */
32  {
33  public:
35  : orig_(original), dim_(original.dim()), pointer_(0UL) {}
36 
37  inline virtual ~RandomSequenceRepeater() {}
38 
39  inline unsigned dim() const {return dim_;}
40  double operator()();
41  void run(double* buf, const unsigned bufLen, const unsigned nPt);
42 
43  inline void repeat() {pointer_ = 0UL;}
44  inline void clear() {pointer_ = 0UL; sequence_.clear();}
45  void skip(unsigned long nSkip);
46 
47  private:
48  AbsRandomGenerator& orig_;
49  const unsigned dim_;
50 
51  std::vector<double> sequence_;
52  unsigned long pointer_;
53  };
54 }
55 
56 #endif // NPSTAT_RANDOMSEQUENCEREPEATER_HH_
Interface definition for pseudo- and quasi-random number generators.
Definition: RandomSequenceRepeater.hh:32
void run(double *buf, const unsigned bufLen, const unsigned nPt)
unsigned dim() const
Definition: RandomSequenceRepeater.hh:39
Definition: AbsArrayProjector.hh:14
Definition: AbsRandomGenerator.hh:27
virtual unsigned dim() const =0