CMS 3D CMS Logo

Public Types | Public Member Functions | Private Member Functions | Private Attributes

PixelDataFormatter Class Reference

#include <PixelDataFormatter.h>

List of all members.

Public Types

typedef std::vector< PixelDigiDetDigis
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
typedef uint32_t Word32
typedef uint64_t Word64

Public Member Functions

FEDRawDataformatData (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 SiPixelFedCabling *map)
void setErrorStatus (bool ErrorStatus)
void setQualityStatus (bool QualityStatus, const SiPixelQuality *QualityInfo)

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 PixelDigi &digi) const
std::string print (const Word64 &word) const
int word2digi (const int fedId, const SiPixelFrameConverter *converter, const bool includeError, const bool useQuality, const Word32 &word, Digis &digis) const

Private Attributes

int allDetDigis
const SiPixelQualitybadPixelInfo
bool debug
ErrorChecker errorcheck
int hasDetDigis
bool includeErrors
const SiPixelFedCablingtheCablingTree
int theDigiCounter
int theWordCounter
bool useQualityInfo

Detailed Description

Transforms Pixel raw data of a given FED to orca digi and vice versa.

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.


Member Typedef Documentation

Definition at line 52 of file PixelDataFormatter.h.

Definition at line 55 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 56 of file PixelDataFormatter.h.

typedef std::pair<DetDigis::const_iterator, DetDigis::const_iterator> PixelDataFormatter::Range

Definition at line 54 of file PixelDataFormatter.h.

typedef uint32_t PixelDataFormatter::Word32

Definition at line 58 of file PixelDataFormatter.h.

typedef uint64_t PixelDataFormatter::Word64

Definition at line 59 of file PixelDataFormatter.h.


Constructor & Destructor Documentation

PixelDataFormatter::PixelDataFormatter ( const SiPixelFedCabling map)

Definition at line 47 of file PixelDataFormatter.cc.

References allDetDigis, hasDetDigis, includeErrors, and useQualityInfo.

  : theDigiCounter(0), theWordCounter(0), theCablingTree(map), badPixelInfo(0)
{
  int s32 = sizeof(Word32);
  int s64 = sizeof(Word64);
  int s8  = sizeof(char);
  if ( s8 != 1 || s32 != 4*s8 || s64 != 2*s32) {
     LogError("**PixelDataFormatter**")
          <<" unexpected sizes: "
          <<"  size of char is: " << s8
          <<", size of Word32 is: " << s32
          <<", size of Word64 is: " << s64
          <<", send exception" ;
  }
  includeErrors = false;
  useQualityInfo = false;
  allDetDigis = 0;
  hasDetDigis = 0;
}

Member Function Documentation

int PixelDataFormatter::checkError ( const Word32 data) const [private]
int PixelDataFormatter::digi2word ( const SiPixelFrameConverter converter,
uint32_t  detId,
const PixelDigi digi,
std::vector< Word32 > &  words 
) const [private]

Definition at line 224 of file PixelDataFormatter.cc.

References PixelDigi::adc(), ADC_shift, PixelDigi::column(), sipixelobjects::ElectronicIndex::dcol, DCOL_shift, ExpressReco_HICollisions_FallBack::detector, sipixelobjects::ElectronicIndex::link, LINK_shift, LogDebug, print(), sipixelobjects::ElectronicIndex::pxid, PXID_shift, sipixelobjects::ElectronicIndex::roc, ROC_shift, PixelDigi::row(), ntuplemaker::status, theWordCounter, and SiPixelFrameConverter::toCabling().

Referenced by formatData().

{
  LogDebug("PixelDataFormatter")
// <<" detId: " << detId 
  <<print(digi);

  DetectorIndex detector = {detId, digi.row(), digi.column()};
  ElectronicIndex  cabling;
  int status  = converter->toCabling(cabling, detector);
  if (status) return status;

  Word32 word =
             (cabling.link  << LINK_shift)
           | (cabling.roc << ROC_shift)
           | (cabling.dcol << DCOL_shift)
           | (cabling.pxid << PXID_shift)
           | (digi.adc() << ADC_shift);
  words.push_back(word);
  theWordCounter++;
  return 0;
}
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 150 of file PixelDataFormatter.cc.

References allDetDigis, FEDRawData::data(), digi2word(), Exception, hasDetDigis, SiPixelFrameConverter::hasDetUnit(), i, LogDebug, LogTrace, print(), asciidump::s, FEDTrailer::set(), FEDHeader::set(), ntuplemaker::status, theCablingTree, and theDigiCounter.

Referenced by SiPixelDigiToRaw::produce().

{
  vector<Word32> words;

  SiPixelFrameConverter converter(theCablingTree, fedId);
  for (Digis::const_iterator im = digis.begin(); im != digis.end(); im++) {
    allDetDigis++;
    uint32_t rawId = im->first;
    if ( !converter.hasDetUnit(rawId) ) continue;
    hasDetDigis++;
    const DetDigis & detDigis = im->second;
    for (DetDigis::const_iterator it = detDigis.begin(); it != detDigis.end(); it++) {
      theDigiCounter++;
      const PixelDigi & digi = (*it);
      int status = digi2word( &converter, rawId, digi, words); 
      if (status) {
         LogError("PixelDataFormatter::formatData exception") 
            <<" digi2word returns error #"<<status
            <<" Ndigis: "<<theDigiCounter << endl
            <<" detector: "<<rawId<< endl
            << print(digi) <<endl; 
      }
    }
  }
  LogTrace(" allDetDigis/hasDetDigis : ") << allDetDigis<<"/"<<hasDetDigis;

  //
  // since digis are written in the form of 64-bit packets
  // add extra 32-bit word to make number of digis even
  //
  if (words.size() %2 != 0) words.push_back( Word32(0) );


  //
  // size in Bytes; create output structure
  //
  int dataSize = words.size() * sizeof(Word32);
  int nHeaders = 1;
  int nTrailers = 1;
  dataSize += (nHeaders+nTrailers)*sizeof(Word64); 
  FEDRawData * rawData = new FEDRawData(dataSize);

  //
  // get begining of data;
  Word64 * word = reinterpret_cast<Word64* >(rawData->data());

  //
  // write one header
  FEDHeader::set(  reinterpret_cast<unsigned char*>(word), 0, lvl1_ID, 0, fedId); 
  word++;

  //
  // write data
  for (unsigned int i=0; i < words.size(); i+=2) {
    *word = (Word64(words[i]) << 32 ) | words[i+1];
    LogDebug("PixelDataFormatter")  << print(*word);
    word++;
  }

  // write one trailer
  FEDTrailer::set(  reinterpret_cast<unsigned char*>(word), dataSize/sizeof(Word64), 0,0,0);
  word++;

  //
  // check memory
  //
  if (word != reinterpret_cast<Word64* >(rawData->data()+dataSize)) {
    string s = "** PROBLEM in PixelDataFormatter !!!";
    throw cms::Exception(s);
  }

  return rawData;
}
void PixelDataFormatter::interpretRawData ( bool &  errorsInEvent,
int  fedId,
const FEDRawData data,
Digis digis,
Errors errors 
)

Definition at line 79 of file PixelDataFormatter.cc.

References ErrorChecker::checkCRC(), ErrorChecker::checkHeader(), ErrorChecker::checkROC(), ErrorChecker::checkTrailer(), ErrorChecker::conversionError(), FEDRawData::data(), debug, edm::MessageDrop::debugEnabled, errorcheck, includeErrors, edm::MessageDrop::instance(), LogDebug, LogTrace, nWords(), print(), FEDRawData::size(), theCablingTree, theWordCounter, useQualityInfo, w2, word2digi(), and WORD32_mask.

Referenced by SiPixelRawToDigi::produce().

{
  debug = edm::MessageDrop::instance()->debugEnabled;
  int nWords = rawData.size()/sizeof(Word64);
  if (nWords==0) return;

  SiPixelFrameConverter * converter = (theCablingTree) ? 
      new SiPixelFrameConverter(theCablingTree, fedId) : 0;

  // check CRC bit
  const Word64* trailer = reinterpret_cast<const Word64* >(rawData.data())+(nWords-1);
  bool CRC_OK = errorcheck.checkCRC(errorsInEvent, fedId, trailer, errors);
  
  if(CRC_OK) {
    // check headers
    const Word64* header = reinterpret_cast<const Word64* >(rawData.data()); header--;
    bool moreHeaders = true;
    while (moreHeaders) {
      header++;
      if (debug) LogTrace("")<<"HEADER:  " <<  print(*header);
      bool headerStatus = errorcheck.checkHeader(errorsInEvent, fedId, header, errors);
      moreHeaders = headerStatus;
    }

    // check trailers
    bool moreTrailers = true;
    trailer++;
    while (moreTrailers) {
      trailer--;
      if (debug) LogTrace("")<<"TRAILER: " <<  print(*trailer);
      bool trailerStatus = errorcheck.checkTrailer(errorsInEvent, fedId, nWords, trailer, errors);
      moreTrailers = trailerStatus;
    }

    // data words
    theWordCounter += 2*(nWords-2);
    if (debug) LogTrace("")<<"data words: "<< (trailer-header-1);
    for (const Word64* word = header+1; word != trailer; word++) {
      if (debug) LogTrace("")<<"DATA:    " <<  print(*word);
      Word32 w1 =  *word       & WORD32_mask;
      Word32 w2 =  *word >> 32 & WORD32_mask;
      if (w1==0) theWordCounter--;
      if (w2==0) theWordCounter--;

      // check status of word...
      bool notErrorROC1 = errorcheck.checkROC(errorsInEvent, fedId, converter, w1, errors);
      if (notErrorROC1) {
        int status1 = word2digi(fedId, converter, includeErrors, useQualityInfo, w1, digis);
        if (status1) {
            LogDebug("PixelDataFormatter::interpretRawData") 
                    << "status #" <<status1<<" returned for word1";
            errorsInEvent = true;
            errorcheck.conversionError(fedId, converter, status1, w1, errors);
        }
      }
      bool notErrorROC2 = errorcheck.checkROC(errorsInEvent, fedId, converter, w2, errors);
      if (notErrorROC2) {
        int status2 = word2digi(fedId, converter, includeErrors, useQualityInfo, w2, digis);
        if (status2) {
            LogDebug("PixelDataFormatter::interpretRawData") 
                    << "status #" <<status2<<" returned for word2";
            errorsInEvent = true;
            errorcheck.conversionError(fedId, converter, status2, w2, errors);
        }
      }
    }
  }  // end if(CRC_OK)
  delete converter;
}
int PixelDataFormatter::nDigis ( ) const [inline]

Definition at line 66 of file PixelDataFormatter.h.

References theDigiCounter.

Referenced by SiPixelDigiToRaw::produce(), and SiPixelRawToDigi::produce().

{ return theDigiCounter; }
int PixelDataFormatter::nWords ( ) const [inline]
std::string PixelDataFormatter::print ( const PixelDigi digi) const [private]

Definition at line 295 of file PixelDataFormatter.cc.

References PixelDigi::adc(), PixelDigi::column(), and PixelDigi::row().

Referenced by digi2word(), formatData(), interpretRawData(), and word2digi().

{
  ostringstream str;
  str << " DIGI: row: " << digi.row() <<", col: " << digi.column() <<", adc: " << digi.adc();
  return str.str();
}
std::string PixelDataFormatter::print ( const Word64 word) const [private]

Definition at line 302 of file PixelDataFormatter.cc.

{
  ostringstream str;
  //str  <<"word64:  " << *reinterpret_cast<const bitset<64>*> (&word);
  str  <<"word64:  " << reinterpret_cast<const bitset<64>&> (word);
  return str.str();
}
void PixelDataFormatter::setErrorStatus ( bool  ErrorStatus)
void PixelDataFormatter::setQualityStatus ( bool  QualityStatus,
const SiPixelQuality QualityInfo 
)

Definition at line 73 of file PixelDataFormatter.cc.

References badPixelInfo, and useQualityInfo.

Referenced by SiPixelRawToDigi::produce().

{
  useQualityInfo = QualityStatus;
  badPixelInfo = QualityInfo;
}
int PixelDataFormatter::word2digi ( const int  fedId,
const SiPixelFrameConverter converter,
const bool  includeError,
const bool  useQuality,
const Word32 word,
Digis digis 
) const [private]

Definition at line 248 of file PixelDataFormatter.cc.

References ecalMGPA::adc(), ADC_mask, ADC_shift, badPixelInfo, sipixelobjects::DetectorIndex::col, sipixelobjects::ElectronicIndex::dcol, DCOL_mask, DCOL_shift, debug, SiPixelFedCabling::findItem(), sipixelobjects::PixelROC::idInDetUnit(), SiPixelQuality::IsRocBad(), sipixelobjects::ElectronicIndex::link, LINK_mask, LINK_shift, LogTrace, path(), print(), sipixelobjects::ElectronicIndex::pxid, PXID_mask, PXID_shift, sipixelobjects::DetectorIndex::rawId, sipixelobjects::ElectronicIndex::roc, ROC_mask, ROC_shift, sipixelobjects::LocalPixel::rocCol(), sipixelobjects::LocalPixel::rocRow(), sipixelobjects::DetectorIndex::row, ntuplemaker::status, theCablingTree, theDigiCounter, and SiPixelFrameConverter::toDetector().

Referenced by interpretRawData().

{
  // do not interpret false digis
  if (word == 0 ) return 0;

  ElectronicIndex cabling;
  cabling.dcol = (word >> DCOL_shift) & DCOL_mask;
  cabling.pxid = (word >> PXID_shift) & PXID_mask;
  cabling.link = (word >> LINK_shift) & LINK_mask;
  cabling.roc  = (word >> ROC_shift) & ROC_mask;
  int adc      = (word >> ADC_shift) & ADC_mask;

  if (debug) {
    LocalPixel::DcolPxid pixel = {cabling.dcol,cabling.pxid};
    LocalPixel local(pixel);
    LogTrace("")<<" link: "<<cabling.link<<", roc: "<<cabling.roc
                <<" rocRow: "<<local.rocRow()<<", rocCol:"<<local.rocCol()
                <<" (dcol: "<<cabling.dcol<<", pxid:"<<cabling.pxid<<"), adc:"<<adc;
  }

  if (!converter) return 0;

  DetectorIndex detIdx;
  int status = converter->toDetector(cabling, detIdx);
  if (status) return status;

  // exclude ROC(raw) based on bad ROC list bad in SiPixelQuality
  // enable: process.siPixelDigis.UseQualityInfo = True
  // 20-10-2010 A.Y.
  if (useQuality&&badPixelInfo) {
    CablingPathToDetUnit path = {fedId, cabling.link, cabling.roc};
    const PixelROC * roc = theCablingTree->findItem(path);
    short rocInDet = (short) roc->idInDetUnit();
    bool badROC = badPixelInfo->IsRocBad(detIdx.rawId, rocInDet);
    if (badROC) return 0;
  }

  PixelDigi pd(detIdx.row, detIdx.col, adc);
  digis[detIdx.rawId].push_back(pd);

  theDigiCounter++;

  if (debug)  LogTrace("") << print(pd);
  return 0;
}

Member Data Documentation

Definition at line 82 of file PixelDataFormatter.h.

Referenced by formatData(), and PixelDataFormatter().

Definition at line 78 of file PixelDataFormatter.h.

Referenced by setQualityStatus(), and word2digi().

bool PixelDataFormatter::debug [private]

Definition at line 81 of file PixelDataFormatter.h.

Referenced by interpretRawData(), and word2digi().

Definition at line 84 of file PixelDataFormatter.h.

Referenced by interpretRawData(), and setErrorStatus().

Definition at line 83 of file PixelDataFormatter.h.

Referenced by formatData(), and PixelDataFormatter().

Definition at line 79 of file PixelDataFormatter.h.

Referenced by interpretRawData(), PixelDataFormatter(), and setErrorStatus().

Definition at line 77 of file PixelDataFormatter.h.

Referenced by formatData(), interpretRawData(), and word2digi().

int PixelDataFormatter::theDigiCounter [mutable, private]

Definition at line 74 of file PixelDataFormatter.h.

Referenced by formatData(), nDigis(), and word2digi().

int PixelDataFormatter::theWordCounter [mutable, private]

Definition at line 75 of file PixelDataFormatter.h.

Referenced by digi2word(), interpretRawData(), and nWords().

Definition at line 80 of file PixelDataFormatter.h.

Referenced by interpretRawData(), PixelDataFormatter(), and setQualityStatus().