File indexing completed on 2025-08-03 08:20:52
0001 #include "packet_idll1v2.h"
0002
0003 #include <string.h>
0004
0005 using namespace std;
0006
0007 Packet_idll1v2::Packet_idll1v2(PACKET_ptr data)
0008 :Packet_w4 (data)
0009 {
0010
0011 _slot_nr = 0;
0012 _card_nr = 0;
0013 _nsamples = 0;
0014 _evt_nr = 0;
0015 _clock = 0;
0016 _nfibers = 24;
0017 _nsums = 16;
0018 _nchannels = 256;
0019 _ntrigger_words = 0;
0020 _is_decoded = 0;
0021
0022 }
0023
0024 Packet_idll1v2::~Packet_idll1v2()
0025 {
0026
0027 }
0028
0029
0030
0031 const int offset=0;
0032
0033
0034
0035
0036 int Packet_idll1v2::decode ()
0037 {
0038
0039
0040 if (_is_decoded ) return 0;
0041 _is_decoded = 1;
0042
0043
0044 int *k;
0045
0046
0047 int *SubeventData = (int *) findPacketDataStart(packet);
0048
0049 switch ( getHitFormat() )
0050 {
0051 case IDLL1_MBD:
0052 _trigger_type = TRIGGERTYPE::MBD;
0053 _nfibers = 4;
0054 _nsums = 13;
0055 _ntrigger_words = 8;
0056 _monitor = 0;
0057 break;
0058
0059
0060
0061
0062
0063
0064
0065 case IDLL1_EMCAL_MON0:
0066 _trigger_type = TRIGGERTYPE::EMCAL;
0067 _detector_type = DETECTORTYPE::dEMCAL;
0068 _monitor = 0;
0069 _ntrigger_words = 32;
0070 break;
0071
0072 case IDLL1_EMCAL_MON1:
0073 _trigger_type = TRIGGERTYPE::EMCAL;
0074 _detector_type = DETECTORTYPE::dEMCAL;
0075 _monitor = 1;
0076 _ntrigger_words = 32;
0077 break;
0078
0079 case IDLL1_EMCAL_MON2:
0080 _trigger_type = TRIGGERTYPE::EMCAL;
0081 _detector_type = DETECTORTYPE::dEMCAL;
0082 _monitor = 2;
0083 _ntrigger_words = 24;
0084 break;
0085
0086 case IDLL1_EMCAL_MON3:
0087 _trigger_type = TRIGGERTYPE::EMCAL;
0088 _detector_type = DETECTORTYPE::dEMCAL;
0089 _monitor = 3;
0090 _ntrigger_words = 32;
0091 break;
0092
0093
0094
0095
0096
0097
0098 case IDLL1_JET_EMCAL_MON0:
0099 _nfibers = 16;
0100 _nsums = 24;
0101 _trigger_type = TRIGGERTYPE::JET;
0102 _detector_type = DETECTORTYPE::dEMCAL;
0103 _ntrigger_words = 32*9;
0104 _monitor = 0;
0105 break;
0106
0107 case IDLL1_JET_EMCAL_MON1:
0108 _nfibers = 16;
0109 _nsums = 24;
0110 _trigger_type = TRIGGERTYPE::JET;
0111 _detector_type = DETECTORTYPE::dEMCAL;
0112 _ntrigger_words = 32*9;
0113 _monitor = 1;
0114 break;
0115
0116 case IDLL1_JET_EMCAL_MON2:
0117 _nfibers = 16;
0118 _nsums = 24;
0119 _trigger_type = TRIGGERTYPE::JET;
0120 _detector_type = DETECTORTYPE::dEMCAL;
0121 _ntrigger_words = 32*9;
0122 _monitor = 2;
0123 break;
0124
0125 case IDLL1_JET_EMCAL_MON3:
0126 _nfibers = 16;
0127 _nsums = 24;
0128 _trigger_type = TRIGGERTYPE::JET;
0129 _detector_type = DETECTORTYPE::dEMCAL;
0130 _ntrigger_words = 32*9;
0131 _monitor = 3;
0132 break;
0133
0134 case IDLL1_JET_EMCAL_MON4:
0135 _nfibers = 16;
0136 _nsums = 24;
0137 _trigger_type = TRIGGERTYPE::JET;
0138 _detector_type = DETECTORTYPE::dEMCAL;
0139 _ntrigger_words = 32*9;
0140 _monitor = 4;
0141 break;
0142 case IDLL1_JET_HCAL_MON0:
0143 _nfibers = 16;
0144 _nsums = 24;
0145 _trigger_type = TRIGGERTYPE::JET;
0146 _detector_type = DETECTORTYPE::dHCAL;
0147 _ntrigger_words = 32*9;
0148 _monitor = 0;
0149 break;
0150
0151 case IDLL1_JET_HCAL_MON1:
0152 _nfibers = 16;
0153 _nsums = 24;
0154 _trigger_type = TRIGGERTYPE::JET;
0155 _detector_type = DETECTORTYPE::dHCAL;
0156 _ntrigger_words = 32*9;
0157 _monitor = 1;
0158 break;
0159
0160 case IDLL1_JET_HCAL_MON2:
0161 _nfibers = 16;
0162 _nsums = 24;
0163 _trigger_type = TRIGGERTYPE::JET;
0164 _detector_type = DETECTORTYPE::dHCAL;
0165 _ntrigger_words = 32*9;
0166 _monitor = 2;
0167 break;
0168
0169 case IDLL1_JET_HCAL_MON3:
0170 _nfibers = 16;
0171 _nsums = 24;
0172 _trigger_type = TRIGGERTYPE::JET;
0173 _detector_type = DETECTORTYPE::dHCAL;
0174 _ntrigger_words = 32*9;
0175 _monitor = 3;
0176 break;
0177
0178 case IDLL1_JET_HCAL_MON4:
0179 _nfibers = 16;
0180 _nsums = 24;
0181 _trigger_type = TRIGGERTYPE::JET;
0182 _detector_type = DETECTORTYPE::dHCAL;
0183 _ntrigger_words = 32*9;
0184 _monitor = 4;
0185 break;
0186
0187 default:
0188 _trigger_type = TRIGGERTYPE::NONE;
0189 break;
0190 }
0191
0192
0193 k = &SubeventData[offset];
0194
0195 _slot_nr = (k[0] & 0xffff) / 2;
0196 _card_nr = (k[0] & 0xffff) % 2;
0197
0198 _evt_nr = ( k[3] & 0xffff );
0199 _clock = ( k[2] & 0xffff);
0200
0201 int dlength = getDataLength() - 2;
0202
0203 _nsamples = (dlength - 4)/256;
0204 if (_trigger_type == TRIGGERTYPE::MBD)
0205 {
0206 _nsamples = 5;
0207 }
0208 int ijk, count, ib, iturn, iw;
0209
0210 for (int is=0; is< _nsamples; is++ ) {
0211
0212 for (int ch=0; ch< 256/2; ch++) {
0213 if (ch == 95 && is >= _nsamples - 2){
0214 array[(ch*2)][is] = k[2*(127*_nsamples)+2*is+4] & 0xffff;
0215 array[((ch*2+1))][is] = k[2*(127*_nsamples)+2*is + 1 + 4] & 0xffff;
0216 }
0217 else if(ch == 127 && is >= _nsamples - 2){
0218 array[(ch*2)][is] = k[2*(95*_nsamples)+2*is+4] & 0xffff;
0219 array[((ch*2+1))][is] = k[2*(95*_nsamples)+2*is + 1 + 4] & 0xffff;
0220 }
0221 else{
0222 array[(ch*2)][is] = k[2*(ch*_nsamples)+2*is+4] & 0xffff;
0223 array[((ch*2+1))][is] = k[2*(ch*_nsamples)+2*is + 1 + 4] & 0xffff;
0224 }
0225 }
0226 }
0227
0228
0229
0230 if (_trigger_type == TRIGGERTYPE::EMCAL)
0231 {
0232 for (int is=0; is<_nsamples; is++) {
0233 for (int ch = 0; ch < 24; ch++)
0234 {
0235 for (int ia = 0; ia < 8; ia++)
0236 {
0237 itrig_sums[ch][ia*2][is] = ((array[8*ch + ia][is] & 0xff));
0238 itrig_sums[ch][ia*2+1][is] = ((array[8*ch + ia][is] >> 8 ) & 0xff);
0239 }
0240 }
0241 if (_monitor == 0)
0242 {
0243 for (int ix = 0 ; ix < 64; ix ++)
0244 {
0245 int ic1 = 192 + ix;
0246 itrig_emcal_2x2sum[ix][is] = array[ic1][is] & 0x3ff;
0247 }
0248 }
0249 else if (_monitor == 1)
0250 {
0251 for (int ix = 0 ; ix < 64; ix ++)
0252 {
0253 int ic1 = 192 + ix;
0254 itrig_emcal_2x2map[ix*2][is] = array[ic1][is] & 0xff;
0255 itrig_emcal_2x2map[ix*2+1][is] = (array[ic1][is] >> 8)& 0xff;
0256 }
0257 }
0258 else if (_monitor == 3)
0259 {
0260 for (int ix=0; ix<2; ix++) {
0261 for (int iy=0; iy<12; iy++) {
0262 int ic1 = 192 + iy;
0263 if((ix%2) == 0)
0264 {
0265 itrig_emcal_8x8map[ix][iy][is] = array[ic1][is] & 0xff;
0266 }
0267 else
0268 {
0269 itrig_emcal_8x8map[ix][iy][is] = (array[ic1][is] >> 8) & 0xff;
0270 }
0271 }
0272 }
0273 }
0274 }
0275 }
0276 else if (_trigger_type == TRIGGERTYPE::JET)
0277 {
0278 for (int iss = 0; iss < _nsamples; iss++)
0279 {
0280 for (int is=0; is<192; is++) {
0281 int ieta = is/16;
0282 int iphi = is%16;
0283 jet_map[(iphi*2)][ieta][iss] = array[is][iss] & 0xff;
0284 jet_map[(iphi*2)+1][ieta][iss] = (array[is][iss]>>8) & 0xff;
0285 }
0286 for (int i = 0; i < 32; i++)
0287 {
0288 for (int j = 0 ; j < 9; j++)
0289 {
0290 jet_sum_result[i][j][iss] = 0;
0291 }
0292 }
0293
0294 int ic2 = 192;
0295 for (int is=0; is<_ntrigger_words; is++) {
0296
0297 int ieta = is/32;
0298 int iphi = is%32;
0299 if ((is/64) == _monitor)
0300 {
0301 jet_sum_result[iphi][ieta][iss] = array[ic2++][iss] & 0xfff;
0302 }
0303 else
0304 {
0305 jet_sum_result[iphi][ieta][iss] = 0;
0306 }
0307 }
0308 }
0309 }
0310 else if (_trigger_type == TRIGGERTYPE::MBD)
0311 {
0312 for (int is=0; is< _nsamples; is++ )
0313 {
0314
0315 for (int ia=0; ia<4; ia++) {
0316 ijk = ia*8;
0317 itrig_charge[ia][0][is] = array[ijk][is] & 0x1ff;
0318 itrig_charge[ia][1][is] = ((array[ijk][is] & 0xfe00) >>9) + ((array[ijk+1][is] & 0x3)<<7) ;
0319 itrig_charge[ia][2][is] = ((array[ijk+1][is] & 0x7fc) >>2) ;
0320 itrig_charge[ia][3][is] = ((array[ijk+1][is] & 0xf800) >>11) + ((array[ijk+2][is] & 0xf)<<5) ;
0321 itrig_charge[ia][4][is] = ((array[ijk+2][is] & 0x1ff0) >>4) ;
0322 itrig_charge[ia][5][is] = ((array[ijk+2][is] & 0xe000) >>13) + ((array[ijk+3][is] & 0x3f)<<3) ;
0323 itrig_charge[ia][6][is] = ((array[ijk+3][is] & 0x7fc0) >>6) ;
0324 itrig_charge[ia][7][is] = ((array[ijk+3][is] & 0x8000) >>15) + ((array[ijk+4][is] & 0xff)<<1) ;
0325 itrig_nhit[ia][is] = (array[ijk+4][is] & 0xff00) >> 8;
0326 itrig_time[ia][0][is] = array[ijk+5][is] & 0xfff;
0327 itrig_time[ia][1][is] = ((array[ijk+5][is] & 0xf000) >>12) + ((array[ijk+6][is] & 0xff)<<4) ;
0328 itrig_time[ia][2][is] = ((array[ijk+6][is] & 0xff00) >>8) + ((array[ijk+7][is] & 0xf)<<8) ;
0329 itrig_time[ia][3][is] = (array[ijk+7][is] & 0xfff0)>>4;
0330 }
0331 ijk = 32;
0332 ib = 0;
0333 iturn = 0;
0334 count = 0;
0335 for (int ia = 0; ia < 8; ia++)
0336 {
0337 triggerwords[ia][is] = 0;
0338 for (iw = 0 ; iw < upperbits[ia] ; iw++)
0339 {
0340 if (iw+ib == 16)
0341 {
0342 ib = iw;
0343 ijk++;
0344 iturn = 1 - iturn;
0345
0346 }
0347
0348 if (!iturn) triggerwords[ia][is] += ((array[ijk][is] & (0x1 << (ib+iw))) >> ib);
0349 else triggerwords[ia][is] += ((array[ijk][is] & (0x1 << (iw - ib))) << ib);
0350
0351
0352
0353 count++;
0354 }
0355 ib = (iturn? iw-ib: iw+ib);
0356 iturn = 0;
0357 }
0358
0359
0360
0361
0362
0363
0364
0365
0366
0367
0368 }
0369
0370 }
0371 return 0;
0372 }
0373
0374
0375 int Packet_idll1v2::iValue(const int sample, const int isum)
0376 {
0377 decode();
0378
0379 if (_trigger_type == TRIGGERTYPE::EMCAL)
0380 {
0381 if ( sample >= _nsamples || sample < 0
0382 || isum >= _nfibers*_nsums + _ntrigger_words || isum < 0) return 0;
0383
0384 if (isum < _nfibers*_nsums)
0385 {
0386 return itrig_sums[isum/_nsums][isum%_nsums][sample];
0387 }
0388
0389 int iisum = isum - _nfibers*_nsums;
0390
0391 switch (_monitor)
0392 {
0393 case 0:
0394 return itrig_emcal_2x2sum[iisum][sample];
0395 break;
0396 case 1:
0397 return itrig_emcal_2x2map[iisum][sample];
0398 break;
0399 case 3:
0400 return itrig_emcal_8x8map[iisum/12][iisum%12][sample];
0401 break;
0402 default:
0403 return 0;
0404 break;
0405 }
0406 }
0407 else if (_trigger_type == TRIGGERTYPE::JET)
0408 {
0409 if ( sample >= _nsamples || sample < 0
0410 || isum >= _nfibers*_nsums + _ntrigger_words || isum < 0) return 0;
0411 if (isum < _nfibers*_nsums)
0412 {
0413 return jet_map[isum%32][isum/32][sample];
0414 }
0415 int iisum = isum - _nfibers*_nsums;
0416 return jet_sum_result[iisum%32][iisum/32][sample];
0417 }
0418 else if (_trigger_type == TRIGGERTYPE::MBD)
0419 {
0420 if ( sample >= _nsamples || sample < 0
0421 || isum >= _nfibers*_nsums + _ntrigger_words || isum < 0) return 0;
0422
0423 if (isum < _nfibers*_nsums)
0424 {
0425
0426 if (isum%13 < 8)
0427 {
0428 return itrig_charge[isum/13][isum%13][sample];
0429 }
0430 else if (isum%13 == 8)
0431 {
0432 return itrig_nhit[isum/13][sample];
0433 }
0434 else
0435 {
0436 return itrig_time[isum/13][(isum - 9)%13][sample];
0437 }
0438 }
0439
0440 return triggerwords[isum - 52][sample];
0441 }
0442
0443 return 0;
0444 }
0445
0446 int Packet_idll1v2::iValue(const int n, const char *what)
0447 {
0448
0449 decode();
0450
0451 if ( strcmp(what,"MONITOR") == 0 )
0452 {
0453 return _monitor;
0454 }
0455
0456 if ( strcmp(what,"CLOCK") == 0 )
0457 {
0458 return _clock;
0459 }
0460
0461 if ( strcmp(what,"EVTNR") == 0 )
0462 {
0463 return _evt_nr;
0464 }
0465
0466 if ( strcmp(what,"SAMPLES") == 0 )
0467 {
0468 return _nsamples;
0469 }
0470
0471
0472 if ( strcmp(what,"CHANNELS") == 0 )
0473 {
0474 return _nfibers*_nsums + _ntrigger_words;
0475 }
0476
0477 if ( strcmp(what,"TRIGGERWORDS") == 0 )
0478 {
0479 return _ntrigger_words;
0480 }
0481
0482 if ( strcmp(what,"FEMWORDS") == 0 )
0483 {
0484 return _nfibers*_nsums;
0485 }
0486 if ( strcmp(what,"FIBERS") == 0 )
0487 {
0488 return _nfibers;
0489 }
0490 if ( strcmp(what,"SUMS") == 0 )
0491 {
0492 return _nsums;
0493 }
0494 if ( strcmp(what,"SLOTNR") == 0 )
0495 {
0496 return _slot_nr;
0497 }
0498
0499 if ( strcmp(what,"CARDNR") == 0 )
0500 {
0501 return _card_nr;
0502 }
0503
0504
0505 return 0;
0506
0507 }
0508
0509 void Packet_idll1v2::dump ( OSTREAM& os )
0510 {
0511 identify(os);
0512
0513
0514 os <<" "<<std::endl;
0515
0516 os << std::dec << std::setprecision(2) << "Trigger Module = " << iValue(0, "SLOTNR") * 2 + iValue(0, "CARDNR") << std::endl;
0517 os << std::dec << std::setprecision(4) << "Evt Nr = " << iValue(0, "EVTNR") <<std::endl;
0518 os << std::dec << std::setprecision(4) << "Clock = " << iValue(0, "CLOCK") <<std::endl;
0519 os << std::dec << std::setprecision(4) << "Monitor = " << iValue(0, "MONITOR") <<std::endl;
0520
0521 if (_trigger_type == TRIGGERTYPE::EMCAL)
0522 {
0523 os <<"-------------------------------------------------------------- "<<std::endl;
0524 for (int ch = 0; ch < iValue(0, "FIBERS"); ch++)
0525 {
0526 os << std::dec<<"Fiber: "<<ch<<std::endl;
0527 for (int ic=0; ic<iValue(0, "SUMS"); ic++) {
0528 os<<std::dec<<" Sum " << ic<<" |";
0529 for (int is=0; is< iValue(0, "SAMPLES"); is++) {
0530 os << std::hex<< " "<<iValue(is, ch*iValue(0, "SUMS") + ic);
0531 }
0532
0533 os <<" |"<<endl;
0534 os <<"-------------------------------------------------------------- "<<std::endl;
0535
0536 }
0537 }
0538 for (int ic = 0; ic < iValue(0, "TRIGGERWORDS"); ic++)
0539 {
0540 os << std::dec<<"SUM "<<ic<<std::endl;
0541 for (int is=0; is<iValue(0,"SAMPLES"); is++) {
0542 os << std::hex<< " "<<iValue(is, iValue(0,"FEMWORDS") + ic);
0543 }
0544 os <<" |"<<endl;
0545 os <<"-------------------------------------------------------------- "<<std::endl;
0546 }
0547
0548 }
0549 else if (_trigger_type == TRIGGERTYPE::JET)
0550 {
0551 os << " -------------- " << (iValue(0, "MONITOR")? "HCAL Data Map" : "EMCAL Data Map") << " -------------- " <<std::endl;
0552 for (int sample = 0; sample < iValue(0, "SAMPLES") ; sample++)
0553 {
0554 os << std::dec<<"BC : "<<sample<<std::endl;
0555 os<<std::dec<<"phibin --> ";
0556 for (int ic=0; ic<32; ic++) os << std::dec << "\t" << ic ;
0557 os << " " << std::endl;
0558 os<<std::dec<<"etabin\t|| \t"<<std::endl;
0559
0560 for (int ic=0; ic<12; ic++)
0561 {
0562 os<<std::dec<< ic << "\t||";
0563 for (int is=0; is<32; is++) {
0564 os << std::hex<< "\t"<<iValue(sample, ic*32 + is);
0565 }
0566 os <<" |"<<endl;
0567 }
0568 os << " "<<std::endl;
0569 }
0570
0571 for (int is = 0; is < _nsamples; is++)
0572 {
0573 os << std::dec<<"Sample: "<<is<<std::endl;
0574 for (int ic=0; ic<9; ic++) {
0575 for (int ie=0; ie<32; ie++) {
0576 os << std::hex<< " "<<iValue(is, iValue(0,"FEMWORDS") + ic*32 + ie);
0577 }
0578
0579 os <<" |"<<endl;
0580 os <<"-------------------------------------------------------------- "<<std::endl;
0581
0582 }
0583 }
0584
0585 }
0586 else if (_trigger_type == TRIGGERTYPE::MBD)
0587 {
0588 for (int ifem = 0; ifem < iValue(0, "FIBERS"); ifem++)
0589 {
0590 os << std::dec<<"FEM : "<<ifem<<std::endl;
0591 for (int iq = 0 ; iq < 8; iq++)
0592 {
0593 os<<std::dec<<"Q" << iq << "\t|| \t";
0594 for (int is=0; is<iValue(0, "SAMPLES"); is++)
0595 {
0596 os << std::hex << iValue(is, ifem*iValue(0,"SUMS") + iq)<<"\t";
0597 }
0598 os <<" |"<<endl;
0599 }
0600 os<<std::dec<<"NH \t|| \t";
0601 for (int is=0; is<iValue(0, "SAMPLES"); is++)
0602 {
0603 os << std::hex << iValue(is, ifem*iValue(0,"SUMS") + 8)<<"\t";
0604 }
0605 os <<" |"<<endl;
0606
0607 for (int iq = 0 ; iq < iValue(0,"FIBERS"); iq++)
0608 {
0609 os<<std::dec<<"T" << iq << "\t|| \t";
0610 for (int is=0; is<iValue(0, "SAMPLES"); is++)
0611 {
0612 os << std::hex <<iValue(is, ifem*iValue(0,"SUMS") + 9 + iq)<<"\t";
0613 }
0614 os <<" |"<<endl;
0615 }
0616 os << " "<<std::endl;
0617 }
0618
0619 for (int iw = 0; iw < iValue(0,"TRIGGERWORDS"); iw++)
0620 {
0621 os<<std::dec<< "W "<<iw << "\t|| \t";
0622 for (int is=0; is<iValue(0,"SAMPLES"); is++)
0623 {
0624 os << std::hex<<iValue(is, iValue(0,"FEMWORDS") + iw) << "\t";
0625 }
0626
0627 os <<" |"<<endl;
0628 }
0629
0630 }
0631
0632 return;
0633 }