Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:04:27

0001 
0002 #include "DataFormats/L1GlobalCaloTrigger/interface/L1GctJetCounts.h"
0003 
0004 using std::endl;
0005 using std::ostream;
0006 using std::vector;
0007 
0008 /// static maximum number of jet counts
0009 /// This can be up to 12 but we use some of the
0010 /// available bandwidth for other information.
0011 const unsigned L1GctJetCounts::MAX_TOTAL_COUNTS = 12;
0012 /// MAX_TRUE_COUNTS specifies the bandwidth remaining
0013 /// for real jet count information.
0014 const unsigned L1GctJetCounts::MAX_TRUE_COUNTS = 6;
0015 
0016 // default constructor
0017 L1GctJetCounts::L1GctJetCounts() : m_data0(0), m_data1(0), m_bx(0) {}
0018 
0019 // constructor for unpacking
0020 L1GctJetCounts::L1GctJetCounts(uint32_t data0, uint32_t data1)
0021     : m_data0(data0 & 0x7fff7fff),  // Mask off bits 15 and 31 for better compression and consistency
0022       m_data1(data1 & 0x7fff7fff),  // with emulator constructor - these bits are not jet count data!
0023       m_bx(0) {}
0024 
0025 // constructor for unpacking
0026 L1GctJetCounts::L1GctJetCounts(uint32_t data0, uint32_t data1, int16_t bx)
0027     : m_data0(data0 & 0x7fff7fff),  // Mask off bits 15 and 31 for better compression and consistency
0028       m_data1(data1 & 0x7fff7fff),  // with emulator constructor - these bits are not jet count data!
0029       m_bx(bx) {}
0030 
0031 // constructor for emulator
0032 L1GctJetCounts::L1GctJetCounts(const std::vector<unsigned>& counts) : m_data0(0), m_data1(0), m_bx(0) {
0033   // Assumes all required output data has been packed
0034   // into 12 5-bit fields
0035   if (counts.size() != MAX_TOTAL_COUNTS) {
0036   } else {
0037     for (unsigned int i = 0; i < 3; ++i) {
0038       m_data0 += (counts[i] << (5 * i));
0039       m_data0 += (counts[i + 3] << (5 * i + 16));
0040       m_data1 += (counts[i + 6] << (5 * i));
0041       m_data1 += (counts[i + 9] << (5 * i + 16));
0042     }
0043   }
0044 }
0045 
0046 // constructor for emulator
0047 L1GctJetCounts::L1GctJetCounts(const std::vector<unsigned>& counts, int16_t bx) : m_data0(0), m_data1(0), m_bx(bx) {
0048   if (counts.size() != MAX_TOTAL_COUNTS) {
0049   } else {
0050     for (unsigned int i = 0; i < 3; ++i) {
0051       m_data0 += (counts[i] << (5 * i));
0052       m_data0 += (counts[i + 3] << (5 * i + 16));
0053       m_data1 += (counts[i + 6] << (5 * i));
0054       m_data1 += (counts[i + 9] << (5 * i + 16));
0055     }
0056   }
0057 }
0058 
0059 // destructor
0060 L1GctJetCounts::~L1GctJetCounts() {}
0061 
0062 // return counts by index
0063 unsigned L1GctJetCounts::count(unsigned i) const {
0064   if (i < 6) {
0065     return ((m_data0 >> (i < 3 ? (5 * i) : ((5 * i) + 1))) & 0x1f);
0066   } else if (i < MAX_TOTAL_COUNTS) {
0067     return ((m_data1 >> (i < 9 ? ((5 * i) - 30) : ((5 * i) - 29))) & 0x1f);
0068   } else {
0069     return 0;
0070   }
0071 }
0072 
0073 // pretty print
0074 ostream& operator<<(ostream& s, const L1GctJetCounts& c) {
0075   s << "L1GctJetCounts : ";
0076   for (unsigned int i = 0; i < 12; ++i) {
0077     s << "\n     count " << i << "=" << c.count(i);
0078   }
0079   return s;
0080 }