CMS 3D CMS Logo

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

#include <CTPPSPixelDataFormatter.h>

Public Types

typedef edm::DetSetVector< CTPPSPixelDigiCollection
 
typedef std::vector< CTPPSPixelDigiDetDigis
 
typedef std::map< int, FEDRawDataRawData
 
typedef uint32_t Word32
 
typedef uint64_t Word64
 

Public Member Functions

 CTPPSPixelDataFormatter (std::map< CTPPSPixelFramePosition, CTPPSPixelROCInfo > const &mapping)
 
void interpretRawData (bool &errorsInEvent, int fedId, const FEDRawData &data, Collection &digis)
 
int nWords () const
 

Private Member Functions

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

Private Attributes

RPixErrorChecker errorcheck
 
Word32 m_ADC_mask
 
int m_ADC_shift
 
Word32 m_DCOL_mask
 
int m_DCOL_shift
 
Word32 m_LINK_mask
 
int m_LINK_shift
 
Word32 m_PXID_mask
 
int m_PXID_shift
 
Word32 m_ROC_mask
 
int m_ROC_shift
 
const std::map< CTPPSPixelFramePosition, CTPPSPixelROCInfo > & mapping_
 
int maxROCIndex
 
int theWordCounter
 

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 47 of file CTPPSPixelDataFormatter.h.

Member Typedef Documentation

Definition at line 51 of file CTPPSPixelDataFormatter.h.

Definition at line 54 of file CTPPSPixelDataFormatter.h.

Definition at line 53 of file CTPPSPixelDataFormatter.h.

Definition at line 56 of file CTPPSPixelDataFormatter.h.

Definition at line 57 of file CTPPSPixelDataFormatter.h.

Constructor & Destructor Documentation

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

Definition at line 31 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, m_ROC_shift, and maxROCIndex.

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 }
const std::map< CTPPSPixelFramePosition, CTPPSPixelROCInfo > & mapping_

Member Function Documentation

int CTPPSPixelDataFormatter::checkError ( const Word32 data) const
private
void CTPPSPixelDataFormatter::interpretRawData ( bool &  errorsInEvent,
int  fedId,
const FEDRawData data,
Collection digis 
)

check CRC bit

check headers

check trailers

data words

Definition at line 64 of file CTPPSPixelDataFormatter.cc.

References ecalMGPA::adc(), RPixErrorChecker::checkCRC(), RPixErrorChecker::checkHeader(), RPixErrorChecker::checkROC(), RPixErrorChecker::checkTrailer(), FEDRawData::data(), edm::DetSet< T >::data, errorcheck, edm::DetSetVector< T >::find_or_insert(), RecoTauValidation_cfi::header, CTPPSPixelROCInfo::iD, likely, LogTrace, 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, m_ROC_shift, mapping_, maxROCIndex, nWords(), print(), CTPPSPixelROC::rawId(), CTPPSPixelROCInfo::roc, FEDRawData::size(), theWordCounter, CTPPSPixelROC::toGlobalfromDcol(), and unlikely.

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

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 }
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
uint32_t iD
the symbolic id
#define unlikely(x)
#define likely(x)
uint64_t Word64
#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
collection_type data
Definition: DetSet.h:78
int CTPPSPixelDataFormatter::nWords ( ) const
inline
std::string CTPPSPixelDataFormatter::print ( const Word64 word) const
private

Definition at line 178 of file CTPPSPixelDataFormatter.cc.

References harvestTrackValidationPlots::str.

Referenced by interpretRawData().

179 {
180  ostringstream str;
181  str <<"word64: " << reinterpret_cast<const bitset<64>&> (word);
182  return str.str();
183 }

Member Data Documentation

RPixErrorChecker CTPPSPixelDataFormatter::errorcheck
private

Definition at line 71 of file CTPPSPixelDataFormatter.h.

Referenced by interpretRawData().

Word32 CTPPSPixelDataFormatter::m_ADC_mask
private

Definition at line 74 of file CTPPSPixelDataFormatter.h.

Referenced by CTPPSPixelDataFormatter(), and interpretRawData().

int CTPPSPixelDataFormatter::m_ADC_shift
private

Definition at line 73 of file CTPPSPixelDataFormatter.h.

Referenced by CTPPSPixelDataFormatter(), and interpretRawData().

Word32 CTPPSPixelDataFormatter::m_DCOL_mask
private

Definition at line 74 of file CTPPSPixelDataFormatter.h.

Referenced by CTPPSPixelDataFormatter(), and interpretRawData().

int CTPPSPixelDataFormatter::m_DCOL_shift
private

Definition at line 73 of file CTPPSPixelDataFormatter.h.

Referenced by CTPPSPixelDataFormatter(), and interpretRawData().

Word32 CTPPSPixelDataFormatter::m_LINK_mask
private

Definition at line 74 of file CTPPSPixelDataFormatter.h.

Referenced by CTPPSPixelDataFormatter(), and interpretRawData().

int CTPPSPixelDataFormatter::m_LINK_shift
private

Definition at line 73 of file CTPPSPixelDataFormatter.h.

Referenced by CTPPSPixelDataFormatter(), and interpretRawData().

Word32 CTPPSPixelDataFormatter::m_PXID_mask
private

Definition at line 74 of file CTPPSPixelDataFormatter.h.

Referenced by CTPPSPixelDataFormatter(), and interpretRawData().

int CTPPSPixelDataFormatter::m_PXID_shift
private

Definition at line 73 of file CTPPSPixelDataFormatter.h.

Referenced by CTPPSPixelDataFormatter(), and interpretRawData().

Word32 CTPPSPixelDataFormatter::m_ROC_mask
private

Definition at line 74 of file CTPPSPixelDataFormatter.h.

Referenced by CTPPSPixelDataFormatter(), and interpretRawData().

int CTPPSPixelDataFormatter::m_ROC_shift
private

Definition at line 73 of file CTPPSPixelDataFormatter.h.

Referenced by CTPPSPixelDataFormatter(), and interpretRawData().

const std::map<CTPPSPixelFramePosition, CTPPSPixelROCInfo>& CTPPSPixelDataFormatter::mapping_
private

Definition at line 82 of file CTPPSPixelDataFormatter.h.

Referenced by interpretRawData().

int CTPPSPixelDataFormatter::maxROCIndex
private

Definition at line 75 of file CTPPSPixelDataFormatter.h.

Referenced by CTPPSPixelDataFormatter(), and interpretRawData().

int CTPPSPixelDataFormatter::theWordCounter
mutableprivate

Definition at line 69 of file CTPPSPixelDataFormatter.h.

Referenced by interpretRawData(), and nWords().