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 }
MatacqTBRawEvent::bxId32
static const field32spec_t bxId32
Definition: MatacqRawEvent.h:96
MatacqTBRawEvent::fragLen
int fragLen
Definition: MatacqRawEvent.h:289
MatacqTBRawEvent::fov32
static const field32spec_t fov32
Definition: MatacqRawEvent.h:94
MatacqTBRawEvent::fedId32
static const field32spec_t fedId32
Definition: MatacqRawEvent.h:95
MatacqTBRawEvent::h1Marker32
static const field32spec_t h1Marker32
Definition: MatacqRawEvent.h:103
MatacqTBRawEvent::int16le_t
Definition: MatacqRawEvent.h:57
MatacqTBRawEvent::setRawData
void setRawData(const unsigned char *buffer, std::size_t bufferSize)
Definition: MatacqRawEvent.cc:33
MatacqTBRawEvent::getChannelCount
int getChannelCount() const
Definition: MatacqRawEvent.h:196
MatacqTBRawEvent::read32
int read32(const uint32le_t *pData, field32spec_t spec) const
Definition: MatacqRawEvent.cc:102
MatacqTBRawEvent::dccLen32
static const field32spec_t dccLen32
Definition: MatacqRawEvent.h:100
MatacqTBRawEvent::field32spec_t::offset
int offset
Definition: MatacqRawEvent.h:88
MatacqTBRawEvent::matacqHeader
const matacqHeader_t * matacqHeader
Definition: MatacqRawEvent.h:301
MatacqTBRawEvent::errorWrongBoe
Definition: MatacqRawEvent.h:40
MatacqTBRawEvent::dccErrors32
static const field32spec_t dccErrors32
Definition: MatacqRawEvent.h:101
testProducerWithPsetDescEmpty_cfi.x1
x1
Definition: testProducerWithPsetDescEmpty_cfi.py:33
MatacqTBRawEvent::lv132
static const field32spec_t lv132
Definition: MatacqRawEvent.h:97
MatacqTBRawEvent::daqHeader
const uint32le_t * daqHeader
Definition: MatacqRawEvent.h:261
MatacqTBRawEvent::field32spec_t
Definition: MatacqRawEvent.h:87
MatacqTBRawEvent::parsedLen
int parsedLen
Definition: MatacqRawEvent.h:309
MatacqTBRawEvent::runNum32
static const field32spec_t runNum32
Definition: MatacqRawEvent.h:102
SiStripPI::max
Definition: SiStripPayloadInspectorHelper.h:169
MatacqRawEvent.h
MatacqTBRawEvent::channelData
std::vector< ChannelData > channelData
Definition: MatacqRawEvent.h:257
MatacqTBRawEvent::boeType32
static const field32spec_t boeType32
Definition: MatacqRawEvent.h:99
MatacqTBRawEvent::error
int32_t error
Definition: MatacqRawEvent.h:277
AlCaHLTBitMon_QueryRunRegistry.string
string string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
MatacqTBRawEvent::getMatacqDataFormatVersion
int getMatacqDataFormatVersion() const
Definition: MatacqRawEvent.h:180
reco_skim_cfg_mod.maxSize
maxSize
Definition: reco_skim_cfg_mod.py:154
MatacqTBRawEvent::tTrigPs
int tTrigPs
Definition: MatacqRawEvent.h:325
MatacqTBRawEvent::triggerType32
static const field32spec_t triggerType32
Definition: MatacqRawEvent.h:98
MatacqTBRawEvent::errorLengthConsistency
Definition: MatacqRawEvent.h:34
MatacqTBRawEvent::matacqHeader_t
Definition: MatacqRawEvent.h:78
MatacqTBRawEvent::errorLength
Definition: MatacqRawEvent.h:37
mps_fire.result
result
Definition: mps_fire.py:311
MatacqTBRawEvent::uint32le_t
Definition: MatacqRawEvent.h:47
MatacqTBRawEvent::getBoe
int getBoe() const
Definition: MatacqRawEvent.h:150
MatacqTBRawEvent::field32spec_t::mask
unsigned int mask
Definition: MatacqRawEvent.h:89