Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 #include "EventFilter/CSCRawToDigi/interface/CSCDDUDataItr.h"
0002 #include "EventFilter/CSCRawToDigi/interface/CSCDDUEventData.h"
0003 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0004 
0005 // theCurrentCSC starts at -1, since user is expected to next() before he dereferences
0006 // for the first time
0007 CSCDDUDataItr::CSCDDUDataItr() : theDDUData(nullptr), theCurrentCSC(-1), theNumberOfCSCs(0), theDataIsOwnedByMe(true) {}
0008 
0009 CSCDDUDataItr::CSCDDUDataItr(const char *buf)
0010     : theDDUData(nullptr), theCurrentCSC(-1), theNumberOfCSCs(0), theDataIsOwnedByMe(true) {
0011   // check if it's OK first
0012   const CSCDDUHeader *dduHeader = reinterpret_cast<const CSCDDUHeader *>(buf);
0013   if (dduHeader->check()) {
0014     theDDUData = new CSCDDUEventData((const uint16_t *)buf);
0015     theNumberOfCSCs = theDDUData->cscData().size();
0016   } else {
0017     LogTrace("CSCDDUDataItr|CSCRawToDigi") << "Failed DDU header check.";
0018   }
0019 }
0020 
0021 CSCDDUDataItr::CSCDDUDataItr(const CSCDDUEventData *dduData)
0022     : theDDUData(dduData),
0023       theCurrentCSC(-1),
0024       theNumberOfCSCs(theDDUData->cscData().size()),
0025       theDataIsOwnedByMe(false) {}
0026 
0027 CSCDDUDataItr::~CSCDDUDataItr() {
0028   if (theDataIsOwnedByMe)
0029     delete theDDUData;
0030 }
0031 
0032 CSCDDUDataItr::CSCDDUDataItr(const CSCDDUDataItr &i)
0033     : theCurrentCSC(i.theCurrentCSC), theNumberOfCSCs(i.theNumberOfCSCs), theDataIsOwnedByMe(i.theDataIsOwnedByMe) {
0034   if (theDataIsOwnedByMe) {
0035     if (i.theDDUData != nullptr) {
0036       theDDUData = new CSCDDUEventData(*(i.theDDUData));
0037     }
0038   } else {
0039     theDDUData = i.theDDUData;
0040   }
0041 }
0042 
0043 void CSCDDUDataItr::operator=(const CSCDDUDataItr &i) {
0044   if (theDataIsOwnedByMe && theDDUData != i.theDDUData) {
0045     delete theDDUData;
0046     if (i.theDDUData != nullptr) {
0047       theDDUData = new CSCDDUEventData(*(i.theDDUData));
0048     }
0049   } else {
0050     theDDUData = i.theDDUData;
0051   }
0052 
0053   theDDUData = i.theDDUData;
0054   theCurrentCSC = i.theCurrentCSC;
0055   theNumberOfCSCs = i.theNumberOfCSCs;
0056   theDataIsOwnedByMe = i.theDataIsOwnedByMe;
0057 }
0058 
0059 bool CSCDDUDataItr::next() { return (++theCurrentCSC < theNumberOfCSCs); }
0060 
0061 const CSCEventData &CSCDDUDataItr::operator*() {
0062   assert(theCurrentCSC >= 0 && theCurrentCSC < theNumberOfCSCs);
0063   return theDDUData->cscData()[theCurrentCSC];
0064 }