Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:15:06

0001 #include "EventFilter/HcalRawToDigi/interface/HcalUHTRData.h"
0002 #include <cstring>
0003 
0004 static const int HEADER_LENGTH_16BIT = 2 * sizeof(uint64_t) / sizeof(uint16_t);
0005 
0006 HcalUHTRData::const_iterator::const_iterator(const uint16_t* ptr, const uint16_t* limit)
0007     : m_ptr(ptr), m_limit(limit), m_stepclass(0), m_technicalDataType(0) {
0008   if (isHeader())
0009     determineMode();
0010 }
0011 
0012 HcalUHTRData::const_iterator& HcalUHTRData::const_iterator::operator++() {
0013   if (m_ptr == m_limit)
0014     return *this;
0015   if (m_stepclass == 0)
0016     m_ptr++;
0017   else if (m_stepclass == 1) {
0018     if (m_microstep == 0) {
0019       m_ptr++;
0020       m_microstep++;
0021     } else {
0022       m_microstep--;
0023     }
0024   } else if (m_stepclass == 2) {
0025     if (isHeader()) {
0026       m_ptr++;
0027     } else {
0028       m_ptr += 2;
0029     }
0030   }
0031 
0032   if (isHeader()) {
0033     determineMode();
0034     m_header_ptr = m_ptr;
0035     m_0th_data_ptr = m_header_ptr + 1;
0036   }
0037   return *this;
0038 }
0039 
0040 void HcalUHTRData::const_iterator::determineMode() {
0041   if (!isHeader())
0042     return;
0043   m_flavor = flavor();
0044   m_stepclass = 0;
0045   if (m_flavor == 5) {
0046     m_stepclass = 1;
0047     m_microstep = 0;
0048   } else if (m_flavor == 2) {
0049     m_stepclass = 2;
0050   }
0051   if (m_flavor == 7) {
0052     m_technicalDataType = technicalDataType();
0053   }
0054 }
0055 
0056 int HcalUHTRData::const_iterator::errFlags() const {
0057   if ((m_flavor == 7 && m_technicalDataType == 15) && !isHeader())
0058     return ((*m_ptr) >> 11) & 0x1;
0059   else
0060     return ((*m_ptr) >> 10) & 0x3;
0061 }
0062 
0063 bool HcalUHTRData::const_iterator::dataValid() const {
0064   if ((m_flavor == 7 && m_technicalDataType == 15) && !isHeader())
0065     return ((*m_ptr) >> 10) & 0x1;
0066   else
0067     return !(errFlags() & 0x2);
0068 }
0069 
0070 int HcalUHTRData::const_iterator::technicalDataType() const {
0071   if (m_flavor == 7)
0072     return ((*m_ptr) >> 8) & 0xF;
0073   else
0074     return 0;
0075 }
0076 
0077 uint8_t HcalUHTRData::const_iterator::adc() const {
0078   if (m_flavor == 5 && m_microstep == 0)
0079     return ((*m_ptr) >> 8) & 0x7F;
0080   else if (m_flavor == 7 && m_technicalDataType == 15)
0081     return (*m_ptr) & 0x7F;
0082   else
0083     return (*m_ptr) & 0xFF;
0084 }
0085 
0086 uint8_t HcalUHTRData::const_iterator::le_tdc() const {
0087   if (m_flavor == 5 || (m_flavor == 7 && m_technicalDataType == 15))
0088     return 0x80;
0089   else if (m_flavor == 2)
0090     return (m_ptr[1] & 0x3F);
0091   else
0092     return (((*m_ptr) & 0x3F00) >> 8);
0093 }
0094 
0095 bool HcalUHTRData::const_iterator::soi() const {
0096   if (m_flavor == 5 || (m_flavor == 7 && m_technicalDataType == 15))
0097     return false;
0098   else if (m_flavor == 2)
0099     return (m_ptr[0] & 0x2000);
0100   else
0101     return (((*m_ptr) & 0x4000));
0102 }
0103 
0104 uint8_t HcalUHTRData::const_iterator::te_tdc() const {
0105   if (m_flavor == 2)
0106     return (m_ptr[1] >> 6) & 0x1F;
0107   else
0108     return 0x80;
0109 }
0110 
0111 uint8_t HcalUHTRData::const_iterator::capid() const {
0112   if (m_flavor == 2)
0113     return (m_ptr[1] >> 12) & 0x3;
0114   else if (m_flavor == 7 && m_technicalDataType == 15) {
0115     return ((*m_ptr) >> 8) & 0x3;
0116   } else if (m_flavor == 1 || m_flavor == 0) {
0117     // For flavor 0,1 we only get the first capid in the header, and so we need
0118     // to count the number of data rows and figure out which cap we want,
0119     // knowing that they go 0->1->2->3->0
0120     return 0;
0121   } else {
0122     return 0;
0123   }
0124 }
0125 
0126 bool HcalUHTRData::const_iterator::ok() const {
0127   if (m_flavor == 2) {
0128     return (m_ptr[0] >> 12) & 0x1;
0129   } else if (m_flavor == 4) {
0130     return (m_ptr[0] >> 13) & 0x1;
0131   } else {
0132     return false;
0133   }
0134 }
0135 
0136 HcalUHTRData::const_iterator HcalUHTRData::begin() const {
0137   return HcalUHTRData::const_iterator(m_raw16 + HEADER_LENGTH_16BIT,
0138                                       m_raw16 + (m_rawLength64 - 1) * sizeof(uint64_t) / sizeof(uint16_t));
0139 }
0140 
0141 HcalUHTRData::const_iterator HcalUHTRData::end() const {
0142   return HcalUHTRData::const_iterator(m_raw16 + (m_rawLength64 - 1) * sizeof(uint64_t) / sizeof(uint16_t),
0143                                       m_raw16 + (m_rawLength64 - 1) * sizeof(uint64_t) / sizeof(uint16_t));
0144 }
0145 
0146 HcalUHTRData::HcalUHTRData()
0147     : m_formatVersion(-2), m_rawLength64(0), m_raw64(nullptr), m_raw16(nullptr), m_ownData(nullptr) {}
0148 
0149 HcalUHTRData::HcalUHTRData(const uint64_t* data, int length)
0150     : m_rawLength64(length), m_raw64(data), m_raw16((const uint16_t*)(data)), m_ownData(nullptr) {
0151   m_formatVersion = (m_raw16[6] >> 12) & 0xF;
0152 }
0153 
0154 HcalUHTRData::HcalUHTRData(const HcalUHTRData& hd)
0155     : m_formatVersion(hd.m_formatVersion),
0156       m_rawLength64(hd.m_rawLength64),
0157       m_raw64(hd.m_raw64),
0158       m_raw16(hd.m_raw16),
0159       m_ownData(nullptr) {}
0160 
0161 HcalUHTRData::HcalUHTRData(int version_to_create) : m_formatVersion(version_to_create) {
0162   // the needed space is for the biggest possible event...
0163   // fibers*maxsamples/fiber
0164   const int needed = (0x20 + FIBERS_PER_UHTR * CHANNELS_PER_FIBER_MAX * (10 + 1)) * sizeof(uint16_t) / sizeof(uint64_t);
0165 
0166   m_ownData = new uint64_t[needed];
0167   memset(m_ownData, 0, sizeof(uint64_t) * needed);
0168   m_rawLength64 = 0;
0169   m_raw64 = m_ownData;
0170   m_raw16 = (const uint16_t*)m_raw64;
0171 }
0172 
0173 HcalUHTRData& HcalUHTRData::operator=(const HcalUHTRData& hd) {
0174   if (m_ownData == nullptr) {
0175     m_formatVersion = hd.m_formatVersion;
0176     m_rawLength64 = hd.m_rawLength64;
0177     m_raw64 = hd.m_raw64;
0178     m_raw16 = hd.m_raw16;
0179   }
0180   return (*this);
0181 }