00001
00002
00003
00004
00005
00006
00012 #include <unistd.h>
00013 #include <stdlib.h>
00014 #include <fstream>
00015 #include <vector>
00016 #include <iostream>
00017 #include <iomanip>
00018 #include <ctime>
00019 #include <limits>
00020 #include <stdexcept>
00021 #include "EventFilter/EcalTBRawToDigi/src/MatacqRawEvent.h"
00022
00023
00024 const MatacqTBRawEvent::field32spec_t MatacqTBRawEvent::fov32 = {0, 0x000000F0};
00025 const MatacqTBRawEvent::field32spec_t MatacqTBRawEvent::fedId32 = {0, 0x000FFF00};
00026 const MatacqTBRawEvent::field32spec_t MatacqTBRawEvent::bxId32 = {0, 0xFFF00000};
00027 const MatacqTBRawEvent::field32spec_t MatacqTBRawEvent::lv132 = {1, 0x00FFFFFF};
00028 const MatacqTBRawEvent::field32spec_t MatacqTBRawEvent::triggerType32 = {1, 0x0F000000};
00029 const MatacqTBRawEvent::field32spec_t MatacqTBRawEvent::boeType32 = {1, 0xF0000000};
00030 const MatacqTBRawEvent::field32spec_t MatacqTBRawEvent::dccLen32 = {2, 0x00FFFFFF};
00031 const MatacqTBRawEvent::field32spec_t MatacqTBRawEvent::dccErrors32 = {2, 0xFF000000};
00032 const MatacqTBRawEvent::field32spec_t MatacqTBRawEvent::runNum32 = {3, 0x00FFFFFF};
00033 const MatacqTBRawEvent::field32spec_t MatacqTBRawEvent::h1Marker32 = {3, 0xF0000000};
00034
00035 void MatacqTBRawEvent::setRawData(const unsigned char* pData, size_t maxSize){
00036 error = 0;
00037 int16le_t* begin16 = (int16le_t*) pData;
00038 int16le_t* pData16 = begin16;
00039 daqHeader = (uint32le_t*) pData16;
00040 const int daqHeaderLen = 16;
00041 pData16 += daqHeaderLen/sizeof(pData16[0]);
00042 matacqHeader = (matacqHeader_t*) pData16;
00043 pData16 += sizeof(matacqHeader_t)/sizeof(pData16[0]);
00044 if(getMatacqDataFormatVersion()>=2){
00045 tTrigPs = *((int32_t*) pData16);
00046 pData16 += 2;
00047 } else{
00048 tTrigPs = std::numeric_limits<int>::max();
00049 }
00050 const int nCh = getChannelCount();
00051 channelData.resize(nCh);
00052 for(int iCh=0; iCh<nCh; ++iCh){
00053
00054 channelData[iCh].chId = *(pData16++);
00055
00056 channelData[iCh].nSamples = *(pData16++);
00057
00058 channelData[iCh].samples = pData16;
00059
00060 pData16 += channelData[iCh].nSamples;
00061 }
00062
00063
00064
00065 int padding = (4-(pData16-begin16))%4;
00066 if(padding<0) padding+=4;
00067 pData16 += padding;
00068 uint32le_t* trailer32 = (uint32le_t*)(pData16);
00069 fragLen = trailer32[1]&0xFFFFFF;
00070
00071
00072
00073
00074
00075
00076 const int nHeaders = 3;
00077 if(fragLen!=read32(daqHeader,dccLen32)+nHeaders
00078 && fragLen != read32(daqHeader,dccLen32)){
00079
00080
00081 error |= errorLengthConsistency;
00082 }
00083
00084
00085 const int trailerLen = 4;
00086 pData16 += trailerLen;
00087
00088 parsedLen = (pData16-begin16) / 4;
00089
00090 if((pData16-begin16)!=(4*fragLen)){
00091 error |= errorLength;
00092 }
00093
00094 if((size_t)(pData16-begin16)>maxSize){
00095 throw std::runtime_error(std::string("Corrupted or truncated data"));
00096 }
00097
00098
00099 if(getBoe()!=0x5){
00100 error |= errorWrongBoe;
00101 }
00102 }
00103
00104 int MatacqTBRawEvent::read32(uint32le_t* pData, field32spec_t spec32) const{
00105 int result = pData[spec32.offset] & spec32.mask;
00106 int mask = spec32.mask;
00107 while((mask&0x1) == 0){
00108 mask >>= 1;
00109 result >>= 1;
00110 }
00111 return result;
00112 }