Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:14:57

0001 // -*- Mode: C++; c-basic-offset: 2; indent-tabs-mode: t; tab-width: 8; -*-
0002 /*
0003  * Original author: Ph. Gras CEA/Saclay 
0004  */
0005 
0006 /**
0007  * \file
0008  * Implementation of the MatacqTBRawEvent class
0009  */
0010 
0011 #include <unistd.h>
0012 #include <cstdlib>
0013 #include <fstream>
0014 #include <vector>
0015 #include <iostream>
0016 #include <iomanip>
0017 #include <ctime>
0018 #include <limits>
0019 #include <stdexcept>
0020 #include "EventFilter/EcalTBRawToDigi/src/MatacqRawEvent.h"
0021 
0022 const MatacqTBRawEvent::field32spec_t MatacqTBRawEvent::fov32 = {0, 0x000000F0};
0023 const MatacqTBRawEvent::field32spec_t MatacqTBRawEvent::fedId32 = {0, 0x000FFF00};
0024 const MatacqTBRawEvent::field32spec_t MatacqTBRawEvent::bxId32 = {0, 0xFFF00000};
0025 const MatacqTBRawEvent::field32spec_t MatacqTBRawEvent::lv132 = {1, 0x00FFFFFF};
0026 const MatacqTBRawEvent::field32spec_t MatacqTBRawEvent::triggerType32 = {1, 0x0F000000};
0027 const MatacqTBRawEvent::field32spec_t MatacqTBRawEvent::boeType32 = {1, 0xF0000000};
0028 const MatacqTBRawEvent::field32spec_t MatacqTBRawEvent::dccLen32 = {2, 0x00FFFFFF};
0029 const MatacqTBRawEvent::field32spec_t MatacqTBRawEvent::dccErrors32 = {2, 0xFF000000};
0030 const MatacqTBRawEvent::field32spec_t MatacqTBRawEvent::runNum32 = {3, 0x00FFFFFF};
0031 const MatacqTBRawEvent::field32spec_t MatacqTBRawEvent::h1Marker32 = {3, 0xF0000000};
0032 
0033 void MatacqTBRawEvent::setRawData(const unsigned char* pData, size_t maxSize) {
0034   error = 0;
0035   const int16le_t* begin16 = (const int16le_t*)pData;
0036   const int16le_t* pData16 = begin16;
0037   daqHeader = (const uint32le_t*)pData16;
0038   const int daqHeaderLen = 16;  //in bytes
0039   pData16 += daqHeaderLen / sizeof(pData16[0]);
0040   matacqHeader = (const matacqHeader_t*)pData16;
0041   pData16 += sizeof(matacqHeader_t) / sizeof(pData16[0]);
0042   if (getMatacqDataFormatVersion() >= 2) {  //trigger position present
0043     tTrigPs = *((const int32_t*)pData16);
0044     pData16 += 2;
0045   } else {
0046     tTrigPs = std::numeric_limits<int>::max();
0047   }
0048   const int nCh = getChannelCount();
0049   channelData.resize(nCh);
0050   for (int iCh = 0; iCh < nCh; ++iCh) {
0051     //channel id:
0052     channelData[iCh].chId = *(pData16++);
0053     //number of time samples for this channel:
0054     channelData[iCh].nSamples = *(pData16++);
0055     //pointer to time sample data of this channel:
0056     channelData[iCh].samples = pData16;
0057     //moves to next channel data block:
0058     pData16 += channelData[iCh].nSamples;
0059   }
0060 
0061   //data trailer chekes:
0062   //FED header is aligned on 64-bit=>padding to skip
0063   int padding = (4 - (pData16 - begin16)) % 4;
0064   if (padding < 0)
0065     padding += 4;
0066   pData16 += padding;
0067   const uint32le_t* trailer32 = (const uint32le_t*)(pData16);
0068   fragLen = trailer32[1] & 0xFFFFFF;
0069 
0070   //std::cout << "Event fragment length including headers: " << fragLen
0071   //     << " 64-bit words\n";
0072 
0073   //FIXME: I am expecting the event length specifies in the header to
0074   //include the header, while it is not the case in current TB 2006 data
0075   const int nHeaders = 3;
0076   if (fragLen != read32(daqHeader, dccLen32) + nHeaders && fragLen != read32(daqHeader, dccLen32)) {
0077     //std::cout << "Error: fragment length is not consistent with DCC "
0078     //  "length\n";
0079     error |= errorLengthConsistency;
0080   }
0081 
0082   //skip trailers
0083   const int trailerLen = 4;
0084   pData16 += trailerLen;
0085 
0086   parsedLen = (pData16 - begin16) / 4;
0087 
0088   if ((pData16 - begin16) != (4 * fragLen)) {
0089     error |= errorLength;
0090   }
0091 
0092   if ((size_t)(pData16 - begin16) > maxSize) {
0093     throw std::runtime_error(std::string("Corrupted or truncated data"));
0094   }
0095 
0096   //some checks
0097   if (getBoe() != 0x5) {
0098     error |= errorWrongBoe;
0099   }
0100 }
0101 
0102 int MatacqTBRawEvent::read32(const uint32le_t* pData, field32spec_t spec32) const {
0103   int result = pData[spec32.offset] & spec32.mask;
0104   int mask = spec32.mask;
0105   while ((mask & 0x1) == 0) {
0106     mask >>= 1;
0107     result >>= 1;
0108   }
0109   return result;
0110 }