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  * $Id: MatacqRawEvent.cc,v 1.5 2010/08/06 20:24:29 wmtan Exp $
4  * Original author: Ph. Gras CEA/Saclay
5  */
6 
12 #include <unistd.h>
13 #include <stdlib.h>
14 #include <fstream>
15 #include <vector>
16 #include <iostream>
17 #include <iomanip>
18 #include <ctime>
19 #include <limits>
20 #include <stdexcept>
22 
23 
34 
35 void MatacqTBRawEvent::setRawData(const unsigned char* pData, size_t maxSize){
36  error = 0;
37  int16le_t* begin16 = (int16le_t*) pData;
38  int16le_t* pData16 = begin16;
39  daqHeader = (uint32le_t*) pData16;
40  const int daqHeaderLen = 16; //in bytes
41  pData16 += daqHeaderLen/sizeof(pData16[0]);
42  matacqHeader = (matacqHeader_t*) pData16;
43  pData16 += sizeof(matacqHeader_t)/sizeof(pData16[0]);
44  if(getMatacqDataFormatVersion()>=2){//trigger position present
45  tTrigPs = *((int32_t*) pData16);
46  pData16 += 2;
47  } else{
49  }
50  const int nCh = getChannelCount();
51  channelData.resize(nCh);
52  for(int iCh=0; iCh<nCh; ++iCh){
53  //channel id:
54  channelData[iCh].chId = *(pData16++);
55  //number of time samples for this channel:
56  channelData[iCh].nSamples = *(pData16++);
57  //pointer to time sample data of this channel:
58  channelData[iCh].samples = pData16;
59  //moves to next channel data block:
60  pData16 += channelData[iCh].nSamples;
61  }
62 
63  //data trailer chekes:
64  //FED header is aligned on 64-bit=>padding to skip
65  int padding = (4-(pData16-begin16))%4;
66  if(padding<0) padding+=4;
67  pData16 += padding;
68  uint32le_t* trailer32 = (uint32le_t*)(pData16);
69  fragLen = trailer32[1]&0xFFFFFF;
70 
71  //std::cout << "Event fragment length including headers: " << fragLen
72  // << " 64-bit words\n";
73 
74  //FIXME: I am expecting the event length specifies in the header to
75  //include the header, while it is not the case in current TB 2006 data
76  const int nHeaders = 3;
77  if(fragLen!=read32(daqHeader,dccLen32)+nHeaders
79  //std::cout << "Error: fragment length is not consistent with DCC "
80  // "length\n";
82  }
83 
84  //skip trailers
85  const int trailerLen = 4;
86  pData16 += trailerLen;
87 
88  parsedLen = (pData16-begin16) / 4;
89 
90  if((pData16-begin16)!=(4*fragLen)){
91  error |= errorLength;
92  }
93 
94  if((size_t)(pData16-begin16)>maxSize){
95  throw std::runtime_error(std::string("Corrupted or truncated data"));
96  }
97 
98  //some checks
99  if(getBoe()!=0x5){
100  error |= errorWrongBoe;
101  }
102 }
103 
105  int result = pData[spec32.offset] & spec32.mask;
106  int mask = spec32.mask;
107  while((mask&0x1) == 0){
108  mask >>= 1;
109  result >>= 1;
110  }
111  return result;
112 }
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
static const field32spec_t runNum32
std::vector< ChannelData > channelData
const T & max(const T &a, const T &b)
tuple maxSize
&#39;/store/data/Commissioning08/BeamHalo/RECO/StuffAlmostToP5_v1/000/061/642/10A0FE34-A67D-DD11-AD05-000...
int getMatacqDataFormatVersion() const
int getBoe() const
tuple result
Definition: query.py:137
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