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( ( Xfiber[
i][
gPos::W280-1] & 0x000000FF ) == 0x000000BC ) {
468 fiberFields[
i][16] = 1;
471 fiberFields[
i][16] = 0;
475 fiberFields[
i][18] = ( Xfiber[
i][
gPos::W280-1] & 0x007F0000) >>16 ;
476 fiberFields[
i][19] = ( Xfiber[
i][
gPos::W280-1] & 0xFF800000) >>23 ;
478 if (XMPD_DTYP_ARR[ XMPD_NFI[
i] ][17] == 8) {
480 fiberFields[
i][17] = ( Xfiber[
i][
gPos::W280-1] & 0x0000FF00) >>8 ;
482 for(
unsigned int k=0;
k<8;
k++){
483 if( fiberFields[
i][17] & (1<<
k) ) {
484 fiberSaturation[
i][
k] = 1;
490 for(
unsigned int k=0;
k<16;
k++){
491 if( (XMPD_DTYP_ARR[ XMPD_NFI[
i] ][
k] != 4 ) && ( XMPD_GTRN_ARR[
i][
k] > -1 ) ) {
492 int krow = XMPD_GTRN_ARR[
i][
k]/12;
493 int kcolumn = XMPD_GTRN_ARR[
i][
k]%12;
495 if( fiberSaturation[
i][kFilled] == 1 ) {
496 Xsaturation[ krow][kcolumn] = 1;
499 kFilled = kFilled + 1;
505 for(
int iFiber = 0; iFiber < Xin; iFiber++) {
507 std::array<uint32_t, 6>
tmp;
508 for(
int i = 0;
i < 6;
i++){
tmp[
i] = Xfiber[iFiber][
i]; };
511 int withoutComma = Xfiber[iFiber][6] & 0xFFFFFF00 ;
512 CRC =
crc9d23(withoutComma, CRC, 1 );
513 uint32_t StoredCRC = ( (Xfiber[iFiber][6]>>23) & 0x000001FF);
514 if( (CRC != StoredCRC) && (StoredCRC != 0 ) ) {
516 std::stringstream sdetail;
517 sdetail <<
"[gFexInputByteStreamTool::gtReconstructABC]: Fiber " << iFiber <<
"of Xin " << Xin <<
": BAD New CRC: " << CRC <<
"Stored CRC "<< StoredCRC ;
518 std::stringstream slocation;
519 slocation <<
"Fiber " << iFiber <<
"of Xin " << Xin;
520 std::stringstream stitle;
521 stitle <<
"Bad CRC" ;
527 int fiber_type = XMPD_NFI[iFiber];
529 for(
int iDatum = 0; iDatum < 16; iDatum++) {
531 int dataType = XMPD_DTYP_ARR[fiber_type][iDatum];
533 int ntower = XMPD_GTRN_ARR[iFiber][iDatum];
535 ATH_MSG_DEBUG(
"[gFexInputByteStreamTool::gtReconstructABC: unused location iFiber "<< iFiber <<
", calo type "<< XCALO_TYPE[iFiber]<<
", data type "<<
dataType <<
", iDatum " << iDatum <<
"tower " << ntower);
537 else if( (ntower < 0) || (ntower >383) ){
539 std::stringstream sdetail;
540 sdetail <<
"[gFexInputByteStreamTool::gtReconstructABC: bad value of ntower: iFiber "<< iFiber<<
", calo type"<< XCALO_TYPE[iFiber]<<
", data type "<<
dataType<<
", iDatum "<< iDatum<<
"tower "<< ntower ;
541 std::stringstream slocation;
542 slocation <<
"iFiber "<< iFiber<<
", calo type"<< XCALO_TYPE[iFiber];
543 std::stringstream stitle;
544 stitle <<
"Bad value of ntower" ;
551 int ihigh = XMPD_DSTRT_ARR[fiber_type][iDatum];
552 int ihword = ihigh/32;
553 int ihbit = ihigh%32;
569 if( XMSK[iFiber] != 1 ) {
574 if( (XCALO_TYPE[iFiber] < 3) && (ntower>-1) && (ntower<384) ) {
580 if(ilword == ihword){
583 etowerData[ntower] = etowerData[ntower] | ( (Xfiber[iFiber][ihword] &
mask) >> ilbit );
586 fiberFieldsUndecoded[iFiber][iDatum] = etowerData[ntower];
588 etowerDataF[ntower] = etowerData[ntower];
589 fiberFields[iFiber][iDatum] = etowerData[ntower];
594 if( etowerData[ntower] & 0x00000800 ){ etowerData[ntower] = (etowerData[ntower] | 0xFFFFF000) ;}
595 etowerData[ntower] = etowerData[ntower]*4;
596 etowerDataF[ntower] = etowerData[ntower];
601 std::stringstream sdetail;
602 sdetail <<
"[gFexInputByteStreamTool::gtReconstructABC]: wrongly packed data "<< fiber_type<<
", "<<
dataType<<
", "<<ilword<<
", " <<ihword ;
603 std::stringstream slocation;
604 slocation <<
"Fiber type "<< fiber_type<<
" and data type"<<
dataType;
605 std::stringstream stitle;
606 stitle <<
"Wrongly packed data" ;
617 hTREXval = Xfiber[iFiber][ihword];
618 lTREXval = Xfiber[iFiber][ilword];
623 if(ilword == ihword){
626 htowerData[ntower] = htowerData[ntower] | ( (hTREXval &
mask) >> (ilbit) );
628 else if ( ihbit == 7 ) {
631 htowerData[ntower] = htowerData[ntower] | ( (hTREXval & hmask) << 4);
633 htowerData[ntower] = htowerData[ntower] | ( ( (lTREXval & lmask) >> 28)&
mask) ;
635 else if ( ihbit == 3) {
638 htowerData[ntower] = htowerData[ntower] | ( ( hTREXval & hmask) << 8);
640 htowerData[ntower] = htowerData[ntower] | ( ( (lTREXval & lmask) >> 24) &
mask) ;
644 std::stringstream sdetail;
645 sdetail <<
"[gFexInputByteStreamTool::gtReconstructABC]: wrongly packed data "<< fiber_type<<
", "<<
dataType<<
", "<<ilword<<
", " <<ihword ;
646 std::stringstream slocation;
647 slocation <<
"Fiber type "<< fiber_type<<
" and data type"<<
dataType;
648 std::stringstream stitle;
649 stitle <<
"Wrongly packed data" ;
657 fiberFieldsUndecoded[iFiber][iDatum] = htowerData[ntower];
658 htowerData[ntower] = 20*htowerData[ntower];
659 htowerDataF[ntower] = htowerData[ntower];
660 fiberFields[iFiber][iDatum] = htowerData[ntower];
664 fiberFieldsUndecoded[iFiber][1] = htowerData[ntower];
666 htowerDataF[ntower] = htowerData[ntower];
667 fiberFields[iFiber][1] = htowerData[ntower];
671 if( htowerData[ntower] & 0x00000800 ){ htowerData[ntower] = (htowerData[ntower] | 0xFFFFF000) ;}
672 htowerData[ntower] = htowerData[ntower]*4;
673 htowerDataF[ntower] = htowerData[ntower];
682 if( (ntower > 32) || (ntower < 0) ){
684 std::stringstream sdetail;
685 sdetail <<
"[gFexInputByteStreamTool::gtReconstructABC]: bad value of nTower for extended region 2.4 - 2.5 in eta" ;
686 std::stringstream slocation;
687 slocation <<
"Fiber type "<< fiber_type<<
" and data type"<<
dataType;
688 std::stringstream stitle;
689 stitle <<
"Bad value of nTower in extended eta" ;
693 if(ilword == ihword){
694 int mask = 0x00000FFF;
696 xetowerData[ntower] = xetowerData[ntower] | ( (Xfiber[iFiber][ihword]&
mask) >> (ilbit) );
698 else if ( ihbit == 7 ) {
701 xetowerData[ntower] = xetowerData[ntower] | ( (Xfiber[iFiber][ihword]&hmask) << 4);
703 xetowerData[ntower] = xetowerData[ntower] | ( ( (Xfiber[iFiber][ilword]&lmask) >> 28)&
mask) ;
705 else if ( ihbit == 3) {
708 xetowerData[ntower] = xetowerData[ntower] | ( (Xfiber[iFiber][ihword]&hmask) << 8);
710 xetowerData[ntower] = xetowerData[ntower] | ( ( (Xfiber[iFiber][ilword]&lmask) >> 24)&
mask) ;
714 std::stringstream sdetail;
715 sdetail <<
"[gFexInputByteStreamTool::gtReconstructABC]: wrongly packed data "<< fiber_type<<
", "<<
dataType<<
", "<<ilword<<
", " <<ihword ;
716 std::stringstream slocation;
717 slocation <<
"Fiber type "<< fiber_type<<
" and data type"<<
dataType;
718 std::stringstream stitle;
719 stitle <<
"Wrongly packed data" ;
725 fiberFieldsUndecoded[iFiber][iDatum] = xetowerData[ntower];
726 undoMLE( xetowerData[ntower] );
727 xetowerDataF[ntower] = xetowerData[ntower];
728 fiberFields[iFiber][iDatum] = xetowerData[ntower];
733 if( xetowerData[ntower] & 0x00000800 ){ xetowerData[ntower] = (xetowerData[ntower] | 0xFFFFF000) ;}
734 xetowerData[ntower] = xetowerData[ntower]*4;
735 xetowerDataF[ntower] = xetowerData[ntower];
743 if(ilword == ihword){
746 xhtowerData[ntower] = xhtowerData[ntower] | ( (Xfiber[iFiber][ihword]&
mask) >> (ilbit) );
748 else if ( ihbit == 7 ) {
751 xhtowerData[ntower] = xhtowerData[ntower] | ( (Xfiber[iFiber][ihword]&hmask) << 4);
753 xhtowerData[ntower] = xhtowerData[ntower] | ( ( (Xfiber[iFiber][ilword]&lmask) >> 28)&
mask) ;
755 else if ( ihbit == 3) {
758 xhtowerData[ntower] = xhtowerData[ntower] | ( (Xfiber[iFiber][ihword]&hmask) << 8);
760 xhtowerData[ntower] = xhtowerData[ntower] | ( ( (Xfiber[iFiber][ilword]&lmask) >> 24)&
mask) ;
764 std::stringstream sdetail;
765 sdetail <<
"[gFexInputByteStreamTool::gtReconstructABC]: wrongly packed data "<< fiber_type<<
", "<<
dataType<<
", "<<ilword<<
", " <<ihword ;
766 std::stringstream slocation;
767 slocation <<
"Fiber type "<< fiber_type<<
" and data type"<<
dataType;
768 std::stringstream stitle;
769 stitle <<
"Wrongly packed data" ;
775 std::stringstream sdetail;
776 sdetail <<
"[gFexInputByteStreamTool::gtReconstructABC]: bad value of nTower for extended region 2.4 - 2.5 in eta" ;
777 std::stringstream slocation;
778 slocation <<
"Fiber type "<< fiber_type<<
" and data type"<<
dataType;
779 std::stringstream stitle;
780 stitle <<
"Bad value of nTower in extended eta" ;
786 fiberFieldsUndecoded[iFiber][iDatum] = xhtowerData[ntower];
787 undoMLE( xhtowerData[ntower] );
788 xhtowerDataF[ntower] = xhtowerData[ntower];
789 fiberFields[iFiber][iDatum] = xhtowerData[ntower];
793 if( xhtowerData[ntower] & 0x00000800 ){ xhtowerData[ntower] = (xhtowerData[ntower] | 0xFFFFF000) ;}
794 xhtowerData[ntower] = xhtowerData[ntower]*4;
795 xhtowerDataF[ntower] = xhtowerData[ntower];
803 if(ilword == ihword){
806 ohtowerData[ntower] = ohtowerData[ntower] | ( (Xfiber[iFiber][ihword]&
mask) >> (ilbit) );
808 else if ( ihbit == 7 ) {
811 ohtowerData[ntower] = ohtowerData[ntower] | ( (Xfiber[iFiber][ihword]&hmask) << 4);
813 ohtowerData[ntower] = ohtowerData[ntower] | ( ( (Xfiber[iFiber][ilword]&lmask) >> 28)&
mask) ;
815 else if ( ihbit == 3) {
818 ohtowerData[ntower] = ohtowerData[ntower] | ( (Xfiber[iFiber][ihword]&hmask) << 8);
820 ohtowerData[ntower] = ohtowerData[ntower] | ( ( (Xfiber[iFiber][ilword]&lmask) >> 24)&
mask) ;
824 std::stringstream sdetail;
825 sdetail <<
"[gFexInputByteStreamTool::gtReconstructABC]: wrongly packed data "<< fiber_type<<
", "<<
dataType<<
", "<<ilword<<
", " <<ihword ;
826 std::stringstream slocation;
827 slocation <<
"Fiber type "<< fiber_type<<
" and data type"<<
dataType;
828 std::stringstream stitle;
829 stitle <<
"Wrongly packed data" ;
835 std::stringstream sdetail;
836 sdetail <<
"[gFexInputByteStreamTool::gtReconstructABC]: bad value of nTower for extended region 2.4 - 2.5 in eta" ;
837 std::stringstream slocation;
838 slocation <<
"Fiber type "<< fiber_type<<
" and data type"<<
dataType;
839 std::stringstream stitle;
840 stitle <<
"Bad value of nTower in extended eta" ;
845 fiberFieldsUndecoded[iFiber][iDatum] = ohtowerData[ntower];
846 undoMLE( ohtowerData[ntower] );
847 ohtowerDataF[ntower] = ohtowerData[ntower];
848 fiberFields[iFiber][iDatum] = ohtowerData[ntower];
852 if( ohtowerData[ntower] & 0x00000800 ){ ohtowerData[ntower] = (ohtowerData[ntower] | 0xFFFFF000) ;}
853 ohtowerData[ntower] = ohtowerData[ntower]*4;
854 ohtowerDataF[ntower] = ohtowerData[ntower];
863 hHECval = Xfiber[iFiber][ihword];
864 lHECval = Xfiber[iFiber][ilword];
865 if(ilword == ihword){
868 htowerData[ntower] = htowerData[ntower] | ( (hHECval &
mask) >> (ilbit) );
870 else if ( ihbit == 7 ) {
873 htowerData[ntower] = htowerData[ntower] | ( (hHECval & hmask) << 4);
875 htowerData[ntower] = htowerData[ntower] | ( ( (lHECval & lmask) >> 28)&
mask) ;
877 else if ( ihbit == 3) {
880 htowerData[ntower] = htowerData[ntower] | ( ( hHECval & hmask) << 8);
882 htowerData[ntower] = htowerData[ntower] | ( ( (lHECval & lmask) >> 24) &
mask) ;
886 std::stringstream sdetail;
887 sdetail <<
"[gFexInputByteStreamTool::gtReconstructABC]: wrongly packed data "<< fiber_type<<
", "<<
dataType<<
", "<<ilword<<
", " <<ihword ;
888 std::stringstream slocation;
889 slocation <<
"Fiber type "<< fiber_type<<
" and data type"<<
dataType;
890 std::stringstream stitle;
891 stitle <<
"Wrongly packed data" ;
896 fiberFieldsUndecoded[iFiber][iDatum] = htowerData[ntower];
898 htowerDataF[ntower] = htowerData[ntower];
899 fiberFields[iFiber][iDatum] = htowerData[ntower];
903 if( htowerData[ntower] & 0x00000800 ){ htowerData[ntower] = (htowerData[ntower] | 0xFFFFF000) ;}
904 htowerData[ntower] = htowerData[ntower]*4;
905 htowerDataF[ntower] = htowerData[ntower];
912 else if ( (ntower>-1) && (ntower<384) ){
922 if( etowerData[ntower] != 0 ) {
924 std::stringstream sdetail;
925 sdetail <<
"[gFexInputByteStreamTool::gtReconstructABC]: etowerData[nTower] is not zero, inconsistent constants! "<< etowerData[ntower] ;
926 std::stringstream slocation;
927 slocation <<
"Fiber type "<< fiber_type<<
" and data type"<<
dataType;
928 std::stringstream stitle;
929 stitle <<
"etowerData not zero" ;
934 if(ilword == ihword){
935 int mask = 0x00000FFF;
937 etowerData[ntower] = etowerData[ntower] | ( (Xfiber[iFiber][ihword]&
mask) >> (ilbit) );
939 else if ( ihbit == 7 ) {
942 etowerData[ntower] = etowerData[ntower] | ( (Xfiber[iFiber][ihword]&hmask) << 4);
944 etowerData[ntower] = etowerData[ntower] | ( ( (Xfiber[iFiber][ilword]&lmask) >> 28)&
mask) ;
946 else if ( ihbit == 3) {
949 etowerData[ntower] = etowerData[ntower] | ( (Xfiber[iFiber][ihword]&hmask) << 8);
951 etowerData[ntower] = etowerData[ntower] | ( ( (Xfiber[iFiber][ilword]&lmask) >> 24)&
mask) ;
955 std::stringstream sdetail;
956 sdetail <<
"[gFexInputByteStreamTool::gtReconstructABC]: wrongly packed data "<< fiber_type<<
", "<<
dataType<<
", "<<ilword<<
", " <<ihword ;
957 std::stringstream slocation;
958 slocation <<
"Fiber type "<< fiber_type<<
" and data type"<<
dataType;
959 std::stringstream stitle;
960 stitle <<
"Wrongly packed data" ;
966 fiberFieldsUndecoded[iFiber][iDatum] = etowerData[ntower];
968 etowerDataF[ntower] = etowerData[ntower];
969 fiberFields[iFiber][iDatum] = etowerData[ntower];
973 if( etowerData[ntower] & 0x00000800 ){ etowerData[ntower] = (etowerData[ntower] | 0xFFFFF000) ;}
974 etowerData[ntower] = etowerData[ntower]*4;
975 etowerDataF[ntower] = etowerData[ntower];
985 if( htowerData[ntower] != 0 ) {
986 std::stringstream sdetail;
987 sdetail <<
"[gFexInputByteStreamTool::gtReconstructABC]: etowerData[nTower] is not zero, inconsistent constants! "<< etowerData[ntower] ;
988 std::stringstream slocation;
989 slocation <<
"Fiber type "<< fiber_type<<
" and data type"<<
dataType;
990 std::stringstream stitle;
991 stitle <<
"etowerData not zero" ;
996 if(ilword == ihword){
999 htowerData[ntower] = htowerData[ntower] | ( (Xfiber[iFiber][ihword]&
mask) >> (ilbit) );
1001 else if ( ihbit == 7 ) {
1004 htowerData[ntower] = htowerData[ntower] | ( (Xfiber[iFiber][ihword]&hmask) << 4);
1006 htowerData[ntower] = htowerData[ntower] | ( ( (Xfiber[iFiber][ilword]&lmask) >> 28)&
mask) ;
1008 else if ( ihbit == 3) {
1011 htowerData[ntower] = htowerData[ntower] | ( (Xfiber[iFiber][ihword]&hmask) << 8);
1013 htowerData[ntower] = htowerData[ntower] | ( ( (Xfiber[iFiber][ilword]&lmask) >> 24)&
mask) ;
1017 std::stringstream sdetail;
1018 sdetail <<
"[gFexInputByteStreamTool::gtReconstructABC]: wrongly packed data "<< fiber_type<<
", "<<
dataType<<
", "<<ilword<<
", " <<ihword ;
1019 std::stringstream slocation;
1020 slocation <<
"Fiber type "<< fiber_type<<
" and data type"<<
dataType;
1021 std::stringstream stitle;
1022 stitle <<
"Wrongly packed data" ;
1028 fiberFieldsUndecoded[iFiber][iDatum] = htowerData[ntower];
1029 undoMLE( htowerData[ntower] );
1030 htowerDataF[ntower] = htowerData[ntower];
1031 fiberFields[iFiber][iDatum] = htowerData[ntower];
1035 if( htowerData[ntower] & 0x00000800 ){ htowerData[ntower] = (htowerData[ntower] | 0xFFFFF000) ;}
1036 htowerData[ntower] = htowerData[ntower]*4;
1037 htowerDataF[ntower] = htowerData[ntower];
1050 std::stringstream sdetail;
1051 sdetail <<
"[gFexInputByteStreamTool::gtReconstructABC]: wrong detector type "<<
dataType ;
1052 std::stringstream slocation;
1053 slocation <<
"Fiber type "<< fiber_type<<
" and data type"<<
dataType;
1054 std::stringstream stitle;
1055 stitle <<
"Wrong detector type" ;
1066 for(
int itower=0;itower<384;itower++){
1067 int icolumn = itower%12;
1068 int irow = itower/12;
1071 int xF = etowerDataF[itower] + htowerDataF[itower];
1073 int x = ( (etowerData[itower]>>2) + (htowerData[itower]>>2) );
1078 Xgt[irow][icolumn] =
x;
1079 XgtF[irow][icolumn] = xF;
1082 if ( icolumn == 0) {
1083 int xx = ( (xetowerData[irow]>>2) + (xhtowerData[irow]>>2) );
1085 Xgt[irow][icolumn] = Xgt[irow][icolumn] + xx;
1087 if ( icolumn == 4) {
1089 int ox = (ohtowerData[irow] >> 2 ) ;
1091 Xgt[irow][icolumn] = Xgt[irow][icolumn] + ox ;
1095 else if ( XFPGA == 1 ) {
1096 for(
int itower=0;itower<384;itower++){
1097 int icolumn = itower%12;
1098 int irow = itower/12;
1101 int xF = etowerDataF[itower] + htowerDataF[itower] ;
1103 int x = ( (etowerData[itower]>>2) + (htowerData[itower] >> 2) );
1108 Xgt[irow][icolumn] =
x;
1109 XgtF[irow][icolumn] = xF;
1112 if ( icolumn == 11) {
1116 int xx = ( (xetowerData[irow]>>2) + (xhtowerData[irow]>>2) );
1119 Xgt[irow][icolumn] = Xgt[irow][icolumn] + xx;
1121 if ( icolumn == 7 ) {
1124 int xo = ohtowerData[irow]>>2;
1127 Xgt[irow][icolumn] = Xgt[irow][icolumn] + xo;
1131 else if ( XFPGA == 2 ) {
1132 for(
int itower=0;itower<384;itower++){
1133 int icolumn = itower%12;
1134 int irow = itower/12;
1137 int xF = etowerDataF[itower] + htowerDataF[itower] ;
1139 int x = ( (etowerData[itower]>>2 ) + (htowerData[itower]>>2));
1143 Xgt[irow][icolumn] =
x;
1144 XgtF[irow][icolumn] = xF;
1148 ATH_MSG_DEBUG(
"[gFexInputByteStreamTool::gtReconstructABC]: Bad FPGA # "<< XFPGA);
1157 std::array<uint32_t, 32> dIn;
1158 std::array<uint32_t, 9> crc_s;
1159 std::array<uint32_t, 9> crc_r;
1164 int crc_word = 0x000;
1165 unsigned int mask = 0x00000001;
1167 for(
int k =0;
k < numWords;
k++) {
1169 for (
int i =0 ;
i < 32;
i++ ) {
1170 dIn[31-
i] = (inWords[
k] & (
mask <<
i));
1171 dIn[31-
i] = ((dIn[31-
i] >>
i) & 0x00000001);
1175 for (
int i =0 ;
i<32;
i++ ) {
1176 dIn[
i] = inWords[
k] & (
mask <<
i);
1177 dIn[
i] = ((dIn[
i] >>
i) & 0x0000001);
1180 for(
int j=0; j<9; j++){
1181 crc_s[j] = crc_r[j];
1184 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];
1186 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];
1188 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];
1190 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];
1192 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];
1194 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];
1196 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];
1198 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];
1200 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];
1205 for (
int i = 0;
i < 9;
i++) {
1206 crc_word = crc_word | (crc_r[8-
i] <<
i) ;
1210 for(
int i = 0;
i < 9;
i++ ){
1211 crc_word = crc_word | (crc_r[
i] <<
i);
1220 int mask = 0x00000001;
1222 std::array<uint32_t, 23> dIn;
1224 std::array<uint32_t, 9> crc_r;
1225 std::array<uint32_t, 9> crc_in_s;
1230 int crc_word = 0x000;
1235 for(
int i = 0;
i < 23;
i++){
1236 dIn[22-
i] = ( inword & (
mask <<
i));
1237 dIn[22-
i] = ( dIn[22-
i] >>
i);
1239 for(
int i = 0;
i < 9;
i++){
1240 crc_in_s[8-
i] = ( in_crc & (
mask <<
i) );
1241 crc_in_s[8-
i] = ( crc_in_s[8-
i] >>
i );
1245 for(
int i = 0;
i < 23;
i++) {
1246 dIn[
i] = ( inword & (
mask <<
i) );
1247 dIn[
i] = (dIn[
i] >>
i);
1249 for(
int i=0;
i<9;
i++){
1250 crc_in_s[
i] = ( in_crc & (
mask <<
i));
1251 crc_in_s[
i] = (crc_in_s[
i] >>
i);
1255 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];
1256 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];
1257 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];
1258 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];
1259 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];
1260 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];
1261 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];
1262 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];
1263 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];
1267 for(
int i = 0;
i < 9;
i++) {
1268 crc_word = ( crc_word | (crc_r[8-
i] <<
i));
1272 for(
int i = 0;
i < 9;
i++) {
1273 crc_word = ( crc_word | (crc_r[
i] <<
i) );
1281 int din = (0x00000FFF & datumPtr );
1283 if( din > 0x0FDE ) din = 0x4EE;
1285 if( (din > 0) && ( din < 962 ) ) din = 962;
1287 if( din == 0) din = 0x4EE;
1291 int FPGA_CONVLIN_TH1 = 5;
1292 int FPGA_CONVLIN_TH2 = 749;
1293 int FPGA_CONVLIN_TH3 = 1773;
1294 int FPGA_CONVLIN_TH4 = 2541;
1295 int FPGA_CONVLIN_TH5 = 4029;
1297 int FPGA_CONVLIN_OF0 = -5072;
1298 int FPGA_CONVLIN_OF1 = -2012;
1299 int FPGA_CONVLIN_OF2 = -1262;
1300 int FPGA_CONVLIN_OF3 = -3036;
1301 int FPGA_CONVLIN_OF4 = -8120;
1302 int FPGA_CONVLIN_OF5 = -4118720;
1327 r1shv = ((din & 0x0000007F) << 9 ) & 0x0000FE00 ;
1328 r2shv = ((din & 0x00000FFF) << 1 ) & 0x00001FFE ;
1329 r3shv = (din & 0x00000FFF) ;
1330 r4shv = ((din & 0x00000FFF) << 1 ) & 0x00001FFE ;
1331 r5shv = ((din & 0x00000FFF) << 2 ) & 0x00003FFC ;
1332 r6shv = ((din & 0x00000FFF) << 10 ) & 0x003FFC00 ;
1334 r1conv = r1shv + FPGA_CONVLIN_OF0;
1335 r2conv = r2shv + FPGA_CONVLIN_OF1;
1336 r3conv = r3shv + FPGA_CONVLIN_OF2;
1337 r4conv = r4shv + FPGA_CONVLIN_OF3;
1338 r5conv = r5shv + FPGA_CONVLIN_OF4;
1339 r6conv = r6shv + FPGA_CONVLIN_OF5;
1347 if ( din > FPGA_CONVLIN_TH1 ){
1353 if ( din > FPGA_CONVLIN_TH2 ){
1358 if ( din > FPGA_CONVLIN_TH3 ){
1363 if ( din > FPGA_CONVLIN_TH4 ){
1368 if ( din > FPGA_CONVLIN_TH5 ){
1377 if( (! oth0) & (! oth1 ) & (! oth2 ) & (! oth3 ) & (! oth4 ) & (! oth5 ) ) {
1380 else if( ( oth0) & (! oth1 ) & (! oth2 ) & (! oth3 ) & (! oth4 ) & (! oth5 ) ) {
1383 else if( ( oth0) & ( oth1 ) & (! oth2 ) & (! oth3 ) & (! oth4 ) & (! oth5 ) ) {
1386 else if( ( oth0) & ( oth1 ) & ( oth2 ) & (! oth3 ) & (! oth4 ) & (! oth5 ) ) {
1389 else if( ( oth0) & ( oth1 ) & ( oth2 ) & ( oth3 ) & (! oth4 ) & (! oth5 ) ) {
1392 else if( ( oth0) & ( oth1 ) & ( oth2 ) & ( oth3 ) & ( oth4 ) & (! oth5 ) ) {
1395 else if( ( oth0) & ( oth1 ) & ( oth2 ) & ( oth3 ) & ( oth4 ) & ( oth5 ) ) {
1410 float s_centralPhiWidth = (2*
M_PI)/32;
1411 float s_forwardPhiWidth = (2*
M_PI)/16;
1413 const std::vector<float> s_EtaCenter = { -4.7, -4.2, -3.7, -3.4, -3.2, -3,
1414 -2.8, -2.6, -2.35, -2.1, -1.9, -1.7, -1.5, -1.3, -1.1, -0.9,
1415 -0.7, -0.5, -0.3, -0.1, 0.1, 0.3, 0.5, 0.7, 0.9, 1.1,
1416 1.3, 1.5, 1.7, 1.9, 2.1, 2.35, 2.6, 2.8, 3.0,
1417 3.2, 3.4, 3.7, 4.2, 4.7};
1425 int towerID_base = 20000;
1426 int iEtaOld=0, iPhiOld=0;
1429 if (
iPhi == ((gFEXtowerID - towerID_base)/24)*2){
1433 if (
iPhi == (((gFEXtowerID - towerID_base - 12)/24)*2) + 1){
1435 iPhiOld = (
iPhi-1)/2;
1439 else if (
iEta == 3){
1440 if (
iPhi == ((gFEXtowerID - towerID_base - 1)/24)*2){
1444 if (
iPhi == (((gFEXtowerID - towerID_base - 13)/24)*2) + 1){
1446 iPhiOld = (
iPhi-1)/2;
1450 else if (
iEta == 36){
1451 if (
iPhi == (((gFEXtowerID - towerID_base - 22)/24)*2) + 1){
1453 iPhiOld = (
iPhi-1)/2;
1455 if (
iPhi == ((gFEXtowerID - towerID_base - 10)/24)*2){
1461 else if (
iEta == 37){
1462 if (
iPhi == (((gFEXtowerID - towerID_base - 23)/24)*2) + 1){
1464 iPhiOld = (
iPhi-1)/2;
1466 if (
iPhi == ((gFEXtowerID - towerID_base - 11)/24)*2){
1477 Eta = s_EtaCenter[iEtaOld];
1479 float Phi_gFex = -99;
1481 if (( iEtaOld <= 3 ) || ( (iEtaOld >= 36) )){
1482 Phi_gFex = ( (iPhiOld * s_forwardPhiWidth) + s_forwardPhiWidth/2);
1485 Phi_gFex = ( (iPhiOld * s_centralPhiWidth) + s_centralPhiWidth/2);
1488 if (Phi_gFex <
M_PI) {
1504 if(
x & (0x00000001<<upto) ) {
1505 x = (
x | (0xFFFFFFFF<<(upto+1)) );
1508 x = (
x & 0x000FFFF);
1517 int ABCrows = gtf.size();
1518 int ABcolumns = gtf[0].size();
1521 if(fpga <0 || fpga >2 ) printf(
"*E: gtCalib FPGA number %d out of range\n",fpga);
1526 for(
int irow=0; irow<ABCrows; irow++){
1527 for(
int icolumn=0; icolumn<ABcolumns; icolumn++){
1530 if( towerLSB == 200 ) {
1531 if( gtf[irow][icolumn] > 1500 ){
1534 gtf[irow][icolumn] = gtf[irow][icolumn] +
offset;
1536 if( gtf[irow][icolumn] > 2047 ) {
1537 gtf[irow][icolumn] = 2047;
1538 }
else if( gtf[irow][icolumn] < 0 ){
1539 gtf[irow][icolumn] = 0;
1541 gtf[irow][icolumn] = gtf[irow][icolumn] -
offset;
1543 if( gtf[irow][icolumn] > 1500 ){
1554 gtf[irow][icolumn] = gtf[irow][icolumn] +
offset;
1556 if( gtf[irow][icolumn] > 1023 ){
1557 gtf[irow][icolumn] = 1023;
1558 }
else if ( gtf[irow][icolumn] < 0 ){
1559 gtf[irow][icolumn] = 0;
1561 gtf[irow][icolumn] = gtf[irow][icolumn] -
offset;
1573 return StatusCode::SUCCESS;