-
Notifications
You must be signed in to change notification settings - Fork 0
/
Fast2D.cc
222 lines (165 loc) · 6.05 KB
/
Fast2D.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
/*
-------------------------------------------------------------------------
OBJECT NAME: Fast2D.cc
FULL NAME: Fast2D Probe Class
DESCRIPTION:
COPYRIGHT: University Corporation for Atmospheric Research, 1997-2018
-------------------------------------------------------------------------
*/
#include "Fast2D.h"
#include "OAPUserConfig.h"
#include "portable.h"
using namespace OAP;
const unsigned char Fast2D::SyncString[] = { 0xaa, 0xaa, 0xaa };
const unsigned char Fast2D::OverldString[] = { 0x55, 0x55, 0xaa };
/* -------------------------------------------------------------------- */
Fast2D::Fast2D(UserConfig *cfg, const char xml_entry[], int recSize) : Probe(FAST2D_T, cfg, xml_entry, recSize, 64)
{
_lrLen = recSize;
std::string id = ::XMLgetAttributeValue(xml_entry, "id");
strcpy(_code, id.c_str());
_name = ::XMLgetAttributeValue(xml_entry, "type");
_name += ::XMLgetAttributeValue(xml_entry, "suffix");
_resolution = atoi(::XMLgetAttributeValue(xml_entry, "resolution").c_str());
f2d_init();
printf("Fast2D::OAP id=%s, name=%s, resolution=%zu, armWidth=%f, eaw=%f\n", _code, _name.c_str(), _resolution, _armWidth, _eaw);
}
void Fast2D::f2d_init()
{
// Default for original version of probe.
_dofMask = 0x01;
_timingMask = 0x000000ffffffffffLL;
if (_code[0] == 'C') // 2DC
_armWidth = 61.0;
if (_code[0] == 'P') // 2DP
_armWidth = 261.0;
// Version two of the Fast2D uses a 33Mhz clock.
_clockMhz = 12;
if (_name.find("v2") != std::string::npos)
{
_clockMhz = 33.333333333;
_dofMask = 0x10;
_timingMask = 0x000003ffffffffffLL;
}
SetSampleArea();
}
/* -------------------------------------------------------------------- */
uint64_t Fast2D::TimeWord_Microseconds(const unsigned char *p)
{
// Fast2D uses 40 bit timing word; v2 uses 42 bits.
return (ntohll((uint64_t *)p) & _timingMask) / _clockMhz;
}
/* -------------------------------------------------------------------- */
bool Fast2D::isSyncWord(const unsigned char *p)
{
return memcmp(p, (void *)&SyncString, 2) == 0;
}
/* -------------------------------------------------------------------- */
bool Fast2D::isOverloadWord(const unsigned char *p)
{
return memcmp(p, (void *)&OverldString, 2) == 0;
}
/* -------------------------------------------------------------------- */
struct recStats Fast2D::ProcessRecord(const P2d_rec *record, float version)
{
int startTime, overload = 0;
unsigned long startMilliSec;
double sampleVolume[(nDiodes()<<1)+1], totalLiveTime;
uint64_t firstTimeWord = 0;
ClearStats(record);
stats.DASelapsedTime = stats.thisTime - _prevTime;
stats.SampleVolume = SampleArea() * stats.tas;
if (version == -1) // This means set time stamp only
{
_prevTime = stats.thisTime;
memcpy((char *)&_prevHdr, (char *)record, sizeof(P2d_hdr));
return(stats);
}
#ifdef DEBUG
printf("C4 %02d:%02d:%02d.%d - ", record->hour, record->minute, record->second, record->msec);
#endif
totalLiveTime = 0.0;
switch (_userConfig->GetConcentration()) {
case CENTER_IN:
case RECONSTRUCTION: _numBins = 128; break;
default: _numBins = nDiodes();
}
for (size_t i = 0; i < NumberBins(); ++i)
sampleVolume[i] = stats.tas * sampleArea[i] * 0.001;
// Scan record, compute tBarElapsedtime and stats.
const unsigned char *p = record->data;
startTime = _prevTime / 1000;
startMilliSec = _prevHdr.msec;
// Loop through all slices in record.
for (size_t i = 0; i < nSlices(); ++i, p += sizeof(uint64_t))
{
/* Have particle, will travel.
*/
if (isSyncWord(p) || isOverloadWord(p))
{
uint64_t thisTimeWord = TimeWord_Microseconds(p);
if (firstTimeWord == 0)
firstTimeWord = thisTimeWord;
if (isOverloadWord(p))
{
// Set 'overload' variable here. There is no way to determine overload.
// Leave zero, they are less than a milli-second anyways.
overload = 0;
printf(">>> %s overload @ %02d:%02d:%02d.%-3d. <<<\n", Name().c_str(),
record->hour, record->minute, record->second, record->msec);
if (cp)
cp->reject = true;
}
/* Close out particle. Timeword belongs to previous particle.
* cp should never be zero, this could almost be an assert().
*/
if (cp)
{
cp->timeWord = thisTimeWord;
unsigned long msec = startMilliSec + ((thisTimeWord - firstTimeWord) / 1000);
cp->time = startTime + (msec / 1000);
cp->msec = msec % 1000;
cp->deltaTime = cp->timeWord - _prevTimeWord;
cp->timeWord /= 1000; // Store as millseconds for this probe, since this is not a 48 bit word
totalLiveTime += checkRejectionCriteria(cp, stats);
if ((p[2] & _dofMask))
cp->dofReject = cp->reject = true;
stats.minBar = std::min(stats.minBar, cp->deltaTime);
stats.maxBar = std::max(stats.maxBar, cp->deltaTime);
stats.particles.push_back(cp);
cp = new Particle();
}
_prevTimeWord = thisTimeWord;
++stats.nTimeBars;
continue;
}
if (isBlankSlice(p))
continue;
++cp->w;
checkEdgeDiodes(cp, p);
cp->area += area(p);
cp->h = std::max(height(p), cp->h);
/* If the particle becomes rejected later, we need to now much time the
* particle consumed, so we can add it to the deadTime, so sampleVolume
* can be reduced accordingly.
*/
cp->liveTime = (unsigned long)((float)(cp->w) * stats.frequency);
#ifdef DEBUG
printf("%06x %zu %zu\n", cp->timeWord, cp->w, cp->h);
#endif
}
stats.SampleVolume *= (stats.DASelapsedTime - overload) * 0.001;
stats.tBarElapsedtime = (_prevTimeWord - firstTimeWord);
if (stats.nTimeBars > 0)
stats.meanBar = stats.tBarElapsedtime / stats.nTimeBars;
stats.tBarElapsedtime /= 1000;
stats.frequency /= 1000;
// Compute "science" data.
totalLiveTime /= 1000000; // convert to seconds
computeDerived(sampleVolume, totalLiveTime);
// Save time for next round.
_prevTime = stats.thisTime;
memcpy((char *)&_prevHdr, (char *)record, sizeof(P2d_hdr));
return(stats);
} // END PROCESSFAST2D
// END FAST2D.CC