Pack data.
34{
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];
57 if ( !dataPresent ) {
58 for (int sl = 0; sl < sliceF; ++sl) {
59 if (fadcData[sl] >= fadcThreshold || fadcBcid[sl]) {
60 dataPresent = 1;
61 break;
62 }
63 }
64 }
65 subBlock.packer(dataPresent, 1);
66 if ( !dataPresent ) continue;
67 }
68 const int lutLen = subBlock.minBits(lutData[0]);
69 int minFadc = 0;
70 int minOffset = 0;
71 bool fadcSame = true;
72 for (int sl = 0; sl < sliceF; ++sl) {
73 if (sl == 0) minFadc = fadcData[sl];
74 if (fadcData[sl] < minFadc) {
75 minFadc = fadcData[sl];
76 minOffset = sl;
77 }
78 if (fadcData[sl] != fadcData[0] || fadcBcid[sl] != 0) fadcSame = false;
79 }
80 if (minOffset)
std::swap(fadcData[0], fadcData[minOffset]);
81
83 if (lutData[0] == 0 && lutBcid[0] == 0 && fadcSame) {
85 subBlock.packer(header, 4);
86 if (fadcData[0]) {
87 subBlock.packer(1, 1);
89 } else subBlock.packer(0, 1);
91 } else {
92 const bool minFadcInRange = minFadc >= fadcBaseline &&
94 int anyFadcBcid = 0;
95 int maxFadcLen = 0;
97 for (int sl = 0; sl < sliceF; ++sl) {
98 if (sl != 0) {
99 fadcDout[
idx] = fadcData[sl] - minFadc;
100 fadcLens[
idx] = subBlock.minBits(fadcDout[idx]);
101 if (idx == 0 || fadcLens[idx] > maxFadcLen) {
102 maxFadcLen = fadcLens[
idx];
103 }
105 }
106 if (sl != trigOffset) anyFadcBcid |= fadcBcid[sl];
107 else if (fadcBcid[sl] != (lutBcid[0] & 0x1)) anyFadcBcid |= 1;
108 }
109 if (lutData[0] == 0 && lutBcid[0] == 0 &&
110 !anyFadcBcid && minFadcInRange && maxFadcLen < 4) {
111
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);
120 }
122 } else if (lutLen <= 3 && ((lutData[0] == 0 && lutBcid[0] == 0) ||
124 && !anyFadcBcid && minFadcInRange && maxFadcLen <= 4) {
125
126 const int header = minOffset + 10;
127 subBlock.packer(header, 4);
129 subBlock.packer(format - 2, 2);
130 if (lutData[0]) {
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);
138 }
139 } else {
140
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;
146 }
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]) {
157 }
158 if (anyFadcBcid) {
159 for (
int idx = 0;
idx < sliceF; ++
idx) {
160 subBlock.packer(fadcBcid[idx], 1);
161 }
162 }
163 if (minFadcInRange) {
164 subBlock.packer(0, 1);
165 minFadc -= fadcBaseline;
166 subBlock.packer(minFadc, 4);
167 } else {
168 subBlock.packer(1, 1);
169 subBlock.packer(minFadc, format * 2);
170 }
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);
175 } else {
176 subBlock.packer(1, 1);
177 subBlock.packer(fadcDout[idx], format * 2);
178 }
179 }
180 }
181 }
183 }
184
187 int statusBit = 0;
188 int errorBit = 0;
190 const int errorWord = subBlock.ppmPinError(pin);
193 if (status[pin]) statusBit = 1;
194 if (error[pin]) errorBit = 1;
195 }
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);
202 }
204 if (status[pin] || error[pin]) {
205 if (statusBit) subBlock.packer(status[pin],
s_statusBits);
206 if (errorBit) subBlock.packer(error[pin],
s_errorBits);
207 }
208 }
209 }
210 subBlock.packerFlush();
211 subBlock.setCompStats(compStats);
212 return true;
213}
static const int s_peakOnly
static const int s_glinkPins
static const int s_lutBcidBits
static const int s_errorBits
static const int s_formats
static const int s_statusMask
static const int s_lutDataBits
static const int s_fadcRange
static const int s_statusBits
static const int s_fadcDataBits
void swap(ElementLinkVector< DOBJ > &lhs, ElementLinkVector< DOBJ > &rhs)