![]() |
![]() |
#include <EventFilter/SiPixelRawToDigi/interface/PixelDataFormatter.h>
Public Types | |
typedef std::vector< PixelDigi > | DetDigis |
typedef std::vector < SiPixelRawDataError > | DetErrors |
typedef std::map< uint32_t, DetDigis > | Digis |
typedef std::map< uint32_t, DetErrors > | Errors |
typedef std::pair < DetDigis::const_iterator, DetDigis::const_iterator > | Range |
Public Member Functions | |
FEDRawData * | formatData (unsigned int lvl1_ID, int fedId, const Digis &digis) |
void | interpretRawData (bool &errorsInEvent, int fedId, const FEDRawData &data, Digis &digis, Errors &errors) |
int | nDigis () const |
int | nWords () const |
PixelDataFormatter (const SiPixelFedCablingMap *map) | |
void | setErrorStatus (bool ErrorStatus, bool OrderStatus) |
Private Types | |
typedef unsigned int | Word32 |
typedef long long | Word64 |
Private Member Functions | |
int | checkError (const Word32 &data) const |
int | digi2word (const SiPixelFrameConverter *converter, uint32_t detId, const PixelDigi &digi, std::vector< Word32 > &words) const |
uint32_t | errorDetId (const SiPixelFrameConverter *converter, int fedId, int errorType, const Word32 &word) const |
std::string | print (const Word64 &word) const |
std::string | print (const PixelDigi &digi) const |
int | word2digi (const SiPixelFrameConverter *converter, const bool includeError, const Word32 &word, Digis &digis) const |
Private Attributes | |
bool | checkOrder |
ErrorChecker | errorcheck |
bool | includeErrors |
const SiPixelFedCablingMap * | theCablingMap |
int | theDigiCounter |
int | theWordCounter |
Static Private Attributes | |
static const int | ADC_bits = 8 |
static const int | ADC_shift = 0 |
static const int | DCOL_bits = 5 |
static const int | DCOL_shift = PXID_shift + PXID_bits |
static const int | LINK_bits = 6 |
static const int | LINK_shift = ROC_shift + ROC_bits |
static const int | PXID_bits = 8 |
static const int | PXID_shift = ADC_shift + ADC_bits |
static const int | ROC_bits = 5 |
static const int | ROC_shift = DCOL_shift + DCOL_bits |
FED OUTPUT DATA FORMAT 6/02, d.k. (11/02 updated for 100*150 pixels) ---------------------- 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 PixelDataFormatter interpret/format ONLY detector data words (not FED headers or trailer, which are treated elsewhere).
Definition at line 48 of file PixelDataFormatter.h.
typedef std::vector<PixelDigi> PixelDataFormatter::DetDigis |
Definition at line 52 of file PixelDataFormatter.h.
typedef std::vector<SiPixelRawDataError> PixelDataFormatter::DetErrors |
Definition at line 57 of file PixelDataFormatter.h.
typedef std::map<uint32_t, DetDigis> PixelDataFormatter::Digis |
Definition at line 53 of file PixelDataFormatter.h.
typedef std::map<uint32_t, DetErrors> PixelDataFormatter::Errors |
Definition at line 58 of file PixelDataFormatter.h.
typedef std::pair<DetDigis::const_iterator, DetDigis::const_iterator> PixelDataFormatter::Range |
Definition at line 55 of file PixelDataFormatter.h.
typedef unsigned int PixelDataFormatter::Word32 [private] |
Definition at line 80 of file PixelDataFormatter.h.
typedef long long PixelDataFormatter::Word64 [private] |
Definition at line 81 of file PixelDataFormatter.h.
PixelDataFormatter::PixelDataFormatter | ( | const SiPixelFedCablingMap * | map | ) |
Definition at line 36 of file PixelDataFormatter.cc.
References checkOrder, includeErrors, and s32.
00037 : theDigiCounter(0), theWordCounter(0), theCablingMap(map) 00038 { 00039 int s32 = sizeof(Word32); 00040 int s64 = sizeof(Word64); 00041 int s8 = sizeof(char); 00042 if ( s8 != 1 || s32 != 4*s8 || s64 != 2*s32) { 00043 LogError("**PixelDataFormatter**") 00044 <<" unexpected sizes: " 00045 <<" size of char is: " << s8 00046 <<", size of Word32 is: " << s32 00047 <<", size of Word64 is: " << s64 00048 <<", send exception" ; 00049 } 00050 includeErrors = false; 00051 checkOrder = false; 00052 }
int PixelDataFormatter::digi2word | ( | const SiPixelFrameConverter * | converter, | |
uint32_t | detId, | |||
const PixelDigi & | digi, | |||
std::vector< Word32 > & | words | |||
) | const [private] |
Definition at line 210 of file PixelDataFormatter.cc.
References PixelDigi::adc(), ADC_shift, PixelDigi::column(), sipixelobjects::ElectronicIndex::dcol, DCOL_shift, sipixelobjects::ElectronicIndex::link, LINK_shift, LogDebug, print(), sipixelobjects::ElectronicIndex::pxid, PXID_shift, sipixelobjects::ElectronicIndex::roc, ROC_shift, PixelDigi::row(), StDecayID::status, theWordCounter, and SiPixelFrameConverter::toCabling().
Referenced by formatData().
00212 { 00213 LogDebug("PixelDataFormatter") 00214 // <<" detId: " << detId 00215 <<print(digi); 00216 00217 DetectorIndex detector = {detId, digi.row(), digi.column()}; 00218 ElectronicIndex cabling; 00219 int status = converter->toCabling(cabling, detector); 00220 if (status) return status; 00221 00222 Word32 word = 00223 (cabling.link << LINK_shift) 00224 | (cabling.roc << ROC_shift) 00225 | (cabling.dcol << DCOL_shift) 00226 | (cabling.pxid << PXID_shift) 00227 | (digi.adc() << ADC_shift); 00228 words.push_back(word); 00229 theWordCounter++; 00230 return 0; 00231 }
uint32_t PixelDataFormatter::errorDetId | ( | const SiPixelFrameConverter * | converter, | |
int | fedId, | |||
int | errorType, | |||
const Word32 & | word | |||
) | const [private] |
FEDRawData * PixelDataFormatter::formatData | ( | unsigned int | lvl1_ID, | |
int | fedId, | |||
const Digis & | digis | |||
) |
Definition at line 132 of file PixelDataFormatter.cc.
References FEDRawData::data(), digi2word(), lat::endl(), Exception, SiPixelFrameConverter::hasDetUnit(), i, it, LogDebug, LogTrace, print(), s, FEDTrailer::set(), FEDHeader::set(), StDecayID::status, theCablingMap, and theDigiCounter.
00133 { 00134 vector<Word32> words; 00135 00136 static int allDetDigis = 0; 00137 static int hasDetDigis = 0; 00138 SiPixelFrameConverter converter(theCablingMap, fedId); 00139 for (Digis::const_iterator im = digis.begin(); im != digis.end(); im++) { 00140 allDetDigis++; 00141 // uint32_t rawId = im->id; 00142 uint32_t rawId = im->first; 00143 if ( !converter.hasDetUnit(rawId) ) continue; 00144 hasDetDigis++; 00145 // const DetDigis & detDigis = im->data; 00146 const DetDigis & detDigis = im->second; 00147 for (DetDigis::const_iterator it = detDigis.begin(); it != detDigis.end(); it++) { 00148 theDigiCounter++; 00149 const PixelDigi & digi = (*it); 00150 int status = digi2word( &converter, rawId, digi, words); 00151 if (status) { 00152 LogError("PixelDataFormatter::formatData exception") 00153 <<" digi2word returns error #"<<status 00154 <<" Ndigis: "<<theDigiCounter << endl 00155 <<" detector: "<<rawId<< endl 00156 << print(digi) <<endl; 00157 } 00158 } 00159 } 00160 LogTrace(" allDetDigis/hasDetDigis : ") << allDetDigis<<"/"<<hasDetDigis; 00161 00162 // 00163 // since digis are written in the form of 64-bit packets 00164 // add extra 32-bit word to make number of digis even 00165 // 00166 if (words.size() %2 != 0) words.push_back( Word32(0) ); 00167 00168 00169 // 00170 // size in Bytes; create output structure 00171 // 00172 int dataSize = words.size() * sizeof(Word32); 00173 int nHeaders = 1; 00174 int nTrailers = 1; 00175 dataSize += (nHeaders+nTrailers)*sizeof(Word64); 00176 FEDRawData * rawData = new FEDRawData(dataSize); 00177 00178 // 00179 // get begining of data; 00180 Word64 * word = reinterpret_cast<Word64* >(rawData->data()); 00181 00182 // 00183 // write one header 00184 FEDHeader::set( reinterpret_cast<unsigned char*>(word), 0, lvl1_ID, 0, fedId); 00185 word++; 00186 00187 // 00188 // write data 00189 for (unsigned int i=0; i < words.size(); i+=2) { 00190 *word = (Word64(words[i]) << 32 ) | words[i+1]; 00191 LogDebug("PixelDataFormatter") << print(*word); 00192 word++; 00193 } 00194 00195 // write one trailer 00196 FEDTrailer::set( reinterpret_cast<unsigned char*>(word), dataSize/sizeof(Word64), 0,0,0); 00197 word++; 00198 00199 // 00200 // check memory 00201 // 00202 if (word != reinterpret_cast<Word64* >(rawData->data()+dataSize)) { 00203 string s = "** PROBLEM in PixelDataFormatter !!!"; 00204 throw cms::Exception(s); 00205 } 00206 00207 return rawData; 00208 }
void PixelDataFormatter::interpretRawData | ( | bool & | errorsInEvent, | |
int | fedId, | |||
const FEDRawData & | data, | |||
Digis & | digis, | |||
Errors & | errors | |||
) |
Definition at line 61 of file PixelDataFormatter.cc.
References ErrorChecker::checkCRC(), ErrorChecker::checkHeader(), ErrorChecker::checkROC(), ErrorChecker::checkTrailer(), ErrorChecker::conversionError(), FEDRawData::data(), errorcheck, header, includeErrors, LogDebug, LogTrace, nWords(), print(), FEDRawData::size(), theCablingMap, theWordCounter, w1, w2, and word2digi().
Referenced by SiPixelRawToDigi::produce().
00062 { 00063 int nWords = rawData.size()/sizeof(Word64); 00064 if (nWords==0) return; 00065 00066 SiPixelFrameConverter * converter = (theCablingMap) ? 00067 new SiPixelFrameConverter(theCablingMap, fedId) : 0; 00068 00069 // check CRC bit 00070 const Word64* trailer = reinterpret_cast<const Word64* >(rawData.data())+(nWords-1); 00071 bool CRC_OK = errorcheck.checkCRC(errorsInEvent, fedId, trailer, errors); 00072 00073 if(CRC_OK) { 00074 // check headers 00075 const Word64* header = reinterpret_cast<const Word64* >(rawData.data()); header--; 00076 bool moreHeaders = true; 00077 while (moreHeaders) { 00078 header++; 00079 LogTrace("")<<"HEADER: " << print(*header); 00080 bool headerStatus = errorcheck.checkHeader(errorsInEvent, fedId, header, errors); 00081 moreHeaders = headerStatus; 00082 } 00083 00084 // check trailers 00085 bool moreTrailers = true; 00086 trailer++; 00087 while (moreTrailers) { 00088 trailer--; 00089 LogTrace("")<<"TRAILER: " << print(*trailer); 00090 bool trailerStatus = errorcheck.checkTrailer(errorsInEvent, fedId, nWords, trailer, errors); 00091 moreTrailers = trailerStatus; 00092 } 00093 00094 // data words 00095 theWordCounter += 2*(nWords-2); 00096 LogTrace("")<<"data words: "<< (trailer-header-1); 00097 for (const Word64* word = header+1; word != trailer; word++) { 00098 LogTrace("")<<"DATA: " << print(*word); 00099 static const Word64 WORD32_mask = 0xffffffff; 00100 Word32 w1 = *word & WORD32_mask; 00101 Word32 w2 = *word >> 32 & WORD32_mask; 00102 if (w1==0) theWordCounter--; 00103 if (w2==0) theWordCounter--; 00104 00105 // check status of word... 00106 bool notErrorROC1 = errorcheck.checkROC(errorsInEvent, fedId, converter, w1, errors); 00107 if (notErrorROC1) { 00108 int status1 = word2digi(converter, includeErrors, w1, digis); 00109 if (status1) { 00110 LogDebug("PixelDataFormatter::interpretRawData") 00111 << "status #" <<status1<<" returned for word1"; 00112 errorsInEvent = true; 00113 errorcheck.conversionError(fedId, converter, status1, w1, errors); 00114 } 00115 } 00116 bool notErrorROC2 = errorcheck.checkROC(errorsInEvent, fedId, converter, w2, errors); 00117 if (notErrorROC2) { 00118 int status2 = word2digi(converter, includeErrors, w2, digis); 00119 if (status2) { 00120 LogDebug("PixelDataFormatter::interpretRawData") 00121 << "status #" <<status2<<" returned for word2"; 00122 errorsInEvent = true; 00123 errorcheck.conversionError(fedId, converter, status2, w2, errors); 00124 } 00125 } 00126 } 00127 } // end if(CRC_OK) 00128 delete converter; 00129 }
int PixelDataFormatter::nDigis | ( | ) | const [inline] |
Definition at line 64 of file PixelDataFormatter.h.
References theDigiCounter.
Referenced by SiPixelRawToDigi::produce().
00064 { return theDigiCounter; }
int PixelDataFormatter::nWords | ( | ) | const [inline] |
Definition at line 65 of file PixelDataFormatter.h.
References theWordCounter.
Referenced by interpretRawData(), and SiPixelRawToDigi::produce().
00065 { return theWordCounter; }
std::string PixelDataFormatter::print | ( | const Word64 & | word | ) | const [private] |
Definition at line 303 of file PixelDataFormatter.cc.
00304 { 00305 ostringstream str; 00306 //str <<"word64: " << *reinterpret_cast<const bitset<64>*> (&word); 00307 str <<"word64: " << reinterpret_cast<const bitset<64>&> (word); 00308 return str.str(); 00309 }
std::string PixelDataFormatter::print | ( | const PixelDigi & | digi | ) | const [private] |
Definition at line 296 of file PixelDataFormatter.cc.
References PixelDigi::adc(), PixelDigi::column(), and PixelDigi::row().
Referenced by digi2word(), formatData(), interpretRawData(), and word2digi().
00297 { 00298 ostringstream str; 00299 str << " DIGI: row: " << digi.row() <<", col: " << digi.column() <<", adc: " << digi.adc(); 00300 return str.str(); 00301 }
Definition at line 54 of file PixelDataFormatter.cc.
References checkOrder, errorcheck, includeErrors, and ErrorChecker::setErrorStatus().
Referenced by SiPixelRawToDigi::produce().
00055 { 00056 includeErrors = ErrorStatus; 00057 checkOrder = OrderStatus; 00058 errorcheck.setErrorStatus(includeErrors); 00059 }
int PixelDataFormatter::word2digi | ( | const SiPixelFrameConverter * | converter, | |
const bool | includeError, | |||
const Word32 & | word, | |||
Digis & | digis | |||
) | const [private] |
Definition at line 234 of file PixelDataFormatter.cc.
References ecalMGPA::adc(), ADC_bits, ADC_shift, checkOrder, sipixelobjects::DetectorIndex::col, sipixelobjects::ElectronicIndex::dcol, DCOL_bits, DCOL_shift, debug, edm::MessageDrop::debugEnabled, edm::MessageDrop::instance(), sipixelobjects::ElectronicIndex::link, LINK_bits, LINK_shift, LogTrace, print(), sipixelobjects::ElectronicIndex::pxid, PXID_bits, PXID_shift, sipixelobjects::DetectorIndex::rawId, sipixelobjects::ElectronicIndex::roc, ROC_bits, ROC_shift, sipixelobjects::LocalPixel::rocCol(), sipixelobjects::LocalPixel::rocRow(), sipixelobjects::DetectorIndex::row, StDecayID::status, theDigiCounter, and SiPixelFrameConverter::toDetector().
Referenced by interpretRawData().
00236 { 00237 // do not interpret false digis 00238 if (word == 0 ) return 0; 00239 00240 static const Word32 LINK_mask = ~(~Word32(0) << LINK_bits); 00241 static const Word32 ROC_mask = ~(~Word32(0) << ROC_bits); 00242 static const Word32 DCOL_mask = ~(~Word32(0) << DCOL_bits); 00243 static const Word32 PXID_mask = ~(~Word32(0) << PXID_bits); 00244 static const Word32 ADC_mask = ~(~Word32(0) << ADC_bits); 00245 00246 ElectronicIndex cabling; 00247 cabling.dcol = (word >> DCOL_shift) & DCOL_mask; 00248 cabling.pxid = (word >> PXID_shift) & PXID_mask; 00249 cabling.link = (word >> LINK_shift) & LINK_mask; 00250 cabling.roc = (word >> ROC_shift) & ROC_mask; 00251 int adc = (word >> ADC_shift) & ADC_mask; 00252 00253 static ElectronicIndex lastcabl; 00254 static bool lastcablexists = false; 00255 00256 00257 // check to make sure row and dcol values are in order (lowest to highest) 00258 if (checkOrder && lastcablexists && (lastcabl.roc == cabling.roc) ) { 00259 if ((cabling.dcol < lastcabl.dcol) || (cabling.dcol==lastcabl.dcol && cabling.pxid < lastcabl.pxid)) { 00260 LogError("PixelDataFormatter::raw2digi exception") 00261 <<" pixel not in correct order (pxid low to high, dcol low to high)" 00262 <<" link: "<<cabling.link<<", ROC: "<<cabling.roc<<", dcol: " 00263 <<cabling.dcol<<", pxid: "<<cabling.pxid; 00264 return 4; 00265 } 00266 } 00267 00268 00269 static bool debug = edm::MessageDrop::instance()->debugEnabled; 00270 if (debug) { 00271 LocalPixel::DcolPxid pixel = {cabling.dcol,cabling.pxid}; 00272 LocalPixel local(pixel); 00273 LogTrace("")<<" link: "<<cabling.link<<", roc: "<<cabling.roc 00274 <<" rocRow: "<<local.rocRow()<<", rocCol:"<<local.rocCol() 00275 <<" (dcol: "<<cabling.dcol<<",pxid:"<<cabling.pxid<<"), adc:"<<adc; 00276 } 00277 00278 if (!converter) return 0; 00279 00280 DetectorIndex detIdx; 00281 int status = converter->toDetector(cabling, detIdx); 00282 if (status) return status; 00283 00284 PixelDigi pd(detIdx.row, detIdx.col, adc); 00285 digis[detIdx.rawId].push_back(pd); 00286 00287 theDigiCounter++; 00288 if (checkOrder) { 00289 lastcabl = cabling; 00290 lastcablexists = true; 00291 } 00292 if (debug) LogTrace("") << print(pd); 00293 return 0; 00294 }
const int PixelDataFormatter::ADC_bits = 8 [static, private] |
const int PixelDataFormatter::ADC_shift = 0 [static, private] |
bool PixelDataFormatter::checkOrder [private] |
Definition at line 77 of file PixelDataFormatter.h.
Referenced by PixelDataFormatter(), setErrorStatus(), and word2digi().
const int PixelDataFormatter::DCOL_bits = 5 [static, private] |
const int PixelDataFormatter::DCOL_shift = PXID_shift + PXID_bits [static, private] |
ErrorChecker PixelDataFormatter::errorcheck [private] |
Definition at line 78 of file PixelDataFormatter.h.
Referenced by interpretRawData(), and setErrorStatus().
bool PixelDataFormatter::includeErrors [private] |
Definition at line 76 of file PixelDataFormatter.h.
Referenced by interpretRawData(), PixelDataFormatter(), and setErrorStatus().
const int PixelDataFormatter::LINK_bits = 6 [static, private] |
const int PixelDataFormatter::LINK_shift = ROC_shift + ROC_bits [static, private] |
const int PixelDataFormatter::PXID_bits = 8 [static, private] |
const int PixelDataFormatter::PXID_shift = ADC_shift + ADC_bits [static, private] |
const int PixelDataFormatter::ROC_bits = 5 [static, private] |
const int PixelDataFormatter::ROC_shift = DCOL_shift + DCOL_bits [static, private] |
const SiPixelFedCablingMap* PixelDataFormatter::theCablingMap [private] |
Definition at line 75 of file PixelDataFormatter.h.
Referenced by formatData(), and interpretRawData().
int PixelDataFormatter::theDigiCounter [mutable, private] |
Definition at line 72 of file PixelDataFormatter.h.
Referenced by formatData(), nDigis(), and word2digi().
int PixelDataFormatter::theWordCounter [mutable, private] |
Definition at line 73 of file PixelDataFormatter.h.
Referenced by digi2word(), interpretRawData(), and nWords().