CMS 3D CMS Logo

ESUnpacker Class Reference

#include <EventFilter/ESRawToDigi/interface/ESUnpacker.h>

List of all members.

Public Types

typedef unsigned int Word32
typedef long long Word64

Public Member Functions

 ESUnpacker (const 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

string print (const Word64 &word) const

Private Attributes

int bx_
int dac_
bool debug_
int FEch_ [36]
int fedId_
int gain_
FileInPath lookup_
int lv1_
int optoRX0_
int optoRX1_
int optoRX2_
int orbit_number_
int precision_
const ParameterSet pset_
int run_number_
int runtype_
int seqtype_
int trgtype_
int vmajor_
int vminor_


Detailed Description

Definition at line 25 of file ESUnpacker.h.


Member Typedef Documentation

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.


Constructor & Destructor Documentation

ESUnpacker::ESUnpacker ( const ParameterSet ps  ) 

Definition at line 10 of file ESUnpacker.cc.

References GenMuonPlsPt100GeV_cfg::cout, debug_, lat::endl(), 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_.

00011   : pset_(ps), fedId_(0), run_number_(0), orbit_number_(0), bx_(0), lv1_(0), trgtype_(0)
00012 {
00013 
00014   debug_ = pset_.getUntrackedParameter<bool>("debugMode", false);
00015   lookup_ = ps.getParameter<FileInPath>("LookupTable");
00016 
00017   m1  = ~(~Word64(0) << 1);
00018   m2  = ~(~Word64(0) << 2);
00019   m4  = ~(~Word64(0) << 4);
00020   m5  = ~(~Word64(0) << 5);
00021   m6  = ~(~Word64(0) << 6);
00022   m8  = ~(~Word64(0) << 8);
00023   m12 = ~(~Word64(0) << 12);
00024   m16 = ~(~Word64(0) << 16);
00025   m32 = ~(~Word64(0) << 32);
00026 
00027   // read in look-up table
00028   int nLines, iz, ip, ix, iy, fed, kchip, pace, bundle, fiber, optorx;
00029   ifstream file;
00030   file.open(lookup_.fullPath().c_str());
00031   if( file.is_open() ) {
00032 
00033     file >> nLines;
00034 
00035     for (int i=0; i<nLines; ++i) {
00036       file>> iz >> ip >> ix >> iy >> fed >> kchip >> pace >> bundle >> fiber >> optorx;
00037 
00038       zside_[kchip-1][pace-1] = iz;
00039       pl_[kchip-1][pace-1] = ip;
00040       x_[kchip-1][pace-1] = ix;
00041       y_[kchip-1][pace-1] = iy;      
00042     }
00043     
00044   } else {
00045     cout<<"ESUnpacker::ESUnpacker : Look up table file can not be found in "<<lookup_.fullPath().c_str()<<endl;
00046   }
00047 
00048 }

ESUnpacker::~ESUnpacker (  ) 

Definition at line 50 of file ESUnpacker.cc.

00050                         {
00051 }


Member Function Documentation

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(), GenMuonPlsPt100GeV_cfg::cout, dac_, FEDRawData::data(), debug_, lat::endl(), FEch_, fedId_, gain_, header, j, FEDTrailer::lenght(), lv1_, FEDHeader::lvl1ID(), m1, m12, m16, m32, m4, m6, m8, FEDHeader::moreHeaders(), FEDTrailer::moreTrailers(), optoRX0_, optoRX1_, optoRX2_, 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(), ESKCHIPBlock::setOptoBC(), ESDCCHeaderBlock::setOptoBC0(), ESDCCHeaderBlock::setOptoBC1(), ESDCCHeaderBlock::setOptoBC2(), ESKCHIPBlock::setOptoEC(), ESDCCHeaderBlock::setOptoRX0(), ESDCCHeaderBlock::setOptoRX1(), ESDCCHeaderBlock::setOptoRX2(), ESDCCHeaderBlock::setPrecision(), ESDCCHeaderBlock::setRunType(), ESDCCHeaderBlock::setSeqType(), ESDCCHeaderBlock::setTriggerType(), FEDRawData::size(), FEDHeader::sourceID(), trgtype_, vmajor_, vminor_, and word2digi().

Referenced by ESRawToDigi::produce().

00053                                                                                                                                                                 {
00054   
00055   int nWords = rawData.size()/sizeof(Word64);
00056   if (nWords==0) return;
00057   int dccWords = 6;
00058   int head, kid, kPACE[4], kFlag1, kFlag2, kBC, kEC, optoBC, optoEC, ttcEC;
00059   
00060   ESDCCHeaderBlock ESDCCHeader;
00061   ESDCCHeader.setFedId(fedId);
00062 
00063   // Event header
00064   const Word64* header = reinterpret_cast<const Word64* >(rawData.data()); --header;
00065   bool moreHeaders = true;
00066   while (moreHeaders) {
00067     ++header;
00068     FEDHeader ESHeader( reinterpret_cast<const unsigned char*>(header) );
00069     if ( !ESHeader.check() ) {
00070       if (debug_) edm::LogWarning("Invalid Data")<<"ES : Failed header check !";
00071       return;
00072     }
00073 
00074     fedId_ = ESHeader.sourceID();
00075     lv1_   = ESHeader.lvl1ID();
00076     bx_    = ESHeader.bxID();
00077 
00078     if (debug_) {
00079       cout<<"[ESUnpacker]: FED Header candidate. Is header? "<< ESHeader.check();
00080       if (ESHeader.check())
00081         cout <<". BXID: "<<bx_<<" SourceID : "<<fedId_<<" L1ID: "<<lv1_<<endl;
00082       else cout<<" WARNING!, this is not a ES Header"<<endl;
00083     }
00084     
00085     moreHeaders = ESHeader.moreHeaders();
00086   }
00087   if ( fedId != fedId_) {
00088     if (debug_) edm::LogWarning("Invalid Data")<<"Invalid ES data with source id " <<fedId_;
00089     ESDCCHeader.setDCCErrors(1);
00090     dccs.push_back(ESDCCHeader);
00091     return;
00092   }
00093   ESDCCHeader.setLV1(lv1_);
00094   ESDCCHeader.setBX(bx_);
00095 
00096   // Event trailer
00097   const Word64* trailer = reinterpret_cast<const Word64* >(rawData.data())+(nWords-1); ++trailer;
00098   bool moreTrailers = true;
00099   while (moreTrailers) {
00100     --trailer;
00101     FEDTrailer ESTrailer(reinterpret_cast<const unsigned char*>(trailer));
00102     if ( !ESTrailer.check()) { 
00103       ++trailer; 
00104       if (debug_) edm::LogWarning("Invalid Data")<<"ES : Failed trailer check !";
00105       return;
00106     } 
00107     if ( ESTrailer.lenght() != nWords) {
00108       if (debug_) edm::LogWarning("Invalid Data")<<"Invalid ES data : the length is not correct !";
00109       ESDCCHeader.setDCCErrors(2);
00110       dccs.push_back(ESDCCHeader);
00111       return;
00112     }
00113     if ( ESTrailer.lenght() < 8) {
00114       if (debug_) edm::LogWarning("Invalid Data")<<"Invalid ES data : the length is not correct !";
00115       ESDCCHeader.setDCCErrors(3);
00116       dccs.push_back(ESDCCHeader);
00117       return;
00118     }
00119 
00120     if (debug_)  {
00121       cout<<"[ESUnpacker]: FED Trailer candidate. Is trailer? "<<ESTrailer.check();
00122       if (ESTrailer.check())
00123         cout<<". Length of the ES event: "<<ESTrailer.lenght()<<endl;
00124       else cout<<" WARNING!, this is not a ES Trailer"<<endl;
00125     }
00126 
00127     moreTrailers = ESTrailer.moreTrailers();
00128   }
00129 
00130   // DCC data
00131   vector<int> FEch_status;
00132   int dccHeaderCount = 0;
00133   int dccLineCount = 0;
00134   int dccHead, dccLine;
00135   for (const Word64* word=(header+1); word!=(header+dccWords+1); ++word) {
00136     if (debug_) cout<<"DCC   : "<<print(*word)<<endl;
00137     dccHead = (*word >> 60) & m4;
00138     if (dccHead == 3) dccHeaderCount++;
00139     dccLine = (*word >> 56) & m4;
00140     dccLineCount++;
00141     if (dccLine != dccLineCount) {
00142       if (debug_) edm::LogWarning("Invalid Data")<<"Invalid ES data : DCC header order is not correct !";
00143       ESDCCHeader.setDCCErrors(4);
00144       dccs.push_back(ESDCCHeader);
00145       return; 
00146     }
00147     if (dccLineCount == 2) {
00148       runtype_   = (*word >>  0) & m4;
00149       seqtype_   = (*word >>  4) & m4;
00150       dac_       = (*word >>  8) & m12; 
00151       gain_      = (*word >> 20) & m1;
00152       precision_ = (*word >> 21) & m1;
00153       trgtype_   = (*word >> 34) & m6;
00154 
00155       ESDCCHeader.setRunType(runtype_);
00156       ESDCCHeader.setSeqType(seqtype_);
00157       ESDCCHeader.setTriggerType(trgtype_);
00158       ESDCCHeader.setDAC(dac_);
00159       ESDCCHeader.setGain(gain_);
00160       ESDCCHeader.setPrecision(precision_);
00161     }
00162     if (dccLineCount == 3) {
00163       vminor_ = (*word >> 40) & m8;
00164       vmajor_ = (*word >> 48) & m8;
00165     }
00166     if (dccLineCount == 4) optoRX0_  = (*word >> 48) & m8;
00167     if (dccLineCount == 5) optoRX1_  = (*word >> 48) & m8;
00168     if (dccLineCount == 6) optoRX2_  = (*word >> 48) & m8;
00169     if (dccLineCount >=4) {
00170       for (unsigned int j=0; j<12; ++j) {
00171         FEch_[(dccLineCount-4)*12+j] = (*word >> (j*4)) & m4;
00172         FEch_status.push_back(FEch_[(dccLineCount-4)*12+j]);
00173       }
00174     }
00175   }
00176   if (vmajor_ < 4) {
00177     if (debug_) 
00178       edm::LogWarning("Invalid Data")<<"Invalid ES data format : "<<vmajor_<<" "<<vminor_;
00179     return;
00180   }
00181   if (dccHeaderCount != 6) {
00182     edm::LogWarning("Invalid Data")<<"Invalid ES data : DCC header lines are "<<dccHeaderCount;
00183     ESDCCHeader.setDCCErrors(5);
00184     dccs.push_back(ESDCCHeader);
00185     return;
00186   }
00187   ESDCCHeader.setOptoRX0(optoRX0_);
00188   ESDCCHeader.setOptoRX1(optoRX1_);
00189   ESDCCHeader.setOptoRX2(optoRX2_);
00190   ESDCCHeader.setFEChannelStatus(FEch_status);
00191 
00192   // Event data
00193   int opto = 0;
00194   for (const Word64* word=(header+dccWords+1); word!=trailer; ++word) {
00195     if (debug_) cout<<"Event : "<<print(*word)<<endl;
00196 
00197     head = (*word >> 60) & m4;
00198 
00199     if (head == 12) {
00200       word2digi(kid, kPACE, *word, digis);
00201     } else if (head == 9) {
00202       kid      = (*word >> 2) & 0x07ff;
00203       kPACE[0] = (*word >> 16) & m1;
00204       kPACE[1] = (*word >> 17) & m1;
00205       kPACE[2] = (*word >> 18) & m1;
00206       kPACE[3] = (*word >> 19) & m1;
00207       kFlag2   = (*word >> 20) & m4;
00208       kFlag1   = (*word >> 24) & m8;
00209       kBC      = (*word >> 32) & m16;
00210       kEC      = (*word >> 48) & m8;
00211 
00212       ESKCHIPBlock ESKCHIP;
00213       ESKCHIP.setId(kid);
00214       ESKCHIP.setBC(kBC);
00215       ESKCHIP.setEC(kEC);
00216       ESKCHIP.setOptoBC(optoBC);
00217       ESKCHIP.setOptoEC(optoEC);
00218       ESKCHIP.setFlag1(kFlag1);
00219       ESKCHIP.setFlag2(kFlag2);
00220       kchips.push_back(ESKCHIP);
00221     } else if (head == 6) {
00222       ttcEC  = (*word >> 0) & m32;
00223       optoBC = (*word >> 32) & m16;
00224       optoEC = (*word >> 48) & m8;      
00225       if (opto==0) ESDCCHeader.setOptoBC0(optoBC);
00226       else if (opto==1) ESDCCHeader.setOptoBC1(optoBC);
00227       else if (opto==2) ESDCCHeader.setOptoBC2(optoBC);
00228       opto++;
00229     }
00230   }
00231 
00232   dccs.push_back(ESDCCHeader);
00233 }

string ESUnpacker::print ( const Word64 word  )  const [private]

Definition at line 272 of file ESUnpacker.cc.

Referenced by interpretRawData().

00273 {
00274   ostringstream str;
00275   str << "Word64:  " << reinterpret_cast<const bitset<64>&> (word);
00276   return str.str();
00277 }

void ESUnpacker::setBX ( int  i  )  [inline]

Definition at line 40 of file ESUnpacker.h.

References bx_.

00040 {bx_ = i;};

void ESUnpacker::setLV1 ( int  i  )  [inline]

Definition at line 41 of file ESUnpacker.h.

References lv1_.

00041 {lv1_ = i;};

void ESUnpacker::setOrbitNumber ( int  i  )  [inline]

Definition at line 39 of file ESUnpacker.h.

References orbit_number_.

00039 {orbit_number_ = i;};

void ESUnpacker::setRunNumber ( int  i  )  [inline]

Definition at line 38 of file ESUnpacker.h.

References run_number_.

00038 {run_number_ = i;};

void ESUnpacker::setTriggerType ( int  i  )  [inline]

Definition at line 42 of file ESUnpacker.h.

References trgtype_.

00042 {trgtype_ = i;};

void ESUnpacker::word2digi ( int  kchip,
int  kPACE[4],
const Word64 word,
ESDigiCollection digis 
)

Definition at line 235 of file ESUnpacker.cc.

References ecalMGPA::adc(), ESSample::adc(), GenMuonPlsPt100GeV_cfg::cout, debug_, detId, lat::endl(), i, m16, m2, m5, pl_, ESDetId::plane(), edm::SortedCollection< T, SORT >::push_back(), ESDataFrame::sample(), ESDataFrame::setSample(), ESDataFrame::setSize(), ESDetId::six(), ESDetId::siy(), ESDetId::strip(), strip(), ESDetId::validDetId(), x_, y_, ESDetId::zside(), and zside_.

Referenced by interpretRawData().

00236 {
00237 
00238   int pace  = (word >> 53) & m2;
00239   if (kPACE[pace]==0) return;
00240 
00241   int adc[3];
00242   adc[0]    = (word >> 0)  & m16;
00243   adc[1]    = (word >> 16) & m16;
00244   adc[2]    = (word >> 32) & m16;
00245   int strip = (word >> 48) & m5;
00246   if (debug_) cout<<kid<<" "<<strip<<" "<<pace<<" "<<adc[0]<<" "<<adc[1]<<" "<<adc[2]<<endl;
00247 
00248   int zside, plane, ix, iy;
00249   zside = zside_[kid-1][pace];
00250   plane = pl_[kid-1][pace];
00251   ix    = x_[kid-1][pace];
00252   iy    = y_[kid-1][pace];
00253   
00254   if (debug_) cout<<"DetId : "<<zside<<" "<<plane<<" "<<ix<<" "<<iy<<" "<<strip+1<<endl;
00255   
00256   if (ESDetId::validDetId(strip+1, ix, iy, plane, zside)) {
00257     
00258     ESDetId detId(strip+1, ix, iy, plane, zside);
00259     ESDataFrame df(detId);
00260     df.setSize(3);
00261     
00262     for (int i=0; i<3; i++) df.setSample(i, adc[i]);  
00263     
00264     digis.push_back(df);
00265     
00266     if (debug_) 
00267       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()<<endl;
00268   }
00269 
00270 }


Member Data Documentation

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

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

int ESUnpacker::vminor_ [private]

Definition at line 59 of file ESUnpacker.h.

Referenced by interpretRawData().

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


The documentation for this class was generated from the following files:
Generated on Tue Jun 9 18:20:25 2009 for CMSSW by  doxygen 1.5.4