File indexing completed on 2023-03-17 10:59:58
0001 #include "FWCore/Framework/interface/Event.h"
0002 #include "EventFilter/L1TRawToDigi/plugins/PackerFactory.h"
0003
0004 #include "CaloSpareHFPacker.h"
0005 #include "CaloTokens.h"
0006
0007 namespace l1t {
0008 namespace stage1 {
0009 Blocks CaloSpareHFPacker::pack(const edm::Event& event, const PackerTokens* toks) {
0010 edm::Handle<CaloSpareBxCollection> calosparesHFBitCounts;
0011 event.getByToken(static_cast<const CaloTokens*>(toks)->getCaloSpareHFBitCountsToken(), calosparesHFBitCounts);
0012
0013 edm::Handle<CaloSpareBxCollection> calosparesHFRingSums;
0014 event.getByToken(static_cast<const CaloTokens*>(toks)->getCaloSpareHFRingSumsToken(), calosparesHFRingSums);
0015
0016 std::vector<uint32_t> load;
0017
0018 for (int i = calosparesHFBitCounts->getFirstBX(); i <= calosparesHFBitCounts->getLastBX(); ++i) {
0019 int n = 0;
0020
0021 int hfbitcount = 0;
0022 int hfringsum = 0;
0023
0024 for (auto j = calosparesHFBitCounts->begin(i); j != calosparesHFBitCounts->end(i) && n < 2; ++j, ++n) {
0025 hfbitcount = std::min(j->hwPt(), 0xFFF);
0026 }
0027
0028 n = 0;
0029
0030 for (auto j = calosparesHFRingSums->begin(i); j != calosparesHFRingSums->end(i) && n < 2; ++j, ++n) {
0031 hfringsum = std::min(j->hwPt(), 0xFFF);
0032 }
0033
0034 uint16_t object[2] = {0, 0};
0035
0036 object[0] = hfbitcount | ((hfringsum & 0x7) << 12);
0037 object[1] = ((hfringsum >> 3) & 0x1FF) | (0x1) << 10 | (0x1) << 12 | (0x1) << 14;
0038
0039 uint32_t word0 = (object[0] & 0xFFFF);
0040 uint32_t word1 = (object[1] & 0xFFFF);
0041
0042 word0 |= (1 << 15);
0043 word1 |= ((i == 0) << 15);
0044
0045 load.push_back(word0);
0046 load.push_back(word1);
0047 }
0048
0049 return {Block(97, load)};
0050 }
0051 }
0052 }
0053
0054 DEFINE_L1T_PACKER(l1t::stage1::CaloSpareHFPacker);