File indexing completed on 2025-08-03 08:20:41
0001 #include "packet_idll1v1.h"
0002
0003 #include <string.h>
0004
0005 using namespace std;
0006
0007 Packet_idll1v1::Packet_idll1v1(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
0017 _nchannels = 13*4 + 8;
0018 _even_checksum = 0;
0019 _odd_checksum = 0;
0020
0021 _calculated_even_checksum = 0;
0022 _calculated_odd_checksum = 0;
0023
0024 _even_checksum_ok = -1;
0025 _odd_checksum_ok = -1;
0026
0027 _is_decoded = 0;
0028
0029
0030 }
0031
0032
0033 Packet_idll1v1::~Packet_idll1v1()
0034 {
0035
0036 }
0037
0038
0039
0040 const int offset=2;
0041
0042
0043
0044
0045 int Packet_idll1v1::decode ()
0046 {
0047
0048
0049 if (_is_decoded ) return 0;
0050 _is_decoded = 1;
0051
0052
0053 int *k;
0054
0055
0056
0057
0058 int *SubeventData = (int *) findPacketDataStart(packet);
0059
0060 switch ( getHitFormat() )
0061 {
0062 case IDLL1_20S:
0063 _nsamples = 20;
0064 _hitbits = 6;
0065 break;
0066 case IDLL1v2_20S:
0067 _nsamples = 20;
0068 _hitbits = 7;
0069 default:
0070 _nsamples = 20;
0071 _hitbits = 7;
0072 break;
0073 }
0074
0075 int upperbits[10] = { 15,
0076 15,
0077 _hitbits,
0078 _hitbits,
0079 _hitbits,
0080 _hitbits,
0081 9,
0082 10,
0083 16,
0084 25};
0085
0086 _slot_nr = (SubeventData[0] & 0xffff) / 2;
0087 _card_nr = (SubeventData[0] & 0xffff) % 2;
0088
0089 _clock = (SubeventData[1] & 0xffff) ;
0090 _evt_nr = ((SubeventData[1] >> 16) & 0xffff) ;
0091
0092
0093 int index = getDataLength() - 1;
0094 _even_checksum = (SubeventData[index] >> 16) & 0xffff;
0095 _odd_checksum = SubeventData[index] & 0xffff;
0096
0097 k = &SubeventData[offset];
0098
0099 int is;
0100
0101 int ia, ib, iw, ijk, iturn;
0102 int count;
0103 for (is=0; is< _nsamples; is++ ) {
0104
0105 for (ia = 0; ia < 20; ia++)
0106 {
0107
0108 array[2*ia][is] = (k[(ia*_nsamples) + is] & 0xffff) ;
0109 array[2*ia + 1][is] = ((k[(ia*_nsamples) + is] >> 16 ) & 0xffff) ;
0110
0111 }
0112
0113 for (ia=0; ia<4; ia++) {
0114 ijk = ia*8;
0115 itrig_charge[ia][0][is] = array[ijk][is] & 0x1ff;
0116 itrig_charge[ia][1][is] = ((array[ijk][is] & 0xfe00) >>9) + ((array[ijk+1][is] & 0x3)<<7) ;
0117 itrig_charge[ia][2][is] = ((array[ijk+1][is] & 0x7fc) >>2) ;
0118 itrig_charge[ia][3][is] = ((array[ijk+1][is] & 0xf800) >>11) + ((array[ijk+2][is] & 0xf)<<5) ;
0119 itrig_charge[ia][4][is] = ((array[ijk+2][is] & 0x1ff0) >>4) ;
0120 itrig_charge[ia][5][is] = ((array[ijk+2][is] & 0xe000) >>13) + ((array[ijk+3][is] & 0x3f)<<3) ;
0121 itrig_charge[ia][6][is] = ((array[ijk+3][is] & 0x7fc0) >>6) ;
0122 itrig_charge[ia][7][is] = ((array[ijk+3][is] & 0x8000) >>15) + ((array[ijk+4][is] & 0xff)<<1) ;
0123 itrig_nhit[ia][is] = (array[ijk+4][is] & 0xff00) >> 8;
0124 itrig_time[ia][0][is] = array[ijk+5][is] & 0xfff;
0125 itrig_time[ia][1][is] = ((array[ijk+5][is] & 0xf000) >>12) + ((array[ijk+6][is] & 0xff)<<4) ;
0126 itrig_time[ia][2][is] = ((array[ijk+6][is] & 0xff00) >>8) + ((array[ijk+7][is] & 0xf)<<8) ;
0127 itrig_time[ia][3][is] = (array[ijk+7][is] & 0xfff0)>>4;
0128 }
0129
0130 ijk = 32;
0131 ib = 0;
0132 iturn = 0;
0133 count = 0;
0134 for (ia = 0; ia < 8; ia++)
0135 {
0136 triggerwords[ia][is] = 0;
0137 for (iw = 0 ; iw < upperbits[ia] ; iw++)
0138 {
0139 if (iw+ib == 16)
0140 {
0141 ib = iw;
0142 ijk++;
0143 iturn = 1 - iturn;
0144
0145 }
0146
0147 if (!iturn) triggerwords[ia][is] += ((array[ijk][is] & (0x1 << (ib+iw))) >> ib);
0148 else triggerwords[ia][is] += ((array[ijk][is] & (0x1 << (iw - ib))) << ib);
0149
0150
0151
0152 count++;
0153 }
0154 ib = (iturn? iw-ib: iw+ib);
0155 iturn = 0;
0156 }
0157
0158
0159
0160
0161
0162
0163
0164
0165
0166
0167 }
0168
0169 for ( index = 5; index < getDataLength()-3; index+=2)
0170 {
0171 _calculated_even_checksum ^= (SubeventData[index]) & 0xffff;
0172 _calculated_odd_checksum ^= (SubeventData[index+1] >> 16 ) & 0xffff;
0173 }
0174
0175 return 0;
0176 }
0177
0178
0179 int Packet_idll1v1::iValue(const int sample, const int ch)
0180 {
0181 decode();
0182
0183 if ( sample >= _nsamples || sample < 0
0184 || ch >= _nchannels || ch < 0 ) return 0;
0185
0186 if (ch < 52)
0187 {
0188 if (ch%13 < 8)
0189 {
0190 return itrig_charge[ch/13][ch%13][sample];
0191 }
0192 else if (ch%13 == 8)
0193 {
0194 return itrig_nhit[ch/13][sample];
0195 }
0196 else
0197 {
0198 return itrig_time[ch/13][(ch - 9)%13][sample];
0199 }
0200 }
0201 return triggerwords[ch - 52][sample];
0202
0203 }
0204
0205 int Packet_idll1v1::iValue(const int n, const char *what)
0206 {
0207
0208 decode();
0209
0210 if ( strcmp(what,"CLOCK") == 0 )
0211 {
0212 return _clock;
0213 }
0214
0215 if ( strcmp(what,"EVTNR") == 0 )
0216 {
0217 return _evt_nr;
0218 }
0219
0220 if ( strcmp(what,"SAMPLES") == 0 )
0221 {
0222 return _nsamples;
0223 }
0224
0225 if ( strcmp(what,"CHANNELS") == 0 )
0226 {
0227 return _nchannels;
0228 }
0229
0230 if ( strcmp(what,"SLOTNR") == 0 )
0231 {
0232 return _slot_nr;
0233 }
0234
0235 if ( strcmp(what,"CARDNR") == 0 )
0236 {
0237 return _card_nr;
0238 }
0239
0240 if ( strcmp(what,"EVENCHECKSUM") == 0 )
0241 {
0242 return _even_checksum;
0243 }
0244
0245 if ( strcmp(what,"ODDCHECKSUM") == 0 )
0246 {
0247 return _odd_checksum;
0248 }
0249
0250 if ( strcmp(what,"CALCEVENCHECKSUM") == 0 )
0251 {
0252 return _calculated_even_checksum;
0253 }
0254
0255 if ( strcmp(what,"CALCODDCHECKSUM") == 0 )
0256 {
0257 return _calculated_odd_checksum;
0258 }
0259
0260 if ( strcmp(what,"EVENCHECKSUMOK") == 0 )
0261 {
0262 if ( _calculated_even_checksum < 0 ) return -1;
0263 if ( _even_checksum == _calculated_even_checksum) return 1;
0264 return 0;
0265 }
0266
0267 if ( strcmp(what,"ODDCHECKSUMOK") == 0 )
0268 {
0269 if ( _calculated_odd_checksum < 0 ) return -1;
0270 if ( _odd_checksum == _calculated_odd_checksum) return 1;
0271 return 0;
0272 }
0273
0274
0275 return 0;
0276
0277 }
0278
0279 void Packet_idll1v1::dump ( OSTREAM& os )
0280 {
0281 identify(os);
0282
0283 os << "Evt Nr: " << iValue(0,"EVTNR") << std::endl;
0284 os << "Clock: " << iValue(0,"CLOCK") << std::endl;
0285 os << "Channels: " << iValue(0,"CHANNELS") << std::endl;
0286 os << "Samples: " << iValue(0,"SAMPLES") << std::endl;
0287
0288 os << "Slot: " << iValue(0,"SLOTNR") << std::endl;
0289 os << "Card: " << iValue(0,"CARDNR") << std::endl;
0290
0291 os << "Even chksum: 0x" << hex << iValue(0,"EVENCHECKSUM") << " calculated: 0x" << iValue(0,"CALCEVENCHECKSUM");
0292 if ( iValue(0,"EVENCHECKSUMOK") == 1) os << " ok" << endl;
0293 else if ( iValue(0,"EVENCHECKSUMOK") == 0) os << " **wrong" << endl;
0294
0295 os << "Odd chksum: 0x" << hex << iValue(0,"ODDCHECKSUM") << " calculated: 0x" << iValue(0,"CALCODDCHECKSUM");
0296 if ( iValue(0,"ODDCHECKSUMOK") == 1) os << " ok" << endl;
0297 else if ( iValue(0,"ODDCHECKSUMOK") == 0) os << " **wrong" << endl;
0298 os << dec << endl;
0299
0300 for ( int c = 0; c < 4; c++)
0301 {
0302 for (int j = 0; j < 13; j++)
0303 {
0304 os << setw(4) << c << " " << j << " | ";
0305
0306 os << hex;
0307 for ( int s = 0; s < _nsamples; s++)
0308 {
0309 os << setw(6) << iValue(s,c*13 + j);
0310 }
0311 os << dec << endl;
0312 }
0313 }
0314
0315 for (int j = 0; j < 8; j++)
0316 {
0317 os << setw(4) << 25 << " " << j << " | ";
0318
0319 os << hex;
0320 for ( int s = 0; s < _nsamples; s++)
0321 {
0322 os << setw(6) << iValue(s, 52 + j);
0323 }
0324 os << dec << endl;
0325 }
0326
0327 }