Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:14:56

0001 #include "DCCXtalBlock.h"
0002 #include "DCCDataParser.h"
0003 #include "DCCDataMapper.h"
0004 
0005 DCCTBXtalBlock::DCCTBXtalBlock(DCCTBDataParser *parser,
0006                                const uint32_t *buffer,
0007                                uint32_t numbBytes,
0008                                uint32_t wordsToEnd,
0009                                uint32_t wordEventOffset,
0010                                uint32_t expectedXtalID,
0011                                uint32_t expectedStripID)
0012     : DCCTBBlockPrototype(parser, "XTAL", buffer, numbBytes, wordsToEnd, wordEventOffset),
0013       expectedXtalID_(expectedXtalID),
0014       expectedStripID_(expectedStripID) {
0015   //Reset error counters ////
0016   errors_["XTAL::HEADER"] = 0;
0017   errors_["XTAL::BLOCKID"] = 0;
0018   ///////////////////////////
0019 
0020   // Get data fields from the mapper and retrieve data /////////////////////////////////////
0021   mapperFields_ = parser_->mapper()->xtalFields();
0022   parseData();
0023   //////////////////////////////////////////////////////////////////////////////////////////
0024 
0025   // check internal data ////////////
0026   if (parser_->debug()) {
0027     dataCheck();
0028   }
0029   ///////////////////////////////////
0030 }
0031 
0032 void DCCTBXtalBlock::dataCheck() {
0033   std::string checkErrors("");
0034 
0035   std::pair<bool, std::string> res;
0036 
0037   if (expectedXtalID_ != 0) {
0038     res = checkDataField("XTAL ID", expectedXtalID_);
0039     if (!res.first) {
0040       checkErrors += res.second;
0041       (errors_["XTAL::HEADER"])++;
0042     }
0043   }
0044   if (expectedStripID_ != 0) {
0045     res = checkDataField("STRIP ID", expectedStripID_);
0046     if (!res.first) {
0047       checkErrors += res.second;
0048       (errors_["XTAL::HEADER"])++;
0049     }
0050   }
0051   if (!checkErrors.empty()) {
0052     errorString_ += "\n ======================================================================\n";
0053     errorString_ += std::string(" ") + name_ + std::string(" data fields checks errors : ");
0054     errorString_ += checkErrors;
0055     errorString_ += "\n ======================================================================";
0056     blockError_ = true;
0057   }
0058 }
0059 
0060 void DCCTBXtalBlock::increment(uint32_t numb) {
0061   if (!parser_->debug()) {
0062     DCCTBBlockPrototype::increment(numb);
0063   } else {
0064     for (uint32_t counter = 0; counter < numb; counter++, dataP_++, wordCounter_++) {
0065       uint32_t blockID = (*dataP_) >> BPOSITION_BLOCKID;
0066       if (blockID != BLOCKID) {
0067         (errors_["XTAL::BLOCKID"])++;
0068         //errorString_ += std::string("\n") + parser_->index(nunb)+(" blockId has value ") + parser_->getDecString(blockID);
0069         //errorString  += std::string(", while ")+parser_->getDecString(BLOCKID)+std::string(" is expected");
0070       }
0071     }
0072   }
0073 }
0074 
0075 int DCCTBXtalBlock::xtalID() {
0076   int result = -1;
0077 
0078   for (std::set<DCCTBDataField *, DCCTBDataFieldComparator>::iterator it = mapperFields_->begin();
0079        it != mapperFields_->end();
0080        it++) {
0081     if ((*it)->name() == "XTAL ID")
0082       result = getDataField((*it)->name());
0083   }
0084 
0085   return result;
0086 }
0087 
0088 int DCCTBXtalBlock::stripID() {
0089   int result = -1;
0090 
0091   for (std::set<DCCTBDataField *, DCCTBDataFieldComparator>::iterator it = mapperFields_->begin();
0092        it != mapperFields_->end();
0093        it++) {
0094     if ((*it)->name() == "STRIP ID")
0095       result = getDataField((*it)->name());
0096   }
0097 
0098   return result;
0099 }
0100 
0101 std::vector<int> DCCTBXtalBlock::xtalDataSamples() {
0102   std::vector<int> data;
0103 
0104   for (unsigned int i = 1; i <= parser_->numbXtalSamples(); i++) {
0105     std::string name = std::string("ADC#") + parser_->getDecString(i);
0106 
0107     data.push_back(getDataField(name));
0108   }
0109 
0110   return data;
0111 }