00001 #include "otsdaq-core/DataDecoders/DataDecoder.h"
00002 #include "otsdaq-core/MessageFacility/MessageFacility.h"
00003 #include "otsdaq-core/Macros/CoutHeaderMacros.h"
00004
00005 #include <iostream>
00006 #include <cassert>
00007 #include <unistd.h>
00008
00009 using namespace ots;
00010
00011
00012
00013
00014 DataDecoder::DataDecoder(void)
00015 {}
00016
00017
00018 DataDecoder::~DataDecoder(void)
00019 {}
00020
00021
00022 void DataDecoder::convertBuffer(const std::string& buffer, std::queue<uint32_t>& convertedBuffer, bool invert)
00023 {
00024 for(unsigned int i=0; i<buffer.length(); i+=4 )
00025 convertedBuffer.push(convertBuffer(buffer, i, invert));
00026 }
00027
00028
00029 uint32_t DataDecoder::convertBuffer(const std::string& buffer, unsigned int bufferIndex, bool invert)
00030 {
00031 if(invert)
00032 return (unsigned int)(((unsigned char)buffer[bufferIndex ]) << 24)
00033 + (unsigned int)(((unsigned char)buffer[bufferIndex+1]) << 16)
00034 + (unsigned int)(((unsigned char)buffer[bufferIndex+2]) << 8)
00035 + (unsigned int)( (unsigned char)buffer[bufferIndex+3]);
00036 else
00037 return (unsigned int)((unsigned char)buffer[bufferIndex ])
00038 + (unsigned int)(((unsigned char)buffer[bufferIndex+1]) << 8)
00039 + (unsigned int)(((unsigned char)buffer[bufferIndex+2]) << 16)
00040 + (unsigned int)(((unsigned char)buffer[bufferIndex+3]) << 24);
00041
00042 }
00043
00044
00045 bool DataDecoder::isBCOHigh(uint32_t data)
00046 {
00047 return bcoDataDecoder_.isBCOHigh(data);
00048 }
00049
00050
00051 bool DataDecoder::isBCOLow(uint32_t data)
00052 {
00053 return bcoDataDecoder_.isBCOLow(data);
00054 }
00055
00056
00057 bool DataDecoder::isTriggerLow(uint32_t data)
00058 {
00059 return triggerDataDecoder_.isTriggerLow(data);
00060 }
00061
00062
00063 bool DataDecoder::isTriggerHigh(uint32_t data)
00064 {
00065 return triggerDataDecoder_.isTriggerHigh(data);
00066 }
00067
00068
00069 bool DataDecoder::isFSSRData(uint32_t data)
00070 {
00071 return FSSRDataDecoder_.isFSSR(data);
00072 }
00073
00074
00075 bool DataDecoder::isVIPICData(uint32_t data)
00076 {
00077 return VIPICDataDecoder_.isVIPIC(data);
00078 }
00079
00080
00081 bool DataDecoder::isPSI46Data(uint32_t data)
00082 {
00083 return PSI46DataDecoder_.isPSI46(data);
00084 }
00085
00086
00087 bool DataDecoder::isPSI46DigData(uint32_t data)
00088 {
00089 return PSI46DigDataDecoder_.isPSI46Dig(data);
00090 }
00091
00092
00093 uint64_t DataDecoder::mergeBCOHighAndLow(uint32_t dataBCOHigh, uint32_t dataBCOLow)
00094 {
00095 return bcoDataDecoder_.mergeBCOHighAndLow(bcoDataDecoder_.decodeBCOHigh(dataBCOHigh),bcoDataDecoder_.decodeBCOLow(dataBCOLow));
00096 }
00097
00098
00099 uint64_t DataDecoder::mergeTriggerHighAndLow(uint32_t dataTriggerHigh, uint32_t dataTriggerLow)
00100 {
00101 return triggerDataDecoder_.mergeTriggerHighAndLow(triggerDataDecoder_.decodeTriggerHigh(dataTriggerHigh),triggerDataDecoder_.decodeTriggerLow(dataTriggerLow));
00102 }
00103
00104
00105 void DataDecoder::insertBCOHigh(uint64_t& bco, uint32_t dataBCOHigh)
00106 {
00107 bcoDataDecoder_.insertBCOHigh(bco,dataBCOHigh);
00108 }
00109
00110
00111 void DataDecoder::insertBCOLow(uint64_t& bco, uint32_t dataBCOLow)
00112 {
00113 bcoDataDecoder_.insertBCOLow(bco,dataBCOLow);
00114 }
00115
00116
00117 void DataDecoder::decodeData(uint32_t data, DetectorDataBase** decodedData)
00118 {
00119 if(isFSSRData(data))
00120 {
00121 FSSRDataDecoder_.decode(data);
00122 *decodedData = (DetectorDataBase*)(&FSSRDataDecoder_);
00123 }
00124 else if(isVIPICData(data))
00125 {
00126 VIPICDataDecoder_.decode(data);
00127 *decodedData = (DetectorDataBase*)(&VIPICDataDecoder_);
00128 }
00129 else if(isPSI46DigData(data))
00130 {
00131 PSI46DigDataDecoder_.decode(data);
00132 *decodedData = (DetectorDataBase*)(&PSI46DigDataDecoder_);
00133 }
00134 else
00135 *decodedData = 0;
00136 }