Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:26:03

0001 // Code to unpack the "Block of Counters"
0002 
0003 #include "EventFilter/L1TRawToDigi/plugins/UnpackerFactory.h"
0004 
0005 #include "EMTFCollections.h"
0006 #include "EMTFUnpackerTools.h"
0007 
0008 // This is the "header" - no EMTFBlockCounters.h file is needed
0009 namespace l1t {
0010   namespace stage2 {
0011     namespace emtf {
0012 
0013       class CountersBlockUnpacker : public Unpacker {  // "CountersBlockUnpacker" inherits from "Unpacker"
0014       public:
0015         virtual int checkFormat(const Block& block);
0016         bool unpack(const Block& block,
0017                     UnpackerCollections* coll) override;  // Apparently it's always good to use override in C++
0018         // virtual bool packBlock(const Block& block, UnpackerCollections *coll) override;
0019       };
0020 
0021       // class CountersBlockPacker : public Packer { // "CountersBlockPacker" inherits from "Packer"
0022       // public:
0023       //    virtual bool unpack(const Block& block, UnpackerCollections *coll) override; // Apparently it's always good to use override in C++
0024       // };
0025 
0026     }  // namespace emtf
0027   }    // namespace stage2
0028 }  // namespace l1t
0029 
0030 namespace l1t {
0031   namespace stage2 {
0032     namespace emtf {
0033 
0034       int CountersBlockUnpacker::checkFormat(const Block& block) {
0035         auto payload = block.payload();
0036         int errors = 0;
0037 
0038         //Check the number of 16-bit words
0039         if (payload.size() != 4) {
0040           errors += 1;
0041           edm::LogError("L1T|EMTF") << "Payload size in 'Block of Counters' is different than expected";
0042         }
0043 
0044         //Check that each word is 16 bits
0045         if (GetHexBits(payload[0], 16, 31) != 0) {
0046           errors += 1;
0047           edm::LogError("L1T|EMTF") << "Payload[0] has more than 16 bits in 'Block of Counters'";
0048         }
0049         if (GetHexBits(payload[1], 16, 31) != 0) {
0050           errors += 1;
0051           edm::LogError("L1T|EMTF") << "Payload[1] has more than 16 bits in 'Block of Counters'";
0052         }
0053         if (GetHexBits(payload[2], 16, 31) != 0) {
0054           errors += 1;
0055           edm::LogError("L1T|EMTF") << "Payload[2] has more than 16 bits in 'Block of Counters'";
0056         }
0057         if (GetHexBits(payload[3], 16, 31) != 0) {
0058           errors += 1;
0059           edm::LogError("L1T|EMTF") << "Payload[3] has more than 16 bits in 'Block of Counters'";
0060         }
0061 
0062         uint16_t BCa = payload[0];
0063         uint16_t BCb = payload[1];
0064         uint16_t BCc = payload[2];
0065         uint16_t BCd = payload[3];
0066 
0067         //Check Format
0068         if (GetHexBits(BCa, 15, 15) != 0) {
0069           errors += 1;
0070           edm::LogError("L1T|EMTF") << "Format identifier bits in BCa are incorrect";
0071         }
0072         if (GetHexBits(BCb, 15, 15) != 1) {
0073           errors += 1;
0074           edm::LogError("L1T|EMTF") << "Format identifier bits in BCb are incorrect";
0075         }
0076         if (GetHexBits(BCc, 15, 15) != 0) {
0077           errors += 1;
0078           edm::LogError("L1T|EMTF") << "Format identifier bits in BCc are incorrect";
0079         }
0080         if (GetHexBits(BCd, 15, 15) != 0) {
0081           errors += 1;
0082           edm::LogError("L1T|EMTF") << "Format identifier bits in BCd are incorrect";
0083         }
0084 
0085         return errors;
0086       }  // End function: int CountersBlockUnpacker::checkFormat()
0087 
0088       bool CountersBlockUnpacker::unpack(const Block& block, UnpackerCollections* coll) {
0089         // std::cout << "Inside EMTFBlockCounters.cc: unpack" << std::endl;
0090 
0091         // Get the payload for this block, made up of 16-bit words (0xffff)
0092         // Format defined in MTF7Payload::getBlock() in src/Block.cc
0093         // payload[0] = bits 0-15, payload[1] = 16-31, payload[3] = 32-47, etc.
0094         auto payload = block.payload();
0095 
0096         // Check Format of Payload
0097         l1t::emtf::Counters Counters_;
0098         for (int err = 0; err < checkFormat(block); err++)
0099           Counters_.add_format_error();
0100 
0101         // Assign payload to 16-bit words
0102         uint16_t BCa = payload[0];
0103         uint16_t BCb = payload[1];
0104         uint16_t BCc = payload[2];
0105         uint16_t BCd = payload[3];
0106 
0107         // res is a pointer to a collection of EMTFDaqOut class objects
0108         // There is one EMTFDaqOut for each MTF7 (60 deg. sector) in the event
0109         EMTFDaqOutCollection* res;
0110         res = static_cast<EMTFCollections*>(coll)->getEMTFDaqOuts();
0111         int iOut = res->size() - 1;
0112 
0113         ///////////////////////////////
0114         // Unpack the Block of Counters
0115         ///////////////////////////////
0116         if ((res->at(iOut)).HasCounters() == true) {
0117           (res->at(iOut)).add_format_error();
0118           edm::LogError("L1T|EMTF") << "Why is there already a Counters object?";
0119         }
0120 
0121         Counters_.set_me1a_2(GetHexBits(BCa, 0, 0));
0122         Counters_.set_me1a_3(GetHexBits(BCa, 1, 1));
0123         Counters_.set_me1a_4(GetHexBits(BCa, 2, 2));
0124         Counters_.set_me1a_5(GetHexBits(BCa, 3, 3));
0125         Counters_.set_me1a_6(GetHexBits(BCa, 4, 4));
0126         Counters_.set_me1a_7(GetHexBits(BCa, 5, 5));
0127         Counters_.set_me1a_8(GetHexBits(BCa, 6, 6));
0128         Counters_.set_me1a_9(GetHexBits(BCa, 7, 7));
0129         Counters_.set_me1b_2(GetHexBits(BCa, 8, 8));
0130         Counters_.set_me1b_3(GetHexBits(BCa, 9, 9));
0131         Counters_.set_me1b_4(GetHexBits(BCa, 10, 10));
0132         Counters_.set_me1b_5(GetHexBits(BCa, 11, 11));
0133         Counters_.set_me1b_6(GetHexBits(BCa, 12, 12));
0134         Counters_.set_me1b_7(GetHexBits(BCa, 13, 13));
0135         Counters_.set_me1b_8(GetHexBits(BCa, 14, 14));
0136 
0137         Counters_.set_me1b_9(GetHexBits(BCb, 0, 0));
0138         Counters_.set_me2_2(GetHexBits(BCb, 1, 1));
0139         Counters_.set_me2_3(GetHexBits(BCb, 2, 2));
0140         Counters_.set_me2_4(GetHexBits(BCb, 3, 3));
0141         Counters_.set_me2_5(GetHexBits(BCb, 4, 4));
0142         Counters_.set_me2_6(GetHexBits(BCb, 5, 5));
0143         Counters_.set_me2_7(GetHexBits(BCb, 6, 6));
0144         Counters_.set_me2_8(GetHexBits(BCb, 7, 7));
0145         Counters_.set_me2_9(GetHexBits(BCb, 8, 8));
0146         Counters_.set_me3_2(GetHexBits(BCb, 9, 9));
0147         Counters_.set_me3_3(GetHexBits(BCb, 10, 10));
0148         Counters_.set_me3_4(GetHexBits(BCb, 11, 11));
0149         Counters_.set_me3_5(GetHexBits(BCb, 12, 12));
0150         Counters_.set_me3_6(GetHexBits(BCb, 13, 13));
0151         Counters_.set_me3_7(GetHexBits(BCb, 14, 14));
0152 
0153         Counters_.set_me3_8(GetHexBits(BCc, 0, 0));
0154         Counters_.set_me3_9(GetHexBits(BCc, 1, 1));
0155         Counters_.set_me4_2(GetHexBits(BCc, 2, 2));
0156         Counters_.set_me4_3(GetHexBits(BCc, 3, 3));
0157         Counters_.set_me4_4(GetHexBits(BCc, 4, 4));
0158         Counters_.set_me4_5(GetHexBits(BCc, 5, 5));
0159         Counters_.set_me4_6(GetHexBits(BCc, 6, 6));
0160         Counters_.set_me4_7(GetHexBits(BCc, 7, 7));
0161         Counters_.set_me4_8(GetHexBits(BCc, 8, 8));
0162         Counters_.set_me4_9(GetHexBits(BCc, 9, 9));
0163         Counters_.set_me1n_3(GetHexBits(BCc, 10, 10));
0164         Counters_.set_me1n_6(GetHexBits(BCc, 11, 11));
0165         Counters_.set_me1n_9(GetHexBits(BCc, 12, 12));
0166         Counters_.set_me2n_3(GetHexBits(BCc, 13, 13));
0167         Counters_.set_me2n_9(GetHexBits(BCc, 14, 14));
0168 
0169         Counters_.set_me3n_3(GetHexBits(BCd, 0, 0));
0170         Counters_.set_me3n_9(GetHexBits(BCd, 1, 1));
0171         Counters_.set_me4n_3(GetHexBits(BCd, 2, 2));
0172         Counters_.set_me4n_9(GetHexBits(BCd, 3, 3));
0173         Counters_.set_me1a_1(GetHexBits(BCd, 4, 4));
0174         Counters_.set_me1b_1(GetHexBits(BCd, 5, 5));
0175         Counters_.set_me2_1(GetHexBits(BCd, 6, 6));
0176         Counters_.set_me3_1(GetHexBits(BCd, 7, 7));
0177         Counters_.set_me4_1(GetHexBits(BCd, 8, 8));
0178 
0179         Counters_.set_me1a_all(GetHexBits(BCa, 0, 7));
0180         Counters_.set_me1b_all(GetHexBits(BCa, 8, 14, BCb, 0, 0));
0181         Counters_.set_me2_all(GetHexBits(BCb, 1, 8));
0182         Counters_.set_me3_all(GetHexBits(BCb, 9, 14, BCc, 0, 1));
0183         Counters_.set_me4_all(GetHexBits(BCc, 2, 9));
0184         Counters_.set_meN_all(GetHexBits(BCc, 10, 14, BCd, 0, 3));
0185 
0186         Counters_.set_me1a_all((Counters_.ME1a_all() << 1) | Counters_.ME1a_1());
0187         Counters_.set_me1b_all((Counters_.ME1b_all() << 1) | Counters_.ME1b_1());
0188         Counters_.set_me2_all((Counters_.ME2_all() << 1) | Counters_.ME2_1());
0189         Counters_.set_me3_all((Counters_.ME3_all() << 1) | Counters_.ME3_1());
0190         Counters_.set_me4_all((Counters_.ME4_all() << 1) | Counters_.ME4_1());
0191 
0192         Counters_.set_me_all(Counters_.MEN_all() | Counters_.ME4_all() | Counters_.ME3_all() | Counters_.ME2_all() |
0193                              Counters_.ME1b_all() | Counters_.ME1a_all());
0194 
0195         // Counters_.set_dataword(uint64_t bits)  { dataword = bits;      };
0196 
0197         (res->at(iOut)).set_Counters(Counters_);
0198 
0199         // Finished with unpacking Counters
0200         return true;
0201 
0202       }  // End bool CountersBlockUnpacker::unpack
0203 
0204       // bool CountersBlockPacker::pack(const Block& block, UnpackerCollections *coll) {
0205       //    std::cout << "Inside CountersBlockPacker::pack" << std::endl;
0206       //    return true;
0207       // } // End bool CountersBlockPacker::pack
0208 
0209     }  // End namespace emtf
0210   }    // End namespace stage2
0211 }  // End namespace l1t
0212 
0213 DEFINE_L1T_UNPACKER(l1t::stage2::emtf::CountersBlockUnpacker);
0214 // DEFINE_L1T_PACKER(l1t::stage2::CountersBlockPacker);