test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Public Member Functions | Private Member Functions | Private Attributes
Phase2Tracker::Phase2TrackerFEDBuffer Class Reference

#include <Phase2TrackerFEDBuffer.h>

Public Member Functions

size_t bufferSize () const
 
const Phase2TrackerFEDChannelchannel (const uint8_t internalPhase2TrackerFEDChannelNum) const
 
bool checkNoFEOverflows () const
 
std::map< uint32_t, uint32_t > conditionData () const
 
uint16_t daqBXID () const
 
uint16_t daqCRC () const
 
uint32_t daqEventLengthIn64bitWords () const
 
uint32_t daqEventLengthInBytes () const
 
FEDDAQEventType daqEventType () const
 
FEDDAQHeader daqHeader () const
 
uint32_t daqLvl1ID () const
 
uint16_t daqSourceID () const
 
FEDDAQTrailer daqTrailer () const
 
FEDTTSBits daqTTSState () const
 
bool doChecks () const
 
bool doCorruptBufferChecks () const
 
void dump (std::ostream &os) const
 
const uint8_t * getPointerToCondData () const
 
const uint8_t * getPointerToPayload () const
 
const uint8_t * getPointerToTriggerData () const
 
 Phase2TrackerFEDBuffer (const uint8_t *fedBuffer, const size_t fedBufferSize)
 
FEDReadoutMode readoutMode () const
 
Phase2TrackerFEDHeader trackerHeader () const
 
 ~Phase2TrackerFEDBuffer ()
 

Private Member Functions

void findChannels ()
 

Private Attributes

const uint8_t * buffer_
 
const size_t bufferSize_
 
std::vector
< Phase2TrackerFEDChannel
channels_
 
const uint8_t * condDataPointer_
 
FEDDAQHeader daqHeader_
 
FEDDAQTrailer daqTrailer_
 
const uint8_t * payloadPointer_
 
Phase2TrackerFEDHeader trackerHeader_
 
const uint8_t * triggerPointer_
 

Detailed Description

Definition at line 14 of file Phase2TrackerFEDBuffer.h.

Constructor & Destructor Documentation

Phase2Tracker::Phase2TrackerFEDBuffer::Phase2TrackerFEDBuffer ( const uint8_t *  fedBuffer,
const size_t  fedBufferSize 
)

Definition at line 10 of file Phase2TrackerFEDBuffer.cc.

References buffer_, bufferSize_, channels_, daqHeader_, daqTrailer_, TauDecayModes::dec, findChannels(), getPointerToPayload(), i, LogTrace, Phase2Tracker::MAX_CBC_PER_FE, Phase2Tracker::MAX_FE_PER_FED, payloadPointer_, Phase2Tracker::read64(), and trackerHeader_.

11  : buffer_(fedBuffer),
12  bufferSize_(fedBufferSize)
13  {
14 
15  LogTrace("Phase2TrackerFEDBuffer") << "content of buffer with size: "<<int(fedBufferSize)<<std::endl;
16  for ( size_t i = 0; i < fedBufferSize; i += 8)
17  {
18  uint64_t word = read64(i,buffer_);
19  LogTrace("Phase2TrackerFEDBuffer") << " word " << std::setfill(' ') << std::setw(2) << i/8 << " | "
20  << std::hex << std::setw(16) << std::setfill('0') << word << std::dec << std::endl;
21  }
22  LogTrace("Phase2TrackerFEDBuffer") << std::endl;
23 
24  // reserve all channels (should be 16x16 in our case)
26  // first 64 bits word is for DAQ header
27  daqHeader_ = FEDDAQHeader(buffer_);
28  // last 64 bit word is daq trailer
29  daqTrailer_ = FEDDAQTrailer(buffer_+bufferSize_-8);
30  // tracker header follows daq header
31  trackerHeader_ = Phase2TrackerFEDHeader(buffer_+8);
32  // get pointer to payload
34  // fill list of Phase2TrackerFEDChannels and get pointers to trigger and comissioning data
35  findChannels();
36  }
int i
Definition: DBlmapReader.cc:9
static const int MAX_CBC_PER_FE
Definition: utils.h:25
#define LogTrace(id)
std::vector< Phase2TrackerFEDChannel > channels_
unsigned long long uint64_t
Definition: Time.h:15
static const int MAX_FE_PER_FED
Definition: utils.h:24
uint64_t read64(int offset, const uint8_t *buffer)
Definition: utils.h:197
Phase2Tracker::Phase2TrackerFEDBuffer::~Phase2TrackerFEDBuffer ( )

Definition at line 38 of file Phase2TrackerFEDBuffer.cc.

39  {
40  }

Member Function Documentation

size_t Phase2Tracker::Phase2TrackerFEDBuffer::bufferSize ( ) const
inline
const Phase2TrackerFEDChannel& Phase2Tracker::Phase2TrackerFEDBuffer::channel ( const uint8_t  internalPhase2TrackerFEDChannelNum) const
inline

Definition at line 29 of file Phase2TrackerFEDBuffer.h.

References channels_.

Referenced by Phase2Tracker::Phase2TrackerDigiProducer::produce().

29 { return channels_[internalPhase2TrackerFEDChannelNum]; }
std::vector< Phase2TrackerFEDChannel > channels_
bool Phase2Tracker::Phase2TrackerFEDBuffer::checkNoFEOverflows ( ) const
inline

Definition at line 66 of file Phase2TrackerFEDBuffer.h.

66 { return true; } // FEDBufferBase
std::map< uint32_t, uint32_t > Phase2Tracker::Phase2TrackerFEDBuffer::conditionData ( ) const

Definition at line 164 of file Phase2TrackerFEDBuffer.cc.

References buffer_, bufferSize_, condDataPointer_, AlCaHLTBitMon_QueryRunRegistry::data, Exception, i, j, relval_steps::key, LogTrace, findQualityFiles::size, contentValuesCheck::ss, Phase2Tracker::TRIGGER_SIZE, and triggerPointer_.

Referenced by Phase2Tracker::Phase2TrackerCommissioningDigiProducer::produce().

165  {
166  std::map<uint32_t,uint32_t> cdata;
167  // check if there is condition data
168  if(condDataPointer_)
169  {
170  const uint8_t* pointer = condDataPointer_;
171  const uint8_t* stop = buffer_ + bufferSize_ - 8;
172  // first read the size
173  uint32_t size = 0;
174  // somehow the size is not inverted
175  //for (int i=0;i<4;++i) size += *(pointer-4+(i^7)) << (i*8);
176  size = *reinterpret_cast<const uint32_t* >(pointer);
177  LogTrace("Phase2TrackerFEDBuffer") << "Condition Data size = " << size << std::endl;
178  pointer+=8;
179  // now the conditions
180  while(pointer < stop)
181  {
182  // somehow the data is not inverted
183  uint32_t data = 0;
184  //for (int i = 0, j=3 ; i<4; i++,j--)
185  //{ data += (*(pointer+i) << j*8); }
186  data = *reinterpret_cast<const uint32_t*>(pointer);
187  pointer += 4;
188 
189  uint32_t key = 0;
190  for (int i = 0, j=3 ; i<4; i++,j--)
191  { key += (*(pointer+i) << j*8); }
192  pointer += 4;
193 
194  cdata[key] = data;
195  }
196  // final check: cdata size == size
197  if(cdata.size()!=size) {
198  std::ostringstream ss;
199  ss << "[Phase2Tracker::Phase2TrackerFEDBuffer::"<<__func__<<"] " << "\n";
200  ss << "Number of condition data does not match the announced value!"<< "\n";
201  ss << "Expected condition data Size " << size << " entries" << "\n";
202  ss << "Computed condition data Size " << cdata.size() << " entries" << "\n";
203  throw cms::Exception("Phase2TrackerFEDBuffer") << ss.str();
204  }
205  }
206  // REMOVE THIS : inject fake cond data for tests
207  /*
208  cdata[0x0011] = 0x0001;
209  cdata[0x0012] = 0x0002;
210  */
211  // add trigger data
212  cdata[0x0B0000FF] = (TRIGGER_SIZE>0) ? (*triggerPointer_) : 0x00000000;
213  return cdata;
214 
215  }
int i
Definition: DBlmapReader.cc:9
static const int TRIGGER_SIZE
Definition: utils.h:28
int j
Definition: DBlmapReader.cc:9
string key
FastSim: produces sample of signal events, overlayed with premixed minbias events.
#define LogTrace(id)
tuple size
Write out results.
uint16_t Phase2Tracker::Phase2TrackerFEDBuffer::daqBXID ( ) const
inline
uint16_t Phase2Tracker::Phase2TrackerFEDBuffer::daqCRC ( ) const
inline
uint32_t Phase2Tracker::Phase2TrackerFEDBuffer::daqEventLengthIn64bitWords ( ) const
inline
uint32_t Phase2Tracker::Phase2TrackerFEDBuffer::daqEventLengthInBytes ( ) const
inline
FEDDAQEventType Phase2Tracker::Phase2TrackerFEDBuffer::daqEventType ( ) const
inline
FEDDAQHeader Phase2Tracker::Phase2TrackerFEDBuffer::daqHeader ( ) const
inline

Definition at line 25 of file Phase2TrackerFEDBuffer.h.

References daqHeader_.

uint32_t Phase2Tracker::Phase2TrackerFEDBuffer::daqLvl1ID ( ) const
inline
uint16_t Phase2Tracker::Phase2TrackerFEDBuffer::daqSourceID ( ) const
inline
FEDDAQTrailer Phase2Tracker::Phase2TrackerFEDBuffer::daqTrailer ( ) const
inline

Definition at line 26 of file Phase2TrackerFEDBuffer.h.

References daqTrailer_.

FEDTTSBits Phase2Tracker::Phase2TrackerFEDBuffer::daqTTSState ( ) const
inline
bool Phase2Tracker::Phase2TrackerFEDBuffer::doChecks ( ) const
inline

Definition at line 65 of file Phase2TrackerFEDBuffer.h.

65 { return true; } // FEDBuffer
bool Phase2Tracker::Phase2TrackerFEDBuffer::doCorruptBufferChecks ( ) const
inline

Definition at line 67 of file Phase2TrackerFEDBuffer.h.

67 { return true; } // FEDBuffer
void Phase2Tracker::Phase2TrackerFEDBuffer::dump ( std::ostream &  os) const
inline

Definition at line 22 of file Phase2TrackerFEDBuffer.h.

References buffer_, bufferSize_, and Phase2Tracker::printHex().

void printHex(const void *pointer, const size_t lengthInBytes, std::ostream &os)
Definition: utils.h:60
void Phase2Tracker::Phase2TrackerFEDBuffer::findChannels ( )
private

Definition at line 42 of file Phase2TrackerFEDBuffer.cc.

References bufferSize_, channels_, condDataPointer_, Exception, Phase2Tracker::Phase2TrackerFEDHeader::frontendStatus(), Phase2Tracker::Phase2TrackerFEDHeader::getConditionData(), Phase2Tracker::Phase2TrackerFEDHeader::getTrackerHeaderSize(), i, Phase2Tracker::MAX_CBC_PER_FE, NULL, payloadPointer_, Phase2Tracker::READOUT_MODE_PROC_RAW, Phase2Tracker::READOUT_MODE_ZERO_SUPPRESSED, readoutMode(), contentValuesCheck::ss, mps_update::status, Phase2Tracker::STRIPS_PADDING, Phase2Tracker::STRIPS_PER_CBC, trackerHeader_, Phase2Tracker::TRIGGER_SIZE, and triggerPointer_.

Referenced by Phase2TrackerFEDBuffer().

43  {
44  // each FED can be connectd to up to 16 frontends (read from header)
45  // each fronted can be connected to up to 16 CBC
46  // in raw mode, a header of 16bits tells which CBC are activated on this FE
47  // in ZS mode, one byte is used to tell how many clusters are present in the current CBC
48  // one channel corresponds to one CBC chip, undependently of the mode
49 
50  // offset of beginning of current channel
51  size_t offsetBeginningOfChannel = 0;
52 
53  // iterate over all FEs to see if they are active
54  std::vector<bool>::iterator FE_it;
55  std::vector<bool> status = trackerHeader_.frontendStatus();
56 
58  {
59  for (FE_it = status.begin(); FE_it < status.end(); FE_it++)
60  {
61  // if the current fronted is on, fill channels and advance pointer to end of channel
62  if(*FE_it)
63  {
64  // read first FEDCH_PER_FEUNIT bits to know which CBC are on
65  uint16_t cbc_status = static_cast<uint16_t>(*(payloadPointer_ + (offsetBeginningOfChannel^7))<<8);
66  cbc_status += static_cast<uint16_t>(*(payloadPointer_ + ((offsetBeginningOfChannel + 1)^7)));
67 
68  // advance pointer by FEDCH_PER_FEUNIT bits
69  offsetBeginningOfChannel += MAX_CBC_PER_FE/8;
70  for (int i=0; i<MAX_CBC_PER_FE; i++)
71  {
72  // if CBC is ON, fill channel and advance pointer. else, push back empty channel
73  if((cbc_status>>i)&0x1)
74  {
75  // Warning: STRIPS_PADDING+STRIPS_PER_CBC should always be an entire number of bytes
76  channels_.push_back(Phase2TrackerFEDChannel(payloadPointer_,offsetBeginningOfChannel,(STRIPS_PADDING+STRIPS_PER_CBC)/8));
77  offsetBeginningOfChannel += (STRIPS_PADDING+STRIPS_PER_CBC)/8;
78  }
79  else
80  {
81  channels_.push_back(Phase2TrackerFEDChannel(NULL,0,0));
82  }
83  }
84  }
85  else
86  {
87  // else fill with FEDCH_PER_FEUNIT null channels, don't advance the channel pointer
88  channels_.insert(channels_.end(),size_t(MAX_CBC_PER_FE),Phase2TrackerFEDChannel(payloadPointer_,0,0));
89  }
90  }
91  }
93  {
94  for (FE_it = status.begin(); FE_it < status.end(); FE_it++)
95  {
96  if(*FE_it)
97  {
98  for (int i=0; i<MAX_CBC_PER_FE; i++)
99  {
100  // read first byte to get number of clusters and skip it
101  uint8_t n_clusters = static_cast<uint8_t> (*(payloadPointer_ + offsetBeginningOfChannel));
102  offsetBeginningOfChannel += 1;
103  // each channel contains 2 bytes per cluster
104  channels_.push_back(Phase2TrackerFEDChannel(payloadPointer_,offsetBeginningOfChannel,2*n_clusters));
105  // skip clusters
106  offsetBeginningOfChannel += 2*n_clusters;
107  }
108  }
109  else
110  {
111  // else fill with FEDCH_PER_FEUNIT null channels, don't advance the channel pointer
112  channels_.insert(channels_.end(),size_t(MAX_CBC_PER_FE),Phase2TrackerFEDChannel(payloadPointer_,0,0));
113  }
114  }
115  }
116  else
117  {
118  // TODO: throw exception for unrecognised readout mode
119  // check done at Phase2TrackerFEDHeader::readoutMode()
120  }
121  // round the offset to the next 64 bits word
122  int words64 = (offsetBeginningOfChannel + 8 - 1)/8; // size in 64 bit
123  int payloadSize = words64 * 8; // size in bytes
124  triggerPointer_ = payloadPointer_ + payloadSize;
125 
126  // get diff size in bytes:
127  // fedBufferSize - (DAQHeader+TrackHeader+PayloadSize+TriggerSize+DAQTrailer)
128  int bufferDiff = bufferSize_ - 8 - trackerHeader_.getTrackerHeaderSize()
129  - payloadSize - TRIGGER_SIZE - 8;
130 
131  // check if condition data is supposed to be there:
133  {
135  // diff must be equal to condition data size
136  if (bufferDiff <= 0)
137  {
138  std::ostringstream ss;
139  ss << "[Phase2Tracker::Phase2TrackerFEDBuffer::"<<__func__<<"] " << "\n";
140  ss << "FED Buffer Size does not match data => missing condition data? : " << "\n";
141  ss << "Expected Buffer Size " << bufferSize_ << " bytes" << "\n";
142  ss << "Computed Buffer Size " << bufferSize_ + bufferDiff << " bytes" << "\n";
143  throw cms::Exception("Phase2TrackerFEDBuffer") << ss.str();
144  }
145  }
146  else
147  {
148  // put a null pointer to indicate lack of condition data
149  condDataPointer_ = 0;
150  // check buffer size :
151  if (bufferDiff != 0)
152  {
153  std::ostringstream ss;
154  ss << "[Phase2Tracker::Phase2TrackerFEDBuffer::"<<__func__<<"] " << "\n";
155  ss << "FED Buffer Size does not match data => corrupted buffer? : " << "\n";
156  ss << "Expected Buffer Size " << bufferSize_ << " bytes" << "\n";
157  ss << "Computed Buffer Size " << bufferSize_ + bufferDiff << " bytes" << "\n";
158  throw cms::Exception("Phase2TrackerFEDBuffer") << ss.str();
159  }
160  }
161 
162  }
int i
Definition: DBlmapReader.cc:9
static const int TRIGGER_SIZE
Definition: utils.h:28
#define NULL
Definition: scimark2.h:8
std::vector< bool > frontendStatus() const
static const int MAX_CBC_PER_FE
Definition: utils.h:25
std::vector< Phase2TrackerFEDChannel > channels_
static const int STRIPS_PER_CBC
Definition: utils.h:26
static const int STRIPS_PADDING
Definition: utils.h:27
tuple status
Definition: mps_update.py:57
const uint8_t* Phase2Tracker::Phase2TrackerFEDBuffer::getPointerToCondData ( ) const
inline

Definition at line 47 of file Phase2TrackerFEDBuffer.h.

References condDataPointer_.

const uint8_t* Phase2Tracker::Phase2TrackerFEDBuffer::getPointerToPayload ( ) const
inline
const uint8_t* Phase2Tracker::Phase2TrackerFEDBuffer::getPointerToTriggerData ( ) const
inline

Definition at line 48 of file Phase2TrackerFEDBuffer.h.

References triggerPointer_.

FEDReadoutMode Phase2Tracker::Phase2TrackerFEDBuffer::readoutMode ( ) const

Definition at line 217 of file Phase2TrackerFEDBuffer.cc.

References Phase2Tracker::Phase2TrackerFEDHeader::getReadoutMode(), and trackerHeader_.

Referenced by findChannels().

218  {
220  }
Phase2TrackerFEDHeader Phase2Tracker::Phase2TrackerFEDBuffer::trackerHeader ( ) const
inline

Definition at line 28 of file Phase2TrackerFEDBuffer.h.

References trackerHeader_.

Referenced by Phase2Tracker::Phase2TrackerDigiProducer::produce().

28 { return trackerHeader_; }

Member Data Documentation

const uint8_t* Phase2Tracker::Phase2TrackerFEDBuffer::buffer_
private

Definition at line 51 of file Phase2TrackerFEDBuffer.h.

Referenced by conditionData(), dump(), and Phase2TrackerFEDBuffer().

const size_t Phase2Tracker::Phase2TrackerFEDBuffer::bufferSize_
private
std::vector<Phase2TrackerFEDChannel> Phase2Tracker::Phase2TrackerFEDBuffer::channels_
private

Definition at line 53 of file Phase2TrackerFEDBuffer.h.

Referenced by channel(), findChannels(), and Phase2TrackerFEDBuffer().

const uint8_t* Phase2Tracker::Phase2TrackerFEDBuffer::condDataPointer_
private

Definition at line 58 of file Phase2TrackerFEDBuffer.h.

Referenced by conditionData(), findChannels(), and getPointerToCondData().

FEDDAQHeader Phase2Tracker::Phase2TrackerFEDBuffer::daqHeader_
private
FEDDAQTrailer Phase2Tracker::Phase2TrackerFEDBuffer::daqTrailer_
private
const uint8_t* Phase2Tracker::Phase2TrackerFEDBuffer::payloadPointer_
private

Definition at line 57 of file Phase2TrackerFEDBuffer.h.

Referenced by findChannels(), and Phase2TrackerFEDBuffer().

Phase2TrackerFEDHeader Phase2Tracker::Phase2TrackerFEDBuffer::trackerHeader_
private
const uint8_t* Phase2Tracker::Phase2TrackerFEDBuffer::triggerPointer_
private

Definition at line 59 of file Phase2TrackerFEDBuffer.h.

Referenced by conditionData(), findChannels(), and getPointerToTriggerData().