My Project
 All Classes Files Functions Variables Enumerations Enumerator Friends Macros Pages
scancache.h
1 #ifndef SCANCACHE_H
2 #define SCANCACHE_H
3 
4 #include "gcp/control/code/unix/libunix_src/common/genericregs.h"
5 
6 #include "gcp/util/common/TimeVal.h"
7 #include "gcp/util/common/QuadraticInterpolator.h"
8 
9 /*
10  * Set the number of scan entries per cache. This should be large
11  * enough to read all points for any scan. Currently, each step of a
12  * scan pattern can be as little as 10ms second long, so a SCAN_CACHE
13  * of 100000 relects a scan of about 17 minutes.
14  */
15 #define SCAN_CACHE_SIZE 100000
16 
22 struct ScanCacheOffset {
23  double az; /* The AZ offset */
24  double el; /* The EL offset */
25  double dk; /* The PA offset */
26  double azrate; /* The AZ rate */
27  double elrate; /* The EL rate */
28  double dkrate; /* The PA rate */
29  ScanMode currentState; /* The current mode of this scan */
30  ScanMode nextState; /* The current mode of this scan */
31  unsigned irep; /* The current rep */
32  unsigned index; /* The current index */
33  unsigned flag; // The current flag
34  unsigned ms;
35 
36  // Reset an offset container.
37 
38  void reset();
39 
40  // Print method
41 
42  // The gcc 3.2.3 compiler on raki doesn't like this at all -- I
43  // don't know why. Commenting out for now...
44 
45  // friend std::ostream& operator<<(std::ostream& os, ScanCacheOffset& offset);
46 };
47 
51 typedef struct {
52  unsigned int flag; // The flag
53  unsigned int index; /* The integer counter of this point in the scan */
54  double azoff; /* The AZ offset (degrees) */
55  double eloff; /* The EL offset (degrees) */
56  double dkoff; /* The DK offset (degrees) */
58 
62 struct ScanCache {
63  ScanCacheEntry offsets[SCAN_CACHE_SIZE];
64  ScanCacheOffset lastOffset; // The last calculated offset
65 
66  unsigned int size; /* The number of offsets in the offset buffer. */
67 
68  unsigned int istart;
69  unsigned int ibody; // The starting index of the body portion of this scan
70  unsigned int iend; // The starting index of the end portion of this scan
71 
72  // The current 1-second index midpoint of the interpolation
73  // container. For SPT, which updates on 10-ms timescales, this will
74  // represent the next 1-s index needed to bracket the mjd
75  // corresponding to the current 10-ms tick
76 
77  unsigned midIndex;
78  unsigned startIndex_;
79  unsigned nreps; // The number of times we should run through
80  // the current scan pattern
81  unsigned irep; // The current rep
82 
83  // The number of milliseconds per step of the scan
84 
85  unsigned msPerStep;
86 
87  // The number of milliseconds per offset in the cache
88 
89  unsigned msPerSample;
90 
91  ScanMode currentState;
92 
93  gcp::util::TimeVal* startMjd_;
97 
98  // True if we are first starting a scan, or if we are restarting the
99  // body portion
100 
101  bool start;
102 
103  // True if scan offsets should be
104 
105  bool add_;
106 
107  // Initialize this object
108 
109  void initialize();
110 
111  // Free any allocated members
112 
113  void free();
114 
115  // Empty a cache.
116 
117  int empty();
118 
119  // Initialize fixed members.
120 
121  int initialize(unsigned int ibody, unsigned int iend,
122  unsigned int nreps, unsigned int msPerStep,
123  unsigned int msPerSample, bool add);
124 
125  // Add an element to the current cache.
126 
127  int extend(unsigned int index, unsigned flag,
128  double azoff, double eloff, double dkoff);
129 
130  // Return the next offset
131 
133 
134  // Get the scan offsets and rates corresponding to this mjd
135 
136  void setUpForNewInterpolation(gcp::util::TimeVal& mjd, unsigned index);
137 
138  // Get the scan offsets and rates corresponding to this mjd
139 
141 
142  // Empty the interpolation containers
143 
145 
146  // Extend the interpolation containers in preparation for the next
147  // evaluation
148 
150 
151  // Add a new point to the interpolation containers
152 
153  void extend(unsigned index);
154 
155  // Fill the interpolation containers, starting from the passed index
156 
157  void fillInterpolationContainers(unsigned startIndex);
158 
159  // Private method to compute the next offset
160 
162 
163  // Update the state of the offset
164 
165  ScanMode getState(gcp::util::TimeVal& mjd);
166 
167  // Do whatever is appropriate to extend the interpolation containers
168  // in preparation for the next computation
169 
171 
172  // Return true if the next step will end the scan
173 
175 
176  // Return true if the next step is part of the body segment
177 
179 
180  // Return true if the next step is part of the body segment
181 
183 
184  // Print method
185 
186  friend std::ostream& operator<<(std::ostream& os, ScanCache& cache);
187 };
188 
189 
190 #endif
void clearInterpolationContainers()
Definition: scancache.c:171
bool nextStepEndsScan(gcp::util::TimeVal &mjd)
Definition: scancache.c:349
Definition: QuadraticInterpolator.h:48
void computeOffset(ScanCacheOffset *offset, gcp::util::TimeVal &mjd)
Definition: scancache.c:236
Definition: scancache.h:22
bool nextStepStartsNewIteration(gcp::util::TimeVal &mjd)
Definition: scancache.c:405
void fillInterpolationContainers(unsigned startIndex)
Definition: scancache.c:224
ScanMode getState(gcp::util::TimeVal &mjd)
Definition: scancache.c:291
bool nextStepIsBody(gcp::util::TimeVal &mjd)
Definition: scancache.c:371
int empty()
Definition: scancache.c:14
friend std::ostream & operator<<(std::ostream &os, ScanCache &cache)
Definition: scancache.c:425
void getNextOffset(ScanCacheOffset *offset, gcp::util::TimeVal &mjd)
Definition: scancache.c:93
Definition: TimeVal.h:55
void extendInterpolation(gcp::util::TimeVal &mjd)
Definition: scancache.c:182
Definition: scancache.h:51
void setUpForNextIteration(gcp::util::TimeVal &mjd)
Definition: scancache.c:162
void updateInterpolators(gcp::util::TimeVal &mjd)
Definition: scancache.c:323
Definition: scancache.h:62
void setUpForNewInterpolation(gcp::util::TimeVal &mjd, unsigned index)
Definition: scancache.c:139
void reset()
Definition: scancache.c:484