30 declareInterface<PixelRawContByteStreamTool>(
this);
57 return StatusCode::SUCCESS;
64 return StatusCode::SUCCESS;
87 ATH_MSG_ERROR(
"The pixel cabling could not be retrieved in PixelRawContByteStreamTool::convert");
88 return StatusCode::FAILURE;
90 for( ; it_coll!=it_coll_end;++it_coll) {
98 ATH_MSG_ERROR(
"Didn't found ROBID for OfflineID: 0x" << std::hex << offlineId << std::dec);
105 std::vector<const PixelRDORawData*> RDOs;
106 for(; it_b!=it_e; ++it_b){ RDOs.push_back((*it_b)); }
113 ATH_MSG_WARNING(
"IDC contains NULLpointer to collection, skipping collection");
116 return StatusCode::SUCCESS;
119 static const InterfaceID IID_IPixelRawContByteStreamTool(
"PixelRawContByteStreamTool", 1, 0);
122 return IID_IPixelRawContByteStreamTool;
131 ATH_MSG_DEBUG(
"#####################################################################################");
138 bool is_ibl_present =
false;
141 is_ibl_present = (pixSiNum.
numLayers() == 4);
145 bool is_ibl_module =
false;
146 bool is_dbm_module =
false;
147 ATH_MSG_DEBUG(
"in fillROD with " << BCs_per_LVL1ID <<
" LVL1As");
148 ATH_MSG_DEBUG(
"Dimension of the RDO vector: " << RDOs.size());
153 std::unique_ptr<SG::ReadCondHandle<PixelHitDiscCnfgData> > pixHitDiscCnfg;
156 if (rdo_it != rdo_it_end) {
158 std::sort(rdo_it, rdo_it_end, orderInitialRdos);
163 rdo_it = RDOs.begin();
164 if (rdo_it!=rdo_it_end) {
169 bool timing_error =
false;
170 bool condensedMode =
false;
171 bool linkMasked =
false;
179 while (rdo_it!=rdo_it_end) {
189 linknumber = (onlineId >> 24) & 0xFFFF;
192 int TOT = rawdata->
getToT();
198 is_ibl_module =
true;
201 is_dbm_module =
true;
204 ATH_MSG_DEBUG(
" ********************* robId retrieved: 0x" << std::hex << robId << std::dec);
206 ATH_MSG_DEBUG(
"onlineId retrieved: 0x" << std::hex << onlineId <<
", linknumber retrieved: 0x" << linknumber << std::dec
207 <<
", ToT: " << TOT <<
", BCID: " <<
BCID <<
", LVL1ID: " <<
LVL1ID <<
", LVL1A: " << LVL1A);
208 ATH_MSG_DEBUG(
"Is IBL = " << is_ibl_module <<
" or is DBM = " << is_dbm_module);
213 if (!(is_ibl_module||is_dbm_module)) {
214 ATH_MSG_DEBUG(
"This is the PixelCase of the PixelRodEncoder");
218 if (prev_offlineId!=offlineId) {
220 timing_error =
false;
221 if (BCs_per_LVL1ID<LVL1A) {
222 ATH_MSG_DEBUG(
"LVL1A > BCs_per_LVL1ID, timing corrupt, ignoring timing." <<
" Set BCs per LVL1ID: " << BCs_per_LVL1ID);
225 if (prev_offlineId!=0x0) {
228 ATH_MSG_DEBUG(
" ------------------------------------------------------------------------------------------");
233 fake_BCID = last_BCID;
234 int max_BCID = fake_BCID+BCs_per_LVL1ID-LVL1A-1;
236 while ((fake_BCID<max_BCID) && !timing_error) {
240 ATH_MSG_DEBUG(
"(after) empty Pixel Module header/trailer pair written for BCID " << fake_BCID);
247 fake_BCID =
BCID-LVL1A;
249 while ((fake_BCID<
BCID) && !timing_error) {
252 ATH_MSG_DEBUG(
"(before) empty Pixel Module header/trailer pair written for BCID " << fake_BCID);
272 std::cout <<
"[PlotB]: " << robId <<
" " << eta_i <<
" " << phi_i <<
" " << TOT << std::endl;
273 std::cout <<
"[PlotC]: " << robId <<
" " <<
column <<
" " <<
row <<
" " << TOT << std::endl;
275 std::cout <<
"[VAL] " << std::hex << pixelId <<
" 0x" << robId <<
" 0x" << onlineId
283 ATH_MSG_DEBUG(
"Found hit in PIXEL with PixelID: 0x" << std::hex << pixelId << std::dec <<
" FE: " << FE <<
" Row: " <<
row <<
" Column: " <<
column
284 <<
" TOT: " << TOT <<
" BCID: " <<
BCID <<
" LVL1ID: " <<
LVL1ID <<
" LVL1A: " << LVL1A);
285 ATH_MSG_DEBUG(
"Encoded Pixel OfflineID: 0x" << std::hex << offlineId <<
" OnlineID: 0x" << onlineId <<
" -> Linknumber: 0x" << linknumber << std::dec);
287 prev_offlineId = offlineId;
293 ATH_MSG_DEBUG(
"Inside the IBL/DBM case of the PixelRodEncoder");
295 uint32_t linkNum = (onlineId>>24) & 0xFFFF;
297 FE = (linkNum>>(localFE*8)) & 0xF;
299 sLink = onlineId & 0xF;
301 ATH_MSG_WARNING(
"The SLink is not in the correct range [0,3]. This is due to the non-correct onlineId/ROBID definition. Skipping this RDO");
304 n5 = ((sLink & 0x3)<<3) | (FE & 0x7);
305 ATH_MSG_DEBUG(
"FE (w.r.t. SLink) = 0x" << std::hex << FE <<
" sLink: 0x" << sLink <<
" => n5: 0x" << n5 << std::dec);
307 if (!pixHitDiscCnfg) {
308 pixHitDiscCnfg = std::make_unique<SG::ReadCondHandle<PixelHitDiscCnfgData> >(
m_condHitDiscCnfgKey);
311 hitDiscCnfg = (*pixHitDiscCnfg)->getHitDiscCnfgPL();
314 hitDiscCnfg = (*pixHitDiscCnfg)->getHitDiscCnfg3D();
320 ATH_MSG_DEBUG(
"(prev_offlineId != offlineId) = " << (prev_offlineId != offlineId) <<
" (prev_n5 != n5) = " << (prev_n5 != n5) <<
" ");
323 if ((prev_offlineId!=offlineId) || (prev_n5!=n5)) {
325 timing_error =
false;
326 if (BCs_per_LVL1ID < LVL1A) {
327 ATH_MSG_DEBUG(
"LVL1A > BCs_per_LVL1ID, timing corrupt, ignoring timing." <<
" Set BCs per LVL1ID: " << BCs_per_LVL1ID);
331 if (prev_offlineId != 0x0) {
333 condensedMode =
false;
334 ATH_MSG_DEBUG(
"IBL Module trailer (because prev_offlineId != 0x0)");
339 fake_BCID = last_BCID;
340 int max_BCID = fake_BCID+BCs_per_LVL1ID-LVL1A-1;
342 while ((fake_BCID < max_BCID) && !timing_error) {
347 ATH_MSG_DEBUG(
"(after) empty IBL Module header/trailer pair written for BCID " << fake_BCID);
354 fake_BCID =
BCID-LVL1A;
356 while ((fake_BCID<
BCID) && !timing_error) {
359 ATH_MSG_DEBUG(
"(before) empty IBL Module header/trailer pair written for BCID " << fake_BCID);
370 std::vector<const PixelRDORawData*> rdos_sameIBL_offlineId;
377 Identifier pixelId_probe = (*rdo_it)->identify();
380 uint32_t linkNum = (onlineId>>24) & 0xFFFF;
381 unsigned int localFE =
m_pixelReadout->getFE(pixelId_probe, offlineId_probe);
382 uint32_t fe_probe = (linkNum>>(localFE*8)) & 0xF;
385 ATH_MSG_DEBUG(
"offlineId: " << offlineId <<
" offlineId_probe: " << offlineId_probe <<
", fe: " << FE <<
" fe_probe: " << fe_probe);
387 if ((offlineId_probe == offlineId) && (FE == fe_probe)) {
389 rdos_sameIBL_offlineId.push_back((*rdo_it));
402 for (; rdo_same_it != rdo_same_it_end; ++rdo_same_it) {
403 Identifier pixelId_probe = (*rdo_same_it)->identify();
406 int tot = (*rdo_same_it)->getToT();
407 ATH_MSG_DEBUG(
"col: " <<
col <<
" (0x" << std::hex <<
col << std::dec <<
")\trow: "<<
row <<
" (0x" << std::hex <<
row << std::dec <<
")\ttot: " << tot <<
"(0x" <<std::hex << tot << std::dec <<
")");
410 rdo_same_it = rdos_sameIBL_offlineId.begin();
411 rdo_same_it_end = rdos_sameIBL_offlineId.end();
416 std::sort(rdo_same_it, rdo_same_it_end, orderRdos);
420 rdo_same_it = rdos_sameIBL_offlineId.begin();
421 rdo_same_it_end = rdos_sameIBL_offlineId.end();
424 for (; rdo_same_it != rdo_same_it_end; ++rdo_same_it) {
425 Identifier pixelId_probe = (*rdo_same_it)->identify();
428 int tot = (*rdo_same_it)->getToT();
433 ATH_MSG_DEBUG(
"pixelId: " << pixelId_probe <<
", eta_i: " << eta_i <<
", phi_i: " << phi_i <<
", eta_m: " << eta_m <<
", phi_m: ");
434 ATH_MSG_DEBUG(
"col: 0x" << std::hex <<
col << std::dec <<
", row: 0x" <<std::hex <<
row << std::dec <<
", tot = 0x" << std::hex << tot << std::dec);
436 ATH_MSG_DEBUG(
"rdos_sameIBL_offlineId.size() = " << rdos_sameIBL_offlineId.size());
439 rdo_same_it = rdos_sameIBL_offlineId.begin();
440 rdo_same_it_end = rdos_sameIBL_offlineId.end();
441 for (; rdo_same_it != rdo_same_it_end; ++rdo_same_it) {
442 Identifier pixelId_probe = (*rdo_same_it)->identify();
445 int tot = (*rdo_same_it)->getToT();
448 std::cout <<
"[Plot2]: " << robId <<
" " << eta_i <<
" " << phi_i <<
" " << tot << std::endl;
449 std::cout <<
"[Plot3]: " << robId <<
" " <<
col <<
" " <<
row <<
" " << tot << std::endl;
462 std::vector <uint32_t> vRows;
463 std::vector <uint32_t> vCols;
464 std::vector <int> vTots;
465 bool doubleHit =
false;
466 static const uint32_t rowsPerFE = 336;
468 rdo_same_it = rdos_sameIBL_offlineId.begin();
469 rdo_same_it_end = rdos_sameIBL_offlineId.end();
472 ATH_MSG_DEBUG(
"Looking for adjacent pixels and saving col, row and tot information.");
474 for (; rdo_same_it!=rdo_same_it_end; ++rdo_same_it) {
476 Identifier pixelId_probe = (*rdo_same_it)->identify();
479 int totInHitWord (0);
481 std::cout <<
"[VAL] " << std::hex << pixelId_probe <<
" 0x" << robId <<
" 0x" << onlineId
486 if (row0==rowsPerFE) {
487 ATH_MSG_DEBUG(
"Hit in the last row (== 336) of the IBL FE.");
490 if ((rdo_same_it+1)!=rdo_same_it_end) {
491 rdo_test_it = rdo_same_it + 1;
492 Identifier pixelId_probe = (*rdo_test_it)->identify();
496 std::cout <<
"[VAL] " << std::hex << pixelId_probe <<
" 0x" << robId <<
" 0x" << onlineId
501 ATH_MSG_DEBUG(
"Comparing rdo[i] = " << (*rdo_same_it) <<
" with rdo[i+1] = " << (*rdo_test_it));
502 ATH_MSG_DEBUG(
" col0 = 0x" << std::hex << col0 <<
" col1 = 0x" << col1 <<
" row0 = 0x" << row0 <<
"\t row1 = 0x" << row1 << std::dec);
504 if ((col1==col0) && (row1==(row0+1))) {
508 int tot0 = (*rdo_same_it)->getToT();
509 int tot1 = (*rdo_test_it)->getToT();
512 if (hitDiscCnfg==2 && tot0==16) { tot0=2; }
513 if (hitDiscCnfg==2 && tot1==16) { tot1=2; }
516 if (hitDiscCnfg==1) { overflow=15; }
517 if (hitDiscCnfg==2) { overflow=16; }
519 if (tot0>overflow) { tot0=overflow; }
520 if (tot1>overflow) { tot1=overflow; }
522 totInHitWord = (tot0<<4) | tot1;
524 ATH_MSG_DEBUG(
"doubleHit = " << std::boolalpha << doubleHit << std::noboolalpha <<
" ===> (col0 == col1) : 0x" << std::hex << col0 <<
" = 0x" << col1
525 <<
"; (row0 = row1 - 1) : 0x" << row0 <<
" => 0x" << row1 <<
"; (tot0) : 0x" << tot0 <<
", (tot1) : 0x" << tot1 <<
" => totInHitWord: 0x" << totInHitWord << std::dec);
535 int tot0 = (*rdo_same_it)->getToT();
538 if (hitDiscCnfg==2 && tot0==16) { tot0=2; }
541 if (hitDiscCnfg==1) { overflow=15; }
542 if (hitDiscCnfg==2) { overflow=16; }
543 if (tot0>overflow) { tot0=overflow; }
545 totInHitWord = (tot0<<4) | 0x0;
547 ATH_MSG_DEBUG(
"doubleHit = " << std::boolalpha << doubleHit << std::noboolalpha <<
" ===> col0: 0x" << std::hex << col0 << std::dec <<
"; row0: 0x" << std::hex << row0 << std::dec <<
" totInHitWord: 0x" << std::hex << totInHitWord << std::dec);
549 vCols.push_back(col0);
550 vRows.push_back(row0);
551 vTots.push_back(totInHitWord);
556 ATH_MSG_DEBUG(
"CHECKs over the vectors storing columns, rows, ToTs of IBL/DBM hits:");
560 for (; vCols_it != vCols_it_end; ++vCols_it) {
561 ATH_MSG_DEBUG(
"0x" << std::hex << *vCols_it << std::dec <<
" ");
566 for (; vRows_it != vRows_it_end; ++vRows_it) {
567 ATH_MSG_DEBUG(
"0x" << std::hex << *vRows_it << std::dec <<
" ");
572 for (; vTots_it != vTots_it_end; ++vTots_it) {
573 ATH_MSG_DEBUG(
"0x" << std::hex << *vTots_it << std::dec <<
" ");
575 ATH_MSG_DEBUG(
"rdos_sameIBL_offlineId.size() = " << rdos_sameIBL_offlineId.size() <<
" vRows.size() = " << vRows.size() <<
" vCols.size() = " << vCols.size() <<
" vTots.size() = " << vTots.size());
579 if (vRows.size() >= 5) {
580 ATH_MSG_DEBUG(
"5 (or more) IBL hits have been consequently found. They can be written as condensed hits");
581 while (vRows.size()>=5) {
586 if (vRows.size()!=0) {
588 for (; vRows.size() != 0; ) {
590 vRows.erase(vRows.begin());
591 vCols.erase(vCols.begin());
592 vTots.erase(vTots.begin());
597 ATH_MSG_DEBUG(
"Encoded IBL OfflineID: " << std::hex << offlineId <<
" OnlineID: 0x" << onlineId << std::dec);
599 prev_offlineId = offlineId;
605 if (is_ibl_module || is_dbm_module) {
607 condensedMode =
false;
608 ATH_MSG_DEBUG(
"Module IBL/DBM trailer (at end of the loop)");
628 result = PRB_LINKHEADER | ((
bcid & PRB_BCIDmask) << PRB_BCIDskip) | ((lvl1id & PRB_L1IDmask) << PRB_L1IDskip) | ((lvl1idskip & PRB_L1IDSKIPmask) << PRB_L1IDSKIPskip) | ((
module & PRB_MODULEmask) << PRB_MODULEskip) | ((
errors & PRB_HEADERERRORSmask) << PRB_HEADERERRORSskip);
630 std::cout <<
"[PlotA]:0x " << std::hex <<
result << std::dec << std::endl;
631 std::cout <<
"[PlotA]:(dec) " <<
result << std::endl;
643 result = PRB_LINKHEADER | ((
bcid & PRB_BCIDmask_IBL) << PRB_BCIDskip_IBL) | ((lvl1id & PRB_L1IDmask_IBL) << PRB_L1IDskip_IBL) | ((
module & PRB_MODULEmask_IBL) << PRB_MODULEskip_IBL) | ((feFlag & PRB_FeI4BFLAGmask_IBL) << PRB_FeI4BFLAGskip_IBL);
648 std::cout <<
"[Plot1]:0x " << std::hex <<
result << std::dec << std::endl;
649 std::cout <<
"[Plot1]:(dec) " <<
result << std::endl;
660 result = PRB_DATAWORD | ((
row & PRB_ROWmask_IBL) << PRB_ROWskip_IBL) | ((
column & PRB_COLUMNmask_IBL) << PRB_COLUMNskip_IBL) | ((ToT & PRB_TOTmask) << PRB_TOTskip) | ((nLink & PRB_LINKNUMHITmask_IBL) << PRB_LINKNUMHITskip_IBL);
665 std::cout <<
"[Plot1]:0x " << std::hex <<
result << std::dec << std::endl;
666 std::cout <<
"[Plot1]:(dec) " <<
result << std::endl;
677 result = PRB_DATAWORD | ((
row & PRB_ROWmask) << PRB_ROWskip) | ((
column & PRB_COLUMNmask) << PRB_COLUMNskip) | ((ToT & PRB_TOTmask) << PRB_TOTskip) | ((FE & PRB_FEmask) << PRB_FEskip);
679 std::cout <<
"[PlotA]:0x " << std::hex <<
result << std::dec << std::endl;
680 std::cout <<
"[PlotA]:(dec) " <<
result << std::endl;
690 uint32_t result = PRB_LINKTRAILER | ((
errors & PRB_TRAILERERRORSmask) << PRB_TRAILERERRORSskip);
692 std::cout <<
"[PlotA]:0x " << std::hex <<
result << std::dec << std::endl;
693 std::cout <<
"[PlotA]:(dec) " <<
result << std::endl;
705 result = PRB_LINKTRAILER | (timeOutErrorBit << PRB_TIMEOUTERRORskip_IBL) | (condensedModeBit << PRB_CONDENSEDMODEskip_IBL) | (linkMasked << PRB_LINKMASKEDskip_IBL) | ((linknum & PRB_LINKNUMTRAILERmask_IBL) << PRB_LINKNUMTRAILERskip_IBL);
710 std::cout <<
"[Plot1]:0x " << std::hex <<
result << std::dec << std::endl;
711 std::cout <<
"[Plot1]:(dec) " <<
result << std::endl;
727 unsigned int condWord[nCondensedWords];
728 condWord[0] = PRB_FIRSTHITCONDENSEDWORD | vRows[0] | (vCols[0] << skipRow) | (vTots[0] << (skipRow + skipCol) | ((vRows[1] & mask5) << (skipRow + skipCol + skipTOT)));
730 condWord[1] = PRB_MIDDLEHITCONDENSEDWORD | (vRows[1] >> skip5) | (vCols[1] << skip4) | (vTots[1] << (skip4 + skipCol)) | (vRows[2] << (skip4+skipCol+skipTOT)) | ((vCols[2] & mask3) << (skip4+skipCol+skipTOT+skipRow));
732 condWord[2] = PRB_MIDDLEHITCONDENSEDWORD | (vCols[2] >> skip3) | (vTots[2] << skip4) | (vRows[3] << (skip4+skipTOT)) | (vCols[3] << (skip4+skipTOT+skipRow)) | ((vTots[3] & mask3) << (skip4+skipTOT+skipRow+skipCol));
734 condWord[3] = PRB_DATAMASK | (vTots[3] >> skip3) | (vRows[4] << skip5) | (vCols[4] << (skip5+skipRow)) | (vTots[4] << (skip5+skipRow+skipCol));
736 for (
int j(0); j < 4; ++j) {
737 v32rod.push_back(condWord[j]);
739 std::cout <<
"[Plot1]:0x " << std::hex << condWord[j] << std::dec << std::endl;
740 std::cout <<
"[Plot1]:(dec) " << condWord[j] << std::endl;
744 vRows.erase (vRows.begin(), vRows.begin() + 5);
745 vCols.erase (vCols.begin(), vCols.begin() + 5);
746 vTots.erase (vTots.begin(), vTots.begin() + 5);
769 if (col0 == col1)
return (row0 < row1);
772 else if (((col0 == col1-1) && (col1%2 == 0)) || ((col1 == col0-1) && (col0%2 == 0))) {
775 if (row0 == row1)
return (col0 < col1);
777 else return (row0 < row1);
784 if (col0 > 40 && col1 > 40)
return (col0 > col1);
787 else return (col0 < col1);
797 if (offlineId0 < offlineId1) {
800 if (offlineId0 == offlineId1) {
806 uint32_t linkNum0 = (onlineId0>>24) & 0xFFFF;
807 unsigned int localFE0 =
m_pixelReadout->getFE(pixelId0, offlineId0);
808 uint32_t fe0= (linkNum0>>(localFE0*8)) & 0xF;
811 uint32_t linkNum1 = (onlineId1>>24) & 0xFFFF;
812 unsigned int localFE1 =
m_pixelReadout->getFE(pixelId1, offlineId1);
813 uint32_t fe1= (linkNum1>>(localFE1*8)) & 0xF;
825 else {
return false; }