File indexing completed on 2023-03-17 10:59:44
0001 #include "DCCEventBlock.h"
0002 #include "DCCDataParser.h"
0003 #include "DCCDataMapper.h"
0004 #include "DCCTowerBlock.h"
0005 #include "ECALParserException.h"
0006 #include "ECALParserBlockException.h"
0007 #include "DCCSRPBlock.h"
0008 #include "DCCTCCBlock.h"
0009 #include "DCCXtalBlock.h"
0010 #include "DCCTrailerBlock.h"
0011
0012 #include <iomanip>
0013 #include <sstream>
0014
0015 DCCTBEventBlock::DCCTBEventBlock(DCCTBDataParser *parser,
0016 const uint32_t *buffer,
0017 uint32_t numbBytes,
0018 uint32_t wordsToEnd,
0019 uint32_t wordBufferOffset,
0020 uint32_t wordEventOffset)
0021 : DCCTBBlockPrototype(parser, "DCCHEADER", buffer, numbBytes, wordsToEnd),
0022 dccTrailerBlock_(nullptr),
0023 srpBlock_(nullptr),
0024 wordBufferOffset_(wordBufferOffset) {
0025
0026 errors_["DCC::HEADER"] = 0;
0027 errors_["DCC::EVENT LENGTH"] = 0;
0028
0029
0030 uint32_t wToEnd(0);
0031
0032 try {
0033
0034 if (numbBytes == DCCTBDataParser::EMPTYEVENTSIZE) {
0035 mapperFields_ = parser_->mapper()->emptyEventFields();
0036 emptyEvent = true;
0037 } else {
0038 mapperFields_ = parser_->mapper()->dccFields();
0039 emptyEvent = false;
0040 }
0041
0042 try {
0043 parseData();
0044 } catch (ECALTBParserBlockException &e) {
0045 }
0046
0047
0048
0049 if (parser_->debug()) {
0050 dataCheck();
0051 }
0052
0053
0054
0055
0056 if (!emptyEvent && getDataField("DCC ERRORS") != DCCERROR_EMPTYEVENT) {
0057
0058
0059 bool srp(false);
0060 uint32_t sr_ch = getDataField("SR_CHSTATUS");
0061 if (sr_ch != CH_TIMEOUT && sr_ch != CH_DISABLED) {
0062
0063 increment(1, " (while trying to create a SR Block !)");
0064 wToEnd = numbBytes / 4 - wordCounter_ - 1;
0065
0066
0067 srpBlock_ = new DCCTBSRPBlock(this, parser_, dataP_, parser_->srpBlockSize(), wToEnd, wordCounter_);
0068
0069
0070 increment((parser_->srpBlockSize()) / 4 - 1);
0071 if (getDataField("SR")) {
0072 srp = true;
0073 }
0074 }
0075
0076
0077
0078
0079 for (uint32_t i = 1; i <= 4; i++) {
0080 uint32_t tcc_ch = 0;
0081 uint32_t tccId = 0;
0082 if (i == 1) {
0083 tccId = parser_->tcc1Id();
0084 }
0085 if (i == 2) {
0086 tccId = parser_->tcc2Id();
0087 }
0088 if (i == 3) {
0089 tccId = parser_->tcc3Id();
0090 }
0091 if (i == 4) {
0092 tccId = parser_->tcc4Id();
0093 }
0094
0095 std::string tcc = std::string("TCC_CHSTATUS#") + parser_->getDecString(i);
0096 tcc_ch = getDataField(tcc);
0097
0098 if (tcc_ch != CH_TIMEOUT && tcc_ch != CH_DISABLED) {
0099
0100
0101
0102 increment(1, " (while trying to create a" + tcc + " Block !)");
0103
0104 wToEnd = numbBytes / 4 - wordCounter_ - 1;
0105
0106
0107
0108 tccBlocks_.push_back(
0109 new DCCTBTCCBlock(this, parser_, dataP_, parser_->tccBlockSize(), wToEnd, wordCounter_, tccId));
0110
0111
0112 increment((parser_->tccBlockSize()) / 4 - 1);
0113 }
0114 }
0115
0116
0117
0118
0119
0120 uint32_t triggerType = getDataField("TRIGGER TYPE");
0121 uint32_t numbChannels;
0122 if (triggerType == PHYSICTRIGGER) {
0123 numbChannels = 68;
0124 } else if (triggerType == CALIBRATIONTRIGGER) {
0125 numbChannels = 70;
0126 }
0127
0128 else {
0129 std::string error = std::string("\n DCC::HEADER TRIGGER TYPE = ") + parser_->getDecString(triggerType) +
0130 std::string(" is not a valid type !");
0131 ECALTBParserBlockException a(error);
0132 throw a;
0133 }
0134
0135
0136
0137 uint32_t srFlag;
0138 bool suppress(false);
0139
0140 for (uint32_t i = 1; i <= numbChannels; i++) {
0141 std::string chStatusId = std::string("FE_CHSTATUS#") + parser_->getDecString(i);
0142 uint32_t chStatus = getDataField(chStatusId);
0143
0144
0145 if (srp) {
0146 srFlag = srpBlock_->getDataField(std::string("SR#") + parser_->getDecString(i));
0147 if (srFlag == SR_NREAD) {
0148 suppress = true;
0149 } else {
0150 suppress = false;
0151 }
0152 }
0153
0154
0155 if (chStatus != CH_TIMEOUT && chStatus != CH_DISABLED && !suppress && chStatus != CH_SUPPRESS) {
0156
0157 increment(1, " (while trying to create a TOWERHEADER Block for channel " + parser_->getDecString(i) + " !)");
0158
0159
0160
0161 wToEnd = numbBytes / 4 - wordCounter_ - 1;
0162 DCCTBTowerBlock *towerBlock =
0163 new DCCTBTowerBlock(this, parser_, dataP_, TOWERHEADER_SIZE, wToEnd, wordCounter_, i);
0164 towerBlocks_.push_back(towerBlock);
0165 towerBlock->parseXtalData();
0166
0167
0168
0169 increment((towerBlock->getDataField("BLOCK LENGTH")) * 2 - 1);
0170
0171 }
0172 }
0173
0174
0175
0176 increment(1, " (while trying to create a DCC TRAILER Block !)");
0177 wToEnd = numbBytes / 4 - wordCounter_ - 1;
0178 dccTrailerBlock_ = new DCCTBTrailerBlock(parser_, dataP_, TRAILER_SIZE, wToEnd, wordCounter_, blockSize_ / 8, 0);
0179
0180 }
0181
0182 } catch (ECALTBParserException &e) {
0183 } catch (ECALTBParserBlockException &e) {
0184
0185 errorString_ += std::string(e.what());
0186 blockError_ = true;
0187
0188 }
0189 }
0190
0191 DCCTBEventBlock::~DCCTBEventBlock() {
0192 std::vector<DCCTBTCCBlock *>::iterator it1;
0193 for (it1 = tccBlocks_.begin(); it1 != tccBlocks_.end(); it1++) {
0194 delete (*it1);
0195 }
0196 tccBlocks_.clear();
0197
0198 std::vector<DCCTBTowerBlock *>::iterator it2;
0199 for (it2 = towerBlocks_.begin(); it2 != towerBlocks_.end(); it2++) {
0200 delete (*it2);
0201 }
0202 towerBlocks_.clear();
0203
0204 if (srpBlock_ != nullptr) {
0205 delete srpBlock_;
0206 }
0207 if (dccTrailerBlock_ != nullptr) {
0208 delete dccTrailerBlock_;
0209 }
0210 }
0211
0212 void DCCTBEventBlock::dataCheck() {
0213 std::string checkErrors("");
0214
0215
0216 std::pair<bool, std::string> res = checkDataField("BOE", BOE);
0217 if (!res.first) {
0218 checkErrors += res.second;
0219 (errors_["DCC::HEADER"])++;
0220 }
0221
0222
0223
0224 std::string hField = std::string("H");
0225 res = checkDataField(hField, 1);
0226 if (!res.first) {
0227 checkErrors += res.second;
0228 (errors_["DCC::HEADER"])++;
0229 }
0230
0231
0232
0233 uint32_t dccHeaderWords = 0;
0234
0235 if (emptyEvent) {
0236 dccHeaderWords = 2;
0237 } else if (!emptyEvent) {
0238 dccHeaderWords = 7;
0239 }
0240
0241 for (uint32_t i = 1; i <= dccHeaderWords; i++) {
0242 std::string header = std::string("H") + parser_->getDecString(i);
0243 res = checkDataField(header, i);
0244 if (!res.first) {
0245 checkErrors += res.second;
0246 (errors_["DCC::HEADER"])++;
0247 }
0248 }
0249
0250
0251
0252 res = checkDataField("EVENT LENGTH", blockSize_ / 8);
0253 if (!res.first) {
0254 checkErrors += res.second;
0255 (errors_["DCC::EVENT LENGTH"])++;
0256 }
0257
0258
0259 if (!checkErrors.empty()) {
0260 errorString_ += "\n ======================================================================\n";
0261 errorString_ += std::string(" ") + name_ + std::string(" data fields checks errors : ");
0262 errorString_ += checkErrors;
0263 errorString_ += "\n ======================================================================";
0264 blockError_ = true;
0265 }
0266 }
0267
0268 void DCCTBEventBlock::displayEvent(std::ostream &os) {
0269 os << "\n\n\n\n\n >>>>>>>>>>>>>>>>>>>> Event started at word position " << std::dec << wordBufferOffset_
0270 << " <<<<<<<<<<<<<<<<<<<<" << std::endl;
0271
0272
0273 displayData(os);
0274
0275
0276
0277 if (srpBlock_) {
0278 srpBlock_->displayData(os);
0279 }
0280
0281
0282
0283 std::vector<DCCTBTCCBlock *>::iterator it1;
0284 for (it1 = tccBlocks_.begin(); it1 != tccBlocks_.end(); it1++) {
0285 (*it1)->displayData(os);
0286 }
0287
0288
0289 std::vector<DCCTBTowerBlock *>::iterator it2;
0290 for (it2 = towerBlocks_.begin(); it2 != towerBlocks_.end(); it2++) {
0291 (*it2)->displayData(os);
0292
0293
0294 std::vector<DCCTBXtalBlock *> &xtalBlocks = (*it2)->xtalBlocks();
0295 std::vector<DCCTBXtalBlock *>::iterator it3;
0296 for (it3 = xtalBlocks.begin(); it3 != xtalBlocks.end(); it3++) {
0297 (*it3)->displayData(os);
0298 }
0299 }
0300
0301
0302 if (dccTrailerBlock_) {
0303 dccTrailerBlock_->displayData(os);
0304 }
0305 }
0306
0307 std::pair<bool, std::string> DCCTBEventBlock::compare(DCCTBEventBlock *block) {
0308
0309 std::pair<bool, std::string> ret(DCCTBBlockPrototype::compare(block));
0310
0311
0312 std::stringstream out;
0313
0314
0315 if (srpBlock_ && block->srpBlock()) {
0316 std::pair<bool, std::string> temp(srpBlock_->compare(block->srpBlock()));
0317 ret.first = ret.first & temp.first;
0318 out << temp.second;
0319 } else if (!srpBlock_ && block->srpBlock()) {
0320 ret.first = false;
0321 out << "\n ====================================================================="
0322 << "\n ERROR SR block identified in the ORIGINAL BLOCK ... "
0323 << "\n ... but the block is not present in the COMPARISION BLOCK !"
0324 << "\n =====================================================================";
0325 } else if (srpBlock_ && !(block->srpBlock())) {
0326 ret.first = false;
0327 out << "\n ====================================================================="
0328 << "\n ERROR SR block identified in the COMPARISION BLOCK ... "
0329 << "\n ... but the block is not present in the ORIGINAL BLOCK !"
0330 << "\n =====================================================================";
0331 }
0332
0333
0334
0335
0336 int numbTccBlocks_a = tccBlocks_.size();
0337 int numbTccBlocks_b = block->tccBlocks().size();
0338
0339 if (numbTccBlocks_a != numbTccBlocks_b) {
0340 ret.first = false;
0341 out << "\n ====================================================================="
0342 << "\n ERROR number of TCC blocks in the ORIGINAL BLOCK( =" << numbTccBlocks_a << " )"
0343 << "\n and in the COMPARISION BLOCK( = " << numbTccBlocks_b << " is different !"
0344 << "\n =====================================================================";
0345 }
0346
0347 std::vector<DCCTBTCCBlock *>::iterator it1Tcc = tccBlocks_.begin();
0348 std::vector<DCCTBTCCBlock *>::iterator it1TccEnd = tccBlocks_.end();
0349 std::vector<DCCTBTCCBlock *>::iterator it2Tcc = block->tccBlocks().begin();
0350 std::vector<DCCTBTCCBlock *>::iterator it2TccEnd = block->tccBlocks().end();
0351
0352 for (; it1Tcc != it1TccEnd && it2Tcc != it2TccEnd; it1Tcc++, it2Tcc++) {
0353 std::pair<bool, std::string> temp((*it1Tcc)->compare(*it2Tcc));
0354 ret.first = ret.first & temp.first;
0355 out << temp.second;
0356 }
0357
0358
0359
0360
0361 int numbTowerBlocks_a = towerBlocks_.size();
0362 int numbTowerBlocks_b = block->towerBlocks().size();
0363
0364 if (numbTowerBlocks_a != numbTowerBlocks_b) {
0365 ret.first = false;
0366 out << "\n ====================================================================="
0367 << "\n ERROR number of Tower blocks in the ORIGINAL BLOCK( =" << numbTowerBlocks_a << " )"
0368 << "\n and in the COMPARISION BLOCK( = " << numbTowerBlocks_b << " is different !"
0369 << "\n =====================================================================";
0370 }
0371
0372 std::vector<DCCTBTowerBlock *>::iterator it1Tower = towerBlocks_.begin();
0373 std::vector<DCCTBTowerBlock *>::iterator it1TowerEnd = towerBlocks_.end();
0374 std::vector<DCCTBTowerBlock *>::iterator it2Tower = (block->towerBlocks()).begin();
0375 std::vector<DCCTBTowerBlock *>::iterator it2TowerEnd = (block->towerBlocks()).end();
0376
0377 for (; it1Tower != it1TowerEnd && it2Tower != it2TowerEnd; it1Tower++, it2Tower++) {
0378 std::pair<bool, std::string> temp((*it1Tower)->compare(*it2Tower));
0379 ret.first = ret.first & temp.first;
0380 out << temp.second;
0381
0382
0383 std::vector<DCCTBXtalBlock *> xtalBlocks1((*it1Tower)->xtalBlocks());
0384 std::vector<DCCTBXtalBlock *> xtalBlocks2((*it2Tower)->xtalBlocks());
0385
0386 int numbXtalBlocks_a = xtalBlocks1.size();
0387 int numbXtalBlocks_b = xtalBlocks2.size();
0388
0389 if (numbXtalBlocks_a != numbXtalBlocks_b) {
0390 ret.first = false;
0391 out << "\n ====================================================================="
0392 << "\n ERROR number of Xtal blocks in this TOWER ORIGINAL BLOCK( =" << numbXtalBlocks_a << " )"
0393 << "\n and in the TOWER COMPARISION BLOCK( = " << numbXtalBlocks_b << " is different !"
0394 << "\n =====================================================================";
0395 }
0396
0397 std::vector<DCCTBXtalBlock *>::iterator it1Xtal = xtalBlocks1.begin();
0398 std::vector<DCCTBXtalBlock *>::iterator it1XtalEnd = xtalBlocks1.end();
0399 std::vector<DCCTBXtalBlock *>::iterator it2Xtal = xtalBlocks1.begin();
0400 std::vector<DCCTBXtalBlock *>::iterator it2XtalEnd = xtalBlocks2.end();
0401
0402 for (; it1Xtal != it1XtalEnd && it2Xtal != it2XtalEnd; it1Xtal++, it2Xtal++) {
0403 std::pair<bool, std::string> temp((*it1Xtal)->compare(*it2Xtal));
0404 ret.first = ret.first & temp.first;
0405 out << temp.second;
0406 }
0407 }
0408
0409
0410 if (block->trailerBlock() && trailerBlock()) {
0411 std::pair<bool, std::string> temp(trailerBlock()->compare(block->trailerBlock()));
0412 ret.first = ret.first & temp.first;
0413 out << temp.second;
0414 }
0415
0416 ret.second += out.str();
0417
0418 return ret;
0419 }
0420
0421 bool DCCTBEventBlock::eventHasErrors() {
0422 bool ret(false);
0423 ret = blockError();
0424
0425
0426 std::vector<DCCTBTCCBlock *>::iterator it1;
0427 for (it1 = tccBlocks_.begin(); it1 != tccBlocks_.end(); it1++) {
0428 ret |= (*it1)->blockError();
0429 }
0430
0431
0432
0433 if (srpBlock_) {
0434 ret |= srpBlock_->blockError();
0435 }
0436
0437
0438
0439 std::vector<DCCTBTowerBlock *>::iterator it2;
0440 for (it2 = towerBlocks_.begin(); it2 != towerBlocks_.end(); it2++) {
0441 ret |= (*it2)->blockError();
0442
0443
0444 std::vector<DCCTBXtalBlock *> &xtalBlocks = (*it2)->xtalBlocks();
0445 std::vector<DCCTBXtalBlock *>::iterator it3;
0446 for (it3 = xtalBlocks.begin(); it3 != xtalBlocks.end(); it3++) {
0447 ret |= (*it3)->blockError();
0448 }
0449
0450 }
0451
0452
0453
0454 if (dccTrailerBlock_) {
0455 ret |= dccTrailerBlock_->blockError();
0456 }
0457
0458
0459 return ret;
0460 }
0461
0462 std::string DCCTBEventBlock::eventErrorString() {
0463 std::string ret("");
0464
0465 if (eventHasErrors()) {
0466 ret += "\n ======================================================================\n";
0467 ret += std::string(" Event Erros occurred for L1A ( decoded value ) = ");
0468 ret += parser_->getDecString(getDataField("LV1"));
0469 ret += "\n ======================================================================";
0470
0471 ret += errorString();
0472
0473
0474
0475 std::vector<DCCTBTCCBlock *>::iterator it1;
0476 for (it1 = tccBlocks_.begin(); it1 != tccBlocks_.end(); it1++) {
0477 ret += (*it1)->errorString();
0478 }
0479
0480
0481 if (srpBlock_) {
0482 ret += srpBlock_->errorString();
0483 }
0484
0485
0486
0487 std::vector<DCCTBTowerBlock *>::iterator it2;
0488
0489 for (it2 = towerBlocks_.begin(); it2 != towerBlocks_.end(); it2++) {
0490 ret += (*it2)->errorString();
0491
0492
0493 std::vector<DCCTBXtalBlock *> &xtalBlocks = (*it2)->xtalBlocks();
0494 std::vector<DCCTBXtalBlock *>::iterator it3;
0495
0496 std::string temp;
0497 for (it3 = xtalBlocks.begin(); it3 != xtalBlocks.end(); it3++) {
0498 temp += (*it3)->errorString();
0499 }
0500
0501 if (!temp.empty()) {
0502 ret += "\n Fine grain data Errors found ...";
0503 ret += "\n( Tower ID = " + parser_->getDecString((*it2)->getDataField("TT/SC ID"));
0504 ret += ", LV1 = " + parser_->getDecString((*it2)->getDataField("LV1"));
0505 ret += ", BX = " + parser_->getDecString((*it2)->getDataField("BX")) + " )";
0506 ret += temp;
0507 }
0508
0509 }
0510
0511
0512 if (dccTrailerBlock_) {
0513 ret += dccTrailerBlock_->errorString();
0514 }
0515
0516 }
0517
0518 return ret;
0519 }
0520
0521 std::vector<DCCTBTowerBlock *> DCCTBEventBlock::towerBlocksById(uint32_t towerId) {
0522 std::vector<DCCTBTowerBlock *> myVector;
0523 std::vector<DCCTBTowerBlock *>::iterator it;
0524
0525 for (it = towerBlocks_.begin(); it != towerBlocks_.end(); it++) {
0526 try {
0527 std::pair<bool, std::string> idCheck = (*it)->checkDataField("TT/SC ID", towerId);
0528
0529 if (idCheck.first) {
0530 myVector.push_back((*it));
0531 }
0532 } catch (ECALTBParserBlockException &e) {
0533 }
0534 }
0535
0536 return myVector;
0537 }