Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 12:53:37

0001 #include "DataFormats/HcalDigi/interface/HcalUMNioDigi.h"
0002 #include <iostream>
0003 
0004 HcalUMNioDigi::HcalUMNioDigi() {}
0005 HcalUMNioDigi::HcalUMNioDigi(const uint16_t* ptr, int words) {
0006   payload_.reserve(words);
0007   for (int i = 0; i < words; i++) {
0008     payload_.push_back(ptr[i]);
0009   }
0010 }
0011 HcalUMNioDigi::HcalUMNioDigi(const std::vector<uint16_t>& words) : payload_(words) {}
0012 
0013 uint32_t HcalUMNioDigi::runNumber() const {
0014   if (invalid())
0015     return 0;
0016   return payload_[9] + (uint32_t(payload_[10]) << 16);
0017 }
0018 
0019 uint32_t HcalUMNioDigi::orbitNumber() const {
0020   if (invalid())
0021     return 0;
0022   return payload_[5] + (uint32_t(payload_[8]) << 16);
0023 }
0024 uint16_t HcalUMNioDigi::bunchNumber() const {
0025   if (invalid())
0026     return 0;
0027   return (payload_[1] >> 4) & 0xFFF;
0028 }
0029 uint32_t HcalUMNioDigi::eventNumber() const {
0030   if (invalid())
0031     return 0;
0032   return payload_[2] + (uint32_t(payload_[3] & 0xFF) << 16);
0033 }
0034 
0035 uint8_t HcalUMNioDigi::eventType() const {
0036   if (invalid())
0037     return 0;
0038   return (payload_[6] >> 8) & 0xF;
0039 }
0040 uint16_t HcalUMNioDigi::spillCounter() const {
0041   if (invalid())
0042     return 0;
0043   return (payload_[11]) & 0x7FFF;
0044 }
0045 bool HcalUMNioDigi::isSpill() const {
0046   if (invalid())
0047     return false;
0048   return (payload_[11] & 0x8000);
0049 }
0050 
0051 int HcalUMNioDigi::numberUserWords() const {
0052   if (invalid())
0053     return 0;
0054   return (payload_[12] & 0xFF);
0055 }
0056 
0057 uint16_t HcalUMNioDigi::idUserWord(int iword) const {
0058   if (iword >= numberUserWords() || payload_.size() < (size_t)(16 + iword * 3))
0059     return 0;
0060   return payload_[13 + 3 * iword];
0061 }
0062 uint32_t HcalUMNioDigi::valueUserWord(int iword) const {
0063   if (iword >= numberUserWords() || payload_.size() < (size_t)(16 + iword * 3))
0064     return 0;
0065   return payload_[14 + 3 * iword] + (uint32_t(payload_[15 + 3 * iword]) << 16);
0066 }
0067 bool HcalUMNioDigi::hasUserWord(int id) const {
0068   uint32_t dummy;
0069   return getUserWord(id, dummy);
0070 }
0071 uint32_t HcalUMNioDigi::getUserWord(int id) const {
0072   uint32_t dummy(0);
0073   getUserWord(id, dummy);
0074   return dummy;
0075 }
0076 bool HcalUMNioDigi::getUserWord(int id, uint32_t& value) const {
0077   int nwords = numberUserWords();
0078   if (size_t(16 + nwords * 3) > payload_.size())
0079     return false;  // invalid format...
0080 
0081   for (int i = 0; i < nwords; i++) {
0082     if (payload_[14 + 3 * i] == id) {
0083       value = payload_[15 + 3 * i] + (uint32_t(payload_[16 + 3 * i]) << 16);
0084       return true;
0085     }
0086   }
0087   return false;
0088 }
0089 
0090 std::ostream& operator<<(std::ostream& s, const HcalUMNioDigi& digi) {
0091   s << "HcalUMNioDigi orbit/bunch " << digi.orbitNumber() << "/" << digi.bunchNumber() << std::endl;
0092   s << " run/l1a " << digi.runNumber() << "/" << digi.eventNumber() << std::endl;
0093   s << " eventType " << digi.eventType() << std::endl;
0094   for (int i = 0; i < digi.numberUserWords(); i++)
0095     s << "   id=" << digi.idUserWord(i) << " value=" << digi.valueUserWord(i) << std::endl;
0096   return s;
0097 }