14 #include "eformat/SourceIdentifier.h"
15 #include "eformat/Status.h"
26 const std::string&
name,
40 ATH_MSG_DEBUG((gTowersmode==ConversionMode::Encoding ?
"Encoding" :
"Decoding") <<
" gTowers ");
50 return StatusCode::SUCCESS;
60 ATH_CHECK(gTowersContainer.
record(std::make_unique<xAOD::gFexTowerContainer>(), std::make_unique<xAOD::gFexTowerAuxContainer>()));
61 ATH_MSG_DEBUG(
"Recorded gFexTowerContainer (200 MeV resolution, default) with key " << gTowersContainer.
key());
64 ATH_CHECK(gTowers50Container.
record(std::make_unique<xAOD::gFexTowerContainer>(), std::make_unique<xAOD::gFexTowerAuxContainer>()));
65 ATH_MSG_DEBUG(
"Recorded gFexTower50Container (50 MeV resolution) with key " << gTowers50Container.
key());
68 for (
const ROBF* rob : vrobf) {
72 ATH_MSG_DEBUG(
"Starting to decode " << rob->rod_ndata() <<
" ROD words from ROB 0x" << std::hex << rob->rob_source_id());
74 if(rob->rod_ndata() <= 0){
78 const auto dataArray =
std::span{rob->rod_data(), rob->rod_ndata()};
82 unsigned int n_words = rob->rod_ndata();
85 int fpgaPosition = -99;
97 int rows = Afiber.size();
98 int cols = Afiber[0].size();
102 for(
unsigned int iWord=0; iWord<
n_words; iWord++) {
105 fpgaPosition = iWord;
109 fpgaPosition = iWord;
113 fpgaPosition = iWord;
119 for (
int irow = 0; irow <
rows; irow++){
121 Afiber[irow][
icol] = dataArray[fpgaPosition + (7*irow) + 1 +
icol];
127 for (
int irow = 0; irow <
rows; irow++){
129 Bfiber[irow][
icol] = dataArray[fpgaPosition + (7*irow) + 1 +
icol];
135 for (
int irow = 0; irow <
rows; irow++){
137 Cfiber[irow][
icol] = dataArray[fpgaPosition + (7*irow) + 1 +
icol];
231 char IsSaturated = 0;
237 int twr_rows = Atwr.size();
238 int twr_cols = Atwr[0].size();
243 for (
int irow = 0; irow < twr_rows; irow++){
247 Et = Atwr[irow][
icol];
248 EtF = AtwrF[irow][
icol];
249 IsSaturated = Asatur[irow][
icol];
252 gTowersContainer->
push_back( std::make_unique<xAOD::gFexTower>() );
253 gTowersContainer->
back()->initialize(
iEta,
iPhi,
Eta,
Phi, Et, Fpga, IsSaturated, towerID);
254 gTowers50Container->
push_back( std::make_unique<xAOD::gFexTower>() );
255 gTowers50Container->
back()->initialize(
iEta,
iPhi,
Eta,
Phi, EtF, Fpga, IsSaturated, towerID);
265 for (
int irow = 0; irow < twr_rows; irow++){
269 Et = Btwr[irow][
icol];
270 EtF = BtwrF[irow][
icol];
271 IsSaturated = Bsatur[irow][
icol];
273 gTowersContainer->
push_back( std::make_unique<xAOD::gFexTower>() );
274 gTowersContainer->
back()->initialize(
iEta,
iPhi,
Eta,
Phi, Et, Fpga, IsSaturated, towerID);
275 gTowers50Container->
push_back( std::make_unique<xAOD::gFexTower>() );
276 gTowers50Container->
back()->initialize(
iEta,
iPhi,
Eta,
Phi, EtF, Fpga, IsSaturated, towerID);
285 for (
int irow = 0; irow < twr_rows; irow++){
289 Et = Ctwr[irow][
icol];
290 EtF = CtwrF[irow][
icol];
291 IsSaturated = Csatur[irow][
icol];
293 gTowersContainer->
push_back( std::make_unique<xAOD::gFexTower>() );
294 gTowersContainer->
back()->initialize(
iEta,
iPhi,
Eta,
Phi, Et, Fpga, IsSaturated, towerID);
295 gTowers50Container->
push_back( std::make_unique<xAOD::gFexTower>() );
296 gTowers50Container->
back()->initialize(
iEta,
iPhi,
Eta,
Phi, EtF, Fpga, IsSaturated, towerID);
302 Et = Ctwr[irow][
icol];
303 EtF = CtwrF[irow][
icol];
304 IsSaturated = Csatur[irow][
icol];
306 gTowersContainer->
push_back( std::make_unique<xAOD::gFexTower>() );
307 gTowersContainer->
back()->initialize(
iEta,
iPhi,
Eta,
Phi, Et, Fpga, IsSaturated, towerID);
308 gTowers50Container->
push_back( std::make_unique<xAOD::gFexTower>() );
309 gTowers50Container->
back()->initialize(
iEta,
iPhi,
Eta,
Phi, EtF, Fpga, IsSaturated, towerID);
318 return StatusCode::SUCCESS;
326 int rows = inputData.size();
327 int cols = inputData[0].size();
330 for (
int j=0; j<
cols; j++){
335 jf_lar_rx_data[
i][j] = 0;
338 jf_lar_rx_data[
i][j] = (inputData[0][0] & 0x03F0000);
347 int rows = inputData.size();
348 int cols = inputData[0].size();
351 for (
int j=0; j<
cols; j++){
356 jf_lar_rx_data[
i][j] = 0;
359 jf_lar_rx_data[
i][j] = (inputData[0][0] & 0x03F0000);
368 int rows = inputData.size();
369 int cols = inputData[0].size();
372 for (
int j=0; j<
cols; j++){
376 else if( j<
cols-1 ) {
377 outputData[
i][j] = 0;
380 outputData[
i][j] = ( inputData[0][0] & 0x03F0000);
392 const std::array<int, gPos::MAX_FIBERS> &XMPD_NFI,
393 const std::array<int, gPos::MAX_FIBERS> &XCALO_TYPE,
395 const gType & XMPD_DSTRT_ARR,
397 const std::array<int, gPos::MAX_FIBERS> &XMSK,
398 gtFPGA &Xsaturation)
const{
419 Xgt[irow][icolumn] = 0;
420 XgtF[irow][icolumn] = 0;
421 Xsaturation[irow][icolumn] = 0;
439 *BCIDptr = (Xfiber[0][
gPos::W280-1]&0x007F0000) >>16;
442 std::array<int, gPos::AB_TOWERS> etowerData{};
443 std::array<int, gPos::AB_TOWERS> htowerData{};
444 std::array<int, gPos::ABC_ROWS> xetowerData{};
445 std::array<int, gPos::ABC_ROWS> xhtowerData{};
446 std::array<int, gPos::ABC_ROWS> ohtowerData{};
449 std::array<int, gPos::AB_TOWERS> etowerDataF{};
450 std::array<int, gPos::AB_TOWERS> htowerDataF{};
451 std::array<int, gPos::ABC_ROWS> xetowerDataF{};
452 std::array<int, gPos::ABC_ROWS> xhtowerDataF{};
453 std::array<int, gPos::ABC_ROWS> ohtowerDataF{};
460 gFields fiberFieldsUndecoded{{}};
461 gSatur fiberSaturation{{}};
464 for(
unsigned int i=0;
i<100;
i++){
466 if (XMPD_NFI[
i] < 0)
continue;
468 if( ( Xfiber[
i][
gPos::W280-1] & 0x000000FF ) == 0x000000BC ) {
470 fiberFields[
i][16] = 1;
473 fiberFields[
i][16] = 0;
477 fiberFields[
i][18] = ( Xfiber[
i][
gPos::W280-1] & 0x007F0000) >>16 ;
478 fiberFields[
i][19] = ( Xfiber[
i][
gPos::W280-1] & 0xFF800000) >>23 ;
480 if (XMPD_DTYP_ARR[ XMPD_NFI[
i] ][17] == 8) {
482 fiberFields[
i][17] = ( Xfiber[
i][
gPos::W280-1] & 0x0000FF00) >>8 ;
484 for(
unsigned int k=0;
k<8;
k++){
485 if( fiberFields[
i][17] & (1<<
k) ) {
486 fiberSaturation[
i][
k] = 1;
492 for(
unsigned int k=0;
k<16;
k++){
493 if( (XMPD_DTYP_ARR[ XMPD_NFI[
i] ][
k] != 4 ) && ( XMPD_GTRN_ARR[
i][
k] > -1 ) ) {
494 int krow = XMPD_GTRN_ARR[
i][
k]/12;
495 int kcolumn = XMPD_GTRN_ARR[
i][
k]%12;
497 if( fiberSaturation[
i][kFilled] == 1 ) {
498 Xsaturation[ krow][kcolumn] = 1;
501 kFilled = kFilled + 1;
507 for(
int iFiber = 0; iFiber < Xin; iFiber++) {
509 std::array<uint32_t, 6>
tmp;
510 for(
int i = 0;
i < 6;
i++){
tmp[
i] = Xfiber[iFiber][
i]; };
513 int withoutComma = Xfiber[iFiber][6] & 0xFFFFFF00 ;
514 CRC =
crc9d23(withoutComma, CRC, 1 );
515 uint32_t StoredCRC = ( (Xfiber[iFiber][6]>>23) & 0x000001FF);
516 if( (CRC != StoredCRC) && (StoredCRC != 0 ) ) {
518 std::stringstream sdetail;
519 sdetail <<
"[gFexInputByteStreamTool::gtReconstructABC]: Fiber " << iFiber <<
"of Xin " << Xin <<
": BAD New CRC: " << CRC <<
"Stored CRC "<< StoredCRC ;
520 std::stringstream slocation;
521 slocation <<
"Fiber " << iFiber <<
"of Xin " << Xin;
522 std::stringstream stitle;
523 stitle <<
"Bad CRC" ;
529 int fiber_type = XMPD_NFI[iFiber];
531 for(
int iDatum = 0; iDatum < 16; iDatum++) {
533 int dataType = XMPD_DTYP_ARR[fiber_type][iDatum];
535 int ntower = XMPD_GTRN_ARR[iFiber][iDatum];
537 ATH_MSG_DEBUG(
"[gFexInputByteStreamTool::gtReconstructABC: unused location iFiber "<< iFiber <<
", calo type "<< XCALO_TYPE[iFiber]<<
", data type "<<
dataType <<
", iDatum " << iDatum <<
"tower " << ntower);
539 else if( (ntower < 0) || (ntower >383) ){
541 std::stringstream sdetail;
542 sdetail <<
"[gFexInputByteStreamTool::gtReconstructABC: bad value of ntower: iFiber "<< iFiber<<
", calo type"<< XCALO_TYPE[iFiber]<<
", data type "<<
dataType<<
", iDatum "<< iDatum<<
"tower "<< ntower ;
543 std::stringstream slocation;
544 slocation <<
"iFiber "<< iFiber<<
", calo type"<< XCALO_TYPE[iFiber];
545 std::stringstream stitle;
546 stitle <<
"Bad value of ntower" ;
553 int ihigh = XMPD_DSTRT_ARR[fiber_type][iDatum];
554 int ihword = ihigh/32;
555 int ihbit = ihigh%32;
571 if( XMSK[iFiber] != 1 ) {
576 if( (XCALO_TYPE[iFiber] < 3) && (ntower>-1) && (ntower<384) ) {
582 if(ilword == ihword){
585 etowerData[ntower] = etowerData[ntower] | ( (Xfiber[iFiber][ihword] &
mask) >> ilbit );
588 fiberFieldsUndecoded[iFiber][iDatum] = etowerData[ntower];
590 etowerDataF[ntower] = etowerData[ntower];
591 fiberFields[iFiber][iDatum] = etowerData[ntower];
596 if( etowerData[ntower] & 0x00000800 ){ etowerData[ntower] = (etowerData[ntower] | 0xFFFFF000) ;}
597 etowerData[ntower] = etowerData[ntower]*4;
598 etowerDataF[ntower] = etowerData[ntower];
603 std::stringstream sdetail;
604 sdetail <<
"[gFexInputByteStreamTool::gtReconstructABC]: wrongly packed data "<< fiber_type<<
", "<<
dataType<<
", "<<ilword<<
", " <<ihword ;
605 std::stringstream slocation;
606 slocation <<
"Fiber type "<< fiber_type<<
" and data type"<<
dataType;
607 std::stringstream stitle;
608 stitle <<
"Wrongly packed data" ;
619 hTREXval = Xfiber[iFiber][ihword];
620 lTREXval = Xfiber[iFiber][ilword];
625 if(ilword == ihword){
628 htowerData[ntower] = htowerData[ntower] | ( (hTREXval &
mask) >> (ilbit) );
630 else if ( ihbit == 7 ) {
633 htowerData[ntower] = htowerData[ntower] | ( (hTREXval & hmask) << 4);
635 htowerData[ntower] = htowerData[ntower] | ( ( (lTREXval & lmask) >> 28)&
mask) ;
637 else if ( ihbit == 3) {
640 htowerData[ntower] = htowerData[ntower] | ( ( hTREXval & hmask) << 8);
642 htowerData[ntower] = htowerData[ntower] | ( ( (lTREXval & lmask) >> 24) &
mask) ;
646 std::stringstream sdetail;
647 sdetail <<
"[gFexInputByteStreamTool::gtReconstructABC]: wrongly packed data "<< fiber_type<<
", "<<
dataType<<
", "<<ilword<<
", " <<ihword ;
648 std::stringstream slocation;
649 slocation <<
"Fiber type "<< fiber_type<<
" and data type"<<
dataType;
650 std::stringstream stitle;
651 stitle <<
"Wrongly packed data" ;
659 fiberFieldsUndecoded[iFiber][iDatum] = htowerData[ntower];
660 htowerData[ntower] = 20*htowerData[ntower];
661 htowerDataF[ntower] = htowerData[ntower];
662 fiberFields[iFiber][iDatum] = htowerData[ntower];
666 fiberFieldsUndecoded[iFiber][1] = htowerData[ntower];
668 htowerDataF[ntower] = htowerData[ntower];
669 fiberFields[iFiber][1] = htowerData[ntower];
673 if( htowerData[ntower] & 0x00000800 ){ htowerData[ntower] = (htowerData[ntower] | 0xFFFFF000) ;}
674 htowerData[ntower] = htowerData[ntower]*4;
675 htowerDataF[ntower] = htowerData[ntower];
684 if( (ntower > 32) || (ntower < 0) ){
686 std::stringstream sdetail;
687 sdetail <<
"[gFexInputByteStreamTool::gtReconstructABC]: bad value of nTower for extended region 2.4 - 2.5 in eta" ;
688 std::stringstream slocation;
689 slocation <<
"Fiber type "<< fiber_type<<
" and data type"<<
dataType;
690 std::stringstream stitle;
691 stitle <<
"Bad value of nTower in extended eta" ;
695 if(ilword == ihword){
696 int mask = 0x00000FFF;
698 xetowerData[ntower] = xetowerData[ntower] | ( (Xfiber[iFiber][ihword]&
mask) >> (ilbit) );
700 else if ( ihbit == 7 ) {
703 xetowerData[ntower] = xetowerData[ntower] | ( (Xfiber[iFiber][ihword]&hmask) << 4);
705 xetowerData[ntower] = xetowerData[ntower] | ( ( (Xfiber[iFiber][ilword]&lmask) >> 28)&
mask) ;
707 else if ( ihbit == 3) {
710 xetowerData[ntower] = xetowerData[ntower] | ( (Xfiber[iFiber][ihword]&hmask) << 8);
712 xetowerData[ntower] = xetowerData[ntower] | ( ( (Xfiber[iFiber][ilword]&lmask) >> 24)&
mask) ;
716 std::stringstream sdetail;
717 sdetail <<
"[gFexInputByteStreamTool::gtReconstructABC]: wrongly packed data "<< fiber_type<<
", "<<
dataType<<
", "<<ilword<<
", " <<ihword ;
718 std::stringstream slocation;
719 slocation <<
"Fiber type "<< fiber_type<<
" and data type"<<
dataType;
720 std::stringstream stitle;
721 stitle <<
"Wrongly packed data" ;
727 fiberFieldsUndecoded[iFiber][iDatum] = xetowerData[ntower];
728 undoMLE( xetowerData[ntower] );
729 xetowerDataF[ntower] = xetowerData[ntower];
730 fiberFields[iFiber][iDatum] = xetowerData[ntower];
735 if( xetowerData[ntower] & 0x00000800 ){ xetowerData[ntower] = (xetowerData[ntower] | 0xFFFFF000) ;}
736 xetowerData[ntower] = xetowerData[ntower]*4;
737 xetowerDataF[ntower] = xetowerData[ntower];
745 if(ilword == ihword){
748 xhtowerData[ntower] = xhtowerData[ntower] | ( (Xfiber[iFiber][ihword]&
mask) >> (ilbit) );
750 else if ( ihbit == 7 ) {
753 xhtowerData[ntower] = xhtowerData[ntower] | ( (Xfiber[iFiber][ihword]&hmask) << 4);
755 xhtowerData[ntower] = xhtowerData[ntower] | ( ( (Xfiber[iFiber][ilword]&lmask) >> 28)&
mask) ;
757 else if ( ihbit == 3) {
760 xhtowerData[ntower] = xhtowerData[ntower] | ( (Xfiber[iFiber][ihword]&hmask) << 8);
762 xhtowerData[ntower] = xhtowerData[ntower] | ( ( (Xfiber[iFiber][ilword]&lmask) >> 24)&
mask) ;
766 std::stringstream sdetail;
767 sdetail <<
"[gFexInputByteStreamTool::gtReconstructABC]: wrongly packed data "<< fiber_type<<
", "<<
dataType<<
", "<<ilword<<
", " <<ihword ;
768 std::stringstream slocation;
769 slocation <<
"Fiber type "<< fiber_type<<
" and data type"<<
dataType;
770 std::stringstream stitle;
771 stitle <<
"Wrongly packed data" ;
777 std::stringstream sdetail;
778 sdetail <<
"[gFexInputByteStreamTool::gtReconstructABC]: bad value of nTower for extended region 2.4 - 2.5 in eta" ;
779 std::stringstream slocation;
780 slocation <<
"Fiber type "<< fiber_type<<
" and data type"<<
dataType;
781 std::stringstream stitle;
782 stitle <<
"Bad value of nTower in extended eta" ;
788 fiberFieldsUndecoded[iFiber][iDatum] = xhtowerData[ntower];
789 undoMLE( xhtowerData[ntower] );
790 xhtowerDataF[ntower] = xhtowerData[ntower];
791 fiberFields[iFiber][iDatum] = xhtowerData[ntower];
795 if( xhtowerData[ntower] & 0x00000800 ){ xhtowerData[ntower] = (xhtowerData[ntower] | 0xFFFFF000) ;}
796 xhtowerData[ntower] = xhtowerData[ntower]*4;
797 xhtowerDataF[ntower] = xhtowerData[ntower];
805 if(ilword == ihword){
808 ohtowerData[ntower] = ohtowerData[ntower] | ( (Xfiber[iFiber][ihword]&
mask) >> (ilbit) );
810 else if ( ihbit == 7 ) {
813 ohtowerData[ntower] = ohtowerData[ntower] | ( (Xfiber[iFiber][ihword]&hmask) << 4);
815 ohtowerData[ntower] = ohtowerData[ntower] | ( ( (Xfiber[iFiber][ilword]&lmask) >> 28)&
mask) ;
817 else if ( ihbit == 3) {
820 ohtowerData[ntower] = ohtowerData[ntower] | ( (Xfiber[iFiber][ihword]&hmask) << 8);
822 ohtowerData[ntower] = ohtowerData[ntower] | ( ( (Xfiber[iFiber][ilword]&lmask) >> 24)&
mask) ;
826 std::stringstream sdetail;
827 sdetail <<
"[gFexInputByteStreamTool::gtReconstructABC]: wrongly packed data "<< fiber_type<<
", "<<
dataType<<
", "<<ilword<<
", " <<ihword ;
828 std::stringstream slocation;
829 slocation <<
"Fiber type "<< fiber_type<<
" and data type"<<
dataType;
830 std::stringstream stitle;
831 stitle <<
"Wrongly packed data" ;
837 std::stringstream sdetail;
838 sdetail <<
"[gFexInputByteStreamTool::gtReconstructABC]: bad value of nTower for extended region 2.4 - 2.5 in eta" ;
839 std::stringstream slocation;
840 slocation <<
"Fiber type "<< fiber_type<<
" and data type"<<
dataType;
841 std::stringstream stitle;
842 stitle <<
"Bad value of nTower in extended eta" ;
847 fiberFieldsUndecoded[iFiber][iDatum] = ohtowerData[ntower];
848 undoMLE( ohtowerData[ntower] );
849 ohtowerDataF[ntower] = ohtowerData[ntower];
850 fiberFields[iFiber][iDatum] = ohtowerData[ntower];
854 if( ohtowerData[ntower] & 0x00000800 ){ ohtowerData[ntower] = (ohtowerData[ntower] | 0xFFFFF000) ;}
855 ohtowerData[ntower] = ohtowerData[ntower]*4;
856 ohtowerDataF[ntower] = ohtowerData[ntower];
865 hHECval = Xfiber[iFiber][ihword];
866 lHECval = Xfiber[iFiber][ilword];
867 if(ilword == ihword){
870 htowerData[ntower] = htowerData[ntower] | ( (hHECval &
mask) >> (ilbit) );
872 else if ( ihbit == 7 ) {
875 htowerData[ntower] = htowerData[ntower] | ( (hHECval & hmask) << 4);
877 htowerData[ntower] = htowerData[ntower] | ( ( (lHECval & lmask) >> 28)&
mask) ;
879 else if ( ihbit == 3) {
882 htowerData[ntower] = htowerData[ntower] | ( ( hHECval & hmask) << 8);
884 htowerData[ntower] = htowerData[ntower] | ( ( (lHECval & lmask) >> 24) &
mask) ;
888 std::stringstream sdetail;
889 sdetail <<
"[gFexInputByteStreamTool::gtReconstructABC]: wrongly packed data "<< fiber_type<<
", "<<
dataType<<
", "<<ilword<<
", " <<ihword ;
890 std::stringstream slocation;
891 slocation <<
"Fiber type "<< fiber_type<<
" and data type"<<
dataType;
892 std::stringstream stitle;
893 stitle <<
"Wrongly packed data" ;
898 fiberFieldsUndecoded[iFiber][iDatum] = htowerData[ntower];
900 htowerDataF[ntower] = htowerData[ntower];
901 fiberFields[iFiber][iDatum] = htowerData[ntower];
905 if( htowerData[ntower] & 0x00000800 ){ htowerData[ntower] = (htowerData[ntower] | 0xFFFFF000) ;}
906 htowerData[ntower] = htowerData[ntower]*4;
907 htowerDataF[ntower] = htowerData[ntower];
914 else if ( (ntower>-1) && (ntower<384) ){
924 if( etowerData[ntower] != 0 ) {
926 std::stringstream sdetail;
927 sdetail <<
"[gFexInputByteStreamTool::gtReconstructABC]: etowerData[nTower] is not zero, inconsistent constants! "<< etowerData[ntower] ;
928 std::stringstream slocation;
929 slocation <<
"Fiber type "<< fiber_type<<
" and data type"<<
dataType;
930 std::stringstream stitle;
931 stitle <<
"etowerData not zero" ;
936 if(ilword == ihword){
937 int mask = 0x00000FFF;
939 etowerData[ntower] = etowerData[ntower] | ( (Xfiber[iFiber][ihword]&
mask) >> (ilbit) );
941 else if ( ihbit == 7 ) {
944 etowerData[ntower] = etowerData[ntower] | ( (Xfiber[iFiber][ihword]&hmask) << 4);
946 etowerData[ntower] = etowerData[ntower] | ( ( (Xfiber[iFiber][ilword]&lmask) >> 28)&
mask) ;
948 else if ( ihbit == 3) {
951 etowerData[ntower] = etowerData[ntower] | ( (Xfiber[iFiber][ihword]&hmask) << 8);
953 etowerData[ntower] = etowerData[ntower] | ( ( (Xfiber[iFiber][ilword]&lmask) >> 24)&
mask) ;
957 std::stringstream sdetail;
958 sdetail <<
"[gFexInputByteStreamTool::gtReconstructABC]: wrongly packed data "<< fiber_type<<
", "<<
dataType<<
", "<<ilword<<
", " <<ihword ;
959 std::stringstream slocation;
960 slocation <<
"Fiber type "<< fiber_type<<
" and data type"<<
dataType;
961 std::stringstream stitle;
962 stitle <<
"Wrongly packed data" ;
968 fiberFieldsUndecoded[iFiber][iDatum] = etowerData[ntower];
970 etowerDataF[ntower] = etowerData[ntower];
971 fiberFields[iFiber][iDatum] = etowerData[ntower];
975 if( etowerData[ntower] & 0x00000800 ){ etowerData[ntower] = (etowerData[ntower] | 0xFFFFF000) ;}
976 etowerData[ntower] = etowerData[ntower]*4;
977 etowerDataF[ntower] = etowerData[ntower];
987 if( htowerData[ntower] != 0 ) {
988 std::stringstream sdetail;
989 sdetail <<
"[gFexInputByteStreamTool::gtReconstructABC]: etowerData[nTower] is not zero, inconsistent constants! "<< etowerData[ntower] ;
990 std::stringstream slocation;
991 slocation <<
"Fiber type "<< fiber_type<<
" and data type"<<
dataType;
992 std::stringstream stitle;
993 stitle <<
"etowerData not zero" ;
998 if(ilword == ihword){
1001 htowerData[ntower] = htowerData[ntower] | ( (Xfiber[iFiber][ihword]&
mask) >> (ilbit) );
1003 else if ( ihbit == 7 ) {
1006 htowerData[ntower] = htowerData[ntower] | ( (Xfiber[iFiber][ihword]&hmask) << 4);
1008 htowerData[ntower] = htowerData[ntower] | ( ( (Xfiber[iFiber][ilword]&lmask) >> 28)&
mask) ;
1010 else if ( ihbit == 3) {
1013 htowerData[ntower] = htowerData[ntower] | ( (Xfiber[iFiber][ihword]&hmask) << 8);
1015 htowerData[ntower] = htowerData[ntower] | ( ( (Xfiber[iFiber][ilword]&lmask) >> 24)&
mask) ;
1019 std::stringstream sdetail;
1020 sdetail <<
"[gFexInputByteStreamTool::gtReconstructABC]: wrongly packed data "<< fiber_type<<
", "<<
dataType<<
", "<<ilword<<
", " <<ihword ;
1021 std::stringstream slocation;
1022 slocation <<
"Fiber type "<< fiber_type<<
" and data type"<<
dataType;
1023 std::stringstream stitle;
1024 stitle <<
"Wrongly packed data" ;
1030 fiberFieldsUndecoded[iFiber][iDatum] = htowerData[ntower];
1031 undoMLE( htowerData[ntower] );
1032 htowerDataF[ntower] = htowerData[ntower];
1033 fiberFields[iFiber][iDatum] = htowerData[ntower];
1037 if( htowerData[ntower] & 0x00000800 ){ htowerData[ntower] = (htowerData[ntower] | 0xFFFFF000) ;}
1038 htowerData[ntower] = htowerData[ntower]*4;
1039 htowerDataF[ntower] = htowerData[ntower];
1052 std::stringstream sdetail;
1053 sdetail <<
"[gFexInputByteStreamTool::gtReconstructABC]: wrong detector type "<<
dataType ;
1054 std::stringstream slocation;
1055 slocation <<
"Fiber type "<< fiber_type<<
" and data type"<<
dataType;
1056 std::stringstream stitle;
1057 stitle <<
"Wrong detector type" ;
1068 for(
int itower=0;itower<384;itower++){
1069 int icolumn = itower%12;
1070 int irow = itower/12;
1073 int xF = etowerDataF[itower] + htowerDataF[itower];
1075 int x = ( (etowerData[itower]>>2) + (htowerData[itower]>>2) );
1080 Xgt[irow][icolumn] =
x;
1081 XgtF[irow][icolumn] = xF;
1084 if ( icolumn == 0) {
1085 int xx = ( (xetowerData[irow]>>2) + (xhtowerData[irow]>>2) );
1087 Xgt[irow][icolumn] = Xgt[irow][icolumn] + xx;
1089 if ( icolumn == 4) {
1091 int ox = (ohtowerData[irow] >> 2 ) ;
1093 Xgt[irow][icolumn] = Xgt[irow][icolumn] + ox ;
1097 else if ( XFPGA == 1 ) {
1098 for(
int itower=0;itower<384;itower++){
1099 int icolumn = itower%12;
1100 int irow = itower/12;
1103 int xF = etowerDataF[itower] + htowerDataF[itower] ;
1105 int x = ( (etowerData[itower]>>2) + (htowerData[itower] >> 2) );
1110 Xgt[irow][icolumn] =
x;
1111 XgtF[irow][icolumn] = xF;
1114 if ( icolumn == 11) {
1118 int xx = ( (xetowerData[irow]>>2) + (xhtowerData[irow]>>2) );
1121 Xgt[irow][icolumn] = Xgt[irow][icolumn] + xx;
1123 if ( icolumn == 7 ) {
1126 int xo = ohtowerData[irow]>>2;
1129 Xgt[irow][icolumn] = Xgt[irow][icolumn] + xo;
1133 else if ( XFPGA == 2 ) {
1134 for(
int itower=0;itower<384;itower++){
1135 int icolumn = itower%12;
1136 int irow = itower/12;
1139 int xF = etowerDataF[itower] + htowerDataF[itower] ;
1141 int x = ( (etowerData[itower]>>2 ) + (htowerData[itower]>>2));
1145 Xgt[irow][icolumn] =
x;
1146 XgtF[irow][icolumn] = xF;
1150 ATH_MSG_DEBUG(
"[gFexInputByteStreamTool::gtReconstructABC]: Bad FPGA # "<< XFPGA);
1159 std::array<uint32_t, 32> dIn;
1160 std::array<uint32_t, 9> crc_s;
1161 std::array<uint32_t, 9> crc_r;
1166 int crc_word = 0x000;
1167 unsigned int mask = 0x00000001;
1169 for(
int k =0;
k < numWords;
k++) {
1171 for (
int i =0 ;
i < 32;
i++ ) {
1172 dIn[31-
i] = (inWords[
k] & (
mask <<
i));
1173 dIn[31-
i] = ((dIn[31-
i] >>
i) & 0x00000001);
1177 for (
int i =0 ;
i<32;
i++ ) {
1178 dIn[
i] = inWords[
k] & (
mask <<
i);
1179 dIn[
i] = ((dIn[
i] >>
i) & 0x0000001);
1182 for(
int j=0; j<9; j++){
1183 crc_s[j] = crc_r[j];
1186 crc_r[0] = crc_s[0] ^ crc_s[2] ^ crc_s[3] ^ crc_s[6] ^ crc_s[8] ^ dIn[0] ^ dIn[2] ^ dIn[3] ^ dIn[5] ^ dIn[6] ^ dIn[7] ^ dIn[8] ^ dIn[9] ^ dIn[10] ^ dIn[11] ^ dIn[15] ^ dIn[18] ^ dIn[19] ^ dIn[20] ^ dIn[21] ^ dIn[22] ^ dIn[23] ^ dIn[25] ^ dIn[26] ^ dIn[29] ^ dIn[31];
1188 crc_r[1] = crc_s[1] ^ crc_s[2] ^ crc_s[4] ^ crc_s[6] ^ crc_s[7] ^ crc_s[8] ^ dIn[0] ^ dIn[1] ^ dIn[2] ^ dIn[4] ^ dIn[5] ^ dIn[12] ^ dIn[15] ^ dIn[16] ^ dIn[18] ^ dIn[24] ^ dIn[25] ^ dIn[27] ^ dIn[29] ^ dIn[30] ^ dIn[31];
1190 crc_r[2] = crc_s[2] ^ crc_s[3] ^ crc_s[5] ^ crc_s[7] ^ crc_s[8] ^ dIn[1] ^ dIn[2] ^ dIn[3] ^ dIn[5] ^ dIn[6] ^ dIn[13] ^ dIn[16] ^ dIn[17] ^ dIn[19] ^ dIn[25] ^ dIn[26] ^ dIn[28] ^ dIn[30] ^ dIn[31];
1192 crc_r[3] = crc_s[0] ^ crc_s[2] ^ crc_s[4] ^ dIn[0] ^ dIn[4] ^ dIn[5] ^ dIn[8] ^ dIn[9] ^ dIn[10] ^ dIn[11] ^ dIn[14] ^ dIn[15] ^ dIn[17] ^ dIn[19] ^ dIn[21] ^ dIn[22] ^ dIn[23] ^ dIn[25] ^ dIn[27];
1194 crc_r[4] = crc_s[1] ^ crc_s[2] ^ crc_s[5] ^ crc_s[6] ^ crc_s[8] ^ dIn[0] ^ dIn[1] ^ dIn[2] ^ dIn[3] ^ dIn[7] ^ dIn[8] ^ dIn[12] ^ dIn[16] ^ dIn[19] ^ dIn[21] ^ dIn[24] ^ dIn[25] ^ dIn[28] ^ dIn[29] ^ dIn[31];
1196 crc_r[5] = crc_s[0] ^ crc_s[7] ^ crc_s[8] ^ dIn[0] ^ dIn[1] ^ dIn[4] ^ dIn[5] ^ dIn[6] ^ dIn[7] ^ dIn[10] ^ dIn[11] ^ dIn[13] ^ dIn[15] ^ dIn[17] ^ dIn[18] ^ dIn[19] ^ dIn[21] ^ dIn[23] ^ dIn[30] ^ dIn[31];
1198 crc_r[6] = crc_s[0] ^ crc_s[1] ^ crc_s[2] ^ crc_s[3] ^ crc_s[6] ^ dIn[0] ^ dIn[1] ^ dIn[3] ^ dIn[9] ^ dIn[10] ^ dIn[12] ^ dIn[14] ^ dIn[15] ^ dIn[16] ^ dIn[21] ^ dIn[23] ^ dIn[24] ^ dIn[25] ^ dIn[26] ^ dIn[29];
1200 crc_r[7] = crc_s[0] ^ crc_s[1] ^ crc_s[4] ^ crc_s[6] ^ crc_s[7] ^ crc_s[8] ^ dIn[0] ^ dIn[1] ^ dIn[3] ^ dIn[4] ^ dIn[5] ^ dIn[6] ^ dIn[7] ^ dIn[8] ^ dIn[9] ^ dIn[13] ^ dIn[16] ^ dIn[17] ^ dIn[18] ^ dIn[19] ^ dIn[20] ^ dIn[21] ^ dIn[23] ^ dIn[24] ^ dIn[27] ^ dIn[29] ^ dIn[30] ^ dIn[31];
1202 crc_r[8] = crc_s[1] ^ crc_s[2] ^ crc_s[5] ^ crc_s[7] ^ crc_s[8] ^ dIn[1] ^ dIn[2] ^ dIn[4] ^ dIn[5] ^ dIn[6] ^ dIn[7] ^ dIn[8] ^ dIn[9] ^ dIn[10] ^ dIn[14] ^ dIn[17] ^ dIn[18] ^ dIn[19] ^ dIn[20] ^ dIn[21] ^ dIn[22] ^ dIn[24] ^ dIn[25] ^ dIn[28] ^ dIn[30] ^ dIn[31];
1207 for (
int i = 0;
i < 9;
i++) {
1208 crc_word = crc_word | (crc_r[8-
i] <<
i) ;
1212 for(
int i = 0;
i < 9;
i++ ){
1213 crc_word = crc_word | (crc_r[
i] <<
i);
1222 int mask = 0x00000001;
1224 std::array<uint32_t, 23> dIn;
1226 std::array<uint32_t, 9> crc_r;
1227 std::array<uint32_t, 9> crc_in_s;
1232 int crc_word = 0x000;
1237 for(
int i = 0;
i < 23;
i++){
1238 dIn[22-
i] = ( inword & (
mask <<
i));
1239 dIn[22-
i] = ( dIn[22-
i] >>
i);
1241 for(
int i = 0;
i < 9;
i++){
1242 crc_in_s[8-
i] = ( in_crc & (
mask <<
i) );
1243 crc_in_s[8-
i] = ( crc_in_s[8-
i] >>
i );
1247 for(
int i = 0;
i < 23;
i++) {
1248 dIn[
i] = ( inword & (
mask <<
i) );
1249 dIn[
i] = (dIn[
i] >>
i);
1251 for(
int i=0;
i<9;
i++){
1252 crc_in_s[
i] = ( in_crc & (
mask <<
i));
1253 crc_in_s[
i] = (crc_in_s[
i] >>
i);
1257 crc_r[0] = crc_in_s[1] ^ crc_in_s[4] ^ crc_in_s[5] ^ crc_in_s[6] ^ crc_in_s[7] ^ crc_in_s[8] ^ dIn[0] ^ dIn[2] ^ dIn[3] ^ dIn[5] ^ dIn[6] ^ dIn[7] ^ dIn[8] ^ dIn[9] ^ dIn[10] ^ dIn[11] ^ dIn[15] ^ dIn[18] ^ dIn[19] ^ dIn[20] ^ dIn[21] ^ dIn[22];
1258 crc_r[1] = crc_in_s[1] ^ crc_in_s[2] ^ crc_in_s[4] ^ dIn[0] ^ dIn[1] ^ dIn[2] ^ dIn[4] ^ dIn[5] ^ dIn[12] ^ dIn[15] ^ dIn[16] ^ dIn[18];
1259 crc_r[2] = crc_in_s[2] ^ crc_in_s[3] ^ crc_in_s[5] ^ dIn[1] ^ dIn[2] ^ dIn[3] ^ dIn[5] ^ dIn[6] ^ dIn[13] ^ dIn[16] ^ dIn[17] ^ dIn[19];
1260 crc_r[3] = crc_in_s[0] ^ crc_in_s[1] ^ crc_in_s[3] ^ crc_in_s[5] ^ crc_in_s[7] ^ crc_in_s[8] ^ dIn[0] ^ dIn[4] ^ dIn[5] ^ dIn[8] ^ dIn[9] ^ dIn[10] ^ dIn[11] ^ dIn[14] ^ dIn[15] ^ dIn[17] ^ dIn[19] ^ dIn[21] ^ dIn[22];
1261 crc_r[4] = crc_in_s[2] ^ crc_in_s[5] ^ crc_in_s[7] ^ dIn[0] ^ dIn[1] ^ dIn[2] ^ dIn[3] ^ dIn[7] ^ dIn[8] ^ dIn[12] ^ dIn[16] ^ dIn[19] ^ dIn[21];
1262 crc_r[5] = crc_in_s[1] ^ crc_in_s[3] ^ crc_in_s[4] ^ crc_in_s[5] ^ crc_in_s[7] ^ dIn[0] ^ dIn[1] ^ dIn[4] ^ dIn[5] ^ dIn[6] ^ dIn[7] ^ dIn[10] ^ dIn[11] ^ dIn[13] ^ dIn[15] ^ dIn[17] ^ dIn[18] ^ dIn[19] ^ dIn[21];
1263 crc_r[6] = crc_in_s[0] ^ crc_in_s[1] ^ crc_in_s[2] ^ crc_in_s[7] ^ dIn[0] ^ dIn[1] ^ dIn[3] ^ dIn[9] ^ dIn[10] ^ dIn[12] ^ dIn[14] ^ dIn[15] ^ dIn[16] ^ dIn[21];
1264 crc_r[7] = crc_in_s[2] ^ crc_in_s[3] ^ crc_in_s[4] ^ crc_in_s[5] ^ crc_in_s[6] ^ crc_in_s[7] ^ dIn[0] ^ dIn[1] ^ dIn[3] ^ dIn[4] ^ dIn[5] ^ dIn[6] ^ dIn[7] ^ dIn[8] ^ dIn[9] ^ dIn[13] ^ dIn[16] ^ dIn[17] ^ dIn[18] ^ dIn[19] ^ dIn[20] ^ dIn[21];
1265 crc_r[8] = crc_in_s[0] ^ crc_in_s[3] ^ crc_in_s[4] ^ crc_in_s[5] ^ crc_in_s[6] ^ crc_in_s[7] ^ crc_in_s[8] ^ dIn[1] ^ dIn[2] ^ dIn[4] ^ dIn[5] ^ dIn[6] ^ dIn[7] ^ dIn[8] ^ dIn[9] ^ dIn[10] ^ dIn[14] ^ dIn[17] ^ dIn[18] ^ dIn[19] ^ dIn[20] ^ dIn[21] ^ dIn[22];
1269 for(
int i = 0;
i < 9;
i++) {
1270 crc_word = ( crc_word | (crc_r[8-
i] <<
i));
1274 for(
int i = 0;
i < 9;
i++) {
1275 crc_word = ( crc_word | (crc_r[
i] <<
i) );
1283 int din = (0x00000FFF & datumPtr );
1285 if( din > 0x0FDE ) din = 0x4EE;
1287 if( (din > 0) && ( din < 962 ) ) din = 962;
1289 if( din == 0) din = 0x4EE;
1293 int FPGA_CONVLIN_TH1 = 5;
1294 int FPGA_CONVLIN_TH2 = 749;
1295 int FPGA_CONVLIN_TH3 = 1773;
1296 int FPGA_CONVLIN_TH4 = 2541;
1297 int FPGA_CONVLIN_TH5 = 4029;
1299 int FPGA_CONVLIN_OF0 = -5072;
1300 int FPGA_CONVLIN_OF1 = -2012;
1301 int FPGA_CONVLIN_OF2 = -1262;
1302 int FPGA_CONVLIN_OF3 = -3036;
1303 int FPGA_CONVLIN_OF4 = -8120;
1304 int FPGA_CONVLIN_OF5 = -4118720;
1329 r1shv = ((din & 0x0000007F) << 9 ) & 0x0000FE00 ;
1330 r2shv = ((din & 0x00000FFF) << 1 ) & 0x00001FFE ;
1331 r3shv = (din & 0x00000FFF) ;
1332 r4shv = ((din & 0x00000FFF) << 1 ) & 0x00001FFE ;
1333 r5shv = ((din & 0x00000FFF) << 2 ) & 0x00003FFC ;
1334 r6shv = ((din & 0x00000FFF) << 10 ) & 0x003FFC00 ;
1336 r1conv = r1shv + FPGA_CONVLIN_OF0;
1337 r2conv = r2shv + FPGA_CONVLIN_OF1;
1338 r3conv = r3shv + FPGA_CONVLIN_OF2;
1339 r4conv = r4shv + FPGA_CONVLIN_OF3;
1340 r5conv = r5shv + FPGA_CONVLIN_OF4;
1341 r6conv = r6shv + FPGA_CONVLIN_OF5;
1349 if ( din > FPGA_CONVLIN_TH1 ){
1355 if ( din > FPGA_CONVLIN_TH2 ){
1360 if ( din > FPGA_CONVLIN_TH3 ){
1365 if ( din > FPGA_CONVLIN_TH4 ){
1370 if ( din > FPGA_CONVLIN_TH5 ){
1379 if( (! oth0) & (! oth1 ) & (! oth2 ) & (! oth3 ) & (! oth4 ) & (! oth5 ) ) {
1382 else if( ( oth0) & (! oth1 ) & (! oth2 ) & (! oth3 ) & (! oth4 ) & (! oth5 ) ) {
1385 else if( ( oth0) & ( oth1 ) & (! oth2 ) & (! oth3 ) & (! oth4 ) & (! oth5 ) ) {
1388 else if( ( oth0) & ( oth1 ) & ( oth2 ) & (! oth3 ) & (! oth4 ) & (! oth5 ) ) {
1391 else if( ( oth0) & ( oth1 ) & ( oth2 ) & ( oth3 ) & (! oth4 ) & (! oth5 ) ) {
1394 else if( ( oth0) & ( oth1 ) & ( oth2 ) & ( oth3 ) & ( oth4 ) & (! oth5 ) ) {
1397 else if( ( oth0) & ( oth1 ) & ( oth2 ) & ( oth3 ) & ( oth4 ) & ( oth5 ) ) {
1412 float s_centralPhiWidth = (2*
M_PI)/32;
1413 float s_forwardPhiWidth = (2*
M_PI)/16;
1415 const std::vector<float> s_EtaCenter = { -4.5, -3.8, -3.38, -3.18, -3.15, -3,
1416 -2.8, -2.6, -2.35, -2.1, -1.9, -1.7, -1.5, -1.3, -1.1, -0.9,
1417 -0.7, -0.5, -0.3, -0.1, 0.1, 0.3, 0.5, 0.7, 0.9, 1.1,
1418 1.3, 1.5, 1.7, 1.9, 2.1, 2.35, 2.6, 2.8, 3.0,
1419 3.15, 3.18, 3.38, 3.8, 4.5};
1427 int towerID_base = 20000;
1428 int iEtaOld=0, iPhiOld=0;
1431 if (
iPhi == ((gFEXtowerID - towerID_base)/24)*2){
1435 if (
iPhi == (((gFEXtowerID - towerID_base - 12)/24)*2) + 1){
1437 iPhiOld = (
iPhi-1)/2;
1441 else if (
iEta == 3){
1442 if (
iPhi == ((gFEXtowerID - towerID_base - 1)/24)*2){
1446 if (
iPhi == (((gFEXtowerID - towerID_base - 13)/24)*2) + 1){
1448 iPhiOld = (
iPhi-1)/2;
1452 else if (
iEta == 36){
1453 if (
iPhi == (((gFEXtowerID - towerID_base - 22)/24)*2) + 1){
1455 iPhiOld = (
iPhi-1)/2;
1457 if (
iPhi == ((gFEXtowerID - towerID_base - 10)/24)*2){
1463 else if (
iEta == 37){
1464 if (
iPhi == (((gFEXtowerID - towerID_base - 23)/24)*2) + 1){
1466 iPhiOld = (
iPhi-1)/2;
1468 if (
iPhi == ((gFEXtowerID - towerID_base - 11)/24)*2){
1479 Eta = s_EtaCenter[iEtaOld];
1481 float Phi_gFex = -99;
1483 if (( iEtaOld <= 3 ) || ( (iEtaOld >= 36) )){
1484 Phi_gFex = ( (iPhiOld * s_forwardPhiWidth) + s_forwardPhiWidth/2);
1487 Phi_gFex = ( (iPhiOld * s_centralPhiWidth) + s_centralPhiWidth/2);
1490 if (Phi_gFex <
M_PI) {
1506 if(
x & (0x00000001<<upto) ) {
1507 x = (
x | (0xFFFFFFFF<<(upto+1)) );
1510 x = (
x & 0x000FFFF);
1519 int ABCrows = gtf.size();
1520 int ABcolumns = gtf[0].size();
1523 if(fpga <0 || fpga >2 ) printf(
"*E: gtCalib FPGA number %d out of range\n",fpga);
1528 for(
int irow=0; irow<ABCrows; irow++){
1529 for(
int icolumn=0; icolumn<ABcolumns; icolumn++){
1532 if( towerLSB == 200 ) {
1533 if( gtf[irow][icolumn] > 1500 ){
1536 gtf[irow][icolumn] = gtf[irow][icolumn] +
offset;
1538 if( gtf[irow][icolumn] > 2047 ) {
1539 gtf[irow][icolumn] = 2047;
1540 }
else if( gtf[irow][icolumn] < 0 ){
1541 gtf[irow][icolumn] = 0;
1543 gtf[irow][icolumn] = gtf[irow][icolumn] -
offset;
1545 if( gtf[irow][icolumn] > 1500 ){
1556 gtf[irow][icolumn] = gtf[irow][icolumn] +
offset;
1558 if( gtf[irow][icolumn] > 1023 ){
1559 gtf[irow][icolumn] = 1023;
1560 }
else if ( gtf[irow][icolumn] < 0 ){
1561 gtf[irow][icolumn] = 0;
1563 gtf[irow][icolumn] = gtf[irow][icolumn] -
offset;
1575 return StatusCode::SUCCESS;
1582 Monitored::Scalar(
"gfexDecoderErrorLocation",location.empty() ? std::string(
"UNKNOWN") : location),