00001 #include "otsdaq-core/DataDecoders/VIPICData.h" 00002 00003 #include <iostream> 00004 00005 using namespace ots; 00006 00007 00008 //======================================================================================================================== 00009 VIPICData::VIPICData(void) 00010 { 00011 } 00012 00013 //======================================================================================================================== 00014 VIPICData::~VIPICData(void) 00015 { 00016 } 00017 00018 //======================================================================================================================== 00019 bool VIPICData::isVIPIC(uint32_t data) 00020 { 00021 int type = data & 0x0f; 00022 if (type == 2) 00023 return true; 00024 else 00025 return false; 00026 } 00027 00028 //======================================================================================================================== 00029 VIPICData& VIPICData::decode(uint32_t word) 00030 { 00031 // stibId_ = 0x03 & (word >> 30) ; //FIXME: Missing in Jones' code 00032 // channelNumber_ = 0x07 & (word >> 27) ; 00033 // chipId_ = 0x07 & (word >> 24) ; 00034 // set_ = 0x1f & (word >> 12) ; 00035 // stripNumber_ = 0x0f & (word >> 17) ; 00036 // bco_ = 0xff & (word >> 4) ; 00037 // adc_ = 0x7 & (word >> 1) ; 00038 00039 stibId_ = 0x03 & (word >> 30) ; //FIXME: Missing in Jones' code 00040 channelNumber_ = 0x07 & (word >> 27) ; 00041 chipId_ = 0x07 & (word >> 24) ; 00042 set_ = 0x1f & (word >> 12) ; 00043 stripNumber_ = 0x0f & (word >> 17) ; 00044 bco_ = 0xff & (word >> 8 ) ; 00045 pixel_ = 0xfff & (word >> 20) ; 00046 00047 00048 return *this; 00049 00050 // switch (type) 00051 // { 00052 // case 8: 00053 // { 00054 // switch(datatype) 00055 // { 00056 // case 2: 00057 // { 00058 // bco_counter &= 0x0000000000ffffffULL; 00059 // bco_counter |= ((uint64_t)data)<<24; 00060 // std::cout << __COUT_HDR_FL__ << "BCO = " << hex << bco_counter << dec << " (" << bco_counter-last_bco << ")" << std::endl; 00061 // if ( bco_counter - last_bco > 256 ) { 00062 // nhit = 0; 00063 // } 00064 // break; 00065 // } 00066 // case 1: 00067 // { 00068 // last_bco = bco_counter; 00069 // bco_counter &= 0xffffffffff000000ULL; 00070 // bco_counter |= (uint64_t)data; 00071 // break; 00072 // } 00073 // case 0x0a: { 00074 // int bco = (word>>8)&0xff; 00075 // int trignum_low = word>>16; 00076 // std::cout << __COUT_HDR_FL__ << "Trigger low = " << trignum_low << ", bco = " << hex << bco << dec << std::endl; 00077 // break; 00078 // } 00079 // case 0x0b: { 00080 // int trignum_high = word>>8; 00081 // std::cout << __COUT_HDR_FL__ << "Trigger high = " << trignum_high << std::endl; 00082 // break; 00083 // } 00084 // case 0x0c: 00085 // case 0x0d: 00086 // case 0x0e: 00087 // case 0x0f: { 00088 // int trig0 = (word>>16)&0xff; 00089 // int trig1 = (word>>24)&0xff; 00090 // int bco = (word>>8)&0xff; 00091 // std::cout << __COUT_HDR_FL__ << "Trigger word " << 15-datatype << " : " << std::endl; 00092 // for ( int k=7; k>=0; k-- ) { 00093 // if ( (trig1&(1<<k)) ) { 00094 // std::cout << __COUT_HDR_FL__ << "#" << std::endl; 00095 // } 00096 // else { 00097 // std::cout << __COUT_HDR_FL__ << "_" << std::endl; 00098 // } 00099 // } 00100 // std::cout << __COUT_HDR_FL__ << " " << std::endl; 00101 // for ( int k=7; k>=0; k-- ) { 00102 // if ( (trig0&(1<<k)) ) { 00103 // std::cout << __COUT_HDR_FL__ << "#" << std::endl; 00104 // } 00105 // else { 00106 // std::cout << __COUT_HDR_FL__ << "_" << std::endl; 00107 // } 00108 // } 00109 // std::cout << __COUT_HDR_FL__ << " " << hex << bco << dec << std::endl; 00110 // break; 00111 // } 00112 // default: 00113 // //FIXME: Raises error of invalid data 00114 // break; 00115 // } 00116 // } 00117 // } 00118 00119 00120 00121 // if ( type == 8 ) { 00122 // if ( datatype == 2 ) { 00123 // bco_counter &= 0x0000000000ffffffULL; 00124 // bco_counter |= ((uint64_t)data)<<24; 00125 // std::cout << __COUT_HDR_FL__ << "BCO = " << hex << bco_counter << dec << " (" << bco_counter-last_bco << ")" << std::endl; 00126 // if ( bco_counter - last_bco > 256 ) { 00127 // nhit = 0; 00128 // } 00129 // } 00130 // if ( datatype == 1 ) { 00131 // last_bco = bco_counter; 00132 // bco_counter &= 0xffffffffff000000ULL; 00133 // bco_counter |= (uint64_t)data; 00134 // } 00135 // if ( datatype <= 0x0f && datatype >= 0x0c ) { 00136 // int trig0 = (word>>16)&0xff; 00137 // int trig1 = (word>>24)&0xff; 00138 // int bco = (word>>8)&0xff; 00139 // std::cout << __COUT_HDR_FL__ << "Trigger word " << 15-datatype << " : " << std::endl; 00140 // for ( int k=7; k>=0; k-- ) { 00141 // if ( (trig1&(1<<k)) ) { 00142 // std::cout << __COUT_HDR_FL__ << "#" << std::endl; 00143 // } 00144 // else { 00145 // std::cout << __COUT_HDR_FL__ << "_" << std::endl; 00146 // } 00147 // } 00148 // std::cout << __COUT_HDR_FL__ << " " << std::endl; 00149 // for ( int k=7; k>=0; k-- ) { 00150 // if ( (trig0&(1<<k)) ) { 00151 // std::cout << __COUT_HDR_FL__ << "#" << std::endl; 00152 // } 00153 // else { 00154 // std::cout << __COUT_HDR_FL__ << "_" << std::endl; 00155 // } 00156 // } 00157 // std::cout << __COUT_HDR_FL__ << " " << hex << bco << dec << std::endl; 00158 // } 00159 // if ( datatype == 0x0a ) { 00160 // int bco = (word>>8)&0xff; 00161 // int trignum_low = word>>16; 00162 // std::cout << __COUT_HDR_FL__ << "Trigger low = " << trignum_low << ", bco = " << hex << bco << dec << std::endl; 00163 // } 00164 // if ( datatype == 0x0b ) { 00165 // int trignum_high = word>>8; 00166 // std::cout << __COUT_HDR_FL__ << "Trigger high = " << trignum_high << std::endl; 00167 // } 00168 // } 00169 // else if (type & 1) { 00170 // std::cout << __COUT_HDR_FL__ << "Channel: " << chan_ << " chipid: " << chipid_ << " set: " << set_ << " strip: " << strip_ << " adc: " << adc_ << " bco: " << hex << bco << dec << " istrip: " << istrip_ << std::endl; 00171 // if ( chan > 6 || istrip > 639 ) { 00172 // std::cout << __COUT_HDR_FL__ << "Bad word " << i << " = " << hex << word << dec << " = " << chan << "," << chipid << "," << set << "," << strip << " = " << istrip << std::endl; 00173 // } 00174 // nhit += 1; 00175 // } 00176 // else if ( type == 2 ) { 00177 // int pix = (word>>20)&0xfff; 00178 // int count = (word>>16)&0x0f; 00179 // int bco = (word>>8)&0xff; 00180 // std::cout << __COUT_HDR_FL__ << hex << setw(8) << setfill('0') << word << dec << " VIPIC pixel " << pix << " count = " << count << ", bco = " << hex << bco << dec << std::endl; 00181 // } 00182 // else if ( type == 10 ) { 00183 // int chan = (word>>24)&0x0f; 00184 // int count = (word>>16)&0xff; 00185 // int bco = (word>>8)&0xff; 00186 // std::cout << __COUT_HDR_FL__ << hex << setw(8) << setfill('0') << word << dec << " PSI46 channel " << chan << " count = " << count << ", bco = " << hex << bco << dec << std::endl; 00187 // } 00188 // else if ( type == 6 ) { 00189 // int adc = (word>>8)&0xff; 00190 // int row = (word>>16)&0x3f; 00191 // int col = (word>>22)&0xf; 00192 // std::cout << __COUT_HDR_FL__ << hex << setw(8) << setfill('0') << word << dec << " PSI46 hit col " << col << " row " << row << ", adc = " << adc << std::endl; 00193 // } 00194 00195 00196 //std::cout << __COUT_HDR_FL__ << __PRETTY_FUNCTION__ << " Chan: " << chan << " chipId: " << (int)chipId_ 00197 // << " set: " << (unsigned int)set_ << " strip: " << (int)stripNumber_ << " bco: " << (int)bco_ << std::endl; 00198 00199 } 00200 00201 //======================================================================================================================== 00202 unsigned int VIPICData::getStibId(void) 00203 { 00204 return (unsigned int)stibId_; 00205 } 00206 00207 //======================================================================================================================== 00208 unsigned int VIPICData::getChannelNumber(void) 00209 { 00210 return (unsigned int)channelNumber_; 00211 } 00212 00213 //======================================================================================================================== 00214 unsigned int VIPICData::getChipId(void) 00215 { 00216 return (unsigned int)chipId_; 00217 } 00218 00219 //======================================================================================================================== 00220 unsigned int VIPICData::getStripNumber(void) 00221 { 00222 return (unsigned int)stripNumber_; 00223 } 00224 00225 //======================================================================================================================== 00226 unsigned int VIPICData::getBco(void) 00227 { 00228 return (unsigned int)bco_; 00229 } 00230 00231 //======================================================================================================================== 00232 unsigned int VIPICData::getCol(void) 00233 { 00234 return (unsigned int) pixel_ % 64; 00235 } 00236 00237 //======================================================================================================================== 00238 unsigned int VIPICData::getRow(void) 00239 { 00240 return (unsigned int) pixel_ / 64; 00241 }