CMS 3D CMS Logo

List of all members | Classes | Public Types | Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes
CTPPSPixelDataFormatter Class Reference

#include <CTPPSPixelDataFormatter.h>

Classes

struct  PPSPixelIndex
 

Public Types

typedef edm::DetSetVector< CTPPSPixelDigiCollection
 
typedef std::vector< CTPPSPixelDigiDetDigis
 
typedef std::vector< CTPPSPixelDataErrorDetErrors
 
typedef std::unordered_map< cms_uint32_t, DetDigisDigis
 
typedef std::map< uint32_t, DetErrorsErrors
 
typedef std::unordered_map< int, FEDRawDataRawData
 
typedef uint32_t Word32
 
typedef uint64_t Word64
 

Public Member Functions

 CTPPSPixelDataFormatter (std::map< CTPPSPixelFramePosition, CTPPSPixelROCInfo > const &mapping)
 
void formatRawData (unsigned int lvl1_ID, RawData &fedRawData, const Digis &digis, std::vector< PPSPixelIndex > v_iDdet2fed)
 
void interpretRawData (bool &errorsInEvent, int fedId, const FEDRawData &data, Collection &digis, Errors &errors)
 
int nDigis () const
 
int nWords () const
 
void setErrorStatus (bool theErrorStatus)
 

Static Public Member Functions

static bool compare (const PPSPixelIndex &a, const PPSPixelIndex &b)
 

Private Member Functions

int checkError (const Word32 &data) const
 
std::string print (const Word64 &word) const
 

Private Attributes

Word32 m_ADC_mask
 
int m_ADC_shift
 
int m_allDetDigis
 
Word32 m_DCOL_mask
 
int m_DCOL_shift
 
int m_DigiCounter
 
RPixErrorChecker m_ErrorCheck
 
int m_hasDetDigis
 
bool m_IncludeErrors
 
CTPPSPixelIndices m_Indices
 
Word32 m_LINK_mask
 
int m_LINK_shift
 
const std::map< CTPPSPixelFramePosition, CTPPSPixelROCInfo > & m_Mapping
 
Word32 m_PXID_mask
 
int m_PXID_shift
 
Word32 m_ROC_mask
 
int m_ROC_shift
 
int m_WordCounter
 

Detailed Description

Transform CTPPSPixel raw data of a given FED to digi

FED OUTPUT DATA FORMAT (F.Ferro from SiPixel code)

The output is transmitted through a 64 bit S-link connection. The packet format is defined by the CMS RU group to be : 1st packet header, 64 bits, includes a 6 bit FED id. 2nd packet header, 64 bits. .......................... (detector data) packet trailer, 64 bits. of the 64 bit pixel data records consists of 2 32 bit words. Each 32 bit word includes data from 1 pixel, the bit fields are the following:

6 bit link ID (max 36) - this defines the input link within 1 FED. 5 bit ROC ID (max 24) - this defines the readout chip within one link. 5 bit DCOL ID (max 26) - this defines the double column index with 1 chip. 8 bit pixel ID (max 180) - this defines the pixel address within 1 DCOL. 8 bit ADC vales - this has the charge amplitude.

So, 1 pixel occupies 4 bytes. If the number of pixels is odd, one extra 32 bit word is added (value 0) to fill all 64 bits.

The CTPPSPixelDataFormatter interpret/format ONLY detector data words (not FED headers or trailer, which are treated elsewhere).

Definition at line 53 of file CTPPSPixelDataFormatter.h.

Member Typedef Documentation

Definition at line 55 of file CTPPSPixelDataFormatter.h.

Definition at line 58 of file CTPPSPixelDataFormatter.h.

Definition at line 60 of file CTPPSPixelDataFormatter.h.

Definition at line 66 of file CTPPSPixelDataFormatter.h.

typedef std::map<uint32_t, DetErrors> CTPPSPixelDataFormatter::Errors

Definition at line 61 of file CTPPSPixelDataFormatter.h.

typedef std::unordered_map<int, FEDRawData> CTPPSPixelDataFormatter::RawData

Definition at line 57 of file CTPPSPixelDataFormatter.h.

Definition at line 63 of file CTPPSPixelDataFormatter.h.

Definition at line 64 of file CTPPSPixelDataFormatter.h.

Constructor & Destructor Documentation

CTPPSPixelDataFormatter::CTPPSPixelDataFormatter ( std::map< CTPPSPixelFramePosition, CTPPSPixelROCInfo > const &  mapping)

Definition at line 33 of file CTPPSPixelDataFormatter.cc.

References m_ADC_mask, m_ADC_shift, m_DCOL_mask, m_DCOL_shift, m_LINK_mask, m_LINK_shift, m_PXID_mask, m_PXID_shift, m_ROC_mask, and m_ROC_shift.

35  int s32 = sizeof(Word32);
36  int s64 = sizeof(Word64);
37  int s8 = sizeof(char);
38  if (s8 != 1 || s32 != 4 * s8 || s64 != 2 * s32) {
39  LogError("UnexpectedSizes") << " unexpected sizes: "
40  << " size of char is: " << s8 << ", size of Word32 is: " << s32
41  << ", size of Word64 is: " << s64 << ", send exception";
42  }
43 
44  m_ADC_shift = 0;
45  m_PXID_shift = m_ADC_shift + m_ADC_bits;
46  m_DCOL_shift = m_PXID_shift + m_PXID_bits;
47  m_ROC_shift = m_DCOL_shift + m_DCOL_bits;
48 
49  m_LINK_shift = m_ROC_shift + m_ROC_bits;
50  m_LINK_mask = ~(~CTPPSPixelDataFormatter::Word32(0) << m_LINK_bits);
51  m_ROC_mask = ~(~CTPPSPixelDataFormatter::Word32(0) << m_ROC_bits);
52 
53  m_DCOL_mask = ~(~CTPPSPixelDataFormatter::Word32(0) << m_DCOL_bits);
54  m_PXID_mask = ~(~CTPPSPixelDataFormatter::Word32(0) << m_PXID_bits);
55  m_ADC_mask = ~(~CTPPSPixelDataFormatter::Word32(0) << m_ADC_bits);
56 }
const std::map< CTPPSPixelFramePosition, CTPPSPixelROCInfo > & m_Mapping

Member Function Documentation

int CTPPSPixelDataFormatter::checkError ( const Word32 data) const
private
static bool CTPPSPixelDataFormatter::compare ( const PPSPixelIndex a,
const PPSPixelIndex b 
)
inlinestatic

Definition at line 91 of file CTPPSPixelDataFormatter.h.

References CTPPSPixelDataFormatter::PPSPixelIndex::id, and CTPPSPixelDataFormatter::PPSPixelIndex::roc.

Referenced by formatRawData(), and CTPPSPixelDigiToRaw::produce().

91  {
92  return a.id < b.id || (a.id == b.id && a.roc < b.roc);
93  }
double b
Definition: hdecay.h:118
double a
Definition: hdecay.h:119
void CTPPSPixelDataFormatter::formatRawData ( unsigned int  lvl1_ID,
RawData fedRawData,
const Digis digis,
std::vector< PPSPixelIndex v_iDdet2fed 
)

Definition at line 190 of file CTPPSPixelDataFormatter.cc.

References compare(), pps::pixel::ElectronicIndex::dcol, CTPPSPixelIndices::DColumn(), Exception, l1tstage2_dqm_sourceclient-live_cfg::fedId, mps_fire::i, pps::pixel::ElectronicIndex::link, LogDebug, LogTrace, m_ADC_shift, m_allDetDigis, m_DCOL_shift, m_hasDetDigis, m_Indices, m_LINK_shift, m_PXID_shift, m_ROC_shift, m_WordCounter, print(), pps::pixel::ElectronicIndex::pxid, FastTimerService_cff::range, l1tstage2_dqm_sourceclient-live_cfg::rawData, pps::pixel::ElectronicIndex::roc, alignCSCRings::s, FEDHeader::set(), FEDTrailer::set(), and CTPPSPixelIndices::transformToROC().

Referenced by CTPPSPixelDigiToRaw::produce().

193  {
194  std::map<int, vector<Word32> > words;
195  // translate digis into 32-bit raw words and store in map indexed by Fed
196  m_allDetDigis = 0;
197  m_hasDetDigis = 0;
198  for (auto const& im : digis) {
199  m_allDetDigis++;
200  cms_uint32_t rawId = im.first;
201 
202  const DetDigis& detDigis = im.second;
203  for (auto const& it : detDigis) {
204  int nroc = 999, nlink = 999;
205  int rocPixelRow = -1, rocPixelColumn = -1, rocID = -1;
206  int modulePixelColumn = it.column();
207  int modulePixelRow = it.row();
208 
209  m_Indices.transformToROC(modulePixelColumn, modulePixelRow, rocID, rocPixelColumn, rocPixelRow);
210  const int dcol = m_Indices.DColumn(rocPixelColumn);
211  const int pxid = 2 * (ROCSizeInX - rocPixelRow) + (rocPixelColumn % 2);
212 
213  unsigned int urocID = rocID;
214  PPSPixelIndex myTest = {rawId, urocID, 0, 0, 0};
215  // the range has always at most one element
216  auto range = std::equal_range(iDdet2fed.begin(), iDdet2fed.end(), myTest, compare);
217  if (range.first != range.second) {
218  auto i = range.first - iDdet2fed.begin();
219  nlink = iDdet2fed.at(i).fedch;
220  nroc = iDdet2fed.at(i).rocch + 1;
221 
222  pps::pixel::ElectronicIndex cabling = {nlink, nroc, dcol, pxid};
223 
224  cms_uint32_t word = (cabling.link << m_LINK_shift) | (cabling.roc << m_ROC_shift) |
225  (cabling.dcol << m_DCOL_shift) | (cabling.pxid << m_PXID_shift) | (it.adc() << m_ADC_shift);
226 
227  words[iDdet2fed.at(i).fedid].push_back(word);
228  m_WordCounter++;
229  m_hasDetDigis++;
230 
231  } // range
232  } // for DetDigis
233  } // for Digis
234 
235  LogTrace(" allDetDigis/hasDetDigis : ") << m_allDetDigis << "/" << m_hasDetDigis;
236  for (auto const& feddata : words) {
237  int fedId = feddata.first;
238 
239  // since raw words are written in the form of 64-bit packets
240  // add extra 32-bit word to make number of words even if necessary
241  if (words.find(fedId)->second.size() % 2 != 0)
242  words[fedId].push_back(Word32(0));
243 
244  // size in Bytes; create output structure
245  size_t dataSize = words.find(fedId)->second.size() * sizeof(Word32);
246  int nHeaders = 1;
247  int nTrailers = 1;
248  dataSize += (nHeaders + nTrailers) * sizeof(Word64);
249 
250  FEDRawData rawData{dataSize};
251 
252  // get begining of data;
253  Word64* word = reinterpret_cast<Word64*>(rawData.data());
254 
255  // write one header
256  FEDHeader::set(reinterpret_cast<unsigned char*>(word), 0, lvl1_ID, 0, fedId);
257  word++;
258 
259  // write data
260  unsigned int nWord32InFed = words.find(fedId)->second.size();
261  for (unsigned int i = 0; i < nWord32InFed; i += 2) {
262  *word = (Word64(words.find(fedId)->second[i]) << 32) | words.find(fedId)->second[i + 1];
263  LogDebug("CTPPSPixelDataFormatter") << print(*word);
264  word++;
265  }
266 
267  // write one trailer
268  FEDTrailer::set(reinterpret_cast<unsigned char*>(word), dataSize / sizeof(Word64), 0, 0, 0);
269  word++;
270 
271  // check memory
272  if (word != reinterpret_cast<Word64*>(rawData.data() + dataSize)) {
273  //if (word != reinterpret_cast<Word64* >(rawData->data()+dataSize)) {
274  string s = "** PROBLEM in CTPPSPixelDataFormatter !!!";
275  LogError("CTPPSPixelDataFormatter") << "** PROBLEM in CTPPSPixelDataFormatter!!!";
276  throw cms::Exception(s);
277  } // if (word !=
279  } // for (RI feddata
280 }
#define LogDebug(id)
static bool compare(const PPSPixelIndex &a, const PPSPixelIndex &b)
std::string print(const Word64 &word) const
uint64_t word
static void set(unsigned char *trailer, uint32_t lenght, uint16_t crc, uint8_t evt_stat, uint8_t tts, bool moreTrailers=false)
Set all fields in the trailer.
Definition: FEDTrailer.cc:31
uint64_t Word64
unsigned int cms_uint32_t
Definition: typedefs.h:15
#define LogTrace(id)
std::vector< CTPPSPixelDigi > DetDigis
int transformToROC(const int col, const int row, int &rocId, int &colROC, int &rowROC) const
static void set(unsigned char *header, uint8_t triggerType, uint32_t lvl1ID, uint16_t bxID, uint16_t sourceID, uint8_t version=0, bool moreHeaders=false)
Set all fields in the header.
Definition: FEDHeader.cc:25
static int DColumn(const int colROC)
void CTPPSPixelDataFormatter::interpretRawData ( bool &  errorsInEvent,
int  fedId,
const FEDRawData data,
Collection digis,
Errors errors 
)

check CRC bit

check headers

check trailers

data words

Definition at line 63 of file CTPPSPixelDataFormatter.cc.

References ecalMGPA::adc(), RPixErrorChecker::checkCRC(), RPixErrorChecker::checkHeader(), RPixErrorChecker::checkROC(), RPixErrorChecker::checkTrailer(), RPixErrorChecker::conversionError(), FEDRawData::data(), edm::DetSet< T >::data, RPixErrorChecker::dummyDetId, edm::DetSetVector< T >::find_or_insert(), RecoTauValidation_cfi::header, CTPPSPixelROCInfo::iD, InvalidLinkId, InvalidPixelId, InvalidROCId, LIKELY, MainPageGenerator::link, LogTrace, m_ADC_mask, m_ADC_shift, m_DCOL_mask, m_DCOL_shift, m_ErrorCheck, m_LINK_mask, m_LINK_shift, m_Mapping, m_PXID_mask, m_PXID_shift, m_ROC_mask, m_ROC_shift, m_WordCounter, nWords(), print(), CTPPSPixelROC::rawId(), CTPPSPixelROCInfo::roc, PixelMapPlotter::roc, FEDRawData::size(), CTPPSPixelROC::toGlobalfromDcol(), reco::Unknown, and UNLIKELY.

Referenced by nWords(), and CTPPSPixelRawToDigi::produce().

64  {
65  int nWords = rawData.size() / sizeof(Word64);
66  if (nWords == 0)
67  return;
68 
70  const Word64* trailer = reinterpret_cast<const Word64*>(rawData.data()) + (nWords - 1);
71  if (!m_ErrorCheck.checkCRC(errorsInEvent, fedId, trailer, errors))
72  return;
73 
75  const Word64* header = reinterpret_cast<const Word64*>(rawData.data());
76  header--;
77  bool moreHeaders = true;
78  while (moreHeaders) {
79  header++;
80  LogTrace("") << "HEADER: " << print(*header);
81  bool headerStatus = m_ErrorCheck.checkHeader(errorsInEvent, fedId, header, errors);
82  moreHeaders = headerStatus;
83  }
84 
86  bool moreTrailers = true;
87  trailer++;
88  while (moreTrailers) {
89  trailer--;
90  LogTrace("") << "TRAILER: " << print(*trailer);
91  bool trailerStatus = m_ErrorCheck.checkTrailer(errorsInEvent, fedId, nWords, trailer, errors);
92  moreTrailers = trailerStatus;
93  }
94 
96  m_WordCounter += 2 * (nWords - 2);
97  LogTrace("") << "data words: " << (trailer - header - 1);
98 
99  int link = -1;
100  int roc = -1;
101 
102  bool skipROC = false;
103 
104  edm::DetSet<CTPPSPixelDigi>* detDigis = nullptr;
105 
106  const Word32* bw = (const Word32*)(header + 1);
107  const Word32* ew = (const Word32*)(trailer);
108  if (*(ew - 1) == 0) {
109  ew--;
110  m_WordCounter--;
111  }
112  for (auto word = bw; word < ew; ++word) {
113  LogTrace("") << "DATA: " << print(*word);
114 
115  auto ww = *word;
116  if
117  UNLIKELY(ww == 0) {
118  m_WordCounter--;
119  continue;
120  }
121  int nlink = (ww >> m_LINK_shift) & m_LINK_mask;
122  int nroc = (ww >> m_ROC_shift) & m_ROC_mask;
123 
124  int FMC = 0;
125  uint32_t iD = RPixErrorChecker::dummyDetId; //0xFFFFFFFF; //dummyDetId
126  int convroc = nroc - 1;
127  CTPPSPixelFramePosition fPos(fedId, FMC, nlink, convroc);
128  std::map<CTPPSPixelFramePosition, CTPPSPixelROCInfo>::const_iterator mit;
129  mit = m_Mapping.find(fPos);
130 
131  if (mit == m_Mapping.end()) {
132  if (nlink >= maxLinkIndex) {
134  } else if ((nroc - 1) >= maxRocIndex) {
136  } else {
138  }
139  continue; //skip word
140  }
141 
142  CTPPSPixelROCInfo rocInfo = (*mit).second;
143  iD = rocInfo.iD;
144  CTPPSPixelROC rocp(iD, rocInfo.roc, convroc);
145 
146  if ((nlink != link) | (nroc != roc)) { // new roc
147  link = nlink;
148  roc = nroc;
149 
150  skipROC = LIKELY((roc - 1) < maxRocIndex) ? false : !m_ErrorCheck.checkROC(errorsInEvent, fedId, iD, ww, errors);
151  if (skipROC)
152  continue;
153 
154  auto rawId = rocp.rawId();
155 
156  detDigis = &digis.find_or_insert(rawId);
157  if ((*detDigis).empty())
158  (*detDigis).data.reserve(32); // avoid the first relocations
159  }
160 
161  int adc = (ww >> m_ADC_shift) & m_ADC_mask;
162 
163  int dcol = (ww >> m_DCOL_shift) & m_DCOL_mask;
164  int pxid = (ww >> m_PXID_shift) & m_PXID_mask;
165 
166  if (dcol < min_Dcol || dcol > max_Dcol || pxid < min_Pixid || pxid > max_Pixid) {
167  edm::LogError("CTPPSPixelDataFormatter")
168  << " unphysical dcol and/or pxid "
169  << " nllink=" << nlink << " nroc=" << nroc << " adc=" << adc << " dcol=" << dcol << " pxid=" << pxid;
170 
172 
173  continue;
174  }
175 
176  std::pair<int, int> rocPixel;
177  std::pair<int, int> modPixel;
178 
179  rocPixel = std::make_pair(dcol, pxid);
180 
181  modPixel = rocp.toGlobalfromDcol(rocPixel);
182 
183  CTPPSPixelDigi testdigi(modPixel.first, modPixel.second, adc);
184 
185  if (detDigis)
186  (*detDigis).data.emplace_back(modPixel.first, modPixel.second, adc);
187  }
188 }
Contains mappind data related to a ROC.
void conversionError(int fedId, uint32_t iD, const State &state, const Word32 &errorWord, Errors &errors) const
bool checkCRC(bool &errorsInEvent, int fedId, const Word64 *trailer, Errors &errors) const
bool checkHeader(bool &errorsInEvent, int fedId, const Word64 *header, Errors &errors) const
#define LIKELY(x)
Definition: Likely.h:20
const std::map< CTPPSPixelFramePosition, CTPPSPixelROCInfo > & m_Mapping
std::string print(const Word64 &word) const
uint32_t iD
the symbolic id
static constexpr Word32 dummyDetId
uint64_t word
uint64_t Word64
constexpr int adc(sample_type sample)
get the ADC sample (12 bits)
#define LogTrace(id)
collection_type data
Definition: DetSet.h:81
bool checkTrailer(bool &errorsInEvent, int fedId, unsigned int nWords, const Word64 *trailer, Errors &errors) const
Definition: errors.py:1
#define UNLIKELY(x)
Definition: Likely.h:21
bool checkROC(bool &errorsInEvent, int fedId, uint32_t iD, const Word32 &errorWord, Errors &errors) const
int CTPPSPixelDataFormatter::nDigis ( ) const
inline

Definition at line 76 of file CTPPSPixelDataFormatter.h.

References m_DigiCounter.

Referenced by CTPPSPixelDigiToRaw::produce().

int CTPPSPixelDataFormatter::nWords ( ) const
inline
std::string CTPPSPixelDataFormatter::print ( const Word64 word) const
private

Definition at line 282 of file CTPPSPixelDataFormatter.cc.

References str.

Referenced by formatRawData(), and interpretRawData().

282  {
283  std::ostringstream str;
284  str << "word64: " << reinterpret_cast<const std::bitset<64>&>(word);
285  return str.str();
286 }
uint64_t word
#define str(s)
void CTPPSPixelDataFormatter::setErrorStatus ( bool  theErrorStatus)

Member Data Documentation

Word32 CTPPSPixelDataFormatter::m_ADC_mask
private

Definition at line 102 of file CTPPSPixelDataFormatter.h.

Referenced by CTPPSPixelDataFormatter(), and interpretRawData().

int CTPPSPixelDataFormatter::m_ADC_shift
private
int CTPPSPixelDataFormatter::m_allDetDigis
private

Definition at line 111 of file CTPPSPixelDataFormatter.h.

Referenced by formatRawData().

Word32 CTPPSPixelDataFormatter::m_DCOL_mask
private

Definition at line 102 of file CTPPSPixelDataFormatter.h.

Referenced by CTPPSPixelDataFormatter(), and interpretRawData().

int CTPPSPixelDataFormatter::m_DCOL_shift
private
int CTPPSPixelDataFormatter::m_DigiCounter
private

Definition at line 110 of file CTPPSPixelDataFormatter.h.

Referenced by nDigis().

RPixErrorChecker CTPPSPixelDataFormatter::m_ErrorCheck
private

Definition at line 99 of file CTPPSPixelDataFormatter.h.

Referenced by interpretRawData(), and setErrorStatus().

int CTPPSPixelDataFormatter::m_hasDetDigis
private

Definition at line 112 of file CTPPSPixelDataFormatter.h.

Referenced by formatRawData().

bool CTPPSPixelDataFormatter::m_IncludeErrors
private

Definition at line 98 of file CTPPSPixelDataFormatter.h.

Referenced by setErrorStatus().

CTPPSPixelIndices CTPPSPixelDataFormatter::m_Indices
private

Definition at line 113 of file CTPPSPixelDataFormatter.h.

Referenced by formatRawData().

Word32 CTPPSPixelDataFormatter::m_LINK_mask
private

Definition at line 102 of file CTPPSPixelDataFormatter.h.

Referenced by CTPPSPixelDataFormatter(), and interpretRawData().

int CTPPSPixelDataFormatter::m_LINK_shift
private
const std::map<CTPPSPixelFramePosition, CTPPSPixelROCInfo>& CTPPSPixelDataFormatter::m_Mapping
private

Definition at line 108 of file CTPPSPixelDataFormatter.h.

Referenced by interpretRawData().

Word32 CTPPSPixelDataFormatter::m_PXID_mask
private

Definition at line 102 of file CTPPSPixelDataFormatter.h.

Referenced by CTPPSPixelDataFormatter(), and interpretRawData().

int CTPPSPixelDataFormatter::m_PXID_shift
private
Word32 CTPPSPixelDataFormatter::m_ROC_mask
private

Definition at line 102 of file CTPPSPixelDataFormatter.h.

Referenced by CTPPSPixelDataFormatter(), and interpretRawData().

int CTPPSPixelDataFormatter::m_ROC_shift
private
int CTPPSPixelDataFormatter::m_WordCounter
private

Definition at line 96 of file CTPPSPixelDataFormatter.h.

Referenced by formatRawData(), interpretRawData(), and nWords().