CMS 3D CMS Logo

EMTFBlockCounters.cc
Go to the documentation of this file.
1 // Code to unpack the "Block of Counters"
2 
4 
5 #include "EMTFCollections.h"
6 #include "EMTFUnpackerTools.h"
7 
8 // This is the "header" - no EMTFBlockCounters.h file is needed
9 namespace l1t {
10  namespace stage2 {
11  namespace emtf {
12 
13  class CountersBlockUnpacker : public Unpacker { // "CountersBlockUnpacker" inherits from "Unpacker"
14  public:
15  virtual int checkFormat(const Block& block);
16  bool unpack(const Block& block,
17  UnpackerCollections* coll) override; // Apparently it's always good to use override in C++
18  // virtual bool packBlock(const Block& block, UnpackerCollections *coll) override;
19  };
20 
21  // class CountersBlockPacker : public Packer { // "CountersBlockPacker" inherits from "Packer"
22  // public:
23  // virtual bool unpack(const Block& block, UnpackerCollections *coll) override; // Apparently it's always good to use override in C++
24  // };
25 
26  } // namespace emtf
27  } // namespace stage2
28 } // namespace l1t
29 
30 namespace l1t {
31  namespace stage2 {
32  namespace emtf {
33 
35  auto payload = block.payload();
36  int errors = 0;
37 
38  //Check the number of 16-bit words
39  if (payload.size() != 4) {
40  errors += 1;
41  edm::LogError("L1T|EMTF") << "Payload size in 'Block of Counters' is different than expected";
42  }
43 
44  //Check that each word is 16 bits
45  if (GetHexBits(payload[0], 16, 31) != 0) {
46  errors += 1;
47  edm::LogError("L1T|EMTF") << "Payload[0] has more than 16 bits in 'Block of Counters'";
48  }
49  if (GetHexBits(payload[1], 16, 31) != 0) {
50  errors += 1;
51  edm::LogError("L1T|EMTF") << "Payload[1] has more than 16 bits in 'Block of Counters'";
52  }
53  if (GetHexBits(payload[2], 16, 31) != 0) {
54  errors += 1;
55  edm::LogError("L1T|EMTF") << "Payload[2] has more than 16 bits in 'Block of Counters'";
56  }
57  if (GetHexBits(payload[3], 16, 31) != 0) {
58  errors += 1;
59  edm::LogError("L1T|EMTF") << "Payload[3] has more than 16 bits in 'Block of Counters'";
60  }
61 
62  uint16_t BCa = payload[0];
63  uint16_t BCb = payload[1];
64  uint16_t BCc = payload[2];
65  uint16_t BCd = payload[3];
66 
67  //Check Format
68  if (GetHexBits(BCa, 15, 15) != 0) {
69  errors += 1;
70  edm::LogError("L1T|EMTF") << "Format identifier bits in BCa are incorrect";
71  }
72  if (GetHexBits(BCb, 15, 15) != 1) {
73  errors += 1;
74  edm::LogError("L1T|EMTF") << "Format identifier bits in BCb are incorrect";
75  }
76  if (GetHexBits(BCc, 15, 15) != 0) {
77  errors += 1;
78  edm::LogError("L1T|EMTF") << "Format identifier bits in BCc are incorrect";
79  }
80  if (GetHexBits(BCd, 15, 15) != 0) {
81  errors += 1;
82  edm::LogError("L1T|EMTF") << "Format identifier bits in BCd are incorrect";
83  }
84 
85  return errors;
86  } // End function: int CountersBlockUnpacker::checkFormat()
87 
89  // std::cout << "Inside EMTFBlockCounters.cc: unpack" << std::endl;
90 
91  // Get the payload for this block, made up of 16-bit words (0xffff)
92  // Format defined in MTF7Payload::getBlock() in src/Block.cc
93  // payload[0] = bits 0-15, payload[1] = 16-31, payload[3] = 32-47, etc.
94  auto payload = block.payload();
95 
96  // Check Format of Payload
97  l1t::emtf::Counters Counters_;
98  for (int err = 0; err < checkFormat(block); err++)
99  Counters_.add_format_error();
100 
101  // Assign payload to 16-bit words
102  uint16_t BCa = payload[0];
103  uint16_t BCb = payload[1];
104  uint16_t BCc = payload[2];
105  uint16_t BCd = payload[3];
106 
107  // res is a pointer to a collection of EMTFDaqOut class objects
108  // There is one EMTFDaqOut for each MTF7 (60 deg. sector) in the event
110  res = static_cast<EMTFCollections*>(coll)->getEMTFDaqOuts();
111  int iOut = res->size() - 1;
112 
114  // Unpack the Block of Counters
116  if ((res->at(iOut)).HasCounters() == true) {
117  (res->at(iOut)).add_format_error();
118  edm::LogError("L1T|EMTF") << "Why is there already a Counters object?";
119  }
120 
121  Counters_.set_me1a_2(GetHexBits(BCa, 0, 0));
122  Counters_.set_me1a_3(GetHexBits(BCa, 1, 1));
123  Counters_.set_me1a_4(GetHexBits(BCa, 2, 2));
124  Counters_.set_me1a_5(GetHexBits(BCa, 3, 3));
125  Counters_.set_me1a_6(GetHexBits(BCa, 4, 4));
126  Counters_.set_me1a_7(GetHexBits(BCa, 5, 5));
127  Counters_.set_me1a_8(GetHexBits(BCa, 6, 6));
128  Counters_.set_me1a_9(GetHexBits(BCa, 7, 7));
129  Counters_.set_me1b_2(GetHexBits(BCa, 8, 8));
130  Counters_.set_me1b_3(GetHexBits(BCa, 9, 9));
131  Counters_.set_me1b_4(GetHexBits(BCa, 10, 10));
132  Counters_.set_me1b_5(GetHexBits(BCa, 11, 11));
133  Counters_.set_me1b_6(GetHexBits(BCa, 12, 12));
134  Counters_.set_me1b_7(GetHexBits(BCa, 13, 13));
135  Counters_.set_me1b_8(GetHexBits(BCa, 14, 14));
136 
137  Counters_.set_me1b_9(GetHexBits(BCb, 0, 0));
138  Counters_.set_me2_2(GetHexBits(BCb, 1, 1));
139  Counters_.set_me2_3(GetHexBits(BCb, 2, 2));
140  Counters_.set_me2_4(GetHexBits(BCb, 3, 3));
141  Counters_.set_me2_5(GetHexBits(BCb, 4, 4));
142  Counters_.set_me2_6(GetHexBits(BCb, 5, 5));
143  Counters_.set_me2_7(GetHexBits(BCb, 6, 6));
144  Counters_.set_me2_8(GetHexBits(BCb, 7, 7));
145  Counters_.set_me2_9(GetHexBits(BCb, 8, 8));
146  Counters_.set_me3_2(GetHexBits(BCb, 9, 9));
147  Counters_.set_me3_3(GetHexBits(BCb, 10, 10));
148  Counters_.set_me3_4(GetHexBits(BCb, 11, 11));
149  Counters_.set_me3_5(GetHexBits(BCb, 12, 12));
150  Counters_.set_me3_6(GetHexBits(BCb, 13, 13));
151  Counters_.set_me3_7(GetHexBits(BCb, 14, 14));
152 
153  Counters_.set_me3_8(GetHexBits(BCc, 0, 0));
154  Counters_.set_me3_9(GetHexBits(BCc, 1, 1));
155  Counters_.set_me4_2(GetHexBits(BCc, 2, 2));
156  Counters_.set_me4_3(GetHexBits(BCc, 3, 3));
157  Counters_.set_me4_4(GetHexBits(BCc, 4, 4));
158  Counters_.set_me4_5(GetHexBits(BCc, 5, 5));
159  Counters_.set_me4_6(GetHexBits(BCc, 6, 6));
160  Counters_.set_me4_7(GetHexBits(BCc, 7, 7));
161  Counters_.set_me4_8(GetHexBits(BCc, 8, 8));
162  Counters_.set_me4_9(GetHexBits(BCc, 9, 9));
163  Counters_.set_me1n_3(GetHexBits(BCc, 10, 10));
164  Counters_.set_me1n_6(GetHexBits(BCc, 11, 11));
165  Counters_.set_me1n_9(GetHexBits(BCc, 12, 12));
166  Counters_.set_me2n_3(GetHexBits(BCc, 13, 13));
167  Counters_.set_me2n_9(GetHexBits(BCc, 14, 14));
168 
169  Counters_.set_me3n_3(GetHexBits(BCd, 0, 0));
170  Counters_.set_me3n_9(GetHexBits(BCd, 1, 1));
171  Counters_.set_me4n_3(GetHexBits(BCd, 2, 2));
172  Counters_.set_me4n_9(GetHexBits(BCd, 3, 3));
173  Counters_.set_me1a_1(GetHexBits(BCd, 4, 4));
174  Counters_.set_me1b_1(GetHexBits(BCd, 5, 5));
175  Counters_.set_me2_1(GetHexBits(BCd, 6, 6));
176  Counters_.set_me3_1(GetHexBits(BCd, 7, 7));
177  Counters_.set_me4_1(GetHexBits(BCd, 8, 8));
178 
179  Counters_.set_me1a_all(GetHexBits(BCa, 0, 7));
180  Counters_.set_me1b_all(GetHexBits(BCa, 8, 14, BCb, 0, 0));
181  Counters_.set_me2_all(GetHexBits(BCb, 1, 8));
182  Counters_.set_me3_all(GetHexBits(BCb, 9, 14, BCc, 0, 1));
183  Counters_.set_me4_all(GetHexBits(BCc, 2, 9));
184  Counters_.set_meN_all(GetHexBits(BCc, 10, 14, BCd, 0, 3));
185 
186  Counters_.set_me1a_all((Counters_.ME1a_all() << 1) | Counters_.ME1a_1());
187  Counters_.set_me1b_all((Counters_.ME1b_all() << 1) | Counters_.ME1b_1());
188  Counters_.set_me2_all((Counters_.ME2_all() << 1) | Counters_.ME2_1());
189  Counters_.set_me3_all((Counters_.ME3_all() << 1) | Counters_.ME3_1());
190  Counters_.set_me4_all((Counters_.ME4_all() << 1) | Counters_.ME4_1());
191 
192  Counters_.set_me_all(Counters_.MEN_all() | Counters_.ME4_all() | Counters_.ME3_all() | Counters_.ME2_all() |
193  Counters_.ME1b_all() | Counters_.ME1a_all());
194 
195  // Counters_.set_dataword(uint64_t bits) { dataword = bits; };
196 
197  (res->at(iOut)).set_Counters(Counters_);
198 
199  // Finished with unpacking Counters
200  return true;
201 
202  } // End bool CountersBlockUnpacker::unpack
203 
204  // bool CountersBlockPacker::pack(const Block& block, UnpackerCollections *coll) {
205  // std::cout << "Inside CountersBlockPacker::pack" << std::endl;
206  // return true;
207  // } // End bool CountersBlockPacker::pack
208 
209  } // End namespace emtf
210  } // End namespace stage2
211 } // End namespace l1t
212 
214 // DEFINE_L1T_PACKER(l1t::stage2::CountersBlockPacker);
void set_me3n_3(int bits)
Definition: Counters.h:149
void set_me2_7(int bits)
Definition: Counters.h:123
virtual int checkFormat(const Block &block)
void set_me1b_2(int bits)
Definition: Counters.h:109
void set_me3_7(int bits)
Definition: Counters.h:132
int ME1a_1() const
Definition: Counters.h:164
void set_me3_2(int bits)
Definition: Counters.h:127
void set_me2_1(int bits)
Definition: Counters.h:117
void set_me4_8(int bits)
Definition: Counters.h:142
void set_me_all(int bits)
Definition: Counters.h:160
void set_me4_6(int bits)
Definition: Counters.h:140
void set_me1b_6(int bits)
Definition: Counters.h:113
void set_me4n_9(int bits)
Definition: Counters.h:152
void set_me1n_9(int bits)
Definition: Counters.h:146
void set_me2_all(int bits)
Definition: Counters.h:156
void set_me2_8(int bits)
Definition: Counters.h:124
void set_me2_2(int bits)
Definition: Counters.h:118
void set_me4n_3(int bits)
Definition: Counters.h:151
void set_me3_6(int bits)
Definition: Counters.h:131
void set_me1b_8(int bits)
Definition: Counters.h:115
void set_me3_all(int bits)
Definition: Counters.h:157
Definition: Event.h:15
delete x;
Definition: CaloConfig.h:22
void set_me4_1(int bits)
Definition: Counters.h:135
void set_me1a_9(int bits)
Definition: Counters.h:107
Log< level::Error, false > LogError
void set_me2_4(int bits)
Definition: Counters.h:120
int MEN_all() const
Definition: Counters.h:224
void set_meN_all(int bits)
Definition: Counters.h:159
int ME1b_1() const
Definition: Counters.h:173
int ME4_all() const
Definition: Counters.h:223
Definition: Electron.h:6
void set_me3n_9(int bits)
Definition: Counters.h:150
void set_me4_2(int bits)
Definition: Counters.h:136
void set_me4_5(int bits)
Definition: Counters.h:139
void set_me1n_3(int bits)
Definition: Counters.h:144
void add_format_error()
Definition: Counters.h:161
void set_me1b_4(int bits)
Definition: Counters.h:111
int ME2_1() const
Definition: Counters.h:182
void set_me4_9(int bits)
Definition: Counters.h:143
void set_me3_3(int bits)
Definition: Counters.h:128
std::vector< EMTFDaqOut > EMTFDaqOutCollection
Definition: EMTFDaqOut.h:179
void set_me1a_all(int bits)
Definition: Counters.h:154
void set_me1a_3(int bits)
Definition: Counters.h:101
int ME4_1() const
Definition: Counters.h:200
int ME3_all() const
Definition: Counters.h:222
void set_me1n_6(int bits)
Definition: Counters.h:145
int ME1b_all() const
Definition: Counters.h:220
void set_me1a_6(int bits)
Definition: Counters.h:104
void set_me1b_1(int bits)
Definition: Counters.h:108
void set_me1a_1(int bits)
Definition: Counters.h:99
int ME1a_all() const
Definition: Counters.h:219
void set_me4_3(int bits)
Definition: Counters.h:137
void set_me3_4(int bits)
Definition: Counters.h:129
void set_me4_7(int bits)
Definition: Counters.h:141
void set_me2n_9(int bits)
Definition: Counters.h:148
void set_me1a_4(int bits)
Definition: Counters.h:102
void set_me2_9(int bits)
Definition: Counters.h:125
bool unpack(const Block &block, UnpackerCollections *coll) override
int ME2_all() const
Definition: Counters.h:221
void set_me1a_7(int bits)
Definition: Counters.h:105
void set_me2_5(int bits)
Definition: Counters.h:121
void set_me4_4(int bits)
Definition: Counters.h:138
void set_me1a_8(int bits)
Definition: Counters.h:106
void set_me1a_2(int bits)
Definition: Counters.h:100
void set_me1b_all(int bits)
Definition: Counters.h:155
int ME3_1() const
Definition: Counters.h:191
void set_me3_1(int bits)
Definition: Counters.h:126
#define DEFINE_L1T_UNPACKER(type)
void set_me1a_5(int bits)
Definition: Counters.h:103
Definition: errors.py:1
void set_me1b_7(int bits)
Definition: Counters.h:114
uint16_t GetHexBits(uint16_t word, uint16_t lowBit, uint16_t highBit)
void set_me3_8(int bits)
Definition: Counters.h:133
void set_me2n_3(int bits)
Definition: Counters.h:147
void set_me1b_9(int bits)
Definition: Counters.h:116
void set_me3_5(int bits)
Definition: Counters.h:130
void set_me2_6(int bits)
Definition: Counters.h:122
void set_me3_9(int bits)
Definition: Counters.h:134
void set_me1b_5(int bits)
Definition: Counters.h:112
void set_me4_all(int bits)
Definition: Counters.h:158
void set_me2_3(int bits)
Definition: Counters.h:119
void set_me1b_3(int bits)
Definition: Counters.h:110