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