Pack data.
35 const int dataFormat = subBlock.format();
38 const int sliceL = subBlock.slicesLut();
39 const int sliceF = subBlock.slicesFadc();
40 if (sliceL != 1 || sliceF != 5)
return false;
41 const int trigOffset = subBlock.fadcOffset() - subBlock.lutOffset();
42 const int fadcBaseline = subBlock.fadcBaseline();
43 const int fadcThreshold = subBlock.fadcThreshold();
44 const int channels = subBlock.channelsPerSubBlock();
45 subBlock.setStreamed();
46 std::vector<uint32_t> compStats(
s_formats);
47 std::vector<int> fadcDout(sliceF-1);
48 std::vector<int> fadcLens(sliceF-1);
50 std::vector<int> lutData;
51 std::vector<int> lutBcid;
52 std::vector<int> fadcData;
53 std::vector<int> fadcBcid;
54 subBlock.ppmData(
chan, lutData, fadcData, lutBcid, fadcBcid);
56 int dataPresent = lutData[0] || lutBcid[0];
58 for (
int sl = 0; sl < sliceF; ++sl) {
59 if (fadcData[sl] >= fadcThreshold || fadcBcid[sl]) {
65 subBlock.packer(dataPresent, 1);
66 if ( !dataPresent )
continue;
68 const int lutLen = subBlock.minBits(lutData[0]);
72 for (
int sl = 0; sl < sliceF; ++sl) {
73 if (sl == 0) minFadc = fadcData[sl];
74 if (fadcData[sl] < minFadc) {
75 minFadc = fadcData[sl];
78 if (fadcData[sl] != fadcData[0] || fadcBcid[sl] != 0) fadcSame =
false;
80 if (minOffset)
std::swap(fadcData[0], fadcData[minOffset]);
83 if (lutData[0] == 0 && lutBcid[0] == 0 && fadcSame) {
85 subBlock.packer(
header, 4);
87 subBlock.packer(1, 1);
89 }
else subBlock.packer(0, 1);
92 const bool minFadcInRange = minFadc >= fadcBaseline &&
97 for (
int sl = 0; sl < sliceF; ++sl) {
99 fadcDout[
idx] = fadcData[sl] - minFadc;
100 fadcLens[
idx] = subBlock.minBits(fadcDout[
idx]);
101 if (
idx == 0 || fadcLens[
idx] > maxFadcLen) {
102 maxFadcLen = fadcLens[
idx];
106 if (sl != trigOffset) anyFadcBcid |= fadcBcid[sl];
107 else if (fadcBcid[sl] != (lutBcid[0] & 0
x1)) anyFadcBcid |= 1;
109 if (lutData[0] == 0 && lutBcid[0] == 0 &&
110 !anyFadcBcid && minFadcInRange && maxFadcLen < 4) {
113 if (maxFadcLen == 3)
header += 5;
114 subBlock.packer(
header, 4);
115 minFadc -= fadcBaseline;
116 subBlock.packer(minFadc, 4);
117 if (maxFadcLen < 2) maxFadcLen = 2;
118 for (
int idx = 0;
idx < sliceF-1; ++
idx) {
119 subBlock.packer(fadcDout[
idx], maxFadcLen);
122 }
else if (lutLen <= 3 && ((lutData[0] == 0 && lutBcid[0] == 0) ||
124 && !anyFadcBcid && minFadcInRange && maxFadcLen <= 4) {
126 const int header = minOffset + 10;
127 subBlock.packer(
header, 4);
129 subBlock.packer(
format - 2, 2);
131 subBlock.packer(1, 1);
132 subBlock.packer(lutData[0], 3);
133 }
else subBlock.packer(0, 1);
134 minFadc -= fadcBaseline;
135 subBlock.packer(minFadc, 4);
136 for (
int idx = 0;
idx < sliceF-1; ++
idx) {
137 subBlock.packer(fadcDout[
idx], 4);
141 const int header = minOffset + 10;
142 subBlock.packer(
header, 4);
143 if ( !minFadcInRange) {
144 const int minFadcLen = subBlock.minBits(minFadc);
145 if (minFadcLen > maxFadcLen) maxFadcLen = minFadcLen;
148 if (maxFadcLen <= 8)
format = 4;
149 if (maxFadcLen <= 6)
format = 3;
150 subBlock.packer(
format - 2, 2);
151 if (lutData[0] || lutBcid[0]) subBlock.packer(1, 1);
152 else subBlock.packer(0, 1);
153 subBlock.packer(anyFadcBcid, 1);
154 if (lutData[0] || lutBcid[0]) {
160 subBlock.packer(fadcBcid[
idx], 1);
163 if (minFadcInRange) {
164 subBlock.packer(0, 1);
165 minFadc -= fadcBaseline;
166 subBlock.packer(minFadc, 4);
168 subBlock.packer(1, 1);
169 subBlock.packer(minFadc,
format * 2);
171 for (
int idx = 0;
idx < sliceF-1; ++
idx) {
172 if (fadcLens[
idx] <= 4) {
173 subBlock.packer(0, 1);
174 subBlock.packer(fadcDout[
idx], 4);
176 subBlock.packer(1, 1);
177 subBlock.packer(fadcDout[
idx],
format * 2);
190 const int errorWord = subBlock.ppmPinError(pin);
193 if (
status[pin]) statusBit = 1;
194 if (
error[pin]) errorBit = 1;
196 subBlock.packer(statusBit, 1);
197 subBlock.packer(errorBit, 1);
198 if (statusBit || errorBit) {
200 if (
status[pin] ||
error[pin]) subBlock.packer(1, 1);
201 else subBlock.packer(0, 1);
210 subBlock.packerFlush();
211 subBlock.setCompStats(compStats);