Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:10:37

0001 #include "DCCTowerBlock.h"
0002 #include "DCCEventBlock.h"
0003 #include "DCCDataParser.h"
0004 #include "DCCXtalBlock.h"
0005 #include "DCCDataMapper.h"
0006 #include "ECALParserBlockException.h"
0007 #include <cstdio>
0008 
0009 DCCTBTowerBlock::DCCTBTowerBlock(DCCTBEventBlock *dccBlock,
0010                                  DCCTBDataParser *parser,
0011                                  const uint32_t *buffer,
0012                                  uint32_t numbBytes,
0013                                  uint32_t wordsToEnd,
0014                                  uint32_t wordEventOffset,
0015                                  uint32_t expectedTowerID)
0016     : DCCTBBlockPrototype(parser, "TOWERHEADER", buffer, numbBytes, wordsToEnd, wordEventOffset),
0017       dccBlock_(dccBlock),
0018       expectedTowerID_(expectedTowerID) {
0019   //Reset error counters ///////////
0020   errors_["FE::HEADER"] = 0;
0021   errors_["FE::TT/SC ID"] = 0;
0022   errors_["FE::BLOCK LENGTH"] = 0;
0023   //////////////////////////////////
0024 
0025   // Get data fields from the mapper and retrieve data /////////////////////////////////////
0026   mapperFields_ = parser_->mapper()->towerFields();
0027   parseData();
0028   //////////////////////////////////////////////////////////////////////////////////////////
0029 }
0030 
0031 void DCCTBTowerBlock::parseXtalData() {
0032   uint32_t numbBytes = blockSize_;
0033   uint32_t wordsToEnd = wordsToEndOfEvent_;
0034 
0035   // See if we can construct the correct number of XTAL Blocks////////////////////////////////////////////////////////////////////////////////
0036   uint32_t numbDWInXtalBlock = (parser_->numbXtalSamples()) / 4 + 1;
0037   uint32_t length = getDataField("BLOCK LENGTH");
0038   uint32_t numbOfXtalBlocks = 0;
0039 
0040   if (length > 0) {
0041     numbOfXtalBlocks = (length - 1) / numbDWInXtalBlock;
0042   }
0043   uint32_t xtalBlockSize = numbDWInXtalBlock * 8;
0044   //uint32_t pIncrease         =  numbDWInXtalBlock*2;
0045 
0046   //std::cout<<"\n DEBUG::numbDWInXtal Block "<<dec<<numbDWInXtalBlock<<std::endl;
0047   //std::cout<<"\n DEBUG::length             "<<length<<std::endl;
0048   //std::cout<<"\n DEBUG::xtalBlockSize      "<<xtalBlockSize<<std::endl;
0049   //std::cout<<"\n DEBUG::pIncreade          "<<pIncrease<<std::endl;
0050 
0051   bool zs = dccBlock_->getDataField("ZS");
0052   if (!zs && numbOfXtalBlocks != 25) {
0053     (errors_["FE::BLOCK LENGTH"])++;
0054     errorString_ += "\n ======================================================================\n";
0055     errorString_ += std::string(" ") + name_ + std::string(" ZS is not active, error in the Tower Length !");
0056     errorString_ +=
0057         "\n Tower Length is : " + (parser_->getDecString(numbBytes / 8)) + std::string(" , while it should be : ");
0058     std::string myString = parser_->getDecString((uint32_t)(25 * numbDWInXtalBlock + 1));
0059     errorString_ +=
0060         "\n It was only possible to build : " + parser_->getDecString(numbOfXtalBlocks) + std::string(" XTAL blocks");
0061     errorString_ += "\n ======================================================================";
0062     blockError_ = true;
0063   };
0064   if (numbOfXtalBlocks > 25) {
0065     if (errors_["FE::BLOCK LENGTH"] == 0)
0066       (errors_["FE::BLOCK LENGTH"])++;
0067     errorString_ += "\n ======================================================================\n";
0068     errorString_ += std::string(" ") + name_ + std::string(" Tower Length is larger then expected...!");
0069     errorString_ += "\n Tower Length is : " + parser_->getDecString(numbBytes / 8) +
0070                     std::string(" , while it should be at maximum : ");
0071     std::string myString = parser_->getDecString((uint32_t)(25 * numbDWInXtalBlock + 1));
0072     errorString_ += "\n Action -> data after the xtal 25 is ignored... ";
0073     errorString_ += "\n ======================================================================";
0074     blockError_ = true;
0075   }
0076   ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
0077 
0078   blockSize_ += length * 8;  //??????????????????????
0079 
0080   // Get XTAL Data //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
0081   uint32_t stripID, xtalID;
0082 
0083   for (uint32_t numbXtal = 1; numbXtal <= numbOfXtalBlocks && numbXtal <= 25; numbXtal++) {
0084     increment(1);
0085 
0086     stripID = (numbXtal - 1) / 5 + 1;
0087     xtalID = numbXtal - (stripID - 1) * 5;
0088 
0089     if (!zs) {
0090       xtalBlocks_.push_back(new DCCTBXtalBlock(
0091           parser_, dataP_, xtalBlockSize, wordsToEnd - wordCounter_, wordCounter_ + wordEventOffset_, xtalID, stripID));
0092     } else {
0093       xtalBlocks_.push_back(new DCCTBXtalBlock(
0094           parser_, dataP_, xtalBlockSize, wordsToEnd - wordCounter_, wordCounter_ + wordEventOffset_, 0, 0));
0095     }
0096 
0097     increment(xtalBlockSize / 4 - 1);
0098   }
0099   ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
0100 
0101   // Check internal data ////////////
0102   if (parser_->debug()) {
0103     dataCheck();
0104   };
0105   ///////////////////////////////////
0106 }
0107 
0108 DCCTBTowerBlock::~DCCTBTowerBlock() {
0109   std::vector<DCCTBXtalBlock *>::iterator it;
0110   for (it = xtalBlocks_.begin(); it != xtalBlocks_.end(); it++) {
0111     delete (*it);
0112   }
0113   xtalBlocks_.clear();
0114 }
0115 
0116 void DCCTBTowerBlock::dataCheck() {
0117   std::string checkErrors("");
0118 
0119   std::pair<bool, std::string> res;
0120 
0121   ///////////////////////////////////////////////////////////////////////////
0122   // For TB we don-t check Bx
0123   //res = checkDataField("BX", BXMASK & (dccBlock_->getDataField("BX")));
0124   //if(!res.first){ checkErrors += res.second; (errors_["FE::HEADER"])++; }
0125   ////////////////////////////////////////////////////////////////////////////
0126 
0127   // mod to account for ECAL counters starting from 0 in the front end N. Almeida
0128   res = checkDataField("LV1", L1MASK & (dccBlock_->getDataField("LV1") - 1));
0129   if (!res.first) {
0130     checkErrors += res.second;
0131     (errors_["FE::HEADER"])++;
0132   }
0133 
0134   if (expectedTowerID_ != 0) {
0135     res = checkDataField("TT/SC ID", expectedTowerID_);
0136     if (!res.first) {
0137       checkErrors += res.second;
0138       (errors_["FE::HEADER"])++;
0139     }
0140   }
0141 
0142   if (!checkErrors.empty()) {
0143     std::string myTowerId;
0144 
0145     errorString_ += "\n ======================================================================\n";
0146     errorString_ += std::string(" ") + name_ + std::string("( ID = ") +
0147                     parser_->getDecString((uint32_t)(expectedTowerID_)) + std::string(" ) errors : ");
0148     errorString_ += checkErrors;
0149     errorString_ += "\n ======================================================================";
0150     blockError_ = true;
0151   }
0152 }
0153 
0154 std::vector<DCCTBXtalBlock *> DCCTBTowerBlock::xtalBlocksById(uint32_t stripId, uint32_t xtalId) {
0155   std::vector<DCCTBXtalBlock *> myVector;
0156   std::vector<DCCTBXtalBlock *>::iterator it;
0157 
0158   for (it = xtalBlocks_.begin(); it != xtalBlocks_.end(); it++) {
0159     try {
0160       std::pair<bool, std::string> stripIdCheck = (*it)->checkDataField("STRIP ID", stripId);
0161       std::pair<bool, std::string> xtalIdCheck = (*it)->checkDataField("XTAL ID", xtalId);
0162 
0163       if (xtalIdCheck.first && stripIdCheck.first) {
0164         myVector.push_back((*it));
0165       }
0166 
0167     } catch (ECALTBParserBlockException &e) { /*ignore*/
0168     }
0169   }
0170 
0171   return myVector;
0172 }
0173 
0174 int DCCTBTowerBlock::towerID() {
0175   int result = -1;
0176 
0177   for (std::set<DCCTBDataField *, DCCTBDataFieldComparator>::iterator it = mapperFields_->begin();
0178        it != mapperFields_->end();
0179        it++) {
0180     if ((*it)->name() == "TT/SC ID")
0181       result = getDataField((*it)->name());
0182   }
0183 
0184   return result;
0185 }