CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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 <stdlib.h>
13 #include <fstream>
14 #include <vector>
15 #include <iostream>
16 #include <iomanip>
17 #include <ctime>
18 #include <limits>
19 #include <stdexcept>
21 
22 
33 
34 void MatacqTBRawEvent::setRawData(const unsigned char* pData, size_t maxSize){
35  error = 0;
36  int16le_t* begin16 = (int16le_t*) pData;
37  int16le_t* pData16 = begin16;
38  daqHeader = (uint32le_t*) pData16;
39  const int daqHeaderLen = 16; //in bytes
40  pData16 += daqHeaderLen/sizeof(pData16[0]);
41  matacqHeader = (matacqHeader_t*) pData16;
42  pData16 += sizeof(matacqHeader_t)/sizeof(pData16[0]);
43  if(getMatacqDataFormatVersion()>=2){//trigger position present
44  tTrigPs = *((int32_t*) pData16);
45  pData16 += 2;
46  } else{
48  }
49  const int nCh = getChannelCount();
50  channelData.resize(nCh);
51  for(int iCh=0; iCh<nCh; ++iCh){
52  //channel id:
53  channelData[iCh].chId = *(pData16++);
54  //number of time samples for this channel:
55  channelData[iCh].nSamples = *(pData16++);
56  //pointer to time sample data of this channel:
57  channelData[iCh].samples = pData16;
58  //moves to next channel data block:
59  pData16 += channelData[iCh].nSamples;
60  }
61 
62  //data trailer chekes:
63  //FED header is aligned on 64-bit=>padding to skip
64  int padding = (4-(pData16-begin16))%4;
65  if(padding<0) padding+=4;
66  pData16 += padding;
67  uint32le_t* trailer32 = (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
78  //std::cout << "Error: fragment length is not consistent with DCC "
79  // "length\n";
81  }
82 
83  //skip trailers
84  const int trailerLen = 4;
85  pData16 += trailerLen;
86 
87  parsedLen = (pData16-begin16) / 4;
88 
89  if((pData16-begin16)!=(4*fragLen)){
90  error |= errorLength;
91  }
92 
93  if((size_t)(pData16-begin16)>maxSize){
94  throw std::runtime_error(std::string("Corrupted or truncated data"));
95  }
96 
97  //some checks
98  if(getBoe()!=0x5){
100  }
101 }
102 
104  int result = pData[spec32.offset] & spec32.mask;
105  int mask = spec32.mask;
106  while((mask&0x1) == 0){
107  mask >>= 1;
108  result >>= 1;
109  }
110  return result;
111 }
static const field32spec_t lv132
static const field32spec_t fov32
void setRawData(const unsigned char *buffer, size_t bufferSize)
int read32(uint32le_t *pData, field32spec_t spec) const
static const field32spec_t boeType32
uint32le_t * daqHeader
int getChannelCount() const
tuple result
Definition: mps_fire.py:84
static const field32spec_t runNum32
std::vector< ChannelData > channelData
tuple maxSize
&#39;/store/data/Commissioning08/BeamHalo/RECO/StuffAlmostToP5_v1/000/061/642/10A0FE34-A67D-DD11-AD05-000...
int getMatacqDataFormatVersion() const
int getBoe() const
static const field32spec_t triggerType32
matacqHeader_t * matacqHeader
static const field32spec_t h1Marker32
static const field32spec_t bxId32
static const field32spec_t dccLen32
static const field32spec_t fedId32
static const field32spec_t dccErrors32