35 int cryIcMap[68][5][5],
36 int tbStatusToLocation[71],
37 int tbTowerIDToLocation[201]) {
38 LogDebug(
"EcalTB07RawToDigi") <<
"@SUB=EcalTB07DaqFormatter";
55 for (
int i = 0;
i < 68; ++
i)
56 for (
int j = 0;
j < 5; ++
j)
57 for (
int k = 0;
k < 5; ++
k)
60 for (
int i = 0;
i < 71; ++
i)
63 for (
int i = 0;
i < 201; ++
i)
83 const unsigned char* pData = fedData.
data();
84 int length = fedData.
size();
86 unsigned int tower = 0;
90 LogDebug(
"EcalTB07RawToDigi") <<
"@SUB=EcalTB07DaqFormatter::interpretRawData" 98 theParser_->
parseBuffer(reinterpret_cast<const uint32_t*>(pData), static_cast<uint32_t>(length), shit);
103 for (std::vector<DCCTBEventBlock*>::iterator itEventBlock = dccEventBlocks.begin();
104 itEventBlock != dccEventBlocks.end();
106 bool _displayParserMessages =
false;
107 if ((*itEventBlock)->eventHasErrors() && _displayParserMessages) {
108 edm::LogWarning(
"EcalTB07RawToDigi") <<
"@SUB=EcalTB07DaqFormatter::interpretRawData" 109 <<
"errors found from parser... ";
110 edm::LogWarning(
"EcalTB07RawToDigi") << (*itEventBlock)->eventErrorString();
111 edm::LogWarning(
"EcalTB07RawToDigi") <<
"@SUB=EcalTB07DaqFormatter::interpretRawData" 112 <<
"... errors from parser notified";
118 theDCCheader.
setId(46);
119 int fedId = (*itEventBlock)->getDataField(
"FED/DCC ID");
122 theDCCheader.
setRunNumber((*itEventBlock)->getDataField(
"RUN NUMBER"));
123 short trigger_type = (*itEventBlock)->getDataField(
"TRIGGER TYPE");
124 short zs = (*itEventBlock)->getDataField(
"ZS");
125 short tzs = (*itEventBlock)->getDataField(
"TZS");
126 short sr = (*itEventBlock)->getDataField(
"SR");
127 bool dataIsSuppressed;
131 dataIsSuppressed =
true;
133 dataIsSuppressed =
false;
135 if (trigger_type > 0 && trigger_type < 5) {
138 edm::LogWarning(
"EcalTB07RawToDigiTriggerType") <<
"@SUB=EcalTB07DaqFormatter::interpretRawData" 139 <<
"unrecognized TRIGGER TYPE: " << trigger_type;
141 theDCCheader.
setLV1((*itEventBlock)->getDataField(
"LV1"));
142 theDCCheader.
setOrbit((*itEventBlock)->getDataField(
"ORBIT COUNTER"));
143 theDCCheader.
setBX((*itEventBlock)->getDataField(
"BX"));
144 theDCCheader.
setErrors((*itEventBlock)->getDataField(
"DCC ERRORS"));
148 theDCCheader.
setSrpStatus((*itEventBlock)->getDataField(
"SR_CHSTATUS"));
150 std::vector<short> theTCCs;
153 sprintf(TCCnum,
"TCC_CHSTATUS#%d",
i + 1);
155 theTCCs.push_back((*itEventBlock)->getDataField(TCCnumS));
159 std::vector<DCCTBTCCBlock*> tccBlocks = (*itEventBlock)->tccBlocks();
161 for (std::vector<DCCTBTCCBlock*>::iterator itTCCBlock = tccBlocks.begin(); itTCCBlock != tccBlocks.end();
163 std::vector<std::pair<int, bool> > TpSamples = (*itTCCBlock)->triggerSamples();
165 std::vector<int> TpFlags = (*itTCCBlock)->triggerFlags();
168 if (TpSamples.size() == 68 && TpFlags.size() == 68) {
169 for (
int i = 0;
i < ((
int)TpSamples.size());
i++) {
188 <<
"@SUBS=EcalTB07DaqFormatter::interpretRawData" 189 <<
"tower: " << (
i + 1) <<
" primitive: " << TpSamples[
i].
first <<
" flag: " << TpSamples[
i].
second;
191 LogDebug(
"EcalTB07RawToDigiTpg") <<
"@SUBS=EcalTB07DaqFormatter::interpretRawData" 192 <<
"tower: " << (
i + 1) <<
" flag: " << TpFlags[
i];
198 <<
"68 elements not found for TpFlags or TpSamples, collection will be empty";
204 std::vector<short> theTTstatus;
206 sprintf(
buffer,
"FE_CHSTATUS#%d",
i);
208 TowerStatus[
i] = (*itEventBlock)->getDataField(Tower);
209 theTTstatus.push_back(TowerStatus[
i]);
212 bool checkTowerStatus = TowerStatus[1] == 0 && TowerStatus[2] == 0 && TowerStatus[3] == 0 && TowerStatus[4] == 0;
214 checkTowerStatus = checkTowerStatus && TowerStatus[
i] == 1;
215 if (!checkTowerStatus) {
217 std::cout <<
"tower " <<
i <<
" has status " << TowerStatus[
i] << std::endl;
224 uint32_t DCCruntype = (*itEventBlock)->getDataField(
"RUN TYPE");
225 theRuntypeDecoder.
Decode(DCCruntype, &theDCCheader);
227 DCCheaderCollection.
push_back(theDCCheader);
238 std::vector<DCCTBTowerBlock*> dccTowerBlocks = (*itEventBlock)->towerBlocks();
239 LogDebug(
"EcalTB07RawToDigi") <<
"@SUBS=EcalTB07DaqFormatter::interpretRawData" 240 <<
"dccTowerBlocks size " << dccTowerBlocks.size();
244 for (
int v = 0;
v < 71;
v++) {
262 if (TowerStatus[u] == 0 || TowerStatus[u] == 9 || TowerStatus[u] == 10) {
275 <<
"@SUB=EcalTB07DaqFormatter::interpretRawData" 276 <<
"number of TowerBlocks found (" << dccTowerBlocks.size() <<
") differs from expected (" 286 for (std::vector<DCCTBTowerBlock*>::iterator itTowerBlock = dccTowerBlocks.begin();
287 itTowerBlock != dccTowerBlocks.end();
289 tower = (*itTowerBlock)->towerID();
307 <<
"@SUBS=EcalTB07DaqFormatter::interpretRawData" 310 <<
"\n Real hardware id is " << (*itTowerBlock)->towerID();
316 <<
"@SUB=EcalTB07DaqFormatter:interpretRawData" 317 <<
"DecodeMEM: tower " <<
tower <<
" is not the same as expected " 333 if (0 < (*itTowerBlock)->towerID() && ((*itTowerBlock)->towerID() < (
kTriggerTowers + 1) ||
334 (*itTowerBlock)->towerID() == 71 || (*itTowerBlock)->towerID() == 80)) {
335 std::vector<DCCTBXtalBlock*>& xtalDataBlocks = (*itTowerBlock)->xtalBlocks();
340 <<
"EcalTB07DaqFormatter::interpretRawData, no zero suppression " 341 <<
"wrong tower block size is: " << xtalDataBlocks.size() <<
" at LV1 " 350 short cryInTower = 0;
352 short expStripInTower;
354 short expCryInTower = 0;
357 for (std::vector<DCCTBXtalBlock*>::iterator itXtalBlock = xtalDataBlocks.begin();
358 itXtalBlock != xtalDataBlocks.end();
361 strip = (*itXtalBlock)->stripID();
362 ch = (*itXtalBlock)->xtalID();
365 expStripInTower = expCryInTower / 5 + 1;
366 expCryInStrip = expCryInTower % 5 + 1;
375 if (dataIsSuppressed) {
376 if (
strip < 1 || 5 <
strip || ch < 1 || 5 < ch) {
378 for (
int StripInTower_ = 1; StripInTower_ < 6; StripInTower_++) {
379 for (
int CryInStrip_ = 1; CryInStrip_ < 6; CryInStrip_++) {
380 int ic =
cryIc(
tower, StripInTower_, CryInStrip_);
387 <<
"EcalTB07DaqFormatter::interpretRawData with zero suppression, " 388 <<
" wrong channel id, since out of range: " 390 <<
"\t at LV1 : " << (*itEventBlock)->getDataField(
"LV1");
397 if (cryInTower >= expCryInTower) {
398 expCryInTower = cryInTower + 1;
404 <<
"EcalTB07DaqFormatter::interpretRawData with zero suppression, " 405 <<
" based on ch ordering within tt, wrong channel id: " 406 <<
"\t strip: " <<
strip <<
"\t channel: " << ch <<
"\t cryInTower " << cryInTower
408 <<
"\t at LV1: " << (*itEventBlock)->getDataField(
"LV1");
411 for (
int StripInTower_ = 1; StripInTower_ < 6; StripInTower_++) {
412 for (
int CryInStrip_ = 1; CryInStrip_ < 6; CryInStrip_++) {
413 int ic =
cryIc(
tower, StripInTower_, CryInStrip_);
431 int ic =
cryIc(
tower, expStripInTower, expCryInStrip);
436 <<
"EcalTB07DaqFormatter::interpretRawData no zero suppression " 437 <<
" wrong channel id for channel: " << expCryInStrip <<
"\t strip: " << expStripInTower
439 <<
"\t at LV1: " << (*itEventBlock)->getDataField(
"LV1")
440 <<
"\t (in the data, found channel: " << ch <<
"\t strip: " <<
strip <<
" ).";
476 std::vector<int> xtalDataSamples = (*itXtalBlock)->xtalDataSamples();
481 bool gainIsOk =
true;
482 unsigned gain_mask = 12288;
483 std::vector<int> xtalGain;
485 for (
unsigned short i = 0;
i < xtalDataSamples.size(); ++
i) {
487 eeFrame.setSample(
i, xtalDataSamples[
i]);
489 if ((xtalDataSamples[
i] & gain_mask) == 0) {
493 xtalGain.push_back(0);
494 xtalGain[
i] |= (xtalDataSamples[
i] >> 12);
499 <<
"@SUB=EcalTB07DaqFormatter::interpretRawData" 500 <<
" gain==0 for strip: " << expStripInTower <<
"\t channel: " << expCryInStrip
502 <<
"\t at LV1: " << (*itEventBlock)->getDataField(
"LV1");
514 short firstGainWrong = -1;
515 short numGainWrong = 0;
517 for (
unsigned short i = 0;
i < xtalGain.size();
i++) {
518 if (
i > 0 && xtalGain[
i - 1] > xtalGain[
i]) {
521 if (firstGainWrong == -1) {
524 <<
"@SUB=EcalTB07DaqFormatter::interpretRawData" 525 <<
"channelHasGainSwitchProblem: crystal eta = " <<
id.ieta() <<
" phi = " <<
id.iphi();
528 <<
"@SUB=EcalTB07DaqFormatter::interpretRawData" 529 <<
"channelHasGainSwitchProblem: sample = " << (
i - 1) <<
" gain: " << xtalGain[
i - 1]
530 <<
" sample: " <<
i <<
" gain: " << xtalGain[
i];
534 if (numGainWrong > 0) {
538 <<
"@SUB=EcalTB07DaqFormatter:interpretRawData" 539 <<
"channelHasGainSwitchProblem: more than 1 wrong transition";
541 for (
unsigned short i1 = 0;
i1 < xtalDataSamples.size(); ++
i1) {
542 int countADC = 0x00000FFF;
543 countADC &= xtalDataSamples[
i1];
544 LogDebug(
"EcalTB07RawToDigi") <<
"Sample " <<
i1 <<
" ADC " << countADC <<
" Gain " << xtalGain[
i1];
562 else if ((*itTowerBlock)->towerID() == 69 || (*itTowerBlock)->towerID() == 70) {
563 LogDebug(
"EcalTB07RawToDigi") <<
"@SUB=EcalTB07DaqFormatter::interpretRawData" 564 <<
"processing mem box num: " << (*itTowerBlock)->towerID();
575 memblocksizecollection,
584 <<
"@SUB=EcalTB07DaqFormatter::interpretRawData" 585 <<
" processing tt with ID not existing ( " << (*itTowerBlock)->towerID() <<
")";
601 LogDebug(
"EcalTB07RawToDigi") <<
"@SUB=EcalTB07DaqFormatter::DecodeMEM" 602 <<
"in mem " << towerblock->
towerID();
604 int tower_id = towerblock->
towerID();
605 int mem_id = tower_id - 69;
610 for (
int sa = 0; sa < 11; sa++) {
617 if (tower_id != 69 && tower_id != 70) {
618 edm::LogWarning(
"EcalTB07RawToDigiTowerId") <<
"@SUB=EcalTB07DaqFormatter:decodeMem" 619 <<
"DecodeMEM: this is not a mem box tower (" << tower_id <<
")";
627 std::vector<DCCTBXtalBlock*>& dccXtalBlocks = towerblock->
xtalBlocks();
628 std::vector<DCCTBXtalBlock*>::iterator itXtal;
632 LogDebug(
"EcalTB07RawToDigiDccBlockSize")
633 <<
"@SUB=EcalTB07DaqFormatter:decodeMem" 650 for (itXtal = dccXtalBlocks.begin(); itXtal < dccXtalBlocks.end(); itXtal++) {
651 strip_id = (*itXtal)->getDataField(
"STRIP ID");
652 xtal_id = (*itXtal)->getDataField(
"XTAL ID");
656 if ((wished_strip_id + 1) != ((
int)strip_id) || (wished_ch_id + 1) != ((
int)xtal_id)) {
657 LogDebug(
"EcalTB07RawToDigiChId") <<
"@SUB=EcalTB07DaqFormatter:decodeMem" 658 <<
" in mem " << towerblock->
towerID() <<
", expected:\t strip" 659 << (wished_strip_id + 1) <<
" cry " << (wished_ch_id + 1) <<
"\tfound: " 660 <<
" strip " << strip_id <<
" cry " << xtal_id;
668 memRawSample_[wished_strip_id][wished_ch_id][1] = (*itXtal)->getDataField(
"ADC#1");
669 memRawSample_[wished_strip_id][wished_ch_id][2] = (*itXtal)->getDataField(
"ADC#2");
670 memRawSample_[wished_strip_id][wished_ch_id][3] = (*itXtal)->getDataField(
"ADC#3");
671 memRawSample_[wished_strip_id][wished_ch_id][4] = (*itXtal)->getDataField(
"ADC#4");
672 memRawSample_[wished_strip_id][wished_ch_id][5] = (*itXtal)->getDataField(
"ADC#5");
673 memRawSample_[wished_strip_id][wished_ch_id][6] = (*itXtal)->getDataField(
"ADC#6");
674 memRawSample_[wished_strip_id][wished_ch_id][7] = (*itXtal)->getDataField(
"ADC#7");
675 memRawSample_[wished_strip_id][wished_ch_id][8] = (*itXtal)->getDataField(
"ADC#8");
676 memRawSample_[wished_strip_id][wished_ch_id][9] = (*itXtal)->getDataField(
"ADC#9");
677 memRawSample_[wished_strip_id][wished_ch_id][10] = (*itXtal)->getDataField(
"ADC#10");
690 int memStoreIndex = 0;
692 for (memStoreIndex = 0; memStoreIndex < 500; memStoreIndex++) {
699 if (
strip % 2 == 0) {
700 ipn = mem_id * 5 + channel;
702 ipn = mem_id * 5 + 4 - channel;
709 if (
strip % 2 == 1) {
711 for (
int ib = 0;
ib < 14;
ib++) {
713 new_data = new_data | (tempSample & 1);
717 new_data = tempSample;
722 new_data = (new_data ^ 0x800) & 0x3fff;
728 short sampleGain = (new_data & 0x3000) / 4096;
729 if (sampleGain == 2 || sampleGain == 3) {
734 <<
"@SUB=EcalTB07DaqFormatter:decodeMem" 735 <<
"in mem " << towerblock->
towerID() <<
" :\t strip: " << (
strip + 1) <<
" cry: " << (channel + 1)
736 <<
" has 14th bit non zero! Gain results: " << sampleGain <<
".";
743 data_MEM[memStoreIndex] = new_data & 0x3fff;
754 if (!(memgaincollection.
empty() && memchidcollection.
empty())) {
756 idItr != memgaincollection.
end();
758 int ch = (*idItr).channelId();
764 idItr != memchidcollection.
end();
766 int ch = (*idItr).channelId();
794 int xtal = (
strip - 1) * 5 + ch - 1;
796 std::pair<int, int> ind;
814 ind.second =
phi + 1;
826 ix = 95 - (ic - 1) / 20;
829 ix = 35 - (ic - 1) % 20;
837 iy = 46 + (ic - 1) % 20;
840 iy = 51 + (
int)((ic - 1) / 20);
847 edm::LogWarning(
"EcalTB07RawToDigiChId") <<
"EcalTB07DaqFormatter::interpretRawData (cryIc) " 848 <<
" wrong channel id, since out of range: " 849 <<
"\t strip: " <<
strip <<
"\t channel: " << ch <<
"\t in TT: " <<
tower;
void push_back(const Digi &digi)
std::vector< DCCTBXtalBlock * > & xtalBlocks()
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)
size_t size() const
Lenght of the data buffer in bytes.
void push_back(T const &t)
std::vector< DCCTBEventBlock * > & dccEvents()
U second(std::pair< T, U > const &p)
void setSample(int i, const EcalTriggerPrimitiveSample &sam)
const_iterator begin() const
void reserve(size_t isize)
void setSample(int i, EcalMGPASample sam)
void push_back(const Digi &digi)
void reserve(size_type n)
const unsigned char * data() const
Return a const pointer to the beginning of the data buffer.
void setSample(int i, const EcalFEMSample &sam)
Log< level::Warning, false > LogWarning
void parseBuffer(const uint32_t *buffer, uint32_t bufferSize, bool singleEvent=false)
const_iterator end() const
std::vector< T >::const_iterator const_iterator