38 int cryIcMap[68][5][5],
39 int tbStatusToLocation[71],
40 int tbTowerIDToLocation[201]) {
42 LogDebug(
"EcalTB07RawToDigi") <<
"@SUB=EcalTB07DaqFormatter";
44 parameters.push_back(10);
45 parameters.push_back(1);
46 parameters.push_back(68);
47 parameters.push_back(68);
48 parameters.push_back(1);
49 parameters.push_back(1);
50 parameters.push_back(1);
51 parameters.push_back(2);
52 parameters.push_back(3);
53 parameters.push_back(4);
59 for(
int i=0;
i<68; ++
i)
60 for (
int j=0;
j<5; ++
j)
61 for (
int k=0;
k<5; ++
k)
64 for(
int i=0;
i<71; ++
i)
67 for(
int i=0;
i<201; ++
i)
91 const unsigned char * pData = fedData.
data();
92 int length = fedData.
size();
98 LogDebug(
"EcalTB07RawToDigi") <<
"@SUB=EcalTB07DaqFormatter::interpretRawData"
108 theParser_->
parseBuffer( reinterpret_cast<uint32_t*>(const_cast<unsigned char*>(pData)), static_cast<uint32_t>(length), shit );
113 for( std::vector< DCCTBEventBlock * >::iterator itEventBlock = dccEventBlocks.begin();
114 itEventBlock != dccEventBlocks.end();
117 bool _displayParserMessages =
false;
118 if( (*itEventBlock)->eventHasErrors() && _displayParserMessages)
120 edm::LogWarning(
"EcalTB07RawToDigi") <<
"@SUB=EcalTB07DaqFormatter::interpretRawData"
121 <<
"errors found from parser... ";
122 edm::LogWarning(
"EcalTB07RawToDigi") << (*itEventBlock)->eventErrorString();
123 edm::LogWarning(
"EcalTB07RawToDigi") <<
"@SUB=EcalTB07DaqFormatter::interpretRawData"
124 <<
"... errors from parser notified";
130 theDCCheader.
setId(46);
131 int fedId = (*itEventBlock)->getDataField(
"FED/DCC ID");
134 theDCCheader.
setRunNumber((*itEventBlock)->getDataField(
"RUN NUMBER"));
135 short trigger_type = (*itEventBlock)->getDataField(
"TRIGGER TYPE");
136 short zs = (*itEventBlock)->getDataField(
"ZS");
137 short tzs = (*itEventBlock)->getDataField(
"TZS");
138 short sr = (*itEventBlock)->getDataField(
"SR");
139 bool dataIsSuppressed;
142 if ( zs && !(tzs) ) dataIsSuppressed =
true;
143 else dataIsSuppressed =
false;
146 else{
edm::LogWarning(
"EcalTB07RawToDigiTriggerType") <<
"@SUB=EcalTB07DaqFormatter::interpretRawData"
147 <<
"unrecognized TRIGGER TYPE: "<<trigger_type;}
148 theDCCheader.
setLV1((*itEventBlock)->getDataField(
"LV1"));
149 theDCCheader.
setOrbit((*itEventBlock)->getDataField(
"ORBIT COUNTER"));
150 theDCCheader.
setBX((*itEventBlock)->getDataField(
"BX"));
151 theDCCheader.
setErrors((*itEventBlock)->getDataField(
"DCC ERRORS"));
155 theDCCheader.
setSrpStatus((*itEventBlock)->getDataField(
"SR_CHSTATUS"));
160 std::vector<short> theTCCs;
163 char TCCnum[20]; sprintf(TCCnum,
"TCC_CHSTATUS#%d",
i+1);
std::string TCCnumS(TCCnum);
164 theTCCs.push_back ((*itEventBlock)->getDataField(TCCnumS) );
169 std::vector< DCCTBTCCBlock * > tccBlocks = (*itEventBlock)->tccBlocks();
171 for( std::vector< DCCTBTCCBlock * >::iterator itTCCBlock = tccBlocks.begin();
172 itTCCBlock != tccBlocks.end();
176 std::vector< std::pair<int,bool> > TpSamples = (* itTCCBlock) -> triggerSamples() ;
178 std::vector<int> TpFlags = (* itTCCBlock) -> triggerFlags() ;
181 if (TpSamples.size()==68 && TpFlags.size()==68)
183 for(
int i=0;
i<((int)TpSamples.size());
i++)
191 if(phiTT<=0)phiTT=phiTT+72;
202 LogDebug(
"EcalTB07RawToDigiTpg") <<
"@SUBS=EcalTB07DaqFormatter::interpretRawData"
203 <<
"tower: " << (i+1)
204 <<
" primitive: " << TpSamples[i].first
205 <<
" flag: " << TpSamples[i].second;
207 LogDebug(
"EcalTB07RawToDigiTpg") <<
"@SUBS=EcalTB07DaqFormatter::interpretRawData"<<
208 "tower: " << (i+1) <<
" flag: " << TpFlags[i];
214 edm::LogWarning(
"EcalTB07RawToDigiTpg") <<
"68 elements not found for TpFlags or TpSamples, collection will be empty";
223 std::vector<short> theTTstatus;
226 sprintf(buffer,
"FE_CHSTATUS#%d",
i);
228 TowerStatus[
i]= (*itEventBlock)->getDataField(Tower);
229 theTTstatus.push_back(TowerStatus[
i]);
232 bool checkTowerStatus = TowerStatus[1] == 0 && TowerStatus[2] == 0 && TowerStatus[3] == 0 && TowerStatus[4] == 0;
233 for (
int i=5;
i < MAX_TT_SIZE+1; ++
i) checkTowerStatus = checkTowerStatus && TowerStatus[
i] == 1;
234 if (!checkTowerStatus) {
235 for(
int i=1;
i<MAX_TT_SIZE+1; ++
i) {
236 std::cout <<
"tower " <<
i <<
" has status " << TowerStatus[
i] << std::endl;
243 uint32_t DCCruntype = (*itEventBlock)->getDataField(
"RUN TYPE");
244 theRuntypeDecoder.
Decode(DCCruntype, &theDCCheader);
246 DCCheaderCollection.
push_back(theDCCheader);
257 std::vector< DCCTBTowerBlock * > dccTowerBlocks = (*itEventBlock)->towerBlocks();
258 LogDebug(
"EcalTB07RawToDigi") <<
"@SUBS=EcalTB07DaqFormatter::interpretRawData"
259 <<
"dccTowerBlocks size " << dccTowerBlocks.size();
264 for (
int v=0;
v<71;
v++){
283 if( TowerStatus[u] ==0 || TowerStatus[u] ==9 || TowerStatus[u] ==10 )
297 edm::LogWarning(
"EcalTB07RawToDigiNumTowerBlocks") <<
"@SUB=EcalTB07DaqFormatter::interpretRawData"
298 <<
"number of TowerBlocks found (" << dccTowerBlocks.size()
300 <<
") skipping event";
314 for( std::vector< DCCTBTowerBlock * >::iterator itTowerBlock = dccTowerBlocks.begin();
315 itTowerBlock!= dccTowerBlocks.end();
318 tower=(*itTowerBlock)->towerID();
338 edm::LogWarning(
"EcalTB07RawToDigiTowerId") <<
"@SUBS=EcalTB07DaqFormatter::interpretRawData"
339 <<
"TTower id found (=" << tower
341 <<
") " << (_expTowersIndex+1) <<
"-th tower checked"
342 <<
"\n Real hardware id is " << (*itTowerBlock)->towerID();
349 edm::LogWarning(
"EcalTB07RawToDigiTowerId") <<
"@SUB=EcalTB07DaqFormatter:interpretRawData"
350 <<
"DecodeMEM: tower " << tower
351 <<
" is not the same as expected " << ((int)
_ExpectedTowers[_expTowersIndex])
352 <<
" (according to DCC header channel status)";
369 if ( 0< (*itTowerBlock)->towerID() &&
371 (*itTowerBlock)->towerID() == 71 ||
372 (*itTowerBlock)->towerID() == 80)
376 std::vector<DCCTBXtalBlock * > & xtalDataBlocks = (*itTowerBlock)->xtalBlocks();
381 edm::LogWarning(
"EcalTB07RawToDigiTowerSize") <<
"EcalTB07DaqFormatter::interpretRawData, no zero suppression "
382 <<
"wrong tower block size is: " << xtalDataBlocks.size()
383 <<
" at LV1 " << (*itEventBlock)->getDataField(
"LV1")
395 short expStripInTower;
397 short expCryInTower =0;
400 for( std::vector< DCCTBXtalBlock * >::iterator itXtalBlock = xtalDataBlocks.begin();
401 itXtalBlock!= xtalDataBlocks.end();
404 strip =(*itXtalBlock)->stripID();
405 ch =(*itXtalBlock)->xtalID();
408 expStripInTower = expCryInTower/5 +1;
409 expCryInStrip = expCryInTower%5 +1;
420 if (dataIsSuppressed)
423 if ( strip < 1 || 5<strip || ch <1 || 5 < ch)
426 for (
int StripInTower_ =1; StripInTower_ < 6; StripInTower_++){
427 for (
int CryInStrip_ =1; CryInStrip_ < 6; CryInStrip_++){
428 int ic =
cryIc(tower, StripInTower_, CryInStrip_) ;
434 edm::LogWarning(
"EcalTB07RawToDigiChId") <<
"EcalTB07DaqFormatter::interpretRawData with zero suppression, "
435 <<
" wrong channel id, since out of range: "
436 <<
"\t strip: " << strip <<
"\t channel: " << ch
438 <<
"\t at LV1 : " << (*itEventBlock)->getDataField(
"LV1");
446 if( cryInTower >= expCryInTower ){
447 expCryInTower = cryInTower +1;
454 edm::LogWarning(
"EcalTB07RawToDigiChId") <<
"EcalTB07DaqFormatter::interpretRawData with zero suppression, "
455 <<
" based on ch ordering within tt, wrong channel id: "
456 <<
"\t strip: " << strip <<
"\t channel: " << ch
457 <<
"\t cryInTower " << cryInTower
458 <<
"\t expCryInTower: " << expCryInTower
460 <<
"\t at LV1: " << (*itEventBlock)->getDataField(
"LV1");
463 for (
int StripInTower_ =1; StripInTower_ < 6; StripInTower_++){
464 for (
int CryInStrip_ =1; CryInStrip_ < 6; CryInStrip_++){
465 int ic =
cryIc(tower, StripInTower_, CryInStrip_) ;
472 expCryInTower++;
continue;
483 if( cryInTower != expCryInTower ||
488 int ic =
cryIc(tower, expStripInTower, expCryInStrip) ;
492 edm::LogWarning(
"EcalTB07RawToDigiChId") <<
"EcalTB07DaqFormatter::interpretRawData no zero suppression "
493 <<
" wrong channel id for channel: " << expCryInStrip
494 <<
"\t strip: " << expStripInTower
496 <<
"\t at LV1: " << (*itEventBlock)->getDataField(
"LV1")
497 <<
"\t (in the data, found channel: " << ch
498 <<
"\t strip: " << strip <<
" ).";
505 expCryInTower++;
continue;
516 int ic =
cryIc(tower, strip, ch) ;
521 int ix =
getEE_ix(tower, strip, ch);
522 int iy =
getEE_iy(tower, strip, ch);
525 if (
tbName_ ==
"h4" ) iz = -1;
535 std::vector<int> xtalDataSamples = (*itXtalBlock)->xtalDataSamples();
542 unsigned gain_mask = 12288;
543 std::vector <int> xtalGain;
545 for (
unsigned short i=0;
i<xtalDataSamples.size(); ++
i ) {
548 eeFrame .setSample (i, xtalDataSamples[i] );
550 if((xtalDataSamples[i] & gain_mask) == 0){gainIsOk =
false;}
552 xtalGain.push_back(0);
553 xtalGain[
i] |= (xtalDataSamples[
i] >> 12);
558 edm::LogWarning(
"EcalTB07RawToDigiGainZero") <<
"@SUB=EcalTB07DaqFormatter::interpretRawData"
559 <<
" gain==0 for strip: " << expStripInTower
560 <<
"\t channel: " << expCryInStrip
563 <<
"\t at LV1: " << (*itEventBlock)->getDataField(
"LV1");
578 short firstGainWrong=-1;
579 short numGainWrong=0;
581 for (
unsigned short i=0;
i<xtalGain.size();
i++ ) {
583 if (
i>0 && xtalGain[
i-1]>xtalGain[
i]) {
587 if (firstGainWrong == -1) {
589 edm::LogWarning(
"EcalTB07RawToDigiGainSwitch") <<
"@SUB=EcalTB07DaqFormatter::interpretRawData"
590 <<
"channelHasGainSwitchProblem: crystal eta = "
591 <<
id.ieta() <<
" phi = " <<
id.iphi();
593 edm::LogWarning(
"EcalTB07RawToDigiGainSwitch") <<
"@SUB=EcalTB07DaqFormatter::interpretRawData"
594 <<
"channelHasGainSwitchProblem: sample = " << (i-1)
595 <<
" gain: " << xtalGain[i-1] <<
" sample: "
596 << i <<
" gain: " << xtalGain[i];
600 if (numGainWrong>0) {
603 edm::LogWarning(
"EcalTB07RawToDigiGainSwitch") <<
"@SUB=EcalTB07DaqFormatter:interpretRawData"
604 <<
"channelHasGainSwitchProblem: more than 1 wrong transition";
606 for (
unsigned short i1=0; i1<xtalDataSamples.size(); ++i1 ) {
607 int countADC = 0x00000FFF;
608 countADC &= xtalDataSamples[i1];
609 LogDebug(
"EcalTB07RawToDigi") <<
"Sample " << i1 <<
" ADC " << countADC <<
" Gain " << xtalGain[i1];
631 else if ( (*itTowerBlock)->towerID() == 69
632 || (*itTowerBlock)->towerID() == 70 )
635 LogDebug(
"EcalTB07RawToDigi") <<
"@SUB=EcalTB07DaqFormatter::interpretRawData"
636 <<
"processing mem box num: " << (*itTowerBlock)->towerID();
645 DecodeMEM( (*itTowerBlock), pndigicollection ,
646 memttidcollection, memblocksizecollection,
647 memgaincollection, memchidcollection);
657 edm::LogWarning(
"EcalTB07RawToDigiTowerId") <<
"@SUB=EcalTB07DaqFormatter::interpretRawData"
658 <<
" processing tt with ID not existing ( "
659 << (*itTowerBlock)->towerID() <<
")";
681 LogDebug(
"EcalTB07RawToDigi") <<
"@SUB=EcalTB07DaqFormatter::DecodeMEM"
682 <<
"in mem " << towerblock->
towerID();
684 int tower_id = towerblock ->
towerID() ;
685 int mem_id = tower_id-69;
690 for (
int sa=0; sa<11; sa++){
695 if(tower_id != 69 && tower_id != 70)
697 edm::LogWarning(
"EcalTB07RawToDigiTowerId") <<
"@SUB=EcalTB07DaqFormatter:decodeMem"
698 <<
"DecodeMEM: this is not a mem box tower (" << tower_id <<
")";
707 std::vector<DCCTBXtalBlock *> & dccXtalBlocks = towerblock->
xtalBlocks();
708 std::vector<DCCTBXtalBlock*>::iterator itXtal;
713 LogDebug(
"EcalTB07RawToDigiDccBlockSize") <<
"@SUB=EcalTB07DaqFormatter:decodeMem"
714 <<
" wrong dccBlock size, namely: " << dccXtalBlocks.size()
728 int cryCounter = 0;
int strip_id = 0;
int xtal_id = 0;
730 for ( itXtal = dccXtalBlocks.begin(); itXtal < dccXtalBlocks.end(); itXtal++ ) {
731 strip_id = (*itXtal) ->getDataField(
"STRIP ID");
732 xtal_id = (*itXtal) ->getDataField(
"XTAL ID");
736 if( (wished_strip_id+1) != ((
int)strip_id) ||
737 (wished_ch_id+1) != ((
int)xtal_id) )
740 LogDebug(
"EcalTB07RawToDigiChId") <<
"@SUB=EcalTB07DaqFormatter:decodeMem"
741 <<
" in mem " << towerblock->
towerID()
742 <<
", expected:\t strip"
743 << (wished_strip_id+1) <<
" cry " << (wished_ch_id+1) <<
"\tfound: "
744 <<
" strip " << strip_id <<
" cry " << xtal_id;
753 memRawSample_[wished_strip_id][wished_ch_id][1] = (*itXtal)->getDataField(
"ADC#1");
754 memRawSample_[wished_strip_id][wished_ch_id][2] = (*itXtal)->getDataField(
"ADC#2");
755 memRawSample_[wished_strip_id][wished_ch_id][3] = (*itXtal)->getDataField(
"ADC#3");
756 memRawSample_[wished_strip_id][wished_ch_id][4] = (*itXtal)->getDataField(
"ADC#4");
757 memRawSample_[wished_strip_id][wished_ch_id][5] = (*itXtal)->getDataField(
"ADC#5");
758 memRawSample_[wished_strip_id][wished_ch_id][6] = (*itXtal)->getDataField(
"ADC#6");
759 memRawSample_[wished_strip_id][wished_ch_id][7] = (*itXtal)->getDataField(
"ADC#7");
760 memRawSample_[wished_strip_id][wished_ch_id][8] = (*itXtal)->getDataField(
"ADC#8");
761 memRawSample_[wished_strip_id][wished_ch_id][9] = (*itXtal)->getDataField(
"ADC#9");
762 memRawSample_[wished_strip_id][wished_ch_id][10] = (*itXtal)->getDataField(
"ADC#10");
779 for (memStoreIndex=0; memStoreIndex<500; memStoreIndex++) {
787 {ipn= mem_id*5+channel;}
789 {ipn=mem_id*5+4-channel;}
800 new_data=new_data | (tempSample&1);
809 new_data = (new_data ^ 0x800) & 0x3fff;
815 short sampleGain = (new_data &0x3000)/4096;
816 if ( sampleGain==2 || sampleGain==3)
821 edm::LogWarning(
"EcalTB07RawToDigiGainZero") <<
"@SUB=EcalTB07DaqFormatter:decodeMem"
822 <<
"in mem " << towerblock->
towerID()
824 << (strip +1) <<
" cry: " << (channel+1)
825 <<
" has 14th bit non zero! Gain results: "
826 << sampleGain <<
".";
831 memStoreIndex= ipn*50+strip*kSamplesPerChannel+
sample;
833 data_MEM[memStoreIndex]= new_data & 0x3fff;
846 if (! (memgaincollection.
size()==0 && memchidcollection.
size()==0) )
849 idItr != memgaincollection.
end();
851 int ch = (*idItr).channelId();
857 idItr != memchidcollection.
end();
859 int ch = (*idItr).channelId();
870 for (
int pnId = 1; pnId < (kPnPerTowerBlock+1); pnId++){
895 int xtal= (strip-1)*5+ch-1;
897 std::pair<int,int> ind;
926 int ic =
cryIc(tower, strip, ch);
938 int ic =
cryIc(tower, strip, ch);
944 iy = 51 + (int)((ic-1)/20);
951 if ( strip < 1 || 5<strip || ch <1 || 5 < ch || 68<tower)
953 edm::LogWarning(
"EcalTB07RawToDigiChId") <<
"EcalTB07DaqFormatter::interpretRawData (cryIc) "
954 <<
" wrong channel id, since out of range: "
955 <<
"\t strip: " << strip <<
"\t channel: " << ch
956 <<
"\t in TT: " << tower;
961 return cryIcMap_[tower-1][strip-1][ch-1];
970 if ((tower>12 && tower<21) || (tower>28 && tower<37) ||
971 (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