29 declareInterface<PixelRawContByteStreamTool>(
this);
56 return StatusCode::SUCCESS;
63 return StatusCode::SUCCESS;
86 ATH_MSG_ERROR(
"The pixel cabling could not be retrieved in PixelRawContByteStreamTool::convert");
87 return StatusCode::FAILURE;
89 for( ; it_coll!=it_coll_end;++it_coll) {
97 ATH_MSG_ERROR(
"Didn't found ROBID for OfflineID: 0x" << std::hex << offlineId << std::dec);
104 std::vector<const PixelRDORawData*> RDOs;
105 for(; it_b!=it_e; ++it_b){ RDOs.push_back((*it_b)); }
112 ATH_MSG_WARNING(
"IDC contains NULLpointer to collection, skipping collection");
115 return StatusCode::SUCCESS;
118 static const InterfaceID IID_IPixelRawContByteStreamTool(
"PixelRawContByteStreamTool", 1, 0);
121 return IID_IPixelRawContByteStreamTool;
129 ATH_MSG_DEBUG(
"#####################################################################################");
136 bool is_ibl_present =
false;
139 is_ibl_present = (pixSiNum.
numLayers() == 4);
143 bool is_ibl_module =
false;
144 bool is_dbm_module =
false;
145 ATH_MSG_DEBUG(
"in fillROD with " << BCs_per_LVL1ID <<
" LVL1As");
146 ATH_MSG_DEBUG(
"Dimension of the RDO vector: " << RDOs.size());
152 std::unique_ptr<SG::ReadCondHandle<PixelHitDiscCnfgData> > pixHitDiscCnfg;
155 if (rdo_it != rdo_it_end) {
157 std::sort(rdo_it, rdo_it_end, orderInitialRdos);
162 rdo_it = RDOs.begin();
163 if (rdo_it!=rdo_it_end) {
168 bool timing_error =
false;
169 bool condensedMode =
false;
170 bool linkMasked =
false;
178 while (rdo_it!=rdo_it_end) {
188 linknumber = (onlineId >> 24) & 0xFFFF;
191 int TOT = rawdata->
getToT();
197 is_ibl_module =
true;
200 is_dbm_module =
true;
203 ATH_MSG_DEBUG(
" ********************* robId retrieved: 0x" << std::hex << robId << std::dec);
205 ATH_MSG_DEBUG(
"onlineId retrieved: 0x" << std::hex << onlineId <<
", linknumber retrieved: 0x" << linknumber << std::dec
206 <<
", ToT: " << TOT <<
", BCID: " <<
BCID <<
", LVL1ID: " <<
LVL1ID <<
", LVL1A: " << LVL1A);
207 ATH_MSG_DEBUG(
"Is IBL = " << is_ibl_module <<
" or is DBM = " << is_dbm_module);
212 if (!(is_ibl_module||is_dbm_module)) {
213 ATH_MSG_DEBUG(
"This is the PixelCase of the PixelRodEncoder");
217 if (prev_offlineId!=offlineId) {
219 timing_error =
false;
220 if (BCs_per_LVL1ID<LVL1A) {
221 ATH_MSG_DEBUG(
"LVL1A > BCs_per_LVL1ID, timing corrupt, ignoring timing." <<
" Set BCs per LVL1ID: " << BCs_per_LVL1ID);
224 if (prev_offlineId!=0x0) {
227 ATH_MSG_DEBUG(
" ------------------------------------------------------------------------------------------");
232 fake_BCID = last_BCID;
233 int max_BCID = fake_BCID+BCs_per_LVL1ID-LVL1A-1;
235 while ((fake_BCID<max_BCID) && !timing_error) {
239 ATH_MSG_DEBUG(
"(after) empty Pixel Module header/trailer pair written for BCID " << fake_BCID);
246 fake_BCID =
BCID-LVL1A;
248 while ((fake_BCID<
BCID) && !timing_error) {
251 ATH_MSG_DEBUG(
"(before) empty Pixel Module header/trailer pair written for BCID " << fake_BCID);
271 std::cout <<
"[PlotB]: " << robId <<
" " << eta_i <<
" " << phi_i <<
" " << TOT << std::endl;
272 std::cout <<
"[PlotC]: " << robId <<
" " <<
column <<
" " <<
row <<
" " << TOT << std::endl;
274 std::cout <<
"[VAL] " << std::hex << pixelId <<
" 0x" << robId <<
" 0x" << onlineId
282 ATH_MSG_DEBUG(
"Found hit in PIXEL with PixelID: 0x" << std::hex << pixelId << std::dec <<
" FE: " << FE <<
" Row: " <<
row <<
" Column: " <<
column
283 <<
" TOT: " << TOT <<
" BCID: " <<
BCID <<
" LVL1ID: " <<
LVL1ID <<
" LVL1A: " << LVL1A);
284 ATH_MSG_DEBUG(
"Encoded Pixel OfflineID: 0x" << std::hex << offlineId <<
" OnlineID: 0x" << onlineId <<
" -> Linknumber: 0x" << linknumber << std::dec);
286 prev_offlineId = offlineId;
292 ATH_MSG_DEBUG(
"Inside the IBL/DBM case of the PixelRodEncoder");
294 uint32_t linkNum = (onlineId>>24) & 0xFFFF;
296 FE = (linkNum>>(localFE*8)) & 0xF;
298 sLink = onlineId & 0xF;
300 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");
303 n5 = ((sLink & 0x3)<<3) | (FE & 0x7);
304 ATH_MSG_DEBUG(
"FE (w.r.t. SLink) = 0x" << std::hex << FE <<
" sLink: 0x" << sLink <<
" => n5: 0x" << n5 << std::dec);
306 if (!pixHitDiscCnfg) {
307 pixHitDiscCnfg = std::make_unique<SG::ReadCondHandle<PixelHitDiscCnfgData> >(
m_condHitDiscCnfgKey);
310 hitDiscCnfg = (*pixHitDiscCnfg)->getHitDiscCnfgPL();
313 hitDiscCnfg = (*pixHitDiscCnfg)->getHitDiscCnfg3D();
319 ATH_MSG_DEBUG(
"(prev_offlineId != offlineId) = " << (prev_offlineId != offlineId) <<
" (prev_n5 != n5) = " << (prev_n5 != n5) <<
" ");
322 if ((prev_offlineId!=offlineId) || (prev_n5!=n5)) {
324 timing_error =
false;
325 if (BCs_per_LVL1ID < LVL1A) {
326 ATH_MSG_DEBUG(
"LVL1A > BCs_per_LVL1ID, timing corrupt, ignoring timing." <<
" Set BCs per LVL1ID: " << BCs_per_LVL1ID);
330 if (prev_offlineId != 0x0) {
332 condensedMode =
false;
333 ATH_MSG_DEBUG(
"IBL Module trailer (because prev_offlineId != 0x0)");
338 fake_BCID = last_BCID;
339 int max_BCID = fake_BCID+BCs_per_LVL1ID-LVL1A-1;
341 while ((fake_BCID < max_BCID) && !timing_error) {
346 ATH_MSG_DEBUG(
"(after) empty IBL Module header/trailer pair written for BCID " << fake_BCID);
353 fake_BCID =
BCID-LVL1A;
355 while ((fake_BCID<
BCID) && !timing_error) {
358 ATH_MSG_DEBUG(
"(before) empty IBL Module header/trailer pair written for BCID " << fake_BCID);
369 std::vector<const PixelRDORawData*> rdos_sameIBL_offlineId;
376 Identifier pixelId_probe = (*rdo_it)->identify();
379 uint32_t linkNum = (onlineId>>24) & 0xFFFF;
380 unsigned int localFE =
m_pixelReadout->getFE(pixelId_probe, offlineId_probe);
381 uint32_t fe_probe = (linkNum>>(localFE*8)) & 0xF;
384 ATH_MSG_DEBUG(
"offlineId: " << offlineId <<
" offlineId_probe: " << offlineId_probe <<
", fe: " << FE <<
" fe_probe: " << fe_probe);
386 if ((offlineId_probe == offlineId) && (FE == fe_probe)) {
388 rdos_sameIBL_offlineId.push_back((*rdo_it));
401 for (; rdo_same_it != rdo_same_it_end; ++rdo_same_it) {
402 Identifier pixelId_probe = (*rdo_same_it)->identify();
405 int tot = (*rdo_same_it)->getToT();
406 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 <<
")");
409 rdo_same_it = rdos_sameIBL_offlineId.begin();
410 rdo_same_it_end = rdos_sameIBL_offlineId.end();
415 std::sort(rdo_same_it, rdo_same_it_end, orderRdos);
419 rdo_same_it = rdos_sameIBL_offlineId.begin();
420 rdo_same_it_end = rdos_sameIBL_offlineId.end();
423 for (; rdo_same_it != rdo_same_it_end; ++rdo_same_it) {
424 Identifier pixelId_probe = (*rdo_same_it)->identify();
427 int tot = (*rdo_same_it)->getToT();
432 ATH_MSG_DEBUG(
"pixelId: " << pixelId_probe <<
", eta_i: " << eta_i <<
", phi_i: " << phi_i <<
", eta_m: " << eta_m <<
", phi_m: ");
433 ATH_MSG_DEBUG(
"col: 0x" << std::hex <<
col << std::dec <<
", row: 0x" <<std::hex <<
row << std::dec <<
", tot = 0x" << std::hex <<
tot << std::dec);
435 ATH_MSG_DEBUG(
"rdos_sameIBL_offlineId.size() = " << rdos_sameIBL_offlineId.size());
438 rdo_same_it = rdos_sameIBL_offlineId.begin();
439 rdo_same_it_end = rdos_sameIBL_offlineId.end();
440 for (; rdo_same_it != rdo_same_it_end; ++rdo_same_it) {
441 Identifier pixelId_probe = (*rdo_same_it)->identify();
444 int tot = (*rdo_same_it)->getToT();
447 std::cout <<
"[Plot2]: " << robId <<
" " << eta_i <<
" " << phi_i <<
" " <<
tot << std::endl;
448 std::cout <<
"[Plot3]: " << robId <<
" " <<
col <<
" " <<
row <<
" " <<
tot << std::endl;
461 std::vector <uint32_t> vRows;
462 std::vector <uint32_t> vCols;
463 std::vector <int> vTots;
464 bool doubleHit =
false;
465 static const uint32_t rowsPerFE = 336;
467 rdo_same_it = rdos_sameIBL_offlineId.begin();
468 rdo_same_it_end = rdos_sameIBL_offlineId.end();
471 ATH_MSG_DEBUG(
"Looking for adjacent pixels and saving col, row and tot information.");
473 for (; rdo_same_it!=rdo_same_it_end; ++rdo_same_it) {
475 Identifier pixelId_probe = (*rdo_same_it)->identify();
478 int totInHitWord (0);
480 std::cout <<
"[VAL] " << std::hex << pixelId_probe <<
" 0x" << robId <<
" 0x" << onlineId
485 if (row0==rowsPerFE) {
486 ATH_MSG_DEBUG(
"Hit in the last row (== 336) of the IBL FE.");
489 if ((rdo_same_it+1)!=rdo_same_it_end) {
490 rdo_test_it = rdo_same_it + 1;
491 Identifier pixelId_probe = (*rdo_test_it)->identify();
495 std::cout <<
"[VAL] " << std::hex << pixelId_probe <<
" 0x" << robId <<
" 0x" << onlineId
500 ATH_MSG_DEBUG(
"Comparing rdo[i] = " << (*rdo_same_it) <<
" with rdo[i+1] = " << (*rdo_test_it));
501 ATH_MSG_DEBUG(
" col0 = 0x" << std::hex << col0 <<
" col1 = 0x" << col1 <<
" row0 = 0x" << row0 <<
"\t row1 = 0x" << row1 << std::dec);
503 if ((col1==col0) && (row1==(row0+1))) {
507 int tot0 = (*rdo_same_it)->getToT();
508 int tot1 = (*rdo_test_it)->getToT();
511 if (hitDiscCnfg==2 && tot0==16) { tot0=2; }
512 if (hitDiscCnfg==2 && tot1==16) { tot1=2; }
515 if (hitDiscCnfg==1) { overflow=15; }
516 if (hitDiscCnfg==2) { overflow=16; }
518 if (tot0>overflow) { tot0=overflow; }
519 if (tot1>overflow) { tot1=overflow; }
521 totInHitWord = (tot0<<4) | tot1;
523 ATH_MSG_DEBUG(
"doubleHit = " << std::boolalpha << doubleHit << std::noboolalpha <<
" ===> (col0 == col1) : 0x" << std::hex << col0 <<
" = 0x" << col1
524 <<
"; (row0 = row1 - 1) : 0x" << row0 <<
" => 0x" << row1 <<
"; (tot0) : 0x" << tot0 <<
", (tot1) : 0x" << tot1 <<
" => totInHitWord: 0x" << totInHitWord << std::dec);
534 int tot0 = (*rdo_same_it)->getToT();
537 if (hitDiscCnfg==2 && tot0==16) { tot0=2; }
540 if (hitDiscCnfg==1) { overflow=15; }
541 if (hitDiscCnfg==2) { overflow=16; }
542 if (tot0>overflow) { tot0=overflow; }
544 totInHitWord = (tot0<<4) | 0x0;
546 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);
548 vCols.push_back(col0);
549 vRows.push_back(row0);
550 vTots.push_back(totInHitWord);
555 ATH_MSG_DEBUG(
"CHECKs over the vectors storing columns, rows, ToTs of IBL/DBM hits:");
559 for (; vCols_it != vCols_it_end; ++vCols_it) {
560 ATH_MSG_DEBUG(
"0x" << std::hex << *vCols_it << std::dec <<
" ");
565 for (; vRows_it != vRows_it_end; ++vRows_it) {
566 ATH_MSG_DEBUG(
"0x" << std::hex << *vRows_it << std::dec <<
" ");
571 for (; vTots_it != vTots_it_end; ++vTots_it) {
572 ATH_MSG_DEBUG(
"0x" << std::hex << *vTots_it << std::dec <<
" ");
574 ATH_MSG_DEBUG(
"rdos_sameIBL_offlineId.size() = " << rdos_sameIBL_offlineId.size() <<
" vRows.size() = " << vRows.size() <<
" vCols.size() = " << vCols.size() <<
" vTots.size() = " << vTots.size());
578 if (vRows.size() >= 5) {
579 ATH_MSG_DEBUG(
"5 (or more) IBL hits have been consequently found. They can be written as condensed hits");
580 while (vRows.size()>=5) {
585 if (vRows.size()!=0) {
587 for (; vRows.size() != 0; ) {
589 vRows.erase(vRows.begin());
590 vCols.erase(vCols.begin());
591 vTots.erase(vTots.begin());
596 ATH_MSG_DEBUG(
"Encoded IBL OfflineID: " << std::hex << offlineId <<
" OnlineID: 0x" << onlineId << std::dec);
598 prev_offlineId = offlineId;
604 if (is_ibl_module || is_dbm_module) {
606 condensedMode =
false;
607 ATH_MSG_DEBUG(
"Module IBL/DBM trailer (at end of the loop)");
627 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);
629 std::cout <<
"[PlotA]:0x " << std::hex <<
result << std::dec << std::endl;
630 std::cout <<
"[PlotA]:(dec) " <<
result << std::endl;
642 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);
647 std::cout <<
"[Plot1]:0x " << std::hex <<
result << std::dec << std::endl;
648 std::cout <<
"[Plot1]:(dec) " <<
result << std::endl;
659 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);
664 std::cout <<
"[Plot1]:0x " << std::hex <<
result << std::dec << std::endl;
665 std::cout <<
"[Plot1]:(dec) " <<
result << std::endl;
676 result = PRB_DATAWORD | ((
row & PRB_ROWmask) << PRB_ROWskip) | ((
column & PRB_COLUMNmask) << PRB_COLUMNskip) | ((ToT & PRB_TOTmask) << PRB_TOTskip) | ((FE & PRB_FEmask) << PRB_FEskip);
678 std::cout <<
"[PlotA]:0x " << std::hex <<
result << std::dec << std::endl;
679 std::cout <<
"[PlotA]:(dec) " <<
result << std::endl;
689 uint32_t result = PRB_LINKTRAILER | ((
errors & PRB_TRAILERERRORSmask) << PRB_TRAILERERRORSskip);
691 std::cout <<
"[PlotA]:0x " << std::hex <<
result << std::dec << std::endl;
692 std::cout <<
"[PlotA]:(dec) " <<
result << std::endl;
704 result = PRB_LINKTRAILER | (timeOutErrorBit << PRB_TIMEOUTERRORskip_IBL) | (condensedModeBit << PRB_CONDENSEDMODEskip_IBL) | (linkMasked << PRB_LINKMASKEDskip_IBL) | ((linknum & PRB_LINKNUMTRAILERmask_IBL) << PRB_LINKNUMTRAILERskip_IBL);
709 std::cout <<
"[Plot1]:0x " << std::hex <<
result << std::dec << std::endl;
710 std::cout <<
"[Plot1]:(dec) " <<
result << std::endl;
726 unsigned int condWord[nCondensedWords];
727 condWord[0] = PRB_FIRSTHITCONDENSEDWORD | vRows[0] | (vCols[0] << skipRow) | (vTots[0] << (skipRow + skipCol) | ((vRows[1] & mask5) << (skipRow + skipCol + skipTOT)));
729 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));
731 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));
733 condWord[3] = PRB_DATAMASK | (vTots[3] >> skip3) | (vRows[4] << skip5) | (vCols[4] << (skip5+skipRow)) | (vTots[4] << (skip5+skipRow+skipCol));
735 for (
int j(0); j < 4; ++j) {
736 v32rod.push_back(condWord[j]);
738 std::cout <<
"[Plot1]:0x " << std::hex << condWord[j] << std::dec << std::endl;
739 std::cout <<
"[Plot1]:(dec) " << condWord[j] << std::endl;
743 vRows.erase (vRows.begin(), vRows.begin() + 5);
744 vCols.erase (vCols.begin(), vCols.begin() + 5);
745 vTots.erase (vTots.begin(), vTots.begin() + 5);
768 if (col0 == col1)
return (row0 < row1);
771 else if (((col0 == col1-1) && (col1%2 == 0)) || ((col1 == col0-1) && (col0%2 == 0))) {
774 if (row0 == row1)
return (col0 < col1);
776 else return (row0 < row1);
783 if (col0 > 40 && col1 > 40)
return (col0 > col1);
786 else return (col0 < col1);
796 if (offlineId0 < offlineId1) {
799 if (offlineId0 == offlineId1) {
805 uint32_t linkNum0 = (onlineId0>>24) & 0xFFFF;
806 unsigned int localFE0 =
m_pixelReadout->getFE(pixelId0, offlineId0);
807 uint32_t fe0= (linkNum0>>(localFE0*8)) & 0xF;
810 uint32_t linkNum1 = (onlineId1>>24) & 0xFFFF;
811 unsigned int localFE1 =
m_pixelReadout->getFE(pixelId1, offlineId1);
812 uint32_t fe1= (linkNum1>>(localFE1*8)) & 0xF;
824 else {
return false; }