35 LogDebug(
"EcalTBRawToDigi") <<
"@SUB=EcalTBDaqFormatter";
37 parameters.push_back(10);
38 parameters.push_back(1);
39 parameters.push_back(68);
40 parameters.push_back(68);
41 parameters.push_back(1);
42 parameters.push_back(1);
43 parameters.push_back(1);
44 parameters.push_back(2);
45 parameters.push_back(3);
46 parameters.push_back(4);
65 const unsigned char * pData = fedData.
data();
66 int length = fedData.
size();
72 LogDebug(
"EcalTBRawToDigi") <<
"@SUB=EcalTBDaqFormatter::interpretRawData"
81 theParser_->
parseBuffer( reinterpret_cast<uint32_t*>(const_cast<unsigned char*>(pData)), static_cast<uint32_t>(length), shit );
86 for( std::vector< DCCTBEventBlock * >::iterator itEventBlock = dccEventBlocks.begin();
87 itEventBlock != dccEventBlocks.end();
90 bool _displayParserMessages =
false;
91 if( (*itEventBlock)->eventHasErrors() && _displayParserMessages)
93 edm::LogWarning(
"EcalTBRawToDigi") <<
"@SUB=EcalTBDaqFormatter::interpretRawData"
94 <<
"errors found from parser... ";
95 edm::LogWarning(
"EcalTBRawToDigi") << (*itEventBlock)->eventErrorString();
96 edm::LogWarning(
"EcalTBRawToDigi") <<
"@SUB=EcalTBDaqFormatter::interpretRawData"
97 <<
"... errors from parser notified";
103 theDCCheader.
setId(28);
104 int fedId = (*itEventBlock)->getDataField(
"FED/DCC ID");
107 theDCCheader.
setRunNumber((*itEventBlock)->getDataField(
"RUN NUMBER"));
108 short trigger_type = (*itEventBlock)->getDataField(
"TRIGGER TYPE");
109 short zs = (*itEventBlock)->getDataField(
"ZS");
110 short tzs = (*itEventBlock)->getDataField(
"TZS");
111 short sr = (*itEventBlock)->getDataField(
"SR");
112 bool dataIsSuppressed;
115 if ( zs && !(tzs) ) dataIsSuppressed =
true;
116 else dataIsSuppressed =
false;
119 else{
edm::LogWarning(
"EcalTBRawToDigiTriggerType") <<
"@SUB=EcalTBDaqFormatter::interpretRawData"
120 <<
"unrecognized TRIGGER TYPE: "<<trigger_type;}
121 theDCCheader.
setLV1((*itEventBlock)->getDataField(
"LV1"));
122 theDCCheader.
setOrbit((*itEventBlock)->getDataField(
"ORBIT COUNTER"));
123 theDCCheader.
setBX((*itEventBlock)->getDataField(
"BX"));
124 theDCCheader.
setErrors((*itEventBlock)->getDataField(
"DCC ERRORS"));
128 theDCCheader.
setSrpStatus((*itEventBlock)->getDataField(
"SR_CHSTATUS"));
133 std::vector<short> theTCCs;
136 char TCCnum[20]; sprintf(TCCnum,
"TCC_CHSTATUS#%d",
i+1);
std::string TCCnumS(TCCnum);
137 theTCCs.push_back ((*itEventBlock)->getDataField(TCCnumS) );
142 std::vector< DCCTBTCCBlock * > tccBlocks = (*itEventBlock)->tccBlocks();
144 for( std::vector< DCCTBTCCBlock * >::iterator itTCCBlock = tccBlocks.begin();
145 itTCCBlock != tccBlocks.end();
149 std::vector< std::pair<int,bool> > TpSamples = (* itTCCBlock) -> triggerSamples() ;
151 std::vector<int> TpFlags = (* itTCCBlock) -> triggerFlags() ;
154 if (TpSamples.size()==68 && TpFlags.size()==68)
156 for(
int i=0;
i<((int)TpSamples.size());
i++)
164 if(phiTT<=0)phiTT=phiTT+72;
176 LogDebug(
"EcalTBRawToDigiTpg") <<
"@SUBS=EcalTBDaqFormatter::interpretRawData"
177 <<
"tower: " << (i+1)
178 <<
" primitive: " << TpSamples[i].first
179 <<
" flag: " << TpSamples[i].second;
181 LogDebug(
"EcalTBRawToDigiTpg") <<
"@SUBS=EcalTBDaqFormatter::interpretRawData"<<
182 "tower: " << (i+1) <<
" flag: " << TpFlags[i];
188 edm::LogWarning(
"EcalTBRawToDigiTpg") <<
"68 elements not found for TpFlags or TpSamples, collection will be empty";
197 std::vector<short> theTTstatus;
200 sprintf(buffer,
"FE_CHSTATUS#%d",
i);
202 TowerStatus[
i]= (*itEventBlock)->getDataField(Tower);
203 theTTstatus.push_back(TowerStatus[
i]);
210 uint32_t DCCruntype = (*itEventBlock)->getDataField(
"RUN TYPE");
211 theRuntypeDecoder.
Decode(DCCruntype, &theDCCheader);
213 DCCheaderCollection.
push_back(theDCCheader);
215 std::vector< DCCTBTowerBlock * > dccTowerBlocks = (*itEventBlock)->towerBlocks();
216 LogDebug(
"EcalTBRawToDigi") <<
"@SUBS=EcalTBDaqFormatter::interpretRawData"
217 <<
"dccTowerBlocks size " << dccTowerBlocks.size();
222 for (
int v=0;
v<71;
v++){
233 if( TowerStatus[u] ==0 || TowerStatus[u] ==9 || TowerStatus[u] ==10 )
247 edm::LogWarning(
"EcalTBRawToDigiNumTowerBlocks") <<
"@SUB=EcalTBDaqFormatter::interpretRawData"
248 <<
"number of TowerBlocks found (" << dccTowerBlocks.size()
250 <<
") skipping event";
264 for( std::vector< DCCTBTowerBlock * >::iterator itTowerBlock = dccTowerBlocks.begin();
265 itTowerBlock!= dccTowerBlocks.end();
268 tower=(*itTowerBlock)->towerID();
282 edm::LogWarning(
"EcalTBRawToDigiTowerId") <<
"@SUBS=EcalTBDaqFormatter::interpretRawData"
283 <<
"TTower id found (=" << tower
285 <<
") " << (_expTowersIndex+1) <<
"-th tower checked";
292 edm::LogWarning(
"EcalTBRawToDigiTowerId") <<
"@SUB=EcalTBDaqFormatter:interpretRawData"
293 <<
"DecodeMEM: tower " << tower
294 <<
" is not the same as expected " << ((int)
_ExpectedTowers[_expTowersIndex])
295 <<
" (according to DCC header channel status)";
313 if ( 0< (*itTowerBlock)->towerID() &&
317 std::vector<DCCTBXtalBlock * > & xtalDataBlocks = (*itTowerBlock)->xtalBlocks();
322 edm::LogWarning(
"EcalTBRawToDigiTowerSize") <<
"EcalTBDaqFormatter::interpretRawData, no zero suppression "
323 <<
"wrong tower block size is: " << xtalDataBlocks.size()
324 <<
" at LV1 " << (*itEventBlock)->getDataField(
"LV1")
336 short expStripInTower;
338 short expCryInTower =0;
341 for( std::vector< DCCTBXtalBlock * >::iterator itXtalBlock = xtalDataBlocks.begin();
342 itXtalBlock!= xtalDataBlocks.end();
345 strip =(*itXtalBlock)->stripID();
346 ch =(*itXtalBlock)->xtalID();
349 expStripInTower = expCryInTower/5 +1;
350 expCryInStrip = expCryInTower%5 +1;
361 if (dataIsSuppressed)
364 if ( strip < 1 || 5<strip || ch <1 || 5 < ch)
367 for (
int StripInTower_ =1; StripInTower_ < 6; StripInTower_++){
368 for (
int CryInStrip_ =1; CryInStrip_ < 6; CryInStrip_++){
369 int ic =
cryIc(tower, StripInTower_, CryInStrip_) ;
375 edm::LogWarning(
"EcalTBRawToDigiChId") <<
"EcalTBDaqFormatter::interpretRawData with zero suppression, "
376 <<
" wrong channel id, since out of range: "
377 <<
"\t strip: " << strip <<
"\t channel: " << ch
379 <<
"\t at LV1 : " << (*itEventBlock)->getDataField(
"LV1");
387 if( cryInTower >= expCryInTower ){
388 expCryInTower = cryInTower +1;
395 edm::LogWarning(
"EcalTBRawToDigiChId") <<
"EcalTBDaqFormatter::interpretRawData with zero suppression, "
396 <<
" based on ch ordering within tt, wrong channel id: "
397 <<
"\t strip: " << strip <<
"\t channel: " << ch
398 <<
"\t cryInTower " << cryInTower
399 <<
"\t expCryInTower: " << expCryInTower
401 <<
"\t at LV1: " << (*itEventBlock)->getDataField(
"LV1");
404 for (
int StripInTower_ =1; StripInTower_ < 6; StripInTower_++){
405 for (
int CryInStrip_ =1; CryInStrip_ < 6; CryInStrip_++){
406 int ic =
cryIc(tower, StripInTower_, CryInStrip_) ;
413 expCryInTower++;
continue;
424 if( cryInTower != expCryInTower ||
429 int ic =
cryIc(tower, expStripInTower, expCryInStrip) ;
433 edm::LogWarning(
"EcalTBRawToDigiChId") <<
"EcalTBDaqFormatter::interpretRawData no zero suppression "
434 <<
" wrong channel id for channel: " << expCryInStrip
435 <<
"\t strip: " << expStripInTower
437 <<
"\t at LV1: " << (*itEventBlock)->getDataField(
"LV1")
438 <<
"\t (in the data, found channel: " << ch
439 <<
"\t strip: " << strip <<
" ).";
446 expCryInTower++;
continue;
457 int ic =
cryIc(tower, strip, ch) ;
465 std::vector<int> xtalDataSamples = (*itXtalBlock)->xtalDataSamples();
472 unsigned gain_mask = 12288;
473 std::vector <int> xtalGain;
475 for (
unsigned short i=0;
i<xtalDataSamples.size(); ++
i ) {
479 if((xtalDataSamples[i] & gain_mask) == 0){gainIsOk =
false;}
481 xtalGain.push_back(0);
482 xtalGain[
i] |= (xtalDataSamples[
i] >> 12);
487 edm::LogWarning(
"EcalTBRawToDigiGainZero") <<
"@SUB=EcalTBDaqFormatter::interpretRawData"
488 <<
" gain==0 for strip: " << expStripInTower
489 <<
"\t channel: " << expCryInStrip
492 <<
"\t at LV1: " << (*itEventBlock)->getDataField(
"LV1");
506 short firstGainWrong=-1;
507 short numGainWrong=0;
509 for (
unsigned short i=0;
i<xtalGain.size();
i++ ) {
511 if (
i>0 && xtalGain[
i-1]>xtalGain[
i]) {
515 if (firstGainWrong == -1) {
517 edm::LogWarning(
"EcalTBRawToDigiGainSwitch") <<
"@SUB=EcalTBDaqFormatter::interpretRawData"
518 <<
"channelHasGainSwitchProblem: crystal eta = "
519 <<
id.ieta() <<
" phi = " <<
id.iphi();
521 edm::LogWarning(
"EcalTBRawToDigiGainSwitch") <<
"@SUB=EcalTBDaqFormatter::interpretRawData"
522 <<
"channelHasGainSwitchProblem: sample = " << (i-1)
523 <<
" gain: " << xtalGain[i-1] <<
" sample: "
524 << i <<
" gain: " << xtalGain[i];
528 if (numGainWrong>0) {
531 edm::LogWarning(
"EcalTBRawToDigiGainSwitch") <<
"@SUB=EcalTBDaqFormatter:interpretRawData"
532 <<
"channelHasGainSwitchProblem: more than 1 wrong transition";
534 for (
unsigned short i1=0; i1<xtalDataSamples.size(); ++i1 ) {
535 int countADC = 0x00000FFF;
536 countADC &= xtalDataSamples[i1];
537 LogDebug(
"EcalTBRawToDigi") <<
"Sample " << i1 <<
" ADC " << countADC <<
" Gain " << xtalGain[i1];
559 else if ( (*itTowerBlock)->towerID() == 69
560 || (*itTowerBlock)->towerID() == 70 )
563 LogDebug(
"EcalTBRawToDigi") <<
"@SUB=EcalTBDaqFormatter::interpretRawData"
564 <<
"processing mem box num: " << (*itTowerBlock)->towerID();
573 DecodeMEM( (*itTowerBlock), pndigicollection ,
574 memttidcollection, memblocksizecollection,
575 memgaincollection, memchidcollection);
585 edm::LogWarning(
"EcalTBRawToDigiTowerId") <<
"@SUB=EcalTBDaqFormatter::interpretRawData"
586 <<
" processing tt with ID not existing ( "
587 << (*itTowerBlock)->towerID() <<
")";
608 LogDebug(
"EcalTBRawToDigi") <<
"@SUB=EcalTBDaqFormatter::DecodeMEM"
609 <<
"in mem " << towerblock->
towerID();
611 int tower_id = towerblock ->
towerID() ;
612 int mem_id = tower_id-69;
617 for (
int sa=0; sa<11; sa++){
622 if(tower_id != 69 && tower_id != 70)
624 edm::LogWarning(
"EcalTBRawToDigiTowerId") <<
"@SUB=EcalTBDaqFormatter:decodeMem"
625 <<
"DecodeMEM: this is not a mem box tower (" << tower_id <<
")";
634 std::vector<DCCTBXtalBlock *> & dccXtalBlocks = towerblock->
xtalBlocks();
635 std::vector<DCCTBXtalBlock*>::iterator itXtal;
640 LogDebug(
"EcalTBRawToDigiDccBlockSize") <<
"@SUB=EcalTBDaqFormatter:decodeMem"
641 <<
" wrong dccBlock size, namely: " << dccXtalBlocks.size()
655 int cryCounter = 0;
int strip_id = 0;
int xtal_id = 0;
657 for ( itXtal = dccXtalBlocks.begin(); itXtal < dccXtalBlocks.end(); itXtal++ ) {
658 strip_id = (*itXtal) ->getDataField(
"STRIP ID");
659 xtal_id = (*itXtal) ->getDataField(
"XTAL ID");
663 if( (wished_strip_id+1) != ((
int)strip_id) ||
664 (wished_ch_id+1) != ((
int)xtal_id) )
667 LogDebug(
"EcalTBRawToDigiChId") <<
"@SUB=EcalTBDaqFormatter:decodeMem"
668 <<
" in mem " << towerblock->
towerID()
669 <<
", expected:\t strip"
670 << (wished_strip_id+1) <<
" cry " << (wished_ch_id+1) <<
"\tfound: "
671 <<
" strip " << strip_id <<
" cry " << xtal_id;
680 memRawSample_[wished_strip_id][wished_ch_id][1] = (*itXtal)->getDataField(
"ADC#1");
681 memRawSample_[wished_strip_id][wished_ch_id][2] = (*itXtal)->getDataField(
"ADC#2");
682 memRawSample_[wished_strip_id][wished_ch_id][3] = (*itXtal)->getDataField(
"ADC#3");
683 memRawSample_[wished_strip_id][wished_ch_id][4] = (*itXtal)->getDataField(
"ADC#4");
684 memRawSample_[wished_strip_id][wished_ch_id][5] = (*itXtal)->getDataField(
"ADC#5");
685 memRawSample_[wished_strip_id][wished_ch_id][6] = (*itXtal)->getDataField(
"ADC#6");
686 memRawSample_[wished_strip_id][wished_ch_id][7] = (*itXtal)->getDataField(
"ADC#7");
687 memRawSample_[wished_strip_id][wished_ch_id][8] = (*itXtal)->getDataField(
"ADC#8");
688 memRawSample_[wished_strip_id][wished_ch_id][9] = (*itXtal)->getDataField(
"ADC#9");
689 memRawSample_[wished_strip_id][wished_ch_id][10] = (*itXtal)->getDataField(
"ADC#10");
706 for (memStoreIndex=0; memStoreIndex<500; memStoreIndex++) {
714 {ipn= mem_id*5+channel;}
716 {ipn=mem_id*5+4-channel;}
727 new_data=new_data | (tempSample&1);
736 new_data = (new_data ^ 0x800) & 0x3fff;
742 short sampleGain = (new_data &0x3000)/4096;
743 if ( sampleGain==2 || sampleGain==3)
748 edm::LogWarning(
"EcalTBRawToDigiGainZero") <<
"@SUB=EcalTBDaqFormatter:decodeMem"
749 <<
"in mem " << towerblock->
towerID()
751 << (strip +1) <<
" cry: " << (channel+1)
752 <<
" has 14th bit non zero! Gain results: "
753 << sampleGain <<
".";
758 memStoreIndex= ipn*50+strip*kSamplesPerChannel+
sample;
760 data_MEM[memStoreIndex]= new_data & 0x3fff;
773 if (! (memgaincollection.
size()==0 && memchidcollection.
size()==0) )
776 idItr != memgaincollection.
end();
778 int ch = (*idItr).channelId();
784 idItr != memchidcollection.
end();
786 int ch = (*idItr).channelId();
797 for (
int pnId = 1; pnId < (kPnPerTowerBlock+1); pnId++){
834 int xtal= (strip-1)*5+ch-1;
836 std::pair<int,int> ind;
867 if ( strip < 1 || 5<strip || ch <1 || 5 < ch || 68<tower)
869 edm::LogWarning(
"EcalTBRawToDigiChId") <<
"EcalTBDaqFormatter::interpretRawData (cryIc) "
870 <<
" wrong channel id, since out of range: "
871 <<
"\t strip: " << strip <<
"\t channel: " << ch
872 <<
"\t in TT: " << tower;
884 if ((tower>12 && tower<21) || (tower>28 && tower<37) ||
885 (tower>44 && tower<53) || (tower>60 && tower<69))
std::vector< DCCTBXtalBlock * > & xtalBlocks()
const_iterator end() const
Ecal readout channel identification [32:20] Unused (so far) [19:13] DCC id [12:6] tower [5:3] strip [...
void push_back(T const &t)
void push_back(T const &t)
std::vector< DCCTBEventBlock * > & dccEvents()
size_t size() const
Lenght of the data buffer in bytes.
U second(std::pair< T, U > const &p)
void setSample(int i, const EcalTriggerPrimitiveSample &sam)
void reserve(size_t isize)
const_iterator begin() const
void push_back(id_type iid, data_type const *idata)
void parseBuffer(uint32_t *buffer, uint32_t bufferSize, bool singleEvent=false)
void setSample(int i, EcalMGPASample sam)
const unsigned char * data() const
Return a const pointer to the beginning of the data buffer.
void reserve(size_type n)
void setSample(int i, const EcalFEMSample &sam)
std::vector< T >::const_iterator const_iterator