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
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
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
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
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 }