121 const auto& mapper =
m_topgp->getFrontEndMapper();
122 int mapSize = mapper.getMapSize();
123 if (mapSize <= 0)
return;
125 vector<const TOPDigit*>* sortedDigits =
new vector<const TOPDigit*>[mapSize];
127 for (
const auto& digit : digits) {
128 int moduleID = digit.getModuleID();
129 int boardstack = digit.getChannel() / 128;
130 const auto* feemap = mapper.getMap(moduleID, boardstack);
132 B2ERROR(
"TOPPacker: no front-end map available."
133 <<
LogVar(
"moduleID", moduleID)
134 <<
LogVar(
"boardstack", boardstack));
137 sortedDigits[feemap->getIndex()].push_back(&digit);
140 auto subBits =
m_topgp->getGeometry()->getNominalTDC().getSubBits();
141 int sampleDivisions = 0x1 << subBits;
143 for (
const auto& copperID : mapper.getCopperIDs()) {
145 for (
int finesse = 0; finesse < 4; finesse++) {
146 const auto* feemap = mapper.getMapFromCopper(copperID, finesse);
147 if (!feemap)
continue;
148 unsigned scrodID = feemap->getScrodID();
149 unsigned dataFormat =
static_cast<unsigned>(TOP::RawDataType::c_Draft);
150 Buffer[finesse].push_back(scrodID + (dataFormat << 16));
151 for (
const auto& digit : sortedDigits[feemap->getIndex()]) {
152 double rawTime = digit->getRawTime();
153 unsigned tdc = int(rawTime * sampleDivisions) & 0xFFFF;
154 unsigned chan = digit->getChannel() % 128;
155 unsigned flags = (unsigned) digit->getHitQuality();
156 Buffer[finesse].push_back(tdc + (chan << 16) + (flags << 24));
160 info.
exp_num = evtMetaData->getExperiment();
162 info.run_subrun_num = (evtMetaData->getRun() << 8) +
163 (evtMetaData->getSubrun() & 0xFF);
164 info.eve_num = evtMetaData->getEvent();
165 info.node_id = TOP_ID + copperID;
169 info.hslb_crc16_error_bit = 0;
170 info.truncation_mask = 0;
171 info.type_of_data = 0;
174 raw->PackDetectorBuf(
Buffer[0].data(),
Buffer[0].size(),
180 delete [] sortedDigits;
190 const auto& mapper =
m_topgp->getFrontEndMapper();
191 int mapSize = mapper.getMapSize();
192 if (mapSize <= 0)
return;
194 auto* sortedDigits =
new vector<const TOPRawDigit*>[mapSize];
196 for (
const auto& digit : digits) {
197 auto scrodID = digit.getScrodID();
198 const auto* feemap = mapper.getMap(scrodID);
200 B2ERROR(
"TOPPacker: no front-end map available."
201 <<
LogVar(
"scrodID", scrodID));
204 sortedDigits[feemap->getIndex()].push_back(&digit);
207 for (
const auto& copperID : mapper.getCopperIDs()) {
209 for (
int finesse = 0; finesse < 4; finesse++) {
210 const auto* feemap = mapper.getMapFromCopper(copperID, finesse);
211 if (!feemap)
continue;
212 unsigned scrodID = feemap->getScrodID();
213 unsigned dataFormat =
static_cast<unsigned>(TOP::RawDataType::c_Type0Ver16);
216 unsigned head = (dataFormat << 16) | (0xA << 12) | (scrodID & 0x0FFF);
217 Buffer[finesse].push_back(head);
219 for (
const auto& digit : sortedDigits[feemap->getIndex()]) {
221 (digit->getCarrierNumber() << 30) |
222 ((digit->getASICNumber() & 0x3) << 28) |
223 ((digit->getASICChannel() & 0x7) << 25) |
224 ((digit->getASICWindow() & 0x1FF) << 16) |
226 ((digit->getTFine() & 0xF) << 8);
227 Buffer[finesse].push_back(word1);
229 ((digit->getValuePeak() & 0x1FFF) << 16) |
230 (digit->getIntegral() & 0xFFFF);
231 Buffer[finesse].push_back(word2);
233 ((digit->getValueRise0() & 0x1FFF) << 16) |
234 (digit->getValueRise1() & 0x1FFF);
235 Buffer[finesse].push_back(word3);
237 ((digit->getValueFall0() & 0x1FFF) << 16) |
238 (digit->getValueFall1() & 0x1FFF);
239 Buffer[finesse].push_back(word4);
241 (digit->getSampleRise() << 24) |
242 ((digit->getDeltaSamplePeak() & 0xF) << 20) |
243 ((digit->getDeltaSampleFall() & 0xF) << 16);
246 word5 |= (checkSum & 0xFFFF);
247 Buffer[finesse].push_back(word5);
250 unsigned tail = (0x5 << 9) | (Nhits & 0x1FF);
251 Buffer[finesse].push_back(tail);
254 info.
exp_num = evtMetaData->getExperiment();
256 info.run_subrun_num = (evtMetaData->getRun() << 8) +
257 (evtMetaData->getSubrun() & 0xFF);
258 info.eve_num = evtMetaData->getEvent();
259 info.node_id = TOP_ID + copperID;
263 info.hslb_crc16_error_bit = 0;
264 info.truncation_mask = 0;
265 info.type_of_data = 0;
268 raw->PackDetectorBuf(
Buffer[0].data(),
Buffer[0].size(),
274 delete [] sortedDigits;
284 const auto& mapper =
m_topgp->getFrontEndMapper();
285 int mapSize = mapper.getMapSize();
286 if (mapSize <= 0)
return;
288 auto* sortedDigits =
new vector<const TOPRawDigit*>[mapSize];
290 for (
const auto& digit : digits) {
291 auto scrodID = digit.getScrodID();
292 const auto* feemap = mapper.getMap(scrodID);
294 B2ERROR(
"TOPPacker: no front-end map available."
295 <<
LogVar(
"scrodID", scrodID));
298 sortedDigits[feemap->getIndex()].push_back(&digit);
301 unsigned revo9count = 0;
303 if (digits.getEntries() > 0) {
304 revo9count = digits[0]->getRevo9Counter();
305 phase = digits[0]->getPhase();
308 for (
const auto& copperID : mapper.getCopperIDs()) {
310 for (
int finesse = 0; finesse < 4; finesse++) {
311 const auto* feemap = mapper.getMapFromCopper(copperID, finesse);
312 if (!feemap)
continue;
313 unsigned scrodID = feemap->getScrodID();
314 unsigned format =
static_cast<unsigned>(TOP::RawDataType::c_ProductionDebug01);
316 unsigned head0 = (format << 16) | (0xA << 12) | (scrodID & 0x0FFF);
317 Buffer[finesse].push_back(head0);
319 unsigned numWordsCore = sortedDigits[feemap->getIndex()].size() * 5 + 1;
320 unsigned head1 = ((phase & 0xF) << 12) | (numWordsCore & 0xFFF);
321 Buffer[finesse].push_back(head1);
323 unsigned head2 = revo9count & 0xFFFF;
324 Buffer[finesse].push_back(head2);
327 Buffer[finesse].push_back(head3);
330 for (
const auto& digit : sortedDigits[feemap->getIndex()]) {
331 unsigned checkSum = 0;
333 (digit->getCarrierNumber() << 30) |
334 ((digit->getASICNumber() & 0x3) << 28) |
335 ((digit->getASICChannel() & 0x7) << 25) |
336 ((digit->getASICWindow() & 0x1FF) << 16) |
338 ((digit->getTFine() & 0xF) << 8);
339 checkSum += (word0 & 0xFFFF) + ((word0 >> 16) & 0xFFFF);
340 Buffer[finesse].push_back(word0);
342 ((digit->getValuePeak() & 0x1FFF) << 16) |
343 (digit->getIntegral() & 0xFFFF);
344 checkSum += (word1 & 0xFFFF) + ((word1 >> 16) & 0xFFFF);
345 Buffer[finesse].push_back(word1);
347 ((digit->getValueRise0() & 0x1FFF) << 16) |
348 (digit->getValueRise1() & 0x1FFF);
349 checkSum += (word2 & 0xFFFF) + ((word2 >> 16) & 0xFFFF);
350 Buffer[finesse].push_back(word2);
352 ((digit->getValueFall0() & 0x1FFF) << 16) |
353 (digit->getValueFall1() & 0x1FFF);
354 checkSum += (word3 & 0xFFFF) + ((word3 >> 16) & 0xFFFF);
355 Buffer[finesse].push_back(word3);
357 (digit->getSampleRise() << 24) |
358 ((digit->getDeltaSamplePeak() & 0xF) << 20) |
359 ((digit->getDeltaSampleFall() & 0xF) << 16);
360 checkSum += (word4 & 0xFFFF) + ((word4 >> 16) & 0xFFFF);
361 while ((checkSum >> 16) > 0) {
362 checkSum = (checkSum & 0xFFFF) + (checkSum >> 16);
364 word4 |= ((~checkSum) & 0xFFFF);
365 Buffer[finesse].push_back(word4);
368 unsigned tail = (0x5 << 9) | (Nhits & 0x1FF);
369 Buffer[finesse].push_back(tail);
373 info.
exp_num = evtMetaData->getExperiment();
375 info.run_subrun_num = (evtMetaData->getRun() << 8) +
376 (evtMetaData->getSubrun() & 0xFF);
377 info.eve_num = evtMetaData->getEvent();
378 info.node_id = TOP_ID + copperID;
382 info.hslb_crc16_error_bit = 0;
383 info.truncation_mask = 0;
384 info.type_of_data = 0;
387 raw->PackDetectorBuf(
Buffer[0].data(),
Buffer[0].size(),
393 delete [] sortedDigits;