File indexing completed on 2025-08-03 08:20:37
0001 #include "oncsSub_idtpcfeev1.h"
0002
0003 #include <string.h>
0004 #include <stdint.h>
0005 #include <stdint.h>
0006
0007 using namespace std;
0008
0009 oncsSub_idtpcfeev1::oncsSub_idtpcfeev1(subevtdata_ptr data)
0010 :oncsSubevent_w4 (data)
0011 {
0012
0013 _nsamples = 0;
0014 _nchannels = 0;
0015 _nchips = 0;
0016 _is_decoded = 0;
0017
0018 memset(array, 0, 64*1002*sizeof(uint32_t) );
0019
0020
0021 }
0022
0023
0024 oncsSub_idtpcfeev1::~oncsSub_idtpcfeev1()
0025 {
0026
0027 }
0028
0029
0030 #define HEADER_LENGTH 7U
0031
0032 int oncsSub_idtpcfeev1::decode ()
0033 {
0034
0035 if (_is_decoded ) return 0;
0036 _is_decoded = 1;
0037
0038 int recv_length = getLength() - SEVTHEADERLENGTH - getPadding();
0039
0040 _nsamples = 0;
0041 _nchannels = 32;
0042
0043 uint32_t *buffer = ( uint32_t *) &SubeventHdr->data;
0044 unsigned int payload_len = buffer[1] & 0xffff;
0045
0046 _bx_count = ((buffer[4] & 0xffff) << 4) | (buffer[5] & 0xf);
0047
0048 for (int i = 0; i < recv_length; i += (payload_len+1))
0049 {
0050 payload_len = (buffer[i+1] & 0xffff);
0051 unsigned int channel = buffer[i+3] & 0x1f;
0052 unsigned int sampa_addr = (buffer[i+3] >> 5) & 0xf;
0053
0054 if ( sampa_addr > 1)
0055 {
0056 _broken = 1;
0057 return 0;
0058 }
0059 if ( channel >= 32 )
0060 {
0061 _broken = 2;
0062 return 0;
0063 }
0064
0065 if ( sampa_addr > _nchips)
0066 {
0067 _nchips = sampa_addr;
0068 }
0069 for ( unsigned int s = 0; s < payload_len - HEADER_LENGTH; s++)
0070 {
0071 array[sampa_addr*32 + channel][s] = buffer[i+s+HEADER_LENGTH] & 0xffff;
0072 }
0073 _nsamples = payload_len - HEADER_LENGTH;
0074 }
0075
0076 _nchips++;
0077
0078 return 0;
0079 }
0080
0081
0082 int oncsSub_idtpcfeev1::iValue(const int ch, const int sample)
0083 {
0084 decode();
0085
0086 if ( sample >= (int) _nsamples || sample < 0
0087 || ch >= (int) (_nchips * _nchannels) || ch < 0 ) return 0;
0088
0089 return array[ch][sample];
0090
0091 }
0092 int oncsSub_idtpcfeev1::iValue(const int chip, const int ch, const int sample)
0093 {
0094 if ( sample >= (int)_nsamples || sample < 0
0095 || chip >= (int) _nchips || chip < 0
0096 || ch >= (int) _nchannels || ch < 0 ) return 0;
0097
0098 return iValue(chip*32 + ch, sample);
0099
0100 }
0101
0102 int oncsSub_idtpcfeev1::iValue(const int n, const char *what)
0103 {
0104
0105 decode();
0106
0107 if ( strcmp(what,"SAMPLES") == 0 )
0108 {
0109 return _nsamples;
0110 }
0111
0112 if ( strcmp(what,"CHANNELS") == 0 )
0113 {
0114 return _nchannels;
0115 }
0116
0117 if ( strcmp(what,"CHIPS") == 0 )
0118 {
0119 return _nchips;
0120 }
0121
0122 if ( strcmp(what,"BROKEN") == 0 )
0123 {
0124 return _broken;
0125 }
0126
0127 if ( strcmp(what,"BCTR") == 0 )
0128 {
0129 return _bx_count;
0130 }
0131
0132 return 0;
0133
0134 }
0135
0136 void oncsSub_idtpcfeev1::dump ( OSTREAM& os )
0137 {
0138 identify(os);
0139
0140 os << "Chips: " << iValue(0,"CHIPS") << std::endl;
0141 os << "Channels: " << iValue(0,"CHANNELS") << std::endl;
0142 os << "Samples: " << iValue(0,"SAMPLES") << std::endl;
0143 os << "Beam Crossing: " << iValue(0,"BCTR") << std::endl;
0144 os << endl;
0145
0146 for ( int chip = 0; chip < iValue(0,"CHIPS"); chip++)
0147 {
0148 cout << " chip sample +++++++++++++++ Chip " << chip << " ++++++++" << endl;
0149 for ( int s = 0; s < iValue(0,"SAMPLES"); s++)
0150 {
0151
0152 os << setw(3) << chip << setw(5) << s << " | ";
0153
0154 for ( int c = 0; c < iValue(0,"CHANNELS"); c++)
0155 {
0156 os << setw(4) << iValue(chip, c, s) << " ";
0157 }
0158 os << endl;
0159 }
0160 os << endl;
0161 }
0162
0163 }