#include <ESUnpacker.h>
Public Types | |
typedef unsigned int | Word32 |
typedef long long | Word64 |
Public Member Functions | |
ESUnpacker (const edm::ParameterSet &ps) | |
void | interpretRawData (int fedId, const FEDRawData &rawData, ESRawDataCollection &dccs, ESLocalRawDataCollection &kchips, ESDigiCollection &digis) |
void | setBX (int i) |
void | setLV1 (int i) |
void | setOrbitNumber (int i) |
void | setRunNumber (int i) |
void | setTriggerType (int i) |
void | word2digi (int kchip, int kPACE[4], const Word64 &word, ESDigiCollection &digis) |
~ESUnpacker () | |
Protected Attributes | |
Word64 | m1 |
Word64 | m12 |
Word64 | m16 |
Word64 | m2 |
Word64 | m32 |
Word64 | m4 |
Word64 | m5 |
Word64 | m6 |
Word64 | m8 |
int | pl_ [4288][4] |
int | x_ [4288][4] |
int | y_ [4288][4] |
int | zside_ [4288][4] |
Private Member Functions | |
std::string | print (const Word64 &word) const |
Private Attributes | |
int | bx_ |
int | dac_ |
bool | debug_ |
int | FEch_ [36] |
int | fedId_ |
int | gain_ |
edm::FileInPath | lookup_ |
int | lv1_ |
int | optoRX0_ |
int | optoRX1_ |
int | optoRX2_ |
int | orbit_number_ |
int | precision_ |
const edm::ParameterSet | pset_ |
int | run_number_ |
int | runtype_ |
int | seqtype_ |
int | trgtype_ |
int | vmajor_ |
int | vminor_ |
Definition at line 25 of file ESUnpacker.h.
typedef unsigned int ESUnpacker::Word32 |
Definition at line 29 of file ESUnpacker.h.
typedef long long ESUnpacker::Word64 |
Definition at line 30 of file ESUnpacker.h.
ESUnpacker::ESUnpacker | ( | const edm::ParameterSet & | ps | ) |
Definition at line 10 of file ESUnpacker.cc.
References gather_cfg::cout, debug_, mergeVDriftHistosByStation::file, edm::ParameterSet::getParameter(), edm::ParameterSet::getUntrackedParameter(), i, lookup_, m1, m12, m16, m2, m32, m4, m5, m6, m8, submitDQMOfflineCAF::nLines, pl_, pset_, x_, y_, and zside_.
: pset_(ps), fedId_(0), run_number_(0), orbit_number_(0), bx_(0), lv1_(0), trgtype_(0) { debug_ = pset_.getUntrackedParameter<bool>("debugMode", false); lookup_ = ps.getParameter<edm::FileInPath>("LookupTable"); m1 = ~(~Word64(0) << 1); m2 = ~(~Word64(0) << 2); m4 = ~(~Word64(0) << 4); m5 = ~(~Word64(0) << 5); m6 = ~(~Word64(0) << 6); m8 = ~(~Word64(0) << 8); m12 = ~(~Word64(0) << 12); m16 = ~(~Word64(0) << 16); m32 = ~(~Word64(0) << 32); // read in look-up table int nLines, iz, ip, ix, iy, fed, kchip, pace, bundle, fiber, optorx; std::ifstream file; file.open(lookup_.fullPath().c_str()); if( file.is_open() ) { file >> nLines; for (int i=0; i<nLines; ++i) { file>> iz >> ip >> ix >> iy >> fed >> kchip >> pace >> bundle >> fiber >> optorx; zside_[kchip-1][pace-1] = iz; pl_[kchip-1][pace-1] = ip; x_[kchip-1][pace-1] = ix; y_[kchip-1][pace-1] = iy; } } else { std::cout<<"ESUnpacker::ESUnpacker : Look up table file can not be found in "<<lookup_.fullPath().c_str()<<std::endl; } }
ESUnpacker::~ESUnpacker | ( | ) |
Definition at line 50 of file ESUnpacker.cc.
{ }
void ESUnpacker::interpretRawData | ( | int | fedId, |
const FEDRawData & | rawData, | ||
ESRawDataCollection & | dccs, | ||
ESLocalRawDataCollection & | kchips, | ||
ESDigiCollection & | digis | ||
) |
Definition at line 53 of file ESUnpacker.cc.
References bx_, FEDHeader::bxID(), FEDTrailer::check(), FEDHeader::check(), gather_cfg::cout, dac_, FEDRawData::data(), debug_, FEch_, fedId_, gain_, ESDCCHeaderBlock::getOptoRX0(), ESDCCHeaderBlock::getOptoRX1(), ESDCCHeaderBlock::getOptoRX2(), j, FEDTrailer::lenght(), lv1_, FEDHeader::lvl1ID(), m1, m12, m16, m32, m4, m6, m8, FEDHeader::moreHeaders(), FEDTrailer::moreTrailers(), optoRX0_, optoRX1_, optoRX2_, orbit_number_, precision_, print(), edm::SortedCollection< T, SORT >::push_back(), runtype_, seqtype_, ESKCHIPBlock::setBC(), ESDCCHeaderBlock::setBX(), ESDCCHeaderBlock::setDAC(), ESDCCHeaderBlock::setDCCErrors(), ESKCHIPBlock::setEC(), ESDCCHeaderBlock::setFEChannelStatus(), ESDCCHeaderBlock::setFedId(), ESKCHIPBlock::setFlag1(), ESKCHIPBlock::setFlag2(), ESDCCHeaderBlock::setGain(), ESKCHIPBlock::setId(), ESDCCHeaderBlock::setLV1(), ESDCCHeaderBlock::setMajorVersion(), ESDCCHeaderBlock::setMinorVersion(), ESKCHIPBlock::setOptoBC(), ESDCCHeaderBlock::setOptoBC0(), ESDCCHeaderBlock::setOptoBC1(), ESDCCHeaderBlock::setOptoBC2(), ESKCHIPBlock::setOptoEC(), ESDCCHeaderBlock::setOptoRX0(), ESDCCHeaderBlock::setOptoRX1(), ESDCCHeaderBlock::setOptoRX2(), ESDCCHeaderBlock::setOrbitNumber(), ESDCCHeaderBlock::setPrecision(), ESDCCHeaderBlock::setRunType(), ESDCCHeaderBlock::setSeqType(), ESDCCHeaderBlock::setTriggerType(), FEDRawData::size(), FEDHeader::sourceID(), trgtype_, vmajor_, vminor_, and word2digi().
Referenced by ESRawToDigi::produce(), and ESUnpackerWorker::work().
{ int nWords = rawData.size()/sizeof(Word64); if (nWords==0) return; int dccWords = 6; int head, kPACE[4], kFlag1, kFlag2, kBC, kEC, optoBC, optoEC; int kid = -1; ESDCCHeaderBlock ESDCCHeader; ESDCCHeader.setFedId(fedId); // Event header const Word64* header = reinterpret_cast<const Word64* >(rawData.data()); --header; bool moreHeaders = true; while (moreHeaders) { ++header; FEDHeader ESHeader( reinterpret_cast<const unsigned char*>(header) ); if ( !ESHeader.check() ) { if (debug_) edm::LogWarning("Invalid Data")<<"ES : Failed header check !"; return; } fedId_ = ESHeader.sourceID(); lv1_ = ESHeader.lvl1ID(); bx_ = ESHeader.bxID(); if (debug_) { std::cout<<"[ESUnpacker]: FED Header candidate. Is header? "<< ESHeader.check(); if (ESHeader.check()) std::cout <<". BXID: "<<bx_<<" SourceID : "<<fedId_<<" L1ID: "<<lv1_<<std::endl; else std::cout<<" WARNING!, this is not a ES Header"<<std::endl; } moreHeaders = ESHeader.moreHeaders(); } if ( fedId != fedId_) { if (debug_) edm::LogWarning("Invalid Data")<<"Invalid ES data with source id " <<fedId_; ESDCCHeader.setDCCErrors(1); dccs.push_back(ESDCCHeader); return; } ESDCCHeader.setLV1(lv1_); ESDCCHeader.setBX(bx_); // Event trailer int slinkCRC = 1; const Word64* trailer = reinterpret_cast<const Word64* >(rawData.data())+(nWords-1); ++trailer; bool moreTrailers = true; while (moreTrailers) { --trailer; FEDTrailer ESTrailer(reinterpret_cast<const unsigned char*>(trailer)); if ( !ESTrailer.check()) { ++trailer; if (debug_) edm::LogWarning("Invalid Data")<<"ES : Failed trailer check !"; return; } if ( ESTrailer.lenght() != nWords) { if (debug_) edm::LogWarning("Invalid Data")<<"Invalid ES data : the length is not correct !"; ESDCCHeader.setDCCErrors(2); dccs.push_back(ESDCCHeader); return; } if ( ESTrailer.lenght() < 8) { if (debug_) edm::LogWarning("Invalid Data")<<"Invalid ES data : the length is not correct !"; ESDCCHeader.setDCCErrors(3); dccs.push_back(ESDCCHeader); return; } slinkCRC = (*trailer >> 2 ) & 0x1; if (debug_) { std::cout<<"[ESUnpacker]: FED Trailer candidate. Is trailer? "<<ESTrailer.check(); if (ESTrailer.check()) std::cout<<". Length of the ES event: "<<ESTrailer.lenght()<<std::endl; else std::cout<<" WARNING!, this is not a ES Trailer"<<std::endl; } moreTrailers = ESTrailer.moreTrailers(); } if (slinkCRC != 0) { ESDCCHeader.setDCCErrors(101); dccs.push_back(ESDCCHeader); return; } // DCC data std::vector<int> FEch_status; int dccHeaderCount = 0; int dccLineCount = 0; int dccHead, dccLine; int dccCRC1_ = 0; int dccCRC2_ = 0; int dccCRC3_ = 0; for (const Word64* word=(header+1); word!=(header+dccWords+1); ++word) { if (debug_) std::cout<<"DCC : "<<print(*word)<<std::endl; dccHead = (*word >> 60) & m4; if (dccHead == 3) dccHeaderCount++; dccLine = (*word >> 56) & m4; dccLineCount++; if (dccLine != dccLineCount) { if (debug_) edm::LogWarning("Invalid Data")<<"Invalid ES data : DCC header order is not correct !"; ESDCCHeader.setDCCErrors(4); dccs.push_back(ESDCCHeader); return; } if (dccLineCount == 1) { dccCRC1_ = (*word >> 24) & m1; dccCRC2_ = (*word >> 25) & m1; dccCRC3_ = (*word >> 26) & m1; } else if (dccLineCount == 2) { runtype_ = (*word >> 0) & m4; seqtype_ = (*word >> 4) & m4; dac_ = (*word >> 8) & m12; gain_ = (*word >> 20) & m1; precision_ = (*word >> 21) & m1; trgtype_ = (*word >> 34) & m6; ESDCCHeader.setRunType(runtype_); ESDCCHeader.setSeqType(seqtype_); ESDCCHeader.setTriggerType(trgtype_); ESDCCHeader.setDAC(dac_); ESDCCHeader.setGain(gain_); ESDCCHeader.setPrecision(precision_); } if (dccLineCount == 3) { orbit_number_ = (*word >> 0) & m32; vminor_ = (*word >> 40) & m8; vmajor_ = (*word >> 48) & m8; ESDCCHeader.setOrbitNumber(orbit_number_); ESDCCHeader.setMajorVersion(vmajor_); ESDCCHeader.setMinorVersion(vminor_); } if (dccLineCount == 4) optoRX0_ = (*word >> 48) & m8; if (dccLineCount == 5) optoRX1_ = (*word >> 48) & m8; if (dccLineCount == 6) optoRX2_ = (*word >> 48) & m8; if (dccLineCount >=4) { for (unsigned int j=0; j<12; ++j) { FEch_[(dccLineCount-4)*12+j] = (*word >> (j*4)) & m4; FEch_status.push_back(FEch_[(dccLineCount-4)*12+j]); } } } if (vmajor_ < 4) { if (debug_) edm::LogWarning("Invalid Data")<<"Invalid ES data format : "<<vmajor_<<" "<<vminor_; return; } if (dccHeaderCount != 6) { edm::LogWarning("Invalid Data")<<"Invalid ES data : DCC header lines are "<<dccHeaderCount; ESDCCHeader.setDCCErrors(5); dccs.push_back(ESDCCHeader); return; } ESDCCHeader.setOptoRX0(optoRX0_ + dccCRC1_); ESDCCHeader.setOptoRX1(optoRX1_ + dccCRC2_); ESDCCHeader.setOptoRX2(optoRX2_ + dccCRC3_); ESDCCHeader.setFEChannelStatus(FEch_status); // Event data int opto = 0; for (const Word64* word=(header+dccWords+1); word!=trailer; ++word) { if (debug_) std::cout<<"Event : "<<print(*word)<<std::endl; head = (*word >> 60) & m4; if (head == 12) { if ((opto==1 && ESDCCHeader.getOptoRX0()==129) || (opto==2 && ESDCCHeader.getOptoRX1()==129) || (opto==3 && ESDCCHeader.getOptoRX2()==129)) word2digi(kid, kPACE, *word, digis); } else if (head == 9) { kid = (*word >> 2) & 0x07ff; kPACE[0] = (*word >> 16) & m1; kPACE[1] = (*word >> 17) & m1; kPACE[2] = (*word >> 18) & m1; kPACE[3] = (*word >> 19) & m1; kFlag2 = (*word >> 20) & m4; kFlag1 = (*word >> 24) & m8; kBC = (*word >> 32) & m16; kEC = (*word >> 48) & m8; ESKCHIPBlock ESKCHIP; ESKCHIP.setId(kid); ESKCHIP.setBC(kBC); ESKCHIP.setEC(kEC); ESKCHIP.setOptoBC(optoBC); ESKCHIP.setOptoEC(optoEC); ESKCHIP.setFlag1(kFlag1); ESKCHIP.setFlag2(kFlag2); kchips.push_back(ESKCHIP); } else if (head == 6) { optoBC = (*word >> 32) & m16; optoEC = (*word >> 48) & m8; if (opto==0) ESDCCHeader.setOptoBC0(optoBC); else if (opto==1) ESDCCHeader.setOptoBC1(optoBC); else if (opto==2) ESDCCHeader.setOptoBC2(optoBC); opto++; } } dccs.push_back(ESDCCHeader); }
std::string ESUnpacker::print | ( | const Word64 & | word | ) | const [private] |
Definition at line 302 of file ESUnpacker.cc.
Referenced by interpretRawData().
{ std::ostringstream str; str << "Word64: " << reinterpret_cast<const std::bitset<64>&> (word); return str.str(); }
void ESUnpacker::setBX | ( | int | i | ) | [inline] |
void ESUnpacker::setLV1 | ( | int | i | ) | [inline] |
void ESUnpacker::setOrbitNumber | ( | int | i | ) | [inline] |
void ESUnpacker::setRunNumber | ( | int | i | ) | [inline] |
void ESUnpacker::setTriggerType | ( | int | i | ) | [inline] |
void ESUnpacker::word2digi | ( | int | kchip, |
int | kPACE[4], | ||
const Word64 & | word, | ||
ESDigiCollection & | digis | ||
) |
Definition at line 255 of file ESUnpacker.cc.
References ecalMGPA::adc(), ESSample::adc(), gather_cfg::cout, debug_, i, m16, m2, m5, pl_, ESDetId::plane(), ESDigiCollection::push_back(), ESDataFrame::sample(), ESDataFrame::setSample(), ESDataFrame::setSize(), ESDetId::six(), ESDetId::siy(), ESDetId::strip(), ESDetId::validDetId(), vmajor_, vminor_, x_, y_, ESDetId::zside(), and zside_.
Referenced by interpretRawData().
{ int pace = (word >> 53) & m2; if (kPACE[pace]==0) return; if (kid > 1511 || kid < 1) return; int adc[3]; adc[0] = (word >> 0) & m16; adc[1] = (word >> 16) & m16; adc[2] = (word >> 32) & m16; int strip = (word >> 48) & m5; if (debug_) std::cout<<kid<<" "<<strip<<" "<<pace<<" "<<adc[0]<<" "<<adc[1]<<" "<<adc[2]<<std::endl; int zside, plane, ix, iy; zside = zside_[kid-1][pace]; plane = pl_[kid-1][pace]; ix = x_[kid-1][pace]; iy = y_[kid-1][pace]; // convert strip number from electronics id to detector id if (vmajor_ == 4 && (vminor_==2 || vminor_==3)) { if (zside == 1 && plane == 1 && iy <= 20) strip = 31 - strip; if (zside == 1 && plane == 2 && ix > 20) strip = 31 - strip; if (zside == -1 && plane == 1 && iy > 20) strip = 31 - strip; if (zside == -1 && plane == 2 && ix <= 20) strip = 31 - strip; } if (debug_) std::cout<<"DetId : "<<zside<<" "<<plane<<" "<<ix<<" "<<iy<<" "<<strip+1<<std::endl; if (ESDetId::validDetId(strip+1, ix, iy, plane, zside)) { ESDetId detId(strip+1, ix, iy, plane, zside); ESDataFrame df(detId); df.setSize(3); for (int i=0; i<3; i++) df.setSample(i, adc[i]); digis.push_back(df); if (debug_) std::cout<<"Si : "<<detId.zside()<<" "<<detId.plane()<<" "<<detId.six()<<" "<<detId.siy()<<" "<<detId.strip()<<" ("<<kid<<","<<pace<<") "<<df.sample(0).adc()<<" "<<df.sample(1).adc()<<" "<<df.sample(2).adc()<<std::endl; } }
int ESUnpacker::bx_ [private] |
Definition at line 51 of file ESUnpacker.h.
Referenced by interpretRawData(), and setBX().
int ESUnpacker::dac_ [private] |
Definition at line 53 of file ESUnpacker.h.
Referenced by interpretRawData().
bool ESUnpacker::debug_ [private] |
Definition at line 66 of file ESUnpacker.h.
Referenced by ESUnpacker(), interpretRawData(), and word2digi().
int ESUnpacker::FEch_[36] [private] |
Definition at line 64 of file ESUnpacker.h.
Referenced by interpretRawData().
int ESUnpacker::fedId_ [private] |
Definition at line 48 of file ESUnpacker.h.
Referenced by interpretRawData().
int ESUnpacker::gain_ [private] |
Definition at line 54 of file ESUnpacker.h.
Referenced by interpretRawData().
edm::FileInPath ESUnpacker::lookup_ [private] |
Definition at line 67 of file ESUnpacker.h.
Referenced by ESUnpacker().
int ESUnpacker::lv1_ [private] |
Definition at line 52 of file ESUnpacker.h.
Referenced by interpretRawData(), and setLV1().
Word64 ESUnpacker::m1 [protected] |
Definition at line 73 of file ESUnpacker.h.
Referenced by ESUnpacker(), and interpretRawData().
Word64 ESUnpacker::m12 [protected] |
Definition at line 73 of file ESUnpacker.h.
Referenced by ESUnpacker(), and interpretRawData().
Word64 ESUnpacker::m16 [protected] |
Definition at line 73 of file ESUnpacker.h.
Referenced by ESUnpacker(), interpretRawData(), and word2digi().
Word64 ESUnpacker::m2 [protected] |
Definition at line 73 of file ESUnpacker.h.
Referenced by ESUnpacker(), and word2digi().
Word64 ESUnpacker::m32 [protected] |
Definition at line 73 of file ESUnpacker.h.
Referenced by ESUnpacker(), and interpretRawData().
Word64 ESUnpacker::m4 [protected] |
Definition at line 73 of file ESUnpacker.h.
Referenced by ESUnpacker(), and interpretRawData().
Word64 ESUnpacker::m5 [protected] |
Definition at line 73 of file ESUnpacker.h.
Referenced by ESUnpacker(), and word2digi().
Word64 ESUnpacker::m6 [protected] |
Definition at line 73 of file ESUnpacker.h.
Referenced by ESUnpacker(), and interpretRawData().
Word64 ESUnpacker::m8 [protected] |
Definition at line 73 of file ESUnpacker.h.
Referenced by ESUnpacker(), and interpretRawData().
int ESUnpacker::optoRX0_ [private] |
Definition at line 61 of file ESUnpacker.h.
Referenced by interpretRawData().
int ESUnpacker::optoRX1_ [private] |
Definition at line 62 of file ESUnpacker.h.
Referenced by interpretRawData().
int ESUnpacker::optoRX2_ [private] |
Definition at line 63 of file ESUnpacker.h.
Referenced by interpretRawData().
int ESUnpacker::orbit_number_ [private] |
Definition at line 50 of file ESUnpacker.h.
Referenced by interpretRawData(), and setOrbitNumber().
int ESUnpacker::pl_[4288][4] [protected] |
Definition at line 75 of file ESUnpacker.h.
Referenced by ESUnpacker(), and word2digi().
int ESUnpacker::precision_ [private] |
Definition at line 55 of file ESUnpacker.h.
Referenced by interpretRawData().
const edm::ParameterSet ESUnpacker::pset_ [private] |
Definition at line 42 of file ESUnpacker.h.
Referenced by ESUnpacker().
int ESUnpacker::run_number_ [private] |
Definition at line 49 of file ESUnpacker.h.
Referenced by setRunNumber().
int ESUnpacker::runtype_ [private] |
Definition at line 56 of file ESUnpacker.h.
Referenced by interpretRawData().
int ESUnpacker::seqtype_ [private] |
Definition at line 57 of file ESUnpacker.h.
Referenced by interpretRawData().
int ESUnpacker::trgtype_ [private] |
Definition at line 58 of file ESUnpacker.h.
Referenced by interpretRawData(), and setTriggerType().
int ESUnpacker::vmajor_ [private] |
Definition at line 60 of file ESUnpacker.h.
Referenced by interpretRawData(), and word2digi().
int ESUnpacker::vminor_ [private] |
Definition at line 59 of file ESUnpacker.h.
Referenced by interpretRawData(), and word2digi().
int ESUnpacker::x_[4288][4] [protected] |
Definition at line 75 of file ESUnpacker.h.
Referenced by ESUnpacker(), and word2digi().
int ESUnpacker::y_[4288][4] [protected] |
Definition at line 75 of file ESUnpacker.h.
Referenced by ESUnpacker(), and word2digi().
int ESUnpacker::zside_[4288][4] [protected] |
Definition at line 75 of file ESUnpacker.h.
Referenced by ESUnpacker(), and word2digi().