CMS 3D CMS Logo

CTPPSPixelDataFormatter.cc
Go to the documentation of this file.
2 
6 
8 
11 
12 #include <bitset>
13 #include <sstream>
14 #include <iostream>
15 
16 using namespace edm;
17 
18 namespace {
19  constexpr int m_LINK_bits = 6;
20  constexpr int m_ROC_bits = 5;
21  constexpr int m_DCOL_bits = 5;
22  constexpr int m_PXID_bits = 8;
23  constexpr int m_ADC_bits = 8;
24  constexpr int min_Dcol = 0;
25  constexpr int max_Dcol = 25;
26  constexpr int min_Pixid = 2;
27  constexpr int max_Pixid = 161;
28  constexpr int maxRocIndex = 3;
29  constexpr int maxLinkIndex = 13;
30 }
31 
32 CTPPSPixelDataFormatter::CTPPSPixelDataFormatter(std::map<CTPPSPixelFramePosition, CTPPSPixelROCInfo> const &mapping) : m_WordCounter(0), m_Mapping(mapping)
33 {
34  int s32 = sizeof(Word32);
35  int s64 = sizeof(Word64);
36  int s8 = sizeof(char);
37  if ( s8 != 1 || s32 != 4*s8 || s64 != 2*s32) {
38  LogError("UnexpectedSizes")
39  <<" unexpected sizes: "
40  <<" size of char is: " << s8
41  <<", size of Word32 is: " << s32
42  <<", size of Word64 is: " << s64
43  <<", send exception" ;
44  }
45 
46  m_IncludeErrors = false;
47 
48  m_ADC_shift = 0;
49  m_PXID_shift = m_ADC_shift + m_ADC_bits;
50  m_DCOL_shift = m_PXID_shift + m_PXID_bits;
51  m_ROC_shift = m_DCOL_shift + m_DCOL_bits;
52 
53 
54  m_LINK_shift = m_ROC_shift + m_ROC_bits;
55  m_LINK_mask = ~(~CTPPSPixelDataFormatter::Word32(0) << m_LINK_bits);
56  m_ROC_mask = ~(~CTPPSPixelDataFormatter::Word32(0) << m_ROC_bits);
57 
58  m_DCOL_mask = ~(~CTPPSPixelDataFormatter::Word32(0) << m_DCOL_bits);
59  m_PXID_mask = ~(~CTPPSPixelDataFormatter::Word32(0) << m_PXID_bits);
60  m_ADC_mask = ~(~CTPPSPixelDataFormatter::Word32(0) << m_ADC_bits);
61 
62 }
63 
64 
66 {
67  m_IncludeErrors = errorStatus;
69 }
70 
71 
72 void CTPPSPixelDataFormatter::interpretRawData( bool& errorsInEvent, int fedId, const FEDRawData& rawData,
73  Collection & digis, Errors & errors)
74 {
75 
76  int nWords = rawData.size()/sizeof(Word64);
77  if (nWords==0) return;
78 
80  const Word64* trailer = reinterpret_cast<const Word64* >(rawData.data())+(nWords-1);
81  if(!m_ErrorCheck.checkCRC(errorsInEvent, fedId, trailer, errors)) return;
82 
84  const Word64* header = reinterpret_cast<const Word64* >(rawData.data()); header--;
85  bool moreHeaders = true;
86  while (moreHeaders) {
87  header++;
88  LogTrace("")<<"HEADER: " << print(*header);
89  bool headerStatus = m_ErrorCheck.checkHeader(errorsInEvent, fedId, header, errors);
90  moreHeaders = headerStatus;
91  }
92 
94  bool moreTrailers = true;
95  trailer++;
96  while (moreTrailers) {
97  trailer--;
98  LogTrace("")<<"TRAILER: " << print(*trailer);
99  bool trailerStatus = m_ErrorCheck.checkTrailer(errorsInEvent, fedId, nWords, trailer, errors);
100  moreTrailers = trailerStatus;
101  }
102 
104  m_WordCounter += 2*(nWords-2);
105  LogTrace("")<<"data words: "<< (trailer-header-1);
106 
107  int link = -1;
108  int roc = -1;
109 
110  bool skipROC=false;
111 
112  edm::DetSet<CTPPSPixelDigi> * detDigis=nullptr;
113 
114  const Word32 * bw =(const Word32 *)(header+1);
115  const Word32 * ew =(const Word32 *)(trailer);
116  if ( *(ew-1) == 0 ) { ew--; m_WordCounter--;}
117  for (auto word = bw; word < ew; ++word) {
118  LogTrace("")<<"DATA: " << print(*word);
119 
120  auto ww = *word;
121  if UNLIKELY(ww==0) { m_WordCounter--; continue;}
122  int nlink = (ww >> m_LINK_shift) & m_LINK_mask;
123  int nroc = (ww >> m_ROC_shift) & m_ROC_mask;
124 
125  int FMC = 0;
126  uint32_t iD = RPixErrorChecker::dummyDetId;//0xFFFFFFFF; //dummyDetId
127  int convroc = nroc-1;
128  CTPPSPixelFramePosition fPos(fedId, FMC, nlink, convroc);
129  std::map<CTPPSPixelFramePosition, CTPPSPixelROCInfo>::const_iterator mit;
130  mit = m_Mapping.find(fPos);
131 
132  if (mit == m_Mapping.end()){
133  if(nlink >= maxLinkIndex){
134  m_ErrorCheck.conversionError(fedId, iD, InvalidLinkId, ww, errors);
135  }
136  else if((nroc-1)>=maxRocIndex){
137  m_ErrorCheck.conversionError(fedId, iD, InvalidROCId, ww, errors);
138  }else{
139  m_ErrorCheck.conversionError(fedId, iD, Unknown, ww, errors);
140  }
141  continue; //skip word
142  }
143 
144  CTPPSPixelROCInfo rocInfo = (*mit).second;
145  iD = rocInfo.iD;
146  CTPPSPixelROC rocp(iD, rocInfo.roc, convroc);
147 
148  if ( (nlink!=link) | (nroc!=roc) ) { // new roc
149  link = nlink; roc=nroc;
150 
151  skipROC = LIKELY((roc-1)<maxRocIndex) ? false : !m_ErrorCheck.checkROC(errorsInEvent, fedId, iD, ww, errors);
152  if (skipROC) continue;
153 
154  auto rawId = rocp.rawId();
155 
156  detDigis = &digis.find_or_insert(rawId);
157  if ( (*detDigis).empty() ) (*detDigis).data.reserve(32); // avoid the first relocations
158 
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")<< " unphysical dcol and/or pxid " << " nllink=" << nlink
168  << " nroc="<< nroc << " adc=" << adc << " dcol=" << dcol << " pxid=" << pxid;
169 
170  m_ErrorCheck.conversionError(fedId, iD, InvalidPixelId, ww, errors);
171 
172  continue;
173  }
174 
175  std::pair<int,int> rocPixel;
176  std::pair<int,int> modPixel;
177 
178  rocPixel = std::make_pair(dcol,pxid);
179 
180  modPixel = rocp.toGlobalfromDcol(rocPixel);
181 
182  CTPPSPixelDigi testdigi(modPixel.first, modPixel.second, adc);
183 
184  if(detDigis)
185  (*detDigis).data.emplace_back( modPixel.first, modPixel.second, adc);
186 
187  }
188 
189 }
190 
191 
193 {
194  std::ostringstream str;
195  str <<"word64: " << reinterpret_cast<const std::bitset<64>&> (word);
196  return str.str();
197 }
void setErrorStatus(bool theErrorStatus)
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
std::map< uint32_t, DetErrors > Errors
#define LIKELY(x)
Definition: Likely.h:20
const std::map< CTPPSPixelFramePosition, CTPPSPixelROCInfo > & m_Mapping
std::string print(const Word64 &word) const
size_t size() const
Lenght of the data buffer in bytes.
Definition: FEDRawData.h:47
reference find_or_insert(det_id_type id)
Definition: DetSetVector.h:254
uint32_t iD
the symbolic id
static constexpr Word32 dummyDetId
uint32_t rawId() const
return the DetUnit to which this ROC belongs to.
Definition: CTPPSPixelROC.h:34
constexpr int adc(sample_type sample)
get the ADC sample (12 bits)
#define LogTrace(id)
void setErrorStatus(bool errorStatus)
void interpretRawData(bool &errorsInEvent, int fedId, const FEDRawData &data, Collection &digis, Errors &errors)
std::pair< int, int > toGlobalfromDcol(const std::pair< int, int > &rocPixel) const
Definition: CTPPSPixelROC.h:73
collection_type data
Definition: DetSet.h:80
HLT enums.
const unsigned char * data() const
Return a const pointer to the beginning of the data buffer.
Definition: FEDRawData.cc:28
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
#define str(s)
bool checkROC(bool &errorsInEvent, int fedId, uint32_t iD, const Word32 &errorWord, Errors &errors) const
#define constexpr
CTPPSPixelDataFormatter(std::map< CTPPSPixelFramePosition, CTPPSPixelROCInfo > const &mapping)