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 std;
17 using namespace edm;
18 
19 namespace {
20  constexpr int m_LINK_bits = 6;
21  constexpr int m_ROC_bits = 5;
22  constexpr int m_DCOL_bits = 5;
23  constexpr int m_PXID_bits = 8;
24  constexpr int m_ADC_bits = 8;
25  constexpr int min_Dcol = 0;
26  constexpr int max_Dcol = 25;
27  constexpr int min_Pixid = 2;
28  constexpr int max_Pixid = 161;
29 }
30 
31 CTPPSPixelDataFormatter::CTPPSPixelDataFormatter(std::map<CTPPSPixelFramePosition, CTPPSPixelROCInfo> const &mapping) : theWordCounter(0), mapping_(mapping)
32 {
33  int s32 = sizeof(Word32);
34  int s64 = sizeof(Word64);
35  int s8 = sizeof(char);
36  if ( s8 != 1 || s32 != 4*s8 || s64 != 2*s32) {
37  LogError("UnexpectedSizes")
38  <<" unexpected sizes: "
39  <<" size of char is: " << s8
40  <<", size of Word32 is: " << s32
41  <<", size of Word64 is: " << s64
42  <<", send exception" ;
43  }
44 
45 
46  m_ADC_shift = 0;
47  m_PXID_shift = m_ADC_shift + m_ADC_bits;
48  m_DCOL_shift = m_PXID_shift + m_PXID_bits;
49  m_ROC_shift = m_DCOL_shift + m_DCOL_bits;
50 
51 
52  m_LINK_shift = m_ROC_shift + m_ROC_bits;
53  m_LINK_mask = ~(~CTPPSPixelDataFormatter::Word32(0) << m_LINK_bits);
54  m_ROC_mask = ~(~CTPPSPixelDataFormatter::Word32(0) << m_ROC_bits);
55 
56  maxROCIndex=3;
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 void CTPPSPixelDataFormatter::interpretRawData( bool& errorsInEvent, int fedId, const FEDRawData& rawData, Collection & digis)
65 {
66 
67  int nWords = rawData.size()/sizeof(Word64);
68  if (nWords==0) return;
69 
71  const Word64* trailer = reinterpret_cast<const Word64* >(rawData.data())+(nWords-1);
72  if(!errorcheck.checkCRC(errorsInEvent, fedId, trailer)) return;
73 
75  const Word64* header = reinterpret_cast<const Word64* >(rawData.data()); header--;
76  bool moreHeaders = true;
77  while (moreHeaders) {
78  header++;
79  LogTrace("")<<"HEADER: " << print(*header);
80  bool headerStatus = errorcheck.checkHeader(errorsInEvent, fedId, header);
81  moreHeaders = headerStatus;
82  }
83 
85  bool moreTrailers = true;
86  trailer++;
87  while (moreTrailers) {
88  trailer--;
89  LogTrace("")<<"TRAILER: " << print(*trailer);
90  bool trailerStatus = errorcheck.checkTrailer(errorsInEvent, fedId, nWords, trailer);
91  moreTrailers = trailerStatus;
92  }
93 
95  theWordCounter += 2*(nWords-2);
96  LogTrace("")<<"data words: "<< (trailer-header-1);
97 
98  int link = -1;
99  int roc = -1;
100 
101  bool skipROC=false;
102 
103  edm::DetSet<CTPPSPixelDigi> * detDigis=nullptr;
104 
105  const Word32 * bw =(const Word32 *)(header+1);
106  const Word32 * ew =(const Word32 *)(trailer);
107  if ( *(ew-1) == 0 ) { ew--; theWordCounter--;}
108  for (auto word = bw; word < ew; ++word) {
109  LogTrace("")<<"DATA: " << print(*word);
110 
111  auto ww = *word;
112  if unlikely(ww==0) { theWordCounter--; continue;}
113  int nlink = (ww >> m_LINK_shift) & m_LINK_mask;
114  int nroc = (ww >> m_ROC_shift) & m_ROC_mask;
115 
116  int FMC = 0;
117 
118  int convroc = nroc-1;
119  CTPPSPixelFramePosition fPos(fedId, FMC, nlink, convroc);
120  std::map<CTPPSPixelFramePosition, CTPPSPixelROCInfo>::const_iterator mit;
121  mit = mapping_.find(fPos);
122 
123  if (mit == mapping_.end()){
124  if((nroc-1)>=maxROCIndex){
125  errorcheck.checkROC(errorsInEvent, fedId, ww); // check kind of error
126  }else{
127  edm::LogError("")<< " CTPPS Pixel DAQ map error " ;
128  }
129  continue; //skip word
130  }
131 
132  CTPPSPixelROCInfo rocInfo = (*mit).second;
133 
134  CTPPSPixelROC rocp(rocInfo.iD, rocInfo.roc, convroc);
135 
136  if ( (nlink!=link) | (nroc!=roc) ) { // new roc
137  link = nlink; roc=nroc;
138 
139  skipROC = likely((roc-1)<maxROCIndex) ? false : !errorcheck.checkROC(errorsInEvent, fedId, ww);
140  if (skipROC) continue;
141 
142  auto rawId = rocp.rawId();
143 
144  detDigis = &digis.find_or_insert(rawId);
145  if ( (*detDigis).empty() ) (*detDigis).data.reserve(32); // avoid the first relocations
146 
147  }
148 
149  int adc = (ww >> m_ADC_shift) & m_ADC_mask;
150 
151 
152  int dcol = (ww >> m_DCOL_shift) & m_DCOL_mask;
153  int pxid = (ww >> m_PXID_shift) & m_PXID_mask;
154 
155  if(dcol<min_Dcol || dcol>max_Dcol || pxid<min_Pixid || pxid>max_Pixid){
156  edm::LogError("CTPPSPixelDataFormatter")<< " unphysical dcol and/or pxid " << " nllink=" << nlink
157  << " nroc="<< nroc << " adc=" << adc << " dcol=" << dcol << " pxid=" << pxid;
158  continue;
159  }
160 
161  std::pair<int,int> rocPixel;
162  std::pair<int,int> modPixel;
163 
164  rocPixel = std::make_pair(dcol,pxid);
165 
166  modPixel = rocp.toGlobalfromDcol(rocPixel);
167 
168  CTPPSPixelDigi testdigi(modPixel.first, modPixel.second, adc);
169 
170  if(detDigis)
171  (*detDigis).data.emplace_back( modPixel.first, modPixel.second, adc);
172 
173  }
174 
175 }
176 
177 
179 {
180  ostringstream str;
181  str <<"word64: " << reinterpret_cast<const bitset<64>&> (word);
182  return str.str();
183 }
int adc(sample_type sample)
get the ADC sample (12 bits)
Contains mappind data related to a ROC.
bool checkCRC(bool &errorsInEvent, int fedId, const Word64 *trailer) const
bool checkHeader(bool &errorsInEvent, int fedId, const Word64 *header) const
std::string print(const Word64 &word) const
#define constexpr
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
#define unlikely(x)
#define likely(x)
void interpretRawData(bool &errorsInEvent, int fedId, const FEDRawData &data, Collection &digis)
uint32_t rawId() const
return the DetUnit to which this ROC belongs to.
Definition: CTPPSPixelROC.h:34
#define LogTrace(id)
bool checkTrailer(bool &errorsInEvent, int fedId, int nWords, const Word64 *trailer) const
const std::map< CTPPSPixelFramePosition, CTPPSPixelROCInfo > & mapping_
bool checkROC(bool &errorsInEvent, int fedId, Word32 &errorWord) const
std::pair< int, int > toGlobalfromDcol(const std::pair< int, int > &rocPixel) const
Definition: CTPPSPixelROC.h:73
collection_type data
Definition: DetSet.h:78
HLT enums.
const unsigned char * data() const
Return a const pointer to the beginning of the data buffer.
Definition: FEDRawData.cc:28
CTPPSPixelDataFormatter(std::map< CTPPSPixelFramePosition, CTPPSPixelROCInfo > const &mapping)