Simpatico  v1.10
AutoCorrelation.tpp
1 #ifndef UTIL_AUTOCORRELATION_TPP
2 #define UTIL_AUTOCORRELATION_TPP
3 
4 /*
5 * Util Package - C++ Utilities for Scientific Computation
6 *
7 * Copyright 2010 - 2017, The Regents of the University of Minnesota
8 * Distributed under the terms of the GNU General Public License.
9 */
10 
11 #include "AutoCorrelation.h"
12 #include "AutoCorrStage.tpp"
13 
14 #include <string>
15 
16 namespace Util
17 {
18 
19  /*
20  * Constructor
21  */
22  template <typename Data, typename Product>
24  : AutoCorrStage<Data, Product>()
25  {
26  descendants_.append(this);
27  }
28 
29  /*
30  * Read parameters and initialize.
31  */
32  template <typename Data, typename Product>
34  {
35  readOptional(in, "bufferCapacity", bufferCapacity_);
36  readOptional(in, "maxStageId", maxStageId_);
37  readOptional(in, "blockFactor", blockFactor_);
38  allocate();
39  }
40 
41  /*
42  * Load internal state from archive.
43  */
44  template <typename Data, typename Product>
46  {
47  loadParameter<int>(ar, "bufferCapacity", bufferCapacity_);
48  loadParameter<int>(ar, "maxStageId", maxStageId_);
49  loadParameter<int>(ar, "blockFactor", blockFactor_);
50  serializePrivate(ar, 0);
51  }
52 
53  /*
54  * Save internal state to archive.
55  */
56  template <typename Data, typename Product>
58  { ar & *this; }
59 
60  /*
61  * Return the maximum delay.
62  */
63  template <typename Data, typename Product>
65  {
66  int iStage = descendants_.size() - 1;
67  AutoCorrStage<Data, Product>* stagePtr = descendants_[iStage];
68  int interval = stagePtr->stageInterval();
69  int size = stagePtr->bufferSize();
70  return (size - 1)*interval;
71  }
72 
73  /*
74  * Register the creation of a descendant stage.
75  */
76  template <typename Data, typename Product>
77  void
80  { descendants_.append(ptr); }
81 
82 }
83 #endif
int bufferSize() const
Return current size of history buffer.
void allocate()
Allocate memory and initialize to empty state.
Hierarchical auto-correlation function algorithm.
Definition: AutoCorrStage.h:53
Saving / output archive for binary ostream.
Auto-correlation function, using hierarchical algorithm.
AutoCorrelation()
Constructor.
int blockFactor_
Number of values per block (ratio of intervals for successive stages).
Utility classes for scientific computation.
Definition: accumulators.mod:1
void serializePrivate(Archive &ar, const unsigned int version)
Serialize private data members, and descendants.
Saving archive for binary istream.
virtual void readParameters(std::istream &in)
Read parameters from file and initialize.
int maxDelay() const
Return maximum delay, in primary samples.
int maxStageId_
Maximum allowed stage index (controls maximum degree of blocking).
long stageInterval() const
Return the number of primary values per block at this stage.
virtual void save(Serializable::OArchive &ar)
Save internal state to an archive.
virtual void load(Serializable::IArchive &ar)
Load internal state from an archive.
ScalarParam< Type > & readOptional(std::istream &in, const char *label, Type &value)
Add and read a new optional ScalarParam < Type > object.