36 int cryIcMap[68][5][5],
37 int tbStatusToLocation[71],
38 int tbTowerIDToLocation[201]) {
40 LogDebug(
"EcalTB07RawToDigi") <<
"@SUB=EcalTB07DaqFormatter";
42 parameters.push_back(10);
43 parameters.push_back(1);
44 parameters.push_back(68);
45 parameters.push_back(68);
46 parameters.push_back(1);
47 parameters.push_back(1);
48 parameters.push_back(1);
49 parameters.push_back(2);
50 parameters.push_back(3);
51 parameters.push_back(4);
57 for(
int i=0;
i<68; ++
i)
58 for (
int j=0; j<5; ++j)
59 for (
int k=0;
k<5; ++
k)
62 for(
int i=0;
i<71; ++
i)
65 for(
int i=0;
i<201; ++
i)
89 const unsigned char * pData = fedData.
data();
90 int length = fedData.
size();
96 LogDebug(
"EcalTB07RawToDigi") <<
"@SUB=EcalTB07DaqFormatter::interpretRawData" 106 theParser_->
parseBuffer( reinterpret_cast<const uint32_t*>(pData), static_cast<uint32_t>(length), shit );
111 for( std::vector< DCCTBEventBlock * >::iterator itEventBlock = dccEventBlocks.begin();
112 itEventBlock != dccEventBlocks.end();
115 bool _displayParserMessages =
false;
116 if( (*itEventBlock)->eventHasErrors() && _displayParserMessages)
118 edm::LogWarning(
"EcalTB07RawToDigi") <<
"@SUB=EcalTB07DaqFormatter::interpretRawData" 119 <<
"errors found from parser... ";
120 edm::LogWarning(
"EcalTB07RawToDigi") << (*itEventBlock)->eventErrorString();
121 edm::LogWarning(
"EcalTB07RawToDigi") <<
"@SUB=EcalTB07DaqFormatter::interpretRawData" 122 <<
"... errors from parser notified";
128 theDCCheader.
setId(46);
129 int fedId = (*itEventBlock)->getDataField(
"FED/DCC ID");
132 theDCCheader.
setRunNumber((*itEventBlock)->getDataField(
"RUN NUMBER"));
133 short trigger_type = (*itEventBlock)->getDataField(
"TRIGGER TYPE");
134 short zs = (*itEventBlock)->getDataField(
"ZS");
135 short tzs = (*itEventBlock)->getDataField(
"TZS");
136 short sr = (*itEventBlock)->getDataField(
"SR");
137 bool dataIsSuppressed;
140 if ( zs && !(tzs) ) dataIsSuppressed =
true;
141 else dataIsSuppressed =
false;
144 else{
edm::LogWarning(
"EcalTB07RawToDigiTriggerType") <<
"@SUB=EcalTB07DaqFormatter::interpretRawData" 145 <<
"unrecognized TRIGGER TYPE: "<<trigger_type;}
146 theDCCheader.
setLV1((*itEventBlock)->getDataField(
"LV1"));
147 theDCCheader.
setOrbit((*itEventBlock)->getDataField(
"ORBIT COUNTER"));
148 theDCCheader.
setBX((*itEventBlock)->getDataField(
"BX"));
149 theDCCheader.
setErrors((*itEventBlock)->getDataField(
"DCC ERRORS"));
153 theDCCheader.
setSrpStatus((*itEventBlock)->getDataField(
"SR_CHSTATUS"));
158 std::vector<short> theTCCs;
161 char TCCnum[20]; sprintf(TCCnum,
"TCC_CHSTATUS#%d",
i+1);
std::string TCCnumS(TCCnum);
162 theTCCs.push_back ((*itEventBlock)->getDataField(TCCnumS) );
167 std::vector< DCCTBTCCBlock * > tccBlocks = (*itEventBlock)->tccBlocks();
169 for( std::vector< DCCTBTCCBlock * >::iterator itTCCBlock = tccBlocks.begin();
170 itTCCBlock != tccBlocks.end();
174 std::vector< std::pair<int,bool> > TpSamples = (* itTCCBlock) -> triggerSamples() ;
176 std::vector<int> TpFlags = (* itTCCBlock) -> triggerFlags() ;
179 if (TpSamples.size()==68 && TpFlags.size()==68)
181 for(
int i=0;
i<((
int)TpSamples.size());
i++)
189 if(phiTT<=0)phiTT=phiTT+72;
200 LogDebug(
"EcalTB07RawToDigiTpg") <<
"@SUBS=EcalTB07DaqFormatter::interpretRawData" 201 <<
"tower: " << (i+1)
202 <<
" primitive: " << TpSamples[i].first
203 <<
" flag: " << TpSamples[i].second;
205 LogDebug(
"EcalTB07RawToDigiTpg") <<
"@SUBS=EcalTB07DaqFormatter::interpretRawData"<<
206 "tower: " << (i+1) <<
" flag: " << TpFlags[i];
212 edm::LogWarning(
"EcalTB07RawToDigiTpg") <<
"68 elements not found for TpFlags or TpSamples, collection will be empty";
221 std::vector<short> theTTstatus;
224 sprintf(buffer,
"FE_CHSTATUS#%d",
i);
226 TowerStatus[
i]= (*itEventBlock)->getDataField(Tower);
227 theTTstatus.push_back(TowerStatus[
i]);
230 bool checkTowerStatus = TowerStatus[1] == 0 && TowerStatus[2] == 0 && TowerStatus[3] == 0 && TowerStatus[4] == 0;
231 for (
int i=5;
i < MAX_TT_SIZE+1; ++
i) checkTowerStatus = checkTowerStatus && TowerStatus[
i] == 1;
232 if (!checkTowerStatus) {
233 for(
int i=1;
i<MAX_TT_SIZE+1; ++
i) {
234 std::cout <<
"tower " <<
i <<
" has status " << TowerStatus[
i] << std::endl;
241 uint32_t DCCruntype = (*itEventBlock)->getDataField(
"RUN TYPE");
242 theRuntypeDecoder.
Decode(DCCruntype, &theDCCheader);
244 DCCheaderCollection.
push_back(theDCCheader);
255 std::vector< DCCTBTowerBlock * > dccTowerBlocks = (*itEventBlock)->towerBlocks();
256 LogDebug(
"EcalTB07RawToDigi") <<
"@SUBS=EcalTB07DaqFormatter::interpretRawData" 257 <<
"dccTowerBlocks size " << dccTowerBlocks.size();
262 for (
int v=0;
v<71;
v++){
281 if( TowerStatus[u] ==0 || TowerStatus[u] ==9 || TowerStatus[u] ==10 )
295 edm::LogWarning(
"EcalTB07RawToDigiNumTowerBlocks") <<
"@SUB=EcalTB07DaqFormatter::interpretRawData" 296 <<
"number of TowerBlocks found (" << dccTowerBlocks.size()
298 <<
") skipping event";
312 for( std::vector< DCCTBTowerBlock * >::iterator itTowerBlock = dccTowerBlocks.begin();
313 itTowerBlock!= dccTowerBlocks.end();
316 tower=(*itTowerBlock)->towerID();
336 edm::LogWarning(
"EcalTB07RawToDigiTowerId") <<
"@SUBS=EcalTB07DaqFormatter::interpretRawData" 337 <<
"TTower id found (=" << tower
339 <<
") " << (_expTowersIndex+1) <<
"-th tower checked" 340 <<
"\n Real hardware id is " << (*itTowerBlock)->towerID();
347 edm::LogWarning(
"EcalTB07RawToDigiTowerId") <<
"@SUB=EcalTB07DaqFormatter:interpretRawData" 348 <<
"DecodeMEM: tower " << tower
350 <<
" (according to DCC header channel status)";
367 if ( 0< (*itTowerBlock)->towerID() &&
369 (*itTowerBlock)->towerID() == 71 ||
370 (*itTowerBlock)->towerID() == 80)
374 std::vector<DCCTBXtalBlock * > & xtalDataBlocks = (*itTowerBlock)->xtalBlocks();
379 edm::LogWarning(
"EcalTB07RawToDigiTowerSize") <<
"EcalTB07DaqFormatter::interpretRawData, no zero suppression " 380 <<
"wrong tower block size is: " << xtalDataBlocks.size()
381 <<
" at LV1 " << (*itEventBlock)->getDataField(
"LV1")
393 short expStripInTower;
395 short expCryInTower =0;
398 for( std::vector< DCCTBXtalBlock * >::iterator itXtalBlock = xtalDataBlocks.begin();
399 itXtalBlock!= xtalDataBlocks.end();
402 strip =(*itXtalBlock)->stripID();
403 ch =(*itXtalBlock)->xtalID();
406 expStripInTower = expCryInTower/5 +1;
407 expCryInStrip = expCryInTower%5 +1;
418 if (dataIsSuppressed)
421 if ( strip < 1 || 5<strip || ch <1 || 5 < ch)
424 for (
int StripInTower_ =1; StripInTower_ < 6; StripInTower_++){
425 for (
int CryInStrip_ =1; CryInStrip_ < 6; CryInStrip_++){
426 int ic =
cryIc(tower, StripInTower_, CryInStrip_) ;
432 edm::LogWarning(
"EcalTB07RawToDigiChId") <<
"EcalTB07DaqFormatter::interpretRawData with zero suppression, " 433 <<
" wrong channel id, since out of range: " 434 <<
"\t strip: " << strip <<
"\t channel: " << ch
436 <<
"\t at LV1 : " << (*itEventBlock)->getDataField(
"LV1");
444 if( cryInTower >= expCryInTower ){
445 expCryInTower = cryInTower +1;
452 edm::LogWarning(
"EcalTB07RawToDigiChId") <<
"EcalTB07DaqFormatter::interpretRawData with zero suppression, " 453 <<
" based on ch ordering within tt, wrong channel id: " 454 <<
"\t strip: " << strip <<
"\t channel: " << ch
455 <<
"\t cryInTower " << cryInTower
456 <<
"\t expCryInTower: " << expCryInTower
458 <<
"\t at LV1: " << (*itEventBlock)->getDataField(
"LV1");
461 for (
int StripInTower_ =1; StripInTower_ < 6; StripInTower_++){
462 for (
int CryInStrip_ =1; CryInStrip_ < 6; CryInStrip_++){
463 int ic =
cryIc(tower, StripInTower_, CryInStrip_) ;
470 expCryInTower++;
continue;
481 if( cryInTower != expCryInTower ||
486 int ic =
cryIc(tower, expStripInTower, expCryInStrip) ;
490 edm::LogWarning(
"EcalTB07RawToDigiChId") <<
"EcalTB07DaqFormatter::interpretRawData no zero suppression " 491 <<
" wrong channel id for channel: " << expCryInStrip
492 <<
"\t strip: " << expStripInTower
494 <<
"\t at LV1: " << (*itEventBlock)->getDataField(
"LV1")
495 <<
"\t (in the data, found channel: " << ch
496 <<
"\t strip: " << strip <<
" ).";
503 expCryInTower++;
continue;
514 int ic =
cryIc(tower, strip, ch) ;
519 int ix =
getEE_ix(tower, strip, ch);
520 int iy =
getEE_iy(tower, strip, ch);
523 if (
tbName_ ==
"h4" ) iz = -1;
533 std::vector<int> xtalDataSamples = (*itXtalBlock)->xtalDataSamples();
540 unsigned gain_mask = 12288;
541 std::vector <int> xtalGain;
543 for (
unsigned short i=0;
i<xtalDataSamples.size(); ++
i ) {
546 eeFrame .setSample (i, xtalDataSamples[i] );
548 if((xtalDataSamples[i] & gain_mask) == 0){gainIsOk =
false;}
550 xtalGain.push_back(0);
551 xtalGain[
i] |= (xtalDataSamples[
i] >> 12);
556 edm::LogWarning(
"EcalTB07RawToDigiGainZero") <<
"@SUB=EcalTB07DaqFormatter::interpretRawData" 557 <<
" gain==0 for strip: " << expStripInTower
558 <<
"\t channel: " << expCryInStrip
561 <<
"\t at LV1: " << (*itEventBlock)->getDataField(
"LV1");
576 short firstGainWrong=-1;
577 short numGainWrong=0;
579 for (
unsigned short i=0;
i<xtalGain.size();
i++ ) {
581 if (
i>0 && xtalGain[
i-1]>xtalGain[
i]) {
585 if (firstGainWrong == -1) {
587 edm::LogWarning(
"EcalTB07RawToDigiGainSwitch") <<
"@SUB=EcalTB07DaqFormatter::interpretRawData" 588 <<
"channelHasGainSwitchProblem: crystal eta = " 589 <<
id.ieta() <<
" phi = " <<
id.iphi();
591 edm::LogWarning(
"EcalTB07RawToDigiGainSwitch") <<
"@SUB=EcalTB07DaqFormatter::interpretRawData" 592 <<
"channelHasGainSwitchProblem: sample = " << (i-1)
593 <<
" gain: " << xtalGain[i-1] <<
" sample: " 594 << i <<
" gain: " << xtalGain[i];
598 if (numGainWrong>0) {
601 edm::LogWarning(
"EcalTB07RawToDigiGainSwitch") <<
"@SUB=EcalTB07DaqFormatter:interpretRawData" 602 <<
"channelHasGainSwitchProblem: more than 1 wrong transition";
604 for (
unsigned short i1=0; i1<xtalDataSamples.size(); ++i1 ) {
605 int countADC = 0x00000FFF;
606 countADC &= xtalDataSamples[i1];
607 LogDebug(
"EcalTB07RawToDigi") <<
"Sample " << i1 <<
" ADC " << countADC <<
" Gain " << xtalGain[i1];
629 else if ( (*itTowerBlock)->towerID() == 69
630 || (*itTowerBlock)->towerID() == 70 )
633 LogDebug(
"EcalTB07RawToDigi") <<
"@SUB=EcalTB07DaqFormatter::interpretRawData" 634 <<
"processing mem box num: " << (*itTowerBlock)->towerID();
643 DecodeMEM( (*itTowerBlock), pndigicollection ,
644 memttidcollection, memblocksizecollection,
645 memgaincollection, memchidcollection);
655 edm::LogWarning(
"EcalTB07RawToDigiTowerId") <<
"@SUB=EcalTB07DaqFormatter::interpretRawData" 656 <<
" processing tt with ID not existing ( " 657 << (*itTowerBlock)->towerID() <<
")";
679 LogDebug(
"EcalTB07RawToDigi") <<
"@SUB=EcalTB07DaqFormatter::DecodeMEM" 680 <<
"in mem " << towerblock->
towerID();
682 int tower_id = towerblock ->
towerID() ;
683 int mem_id = tower_id-69;
688 for (
int sa=0; sa<11; sa++){
693 if(tower_id != 69 && tower_id != 70)
695 edm::LogWarning(
"EcalTB07RawToDigiTowerId") <<
"@SUB=EcalTB07DaqFormatter:decodeMem" 696 <<
"DecodeMEM: this is not a mem box tower (" << tower_id <<
")";
705 std::vector<DCCTBXtalBlock *> & dccXtalBlocks = towerblock->
xtalBlocks();
706 std::vector<DCCTBXtalBlock*>::iterator itXtal;
711 LogDebug(
"EcalTB07RawToDigiDccBlockSize") <<
"@SUB=EcalTB07DaqFormatter:decodeMem" 712 <<
" wrong dccBlock size, namely: " << dccXtalBlocks.size()
726 int cryCounter = 0;
int strip_id = 0;
int xtal_id = 0;
728 for ( itXtal = dccXtalBlocks.begin(); itXtal < dccXtalBlocks.end(); itXtal++ ) {
729 strip_id = (*itXtal) ->getDataField(
"STRIP ID");
730 xtal_id = (*itXtal) ->getDataField(
"XTAL ID");
734 if( (wished_strip_id+1) != ((
int)strip_id) ||
735 (wished_ch_id+1) != ((
int)xtal_id) )
738 LogDebug(
"EcalTB07RawToDigiChId") <<
"@SUB=EcalTB07DaqFormatter:decodeMem" 739 <<
" in mem " << towerblock->
towerID()
740 <<
", expected:\t strip" 741 << (wished_strip_id+1) <<
" cry " << (wished_ch_id+1) <<
"\tfound: " 742 <<
" strip " << strip_id <<
" cry " << xtal_id;
751 memRawSample_[wished_strip_id][wished_ch_id][1] = (*itXtal)->getDataField(
"ADC#1");
752 memRawSample_[wished_strip_id][wished_ch_id][2] = (*itXtal)->getDataField(
"ADC#2");
753 memRawSample_[wished_strip_id][wished_ch_id][3] = (*itXtal)->getDataField(
"ADC#3");
754 memRawSample_[wished_strip_id][wished_ch_id][4] = (*itXtal)->getDataField(
"ADC#4");
755 memRawSample_[wished_strip_id][wished_ch_id][5] = (*itXtal)->getDataField(
"ADC#5");
756 memRawSample_[wished_strip_id][wished_ch_id][6] = (*itXtal)->getDataField(
"ADC#6");
757 memRawSample_[wished_strip_id][wished_ch_id][7] = (*itXtal)->getDataField(
"ADC#7");
758 memRawSample_[wished_strip_id][wished_ch_id][8] = (*itXtal)->getDataField(
"ADC#8");
759 memRawSample_[wished_strip_id][wished_ch_id][9] = (*itXtal)->getDataField(
"ADC#9");
760 memRawSample_[wished_strip_id][wished_ch_id][10] = (*itXtal)->getDataField(
"ADC#10");
777 for (memStoreIndex=0; memStoreIndex<500; memStoreIndex++) {
785 {ipn= mem_id*5+channel;}
787 {ipn=mem_id*5+4-channel;}
798 new_data=new_data | (tempSample&1);
807 new_data = (new_data ^ 0x800) & 0x3fff;
813 short sampleGain = (new_data &0x3000)/4096;
814 if ( sampleGain==2 || sampleGain==3)
819 edm::LogWarning(
"EcalTB07RawToDigiGainZero") <<
"@SUB=EcalTB07DaqFormatter:decodeMem" 820 <<
"in mem " << towerblock->
towerID()
822 << (
strip +1) <<
" cry: " << (channel+1)
823 <<
" has 14th bit non zero! Gain results: " 824 << sampleGain <<
".";
829 memStoreIndex= ipn*50+
strip*kSamplesPerChannel+
sample;
831 data_MEM[memStoreIndex]= new_data & 0x3fff;
844 if (! (memgaincollection.
empty() && memchidcollection.
empty()) )
847 idItr != memgaincollection.
end();
849 int ch = (*idItr).channelId();
855 idItr != memchidcollection.
end();
857 int ch = (*idItr).channelId();
868 for (
int pnId = 1; pnId < (kPnPerTowerBlock+1); pnId++){
893 int xtal= (strip-1)*5+ch-1;
895 std::pair<int,int> ind;
924 int ic =
cryIc(tower, strip, ch);
936 int ic =
cryIc(tower, strip, ch);
942 iy = 51 + (
int)((ic-1)/20);
949 if ( strip < 1 || 5<strip || ch <1 || 5 < ch || 68<tower)
951 edm::LogWarning(
"EcalTB07RawToDigiChId") <<
"EcalTB07DaqFormatter::interpretRawData (cryIc) " 952 <<
" wrong channel id, since out of range: " 953 <<
"\t strip: " << strip <<
"\t channel: " << ch
954 <<
"\t in TT: " << tower;
959 return cryIcMap_[tower-1][strip-1][ch-1];
968 if ((tower>12 && tower<21) || (tower>28 && tower<37) ||
969 (tower>44 && tower<53) || (tower>60 && tower<69))
void push_back(const Digi &digi)
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 setSample(int i, EcalMGPASample sam)
void push_back(const Digi &digi)
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)
void parseBuffer(const uint32_t *buffer, uint32_t bufferSize, bool singleEvent=false)
std::vector< T >::const_iterator const_iterator