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 std::map< int, FEDRawDataRawData
typedef uint32_t Word32
typedef uint64_t Word64

Public Member Functions

void formatRawData (unsigned int lvl1_ID, RawData &fedRawData, const Digis &digis)
void interpretRawData (bool &errorsInEvent, int fedId, const FEDRawData &data, Digis &digis, Errors &errors)
int nDigis () const
int nWords () const
void passFrameReverter (const SiPixelFrameReverter *reverter)
 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 (uint32_t detId, const PixelDigi &digi, std::map< int, 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
const SiPixelFrameRevertertheFrameReverter
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 50 of file PixelDataFormatter.h.


Member Typedef Documentation

Definition at line 55 of file PixelDataFormatter.h.

Definition at line 58 of file PixelDataFormatter.h.

typedef std::map<uint32_t, DetDigis> PixelDataFormatter::Digis

Definition at line 56 of file PixelDataFormatter.h.

typedef std::map<uint32_t, DetErrors> PixelDataFormatter::Errors

Definition at line 59 of file PixelDataFormatter.h.

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

Definition at line 57 of file PixelDataFormatter.h.

typedef std::map<int, FEDRawData> PixelDataFormatter::RawData

Definition at line 54 of file PixelDataFormatter.h.

typedef uint32_t PixelDataFormatter::Word32

Definition at line 61 of file PixelDataFormatter.h.

typedef uint64_t PixelDataFormatter::Word64

Definition at line 62 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 ( uint32_t  detId,
const PixelDigi digi,
std::map< int, std::vector< Word32 > > &  words 
) const [private]

Definition at line 223 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(), theFrameReverter, theWordCounter, and SiPixelFrameReverter::toCabling().

Referenced by formatRawData().

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

  DetectorIndex detector = {detId, digi.row(), digi.column()};
  ElectronicIndex cabling;
  int fedId  = theFrameReverter->toCabling(cabling, detector);
  if (fedId<0) return fedId;

  Word32 word =
             (cabling.link << LINK_shift)
           | (cabling.roc << ROC_shift)
           | (cabling.dcol << DCOL_shift)
           | (cabling.pxid << PXID_shift)
           | (digi.adc() << ADC_shift);
  words[fedId].push_back(word);
  theWordCounter++;

  return 0;
}
uint32_t PixelDataFormatter::errorDetId ( const SiPixelFrameConverter converter,
int  fedId,
int  errorType,
const Word32 word 
) const [private]
void PixelDataFormatter::formatRawData ( unsigned int  lvl1_ID,
RawData fedRawData,
const Digis digis 
)

Definition at line 155 of file PixelDataFormatter.cc.

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

Referenced by SiPixelDigiToRaw::produce().

{
  std::map<int, vector<Word32> > words;

  // translate digis into 32-bit raw words and store in map indexed by Fed
  for (Digis::const_iterator im = digis.begin(); im != digis.end(); im++) {
    allDetDigis++;
    uint32_t rawId = im->first;
    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( rawId, digi, words);
      if (status) {
         LogError("PixelDataFormatter::formatData exception")
            <<" digi2word returns error #"<<status
            <<" Ndigis: "<<theDigiCounter << endl
            <<" detector: "<<rawId<< endl
            << print(digi) <<endl;
      } // if (status)
    } // for (DetDigis
  } // for (Digis
  LogTrace(" allDetDigis/hasDetDigis : ") << allDetDigis<<"/"<<hasDetDigis;

  typedef std::map<int, vector<Word32> >::const_iterator RI;
  for (RI feddata = words.begin(); feddata != words.end(); feddata++) {
    int fedId = feddata->first;
    // since raw words are written in the form of 64-bit packets
    // add extra 32-bit word to make number of words even if necessary
    if (words.find(fedId)->second.size() %2 != 0) words[fedId].push_back( Word32(0) );

    // size in Bytes; create output structure
    int dataSize = words.find(fedId)->second.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
    unsigned int nWord32InFed = words.find(fedId)->second.size();
    for (unsigned int i=0; i < nWord32InFed; i+=2) {
      *word = (Word64(words.find(fedId)->second[i]) << 32 ) | words.find(fedId)->second[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);
    } // if (word !=
    fedRawData[fedId] = *rawData;
    delete rawData;
  } // for (RI feddata 
}
void PixelDataFormatter::interpretRawData ( bool &  errorsInEvent,
int  fedId,
const FEDRawData data,
Digis digis,
Errors errors 
)

Definition at line 84 of file PixelDataFormatter.cc.

References ErrorChecker::checkCRC(), ErrorChecker::checkHeader(), ErrorChecker::checkROC(), ErrorChecker::checkTrailer(), ErrorChecker::conversionError(), FEDRawData::data(), debug, edm::MessageDrop::debugEnabled, errorcheck, MultipleCompare::header, 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 70 of file PixelDataFormatter.h.

References theDigiCounter.

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

{ return theDigiCounter; }
int PixelDataFormatter::nWords ( ) const [inline]
void PixelDataFormatter::passFrameReverter ( const SiPixelFrameReverter reverter)

Definition at line 79 of file PixelDataFormatter.cc.

References theFrameReverter.

Referenced by SiPixelDigiToRaw::produce().

{
  theFrameReverter = reverter;
}
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(), formatRawData(), 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);
  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 87 of file PixelDataFormatter.h.

Referenced by formatRawData(), and PixelDataFormatter().

Definition at line 83 of file PixelDataFormatter.h.

Referenced by setQualityStatus(), and word2digi().

bool PixelDataFormatter::debug [private]

Definition at line 86 of file PixelDataFormatter.h.

Referenced by interpretRawData(), and word2digi().

Definition at line 89 of file PixelDataFormatter.h.

Referenced by interpretRawData(), and setErrorStatus().

Definition at line 88 of file PixelDataFormatter.h.

Referenced by formatRawData(), and PixelDataFormatter().

Definition at line 84 of file PixelDataFormatter.h.

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

Definition at line 81 of file PixelDataFormatter.h.

Referenced by interpretRawData(), and word2digi().

int PixelDataFormatter::theDigiCounter [mutable, private]

Definition at line 78 of file PixelDataFormatter.h.

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

Definition at line 82 of file PixelDataFormatter.h.

Referenced by digi2word(), and passFrameReverter().

int PixelDataFormatter::theWordCounter [mutable, private]

Definition at line 79 of file PixelDataFormatter.h.

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

Definition at line 85 of file PixelDataFormatter.h.

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