File indexing completed on 2024-04-06 12:19:15
0001
0002
0003
0004
0005
0006
0007
0008 #ifndef __CINT__
0009 #include <iostream>
0010 #include <fstream>
0011 using namespace std;
0012 #endif
0013
0014
0015
0016 class MyDecode {
0017 public:
0018 MyDecode() {}
0019 ~MyDecode() {}
0020 static int error(int error);
0021 static int data(int error);
0022 private:
0023 };
0024
0025
0026
0027 int MyDecode::error(int word) {
0028 int status = -1;
0029 const unsigned int errorMask = 0x3e00000;
0030 const unsigned int dummyMask = 0x03600000;
0031 const unsigned int gapMask = 0x03400000;
0032 const unsigned int timeOut = 0x3a00000;
0033 const unsigned int eventNumError = 0x3e00000;
0034 const unsigned int trailError = 0x3c00000;
0035 const unsigned int fifoError = 0x3800000;
0036
0037
0038 const unsigned int eventNumMask = 0x1fe000;
0039 const unsigned int channelMask = 0xfc000000;
0040 const unsigned int tbmEventMask = 0xff;
0041 const unsigned int overflowMask = 0x100;
0042 const unsigned int tbmStatusMask = 0xff;
0043 const unsigned int BlkNumMask = 0x700;
0044 const unsigned int FsmErrMask = 0x600;
0045 const unsigned int RocErrMask = 0x800;
0046 const unsigned int ChnFifMask = 0x1f;
0047 const unsigned int Fif2NFMask = 0x40;
0048 const unsigned int TrigNFMask = 0x80;
0049
0050 const int offsets[8] = {0,4,9,13,18,22,27,31};
0051
0052
0053 if( (word&errorMask) == dummyMask ) {
0054
0055 return 0;
0056 } else if( (word&errorMask) == gapMask ) {
0057
0058 return 0;
0059 } else if( (word&errorMask)==timeOut ) {
0060
0061 unsigned int index = (word & 0x1F);
0062 unsigned int chip = (word& BlkNumMask)>>8;
0063 int offset = offsets[chip];
0064 cout<<"Timeout Error- channels: ";
0065 for(int i=0;i<5;i++) {
0066 if( (index & 0x1) != 0) {
0067 int chan = offset + i + 1;
0068 cout<<chan<<" ";
0069 }
0070 index = index >> 1;
0071 }
0072
0073
0074 } else if( (word&errorMask) == eventNumError ) {
0075 unsigned int channel = (word & channelMask) >>26;
0076 unsigned int tbm_event = (word & tbmEventMask);
0077
0078 cout<<"Event Number Error- channel: "<<channel<<" tbm event nr. "
0079 <<tbm_event;
0080
0081 } else if( ((word&errorMask) == trailError)) {
0082 unsigned int channel = (word & channelMask) >>26;
0083 unsigned int tbm_status = (word & tbmStatusMask);
0084 if(word & RocErrMask)
0085 cout<<"Number of Rocs Error- "<<"channel: "<<channel<<" ";
0086 if(word & FsmErrMask)
0087 cout<<"Finite State Machine Error- "<<"channel: "<<channel
0088 <<" Error status:0x"<<hex<< ((word & FsmErrMask)>>9)<<dec<<" ";;
0089 if(word & overflowMask)
0090 cout<<"Overflow Error- "<<"channel: "<<channel<<" ";
0091 if(!((word & RocErrMask)|(word & FsmErrMask)|(word & overflowMask)))
0092 cout<<"Trailer Error- ";
0093
0094 cout<<"channel: "<<channel<<" TBM status:0x"<<hex<<tbm_status<<dec<<" ";
0095
0096 } else if((word&errorMask)==fifoError) {
0097 if(word & Fif2NFMask) cout<<"A fifo 2 is Nearly full- ";
0098 if(word & TrigNFMask) cout<<"The trigger fifo is nearly Full - ";
0099 if(word & ChnFifMask) cout<<"fifo-1 is nearly full for channel"<<(word & ChnFifMask);
0100
0101 } else {
0102 cout<<" Unknown error?";
0103 }
0104
0105 unsigned int event = (word & eventNumMask) >>13;
0106
0107
0108 if(event>0) cout<<":event: "<<event;
0109 cout<<endl;
0110
0111 return status;
0112 }
0113
0114 int MyDecode::data(int word) {
0115 const unsigned int plsmsk = 0xff;
0116 const unsigned int pxlmsk = 0xff00;
0117 const unsigned int dclmsk = 0x1f0000;
0118 const unsigned int rocmsk = 0x3e00000;
0119 const unsigned int chnlmsk = 0xfc000000;
0120 int status = -1;
0121
0122 int roc = ((word&rocmsk)>>21);
0123
0124 if(roc>0 && roc<25) {
0125 cout<<"data "<<hex<<word<<dec;
0126 unsigned int channel = ((word&chnlmsk)>>26);
0127 if(channel>0 && channel<37) {
0128
0129 int dcol=(word&dclmsk)>>16;
0130 int pix=(word&pxlmsk)>>8;
0131 int adc=(word&plsmsk);
0132 cout<<" Channel- "<<channel<<" ROC- "<<roc<<" DCOL- "<<dcol<<" Pixel- "
0133 <<pix<<" ADC- "<<adc<<endl;
0134 status=0;
0135 } else {
0136 cout<<"Wrong channel "<<channel<<endl;
0137 return -2;
0138 }
0139 } else {
0140
0141 status=error(word);
0142 }
0143
0144 return status;
0145 }
0146
0147 int dumpBinaryFiles(char * filename) {
0148
0149 ifstream in_file;
0150 in_file.open(filename, ios::binary|ios::in );
0151
0152 if (!in_file) {
0153 cout << " File not found " << endl;
0154 return(1);
0155 }
0156
0157
0158 const int numMax=1000000;
0159 int numEvent=0;
0160 int status=0;
0161 unsigned long long word64=0;
0162
0163
0164 while (numEvent < numMax) {
0165
0166 in_file.read((char*)&word64,8);
0167 if (in_file.eof()) {
0168 std::cout << "End of input file" << std::endl;
0169 return false;
0170 }
0171
0172 cout<<hex<<word64<<dec<<endl;
0173
0174 if ((word64 >> 60) != 0x5){
0175 std::cout << "DATA CORRUPTION!" << std::endl;
0176 std::cout << "Expected to find header, but read: 0x"
0177 <<std::hex<<word64<<std::dec << std::endl;
0178 return false;
0179 }
0180
0181 unsigned int fed_id=(word64>>8)&0xfff;
0182 unsigned int event_id=(word64>>32)&0xffffff;
0183 unsigned int bx_id=(word64>>20)&0xfff;
0184 cout<<" Header "<<hex<<word64<<dec<<" for FED "
0185 <<fed_id<<" "<<event_id<<" "<<bx_id<<endl;
0186 if(event_id==1) cout<<" EVENT 1"<<endl;
0187
0188 numEvent++;
0189 int i=0;
0190 do {
0191 in_file.read((char*)&word64,8);
0192
0193 if( (word64 >> 60) != 0xa ) {
0194 int data1 = int( word64 &0x00000000ffffffffL );
0195 int data2 = int( (word64>>32)&0x00000000ffffffffL );
0196
0197 status = MyDecode::data(data1);
0198 status = MyDecode::data(data2);
0199 i++;
0200 }
0201 } while((word64 >> 60) != 0xa);
0202
0203
0204 int slinkLength = int( (word64>>32) & 0xffffff );
0205 int tts = int( (word64&0xf0)>>4);
0206 int slinkError = int( (word64&0xf00)>>8);
0207 cout<<" Trailer "<<hex<<word64<<dec<<" "<<slinkLength<<"/"<<(i+2)<<" "<<tts<<" "
0208 <<slinkError<<endl;
0209 if(slinkLength != (i+2) ) cout <<"Error in the event length = slink = "<<slinkLength
0210 <<" count = "<<(i+2)<<endl;
0211
0212
0213 int dummy=0;
0214 cout<<" Enter 0 to continue, -1 to stop ";
0215 cin>>dummy;
0216 if(dummy==-1) break;
0217
0218
0219 }
0220
0221 in_file.close();
0222
0223 return(0);
0224 }
0225
0226
0227
0228