CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_6_1_2_SLHC2/src/DataFormats/L1GlobalCaloTrigger/src/L1GctJetCounts.cc

Go to the documentation of this file.
00001 
00002 #include "DataFormats/L1GlobalCaloTrigger/interface/L1GctJetCounts.h"
00003 
00004 using std::vector;
00005 using std::ostream;
00006 using std::endl;
00007 
00011 const unsigned L1GctJetCounts::MAX_TOTAL_COUNTS=12;
00014 const unsigned L1GctJetCounts::MAX_TRUE_COUNTS=6;
00015 
00016 // default constructor
00017 L1GctJetCounts::L1GctJetCounts() :
00018   m_data0(0),
00019   m_data1(0),
00020   m_bx(0)
00021 {
00022 
00023 }
00024 
00025 // constructor for unpacking
00026 L1GctJetCounts::L1GctJetCounts(uint32_t data0, uint32_t data1) :
00027   m_data0(data0 & 0x7fff7fff), // Mask off bits 15 and 31 for better compression and consistency
00028   m_data1(data1 & 0x7fff7fff),  // with emulator constructor - these bits are not jet count data!
00029   m_bx(0)
00030 {
00031 }
00032 
00033 // constructor for unpacking
00034 L1GctJetCounts::L1GctJetCounts(uint32_t data0, uint32_t data1, int16_t bx) :
00035   m_data0(data0 & 0x7fff7fff), // Mask off bits 15 and 31 for better compression and consistency
00036   m_data1(data1 & 0x7fff7fff),  // with emulator constructor - these bits are not jet count data!
00037   m_bx(bx)
00038 {
00039 }
00040 
00041 // constructor for emulator
00042 L1GctJetCounts::L1GctJetCounts(vector<unsigned> counts) :
00043   m_data0(0), 
00044   m_data1(0),
00045   m_bx(0)
00046 {
00047   // Assumes all required output data has been packed 
00048   // into 12 5-bit fields
00049   if (counts.size() != MAX_TOTAL_COUNTS) { }
00050   else {
00051     for (unsigned int i=0; i<3; ++i) {
00052       m_data0 += (counts[i]   << (5*i));
00053       m_data0 += (counts[i+3] << (5*i + 16));
00054       m_data1 += (counts[i+6] << (5*i));
00055       m_data1 += (counts[i+9] << (5*i + 16));
00056     }
00057   }
00058 }
00059 
00060 // constructor for emulator
00061 L1GctJetCounts::L1GctJetCounts(vector<unsigned> counts, int16_t bx) :
00062   m_data0(0), 
00063   m_data1(0),
00064   m_bx(bx)
00065 {
00066   if (counts.size() != MAX_TOTAL_COUNTS) { }
00067   else {
00068     for (unsigned int i=0; i<3; ++i) {
00069       m_data0 += (counts[i]   << (5*i));
00070       m_data0 += (counts[i+3] << (5*i + 16));
00071       m_data1 += (counts[i+6] << (5*i));
00072       m_data1 += (counts[i+9] << (5*i + 16));
00073     }
00074   }
00075 }
00076 
00077 // destructor
00078 L1GctJetCounts::~L1GctJetCounts()
00079 {
00080 
00081 }
00082 
00083 // return counts by index
00084 unsigned L1GctJetCounts::count(unsigned i) const
00085 {
00086   if (i<6){ return ((m_data0 >> (i<3 ? (5*i) : ((5*i)+1))) & 0x1f); }
00087   else if (i < MAX_TOTAL_COUNTS) { return ((m_data1 >> (i<9 ? ((5*i)-30) : ((5*i)-29))) & 0x1f); }    
00088   else { return 0; }
00089 }
00090 
00091 // pretty print
00092 ostream& operator<<(ostream& s, const L1GctJetCounts& c) {
00093   s << "L1GctJetCounts : ";
00094   for (unsigned int i=0 ; i<12 ; ++i) {
00095     s << "\n     count " << i<< "=" << c.count(i);
00096   }
00097   return s;
00098 }