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 }
26 
27 CTPPSPixelDataFormatter::CTPPSPixelDataFormatter(std::map<CTPPSPixelFramePosition, CTPPSPixelROCInfo> const &mapping) : theWordCounter(0), mapping_(mapping)
28 {
29  int s32 = sizeof(Word32);
30  int s64 = sizeof(Word64);
31  int s8 = sizeof(char);
32  if ( s8 != 1 || s32 != 4*s8 || s64 != 2*s32) {
33  LogError("UnexpectedSizes")
34  <<" unexpected sizes: "
35  <<" size of char is: " << s8
36  <<", size of Word32 is: " << s32
37  <<", size of Word64 is: " << s64
38  <<", send exception" ;
39  }
40 
41 
42  m_ADC_shift = 0;
43  m_PXID_shift = m_ADC_shift + m_ADC_bits;
44  m_DCOL_shift = m_PXID_shift + m_PXID_bits;
45  m_ROC_shift = m_DCOL_shift + m_DCOL_bits;
46 
47 
48  m_LINK_shift = m_ROC_shift + m_ROC_bits;
49  m_LINK_mask = ~(~CTPPSPixelDataFormatter::Word32(0) << m_LINK_bits);
50  m_ROC_mask = ~(~CTPPSPixelDataFormatter::Word32(0) << m_ROC_bits);
51 
52  maxROCIndex=3;
53 
54  m_DCOL_mask = ~(~CTPPSPixelDataFormatter::Word32(0) << m_DCOL_bits);
55  m_PXID_mask = ~(~CTPPSPixelDataFormatter::Word32(0) << m_PXID_bits);
56  m_ADC_mask = ~(~CTPPSPixelDataFormatter::Word32(0) << m_ADC_bits);
57 
58 }
59 
60 void CTPPSPixelDataFormatter::interpretRawData( bool& errorsInEvent, int fedId, const FEDRawData& rawData, Collection & digis)
61 {
62 
63  int nWords = rawData.size()/sizeof(Word64);
64  if (nWords==0) return;
65 
67  const Word64* trailer = reinterpret_cast<const Word64* >(rawData.data())+(nWords-1);
68  if(!errorcheck.checkCRC(errorsInEvent, fedId, trailer)) return;
69 
71  const Word64* header = reinterpret_cast<const Word64* >(rawData.data()); header--;
72  bool moreHeaders = true;
73  while (moreHeaders) {
74  header++;
75  LogTrace("")<<"HEADER: " << print(*header);
76  bool headerStatus = errorcheck.checkHeader(errorsInEvent, fedId, header);
77  moreHeaders = headerStatus;
78  }
79 
81  bool moreTrailers = true;
82  trailer++;
83  while (moreTrailers) {
84  trailer--;
85  LogTrace("")<<"TRAILER: " << print(*trailer);
86  bool trailerStatus = errorcheck.checkTrailer(errorsInEvent, fedId, nWords, trailer);
87  moreTrailers = trailerStatus;
88  }
89 
91  theWordCounter += 2*(nWords-2);
92  LogTrace("")<<"data words: "<< (trailer-header-1);
93 
94  int link = -1;
95  int roc = -1;
96 
97  bool skipROC=false;
98 
99  edm::DetSet<CTPPSPixelDigi> * detDigis=nullptr;
100 
101  const Word32 * bw =(const Word32 *)(header+1);
102  const Word32 * ew =(const Word32 *)(trailer);
103  if ( *(ew-1) == 0 ) { ew--; theWordCounter--;}
104  for (auto word = bw; word < ew; ++word) {
105  LogTrace("")<<"DATA: " << print(*word);
106 
107  auto ww = *word;
108  if unlikely(ww==0) { theWordCounter--; continue;}
109  int nlink = (ww >> m_LINK_shift) & m_LINK_mask;
110  int nroc = (ww >> m_ROC_shift) & m_ROC_mask;
111 
112  int FMC = 0;
113 
114  int convroc = nroc-1;
115  CTPPSPixelFramePosition fPos(fedId, FMC, nlink, convroc);
116  std::map<CTPPSPixelFramePosition, CTPPSPixelROCInfo>::const_iterator mit;
117  mit = mapping_.find(fPos);
118 
119  if (mit == mapping_.end()){
120  if((nroc-1)>=maxROCIndex){
121  errorcheck.checkROC(errorsInEvent, fedId, ww); // check kind of error
122  }else{
123  edm::LogError("")<< " CTPPS Pixel DAQ map error " ;
124  }
125  continue; //skip word
126  }
127 
128  CTPPSPixelROCInfo rocInfo = (*mit).second;
129 
130  CTPPSPixelROC rocp(rocInfo.iD, rocInfo.roc, convroc);
131 
132  if ( (nlink!=link) | (nroc!=roc) ) { // new roc
133  link = nlink; roc=nroc;
134 
135  skipROC = likely((roc-1)<maxROCIndex) ? false : !errorcheck.checkROC(errorsInEvent, fedId, ww);
136  if (skipROC) continue;
137 
138  auto rawId = rocp.rawId();
139 
140  detDigis = &digis.find_or_insert(rawId);
141  if ( (*detDigis).empty() ) (*detDigis).data.reserve(32); // avoid the first relocations
142 
143  }
144 
145  int adc = (ww >> m_ADC_shift) & m_ADC_mask;
146 
147 
148  int dcol = (ww >> m_DCOL_shift) & m_DCOL_mask;
149  int pxid = (ww >> m_PXID_shift) & m_PXID_mask;
150 
151  std::pair<int,int> rocPixel;
152  std::pair<int,int> modPixel;
153 
154  rocPixel = std::make_pair(dcol,pxid);
155 
156  modPixel = rocp.toGlobalfromDcol(rocPixel);
157 
158  CTPPSPixelDigi testdigi(modPixel.first, modPixel.second, adc);
159 
160  if(detDigis)
161  (*detDigis).data.emplace_back( modPixel.first, modPixel.second, adc);
162 
163  }
164 
165 }
166 
167 
169 {
170  ostringstream str;
171  str <<"word64: " << reinterpret_cast<const bitset<64>&> (word);
172  return str.str();
173 }
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)