File indexing completed on 2025-08-03 08:20:47
0001 #include "oncsSub_iddigitizerv1.h"
0002
0003 #include <string.h>
0004
0005 using namespace std;
0006
0007 oncsSub_iddigitizerv1::oncsSub_iddigitizerv1(subevtdata_ptr data)
0008 :oncsSubevent_w4 (data)
0009 {
0010
0011 _nsamples = 0;
0012 _l1_delay = 0;
0013 _slot_nr = 0;
0014 _nr_modules = 0;
0015 _clock = 0;
0016 _evtnr = 0;
0017 _nchannels = 0;
0018 _slot_nr_from_data = 0;
0019 _is_decoded = 0;
0020
0021
0022 }
0023
0024
0025 oncsSub_iddigitizerv1::~oncsSub_iddigitizerv1()
0026 {
0027
0028 }
0029
0030
0031
0032 const int offset=3;
0033
0034
0035 int oncsSub_iddigitizerv1::digitizer_decode ()
0036 {
0037
0038 if (_is_decoded ) return 0;
0039 _is_decoded = 1;
0040
0041
0042 int *k;
0043
0044
0045
0046
0047 int *SubeventData = &SubeventHdr->data;
0048
0049 _nsamples = (SubeventData[0] >> 24 ) & 0xff;
0050 _l1_delay = (SubeventData[0] >> 16 ) & 0xff;
0051 _slot_nr = (SubeventData[0] >> 8 ) & 0xff;
0052 _nr_modules = SubeventData[0] & 0xff;
0053
0054 _nchannels = _nr_modules * 64;
0055
0056 _slot_nr_from_data = (SubeventData[1] >> 16 ) & 0xff;
0057
0058 _clock = (SubeventData[2] >> 16 ) & 0xffff;
0059 _evtnr = SubeventData[2] & 0xffff;
0060
0061
0062 if ( _nr_modules > 5 || _nsamples >31 || _slot_nr > 22)
0063 {
0064 return 0;
0065 }
0066
0067
0068 k = &SubeventData[offset];
0069
0070 int index=0;
0071 for ( int ch = 0; ch < _nchannels/2 ; ch++)
0072 {
0073 for ( int sample = 0; sample < _nsamples ; sample++)
0074 {
0075 array[sample][2*ch] = k[index] & 0xffff;
0076 array[sample][2*ch+1] = (k[index]>>16) & 0xffff;
0077 index++;
0078 }
0079 }
0080
0081 return 0;
0082 }
0083
0084
0085 int oncsSub_iddigitizerv1::iValue(const int sample, const int ch)
0086 {
0087 digitizer_decode();
0088
0089 if ( sample >= _nsamples || sample < 0
0090 || ch >= _nchannels || ch < 0 ) return 0;
0091
0092 return array[sample][ch];
0093
0094 }
0095
0096 int oncsSub_iddigitizerv1::iValue(const int n, const char *what)
0097 {
0098
0099 digitizer_decode();
0100
0101 if ( strcmp(what,"SAMPLES") == 0 )
0102 {
0103 return _nsamples;
0104 }
0105
0106 if ( strcmp(what,"CHANNELS") == 0 )
0107 {
0108 return _nchannels;
0109 }
0110
0111 if ( strcmp(what,"L1DELAY") == 0 )
0112 {
0113 return _l1_delay;
0114 }
0115
0116 if ( strcmp(what,"SLOTNR") == 0 )
0117 {
0118 return _slot_nr;
0119 }
0120
0121 if ( strcmp(what,"NRMODULES") == 0 )
0122 {
0123 return _nr_modules;
0124 }
0125
0126 if ( strcmp(what,"CLOCK") == 0 )
0127 {
0128 return _clock;
0129 }
0130
0131 if ( strcmp(what,"EVTNR") == 0 )
0132 {
0133 return _evtnr;
0134 }
0135
0136 return 0;
0137
0138 }
0139
0140 void oncsSub_iddigitizerv1::dump ( OSTREAM& os )
0141 {
0142 identify(os);
0143
0144 os << "Evt Nr: " << iValue(0,"EVTNR") << std::endl;
0145 os << "Clock: " << iValue(0,"CLOCK") << std::endl;
0146 os << "Channels: " << iValue(0,"CHANNELS") << std::endl;
0147 os << "Samples: " << iValue(0,"SAMPLES") << std::endl;
0148 os << "L1 Delay: " << iValue(0,"L1DELAY") << std::endl;
0149 os << "Slot Nr: " << iValue(0,"SLOTNR") << std::endl;
0150 os << "Nr Modules: " << iValue(0,"NRMODULES") << std::endl;
0151 os << endl;
0152
0153
0154
0155 for ( int c = 0; c < _nchannels; c++)
0156 {
0157 os << setw(4) << c << " | ";
0158
0159 for ( int s = 0; s < _nsamples; s++)
0160 {
0161 os << setw(8) << iValue(s,c);
0162 }
0163 os << endl;
0164 }
0165
0166 }