CMS 3D CMS Logo

MatacqRawEvent.cc
Go to the documentation of this file.
1 // -*- Mode: C++; c-basic-offset: 2; indent-tabs-mode: t; tab-width: 8; -*-
2 /*
3  * Original author: Ph. Gras CEA/Saclay
4  */
5 
11 #include <unistd.h>
12 #include <cstdlib>
13 #include <fstream>
14 #include <vector>
15 #include <iostream>
16 #include <iomanip>
17 #include <ctime>
18 #include <limits>
19 #include <stdexcept>
21 
32 
33 void MatacqTBRawEvent::setRawData(const unsigned char* pData, size_t maxSize) {
34  error = 0;
35  const int16le_t* begin16 = (const int16le_t*)pData;
36  const int16le_t* pData16 = begin16;
37  daqHeader = (const uint32le_t*)pData16;
38  const int daqHeaderLen = 16; //in bytes
39  pData16 += daqHeaderLen / sizeof(pData16[0]);
40  matacqHeader = (const matacqHeader_t*)pData16;
41  pData16 += sizeof(matacqHeader_t) / sizeof(pData16[0]);
42  if (getMatacqDataFormatVersion() >= 2) { //trigger position present
43  tTrigPs = *((const int32_t*)pData16);
44  pData16 += 2;
45  } else {
47  }
48  const int nCh = getChannelCount();
49  channelData.resize(nCh);
50  for (int iCh = 0; iCh < nCh; ++iCh) {
51  //channel id:
52  channelData[iCh].chId = *(pData16++);
53  //number of time samples for this channel:
54  channelData[iCh].nSamples = *(pData16++);
55  //pointer to time sample data of this channel:
56  channelData[iCh].samples = pData16;
57  //moves to next channel data block:
58  pData16 += channelData[iCh].nSamples;
59  }
60 
61  //data trailer chekes:
62  //FED header is aligned on 64-bit=>padding to skip
63  int padding = (4 - (pData16 - begin16)) % 4;
64  if (padding < 0)
65  padding += 4;
66  pData16 += padding;
67  const uint32le_t* trailer32 = (const uint32le_t*)(pData16);
68  fragLen = trailer32[1] & 0xFFFFFF;
69 
70  //std::cout << "Event fragment length including headers: " << fragLen
71  // << " 64-bit words\n";
72 
73  //FIXME: I am expecting the event length specifies in the header to
74  //include the header, while it is not the case in current TB 2006 data
75  const int nHeaders = 3;
76  if (fragLen != read32(daqHeader, dccLen32) + nHeaders && fragLen != read32(daqHeader, dccLen32)) {
77  //std::cout << "Error: fragment length is not consistent with DCC "
78  // "length\n";
80  }
81 
82  //skip trailers
83  const int trailerLen = 4;
84  pData16 += trailerLen;
85 
86  parsedLen = (pData16 - begin16) / 4;
87 
88  if ((pData16 - begin16) != (4 * fragLen)) {
89  error |= errorLength;
90  }
91 
92  if ((size_t)(pData16 - begin16) > maxSize) {
93  throw std::runtime_error(std::string("Corrupted or truncated data"));
94  }
95 
96  //some checks
97  if (getBoe() != 0x5) {
99  }
100 }
101 
102 int MatacqTBRawEvent::read32(const uint32le_t* pData, field32spec_t spec32) const {
103  int result = pData[spec32.offset] & spec32.mask;
104  int mask = spec32.mask;
105  while ((mask & 0x1) == 0) {
106  mask >>= 1;
107  result >>= 1;
108  }
109  return result;
110 }
static const field32spec_t lv132
static const field32spec_t fov32
static const field32spec_t boeType32
static const field32spec_t runNum32
std::vector< ChannelData > channelData
int read32(const uint32le_t *pData, field32spec_t spec) const
int getMatacqDataFormatVersion() const
const uint32le_t * daqHeader
static const field32spec_t triggerType32
static const field32spec_t h1Marker32
int getBoe() const
static const field32spec_t bxId32
const matacqHeader_t * matacqHeader
static const field32spec_t dccLen32
void setRawData(const unsigned char *buffer, std::size_t bufferSize)
static const field32spec_t fedId32
int getChannelCount() const
static const field32spec_t dccErrors32