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 27 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.

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 }
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 60 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().

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 }
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

Definition at line 61 of file CTPPSPixelDataFormatter.h.

References data, interpretRawData(), and theWordCounter.

Referenced by interpretRawData().

std::string CTPPSPixelDataFormatter::print ( const Word64 word) const
private

Definition at line 168 of file CTPPSPixelDataFormatter.cc.

References harvestTrackValidationPlots::str.

Referenced by interpretRawData().

169 {
170  ostringstream str;
171  str <<"word64: " << reinterpret_cast<const bitset<64>&> (word);
172  return str.str();
173 }

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().