CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
EMTFBlockHeaders.cc
Go to the documentation of this file.
1 // Code to unpack the AMC13 header, "AMC data header", and "Event Record Header"
2 
4 
5 #include "EMTFCollections.h"
6 #include "EMTFUnpackerTools.h"
7 
8 // This is the "header" - no EMTFBlockHeaders.h file is needed
9 namespace l1t {
10  namespace stage2 {
11  namespace emtf {
12 
13  class HeadersBlockUnpacker : public Unpacker { // "HeadersBlockUnpacker" 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 HeadersBlockPacker : public Packer { // "HeadersBlockPacker" 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() != 12) {
40  errors += 1;
41  edm::LogError("L1T|EMTF") << "Payload size in 'AMC Data Header' 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 'AMC Data Header'";
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 'AMC Data Header'";
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 'AMC Data Header'";
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 'AMC Data Header'";
60  }
61  if (GetHexBits(payload[4], 16, 31) != 0) {
62  errors += 1;
63  edm::LogError("L1T|EMTF") << "Payload[4] has more than 16 bits in 'AMC Data Header'";
64  }
65  if (GetHexBits(payload[5], 16, 31) != 0) {
66  errors += 1;
67  edm::LogError("L1T|EMTF") << "Payload[5] has more than 16 bits in 'AMC Data Header'";
68  }
69  if (GetHexBits(payload[6], 16, 31) != 0) {
70  errors += 1;
71  edm::LogError("L1T|EMTF") << "Payload[6] has more than 16 bits in 'AMC Data Header'";
72  }
73  if (GetHexBits(payload[7], 16, 31) != 0) {
74  errors += 1;
75  edm::LogError("L1T|EMTF") << "Payload[7] has more than 16 bits in 'AMC Data Header'";
76  }
77  if (GetHexBits(payload[8], 16, 31) != 0) {
78  errors += 1;
79  edm::LogError("L1T|EMTF") << "Payload[8] has more than 16 bits in 'AMC Data Header'";
80  }
81  if (GetHexBits(payload[9], 16, 31) != 0) {
82  errors += 1;
83  edm::LogError("L1T|EMTF") << "Payload[9] has more than 16 bits in 'AMC Data Header'";
84  }
85  if (GetHexBits(payload[10], 16, 31) != 0) {
86  errors += 1;
87  edm::LogError("L1T|EMTF") << "Payload[10] has more than 16 bits in 'AMC Data Header'";
88  }
89  if (GetHexBits(payload[11], 16, 31) != 0) {
90  errors += 1;
91  edm::LogError("L1T|EMTF") << "Payload[11] has more than 16 bits in 'AMC Data Header'";
92  }
93 
94  uint16_t HD1a = payload[0];
95  uint16_t HD1b = payload[1];
96  uint16_t HD1c = payload[2];
97  uint16_t HD1d = payload[3];
98  uint16_t HD2a = payload[4];
99  uint16_t HD2b = payload[5];
100  uint16_t HD2c = payload[6];
101  uint16_t HD2d = payload[7];
102  uint16_t HD3a = payload[8];
103  uint16_t HD3b = payload[9];
104  uint16_t HD3c = payload[10];
105  uint16_t HD3d = payload[11];
106 
107  //Check Format
108  if (GetHexBits(HD1a, 12, 15) != 9) {
109  errors += 1;
110  edm::LogError("L1T|EMTF") << "Format identifier bits in HD1a are incorrect";
111  }
112  if (GetHexBits(HD1b, 12, 15) != 9) {
113  errors += 1;
114  edm::LogError("L1T|EMTF") << "Format identifier bits in HD1b are incorrect";
115  }
116  if (GetHexBits(HD1c, 12, 15) != 9) {
117  errors += 1;
118  edm::LogError("L1T|EMTF") << "Format identifier bits in HD1c are incorrect";
119  }
120  if (GetHexBits(HD1d, 12, 15) != 9) {
121  errors += 1;
122  edm::LogError("L1T|EMTF") << "Format identifier bits in HD1d are incorrect";
123  }
124  if (GetHexBits(HD2a, 12, 15) != 10) {
125  errors += 1;
126  edm::LogError("L1T|EMTF") << "Format identifier bits in HD2a are incorrect";
127  }
128  if (GetHexBits(HD2b, 12, 15) != 10) {
129  errors += 1;
130  edm::LogError("L1T|EMTF") << "Format identifier bits in HD2b are incorrect";
131  }
132  if (GetHexBits(HD2c, 12, 15) != 10) {
133  errors += 1;
134  edm::LogError("L1T|EMTF") << "Format identifier bits in HD2c are incorrect";
135  }
136  if (GetHexBits(HD2d, 12, 15) != 10) {
137  errors += 1;
138  edm::LogError("L1T|EMTF") << "Format identifier bits in HD2d are incorrect";
139  }
140  if (GetHexBits(HD3a, 15, 15) != 1) {
141  errors += 1;
142  edm::LogError("L1T|EMTF") << "Format identifier bits in HD3a are incorrect";
143  }
144  if (GetHexBits(HD3b, 15, 15) != 0) {
145  errors += 1;
146  edm::LogError("L1T|EMTF") << "Format identifier bits in HD3b are incorrect";
147  }
148  if (GetHexBits(HD3c, 15, 15) != 0) {
149  errors += 1;
150  edm::LogError("L1T|EMTF") << "Format identifier bits in HD3c are incorrect";
151  }
152  if (GetHexBits(HD3d, 15, 15) != 0) {
153  errors += 1;
154  edm::LogError("L1T|EMTF") << "Format identifier bits in HD3d are incorrect";
155  }
156 
157  return errors;
158  }
159 
161  // std::cout << "Inside EMTFBlockHeaders.cc: unpack" << std::endl;
162 
163  // Get the payload for this block, made up of 16-bit words (0xffff)
164  // Format defined in MTF7Payload::getBlock() in src/Block.cc
165  // payload[0] = bits 0-15, payload[1] = 16-31, payload[3] = 32-47, etc.
166  auto payload = block.payload();
167 
168  // Check Format of Payload
169  l1t::emtf::AMC13Header AMC13Header_;
170  l1t::emtf::MTF7Header MTF7Header_;
171  l1t::emtf::EventHeader EventHeader_;
172  for (int err = 0; err < checkFormat(block); err++)
173  EventHeader_.add_format_error();
174 
175  // Assign payload to 16-bit words
176  uint16_t HD1a = payload[0];
177  uint16_t HD1b = payload[1];
178  // uint16_t HD1c = payload[2];
179  uint16_t HD1d = payload[3];
180  uint16_t HD2a = payload[4];
181  uint16_t HD2b = payload[5];
182  uint16_t HD2c = payload[6];
183  uint16_t HD2d = payload[7];
184  uint16_t HD3a = payload[8];
185  uint16_t HD3b = payload[9];
186  uint16_t HD3c = payload[10];
187  uint16_t HD3d = payload[11];
188 
189  // res is a pointer to a collection of EMTFDaqOut class objects
190  // There is one EMTFDaqOut for each MTF7 (60 deg. sector) in the event
192  res = static_cast<EMTFCollections*>(coll)->getEMTFDaqOuts();
193 
194  EMTFDaqOut EMTFDaqOut_;
195  res->push_back(EMTFDaqOut_);
196  int iOut = res->size() - 1;
197 
199  // Unpack the AMC13 header information
201 
202  if ((res->at(iOut)).HasAMC13Header() == true) {
203  (res->at(iOut)).add_format_error();
204  edm::LogError("L1T|EMTF") << "Why is there already an AMC13Header object?";
205  goto write_AMC13;
206  }
207 
208  // TODO: Write functions in interface/AMC13Spec.h (as in AMCSpec.h) to extract all AMC13 header and trailer info
209  // TODO: Edit interface/Block.h to have a amc13() function similar to amc()
210 
211  // AMC13Header_.set_orn( block.amc13().get() ) { orn = bits; };
212  // AMC13Header_.set_lv1_id( block.amc13().get() ) { lv1_id = bits; };
213  // AMC13Header_.set_bx_id( block.amc13().get() ) { bx_id = bits; };
214  // AMC13Header_.set_source_id( block.amc13().get() ) { source_id = bits; };
215  // AMC13Header_.set_evt_ty( block.amc13().get() ) { evt_ty = bits; };
216  // AMC13Header_.set_fov( block.amc13().get() ) { fov = bits; };
217  // AMC13Header_.set_ufov( block.amc13().get() ) { ufov = bits; };
218  // AMC13Header_.set_res( block.amc13().get() ) { res = bits; };
219  // AMC13Header_.set_namc( block.amc13().get() ) { namc = bits; };
220  // AMC13Header_.set_h( block.amc13().get() ) { h = bits; };
221  // AMC13Header_.set_x( block.amc13().get() ) { x = bits; };
222  // AMC13Header_.set_dataword(uint64_t bits) { dataword = bits; };
223 
224  write_AMC13:
225 
226  (res->at(iOut)).set_AMC13Header(AMC13Header_);
227 
229  // Unpack the MTF7 header information
231 
232  if ((res->at(iOut)).HasMTF7Header() == true) {
233  (res->at(iOut)).add_format_error();
234  edm::LogError("L1T|EMTF") << "Why is there already an MTF7Header object?";
235  goto write_MTF7;
236  }
237 
238  // AMC header info defined in interface/AMCSpec.h
239  MTF7Header_.set_amc_number(block.amc().getAMCNumber());
240  MTF7Header_.set_bx_id(block.amc().getBX());
241  MTF7Header_.set_orbit_number(block.amc().getOrbitNumber());
242  MTF7Header_.set_board_id(block.amc().getBoardID());
243  MTF7Header_.set_lv1_id(block.amc().getLV1ID());
244  MTF7Header_.set_data_length(block.amc().getSize());
245  MTF7Header_.set_user_id(block.amc().getUserData());
246  // MTF7Header_.set_dataword(uint64_t bits) { dataword = bits; };
247 
248  write_MTF7:
249 
250  (res->at(iOut)).set_MTF7Header(MTF7Header_);
251 
253  // Unpack the Event Record header information
255 
256  if ((res->at(iOut)).HasEventHeader() == true) {
257  (res->at(iOut)).add_format_error();
258  edm::LogError("L1T|EMTF") << "Why is there already an EventHeader object?";
259  goto write_Event;
260  }
261  if (EventHeader_.Format_errors() > 0)
262  goto write_Event;
263 
264  EventHeader_.set_l1a(GetHexBits(HD1a, 0, 11, HD1b, 0, 11));
265  EventHeader_.set_l1a_BXN(GetHexBits(HD1d, 0, 11));
266  EventHeader_.set_sp_TS(GetHexBits(HD2b, 8, 11));
267  EventHeader_.set_endcap(GetHexBits(HD2b, 11, 11) ? -1 : 1);
268  EventHeader_.set_sector(GetHexBits(HD2b, 8, 10) + 1);
269  EventHeader_.set_sp_ersv(GetHexBits(HD2b, 5, 7));
270  EventHeader_.set_sp_addr(GetHexBits(HD2b, 0, 4));
271  EventHeader_.set_tbin(GetHexBits(HD2c, 8, 10));
272  EventHeader_.set_ddm(GetHexBits(HD2c, 7, 7));
273  EventHeader_.set_spa(GetHexBits(HD2c, 6, 6));
274  EventHeader_.set_rpca(GetHexBits(HD2c, 5, 5));
275  EventHeader_.set_skip(GetHexBits(HD2c, 4, 4));
276  EventHeader_.set_rdy(GetHexBits(HD2c, 3, 3));
277  EventHeader_.set_bsy(GetHexBits(HD2c, 2, 2));
278  EventHeader_.set_osy(GetHexBits(HD2c, 1, 1));
279  EventHeader_.set_wof(GetHexBits(HD2c, 0, 0));
280  EventHeader_.set_me1a(GetHexBits(HD2d, 0, 11));
281  EventHeader_.set_me1b(GetHexBits(HD3a, 0, 8));
282  EventHeader_.set_me2(GetHexBits(HD3b, 0, 10));
283  EventHeader_.set_me3(GetHexBits(HD3c, 0, 10));
284  EventHeader_.set_me4(GetHexBits(HD3d, 0, 10));
285  EventHeader_.set_cppf(GetHexBits(HD3a, 11, 14, HD3b, 11, 13));
286  EventHeader_.set_cppf_crc(GetHexBits(HD3c, 11, 14, HD3d, 11, 13));
287  EventHeader_.set_gem(GetHexBits(HD2a, 0, 6));
288  EventHeader_.set_gem_crc(GetHexBits(HD2a, 7, 11, HD3a, 9, 10));
289  // EventHeader_.set_dataword(uint64_t bits) { dataword = bits; };
290 
291  write_Event:
292 
293  (res->at(iOut)).set_EventHeader(EventHeader_);
294 
295  // Finished with unpacking headers
296  return true;
297 
298  } // End bool HeadersBlockUnpacker::unpack
299 
300  // bool HeadersBlockPacker::pack(const Block& block, UnpackerCollections *coll) {
301  // std::cout << "Inside HeadersBlockPacker::pack" << std::endl;
302  // return true;
303  // } // End bool HeadersBlockPacker::pack
304 
305  } // End namespace emtf
306  } // End namespace stage2
307 } // End namespace l1t
308 
310 // DEFINE_L1T_PACKER(l1t::stage2::HeadersBlockPacker);
void set_cppf_crc(int bits)
Definition: EventHeader.h:66
void set_endcap(int bits)
Definition: EventHeader.h:47
int Format_errors() const
Definition: EventHeader.h:97
const std::vector< uint32_t > & payload() const
Definition: Block.h:86
void set_lv1_id(int bits)
Definition: MTF7Header.h:32
void set_sp_TS(int bits)
Definition: EventHeader.h:46
void set_orbit_number(int bits)
Definition: MTF7Header.h:30
void set_skip(int bits)
Definition: EventHeader.h:55
void set_amc_number(int bits)
Definition: MTF7Header.h:28
void set_me3(int bits)
Definition: EventHeader.h:63
Log< level::Error, false > LogError
void set_bsy(int bits)
Definition: EventHeader.h:57
void set_me4(int bits)
Definition: EventHeader.h:64
void set_sector(int bits)
Definition: EventHeader.h:48
void set_data_length(int bits)
Definition: MTF7Header.h:33
virtual int checkFormat(const Block &block)
void set_bx_id(int bits)
Definition: MTF7Header.h:29
void set_rpca(int bits)
Definition: EventHeader.h:54
void set_me1b(int bits)
Definition: EventHeader.h:61
void set_board_id(int bits)
Definition: MTF7Header.h:31
void set_gem(int bits)
Definition: EventHeader.h:67
void set_spa(int bits)
Definition: EventHeader.h:53
void set_ddm(int bits)
Definition: EventHeader.h:52
void set_sp_addr(int bits)
Definition: EventHeader.h:50
std::vector< EMTFDaqOut > EMTFDaqOutCollection
Definition: EMTFDaqOut.h:179
void set_me1a(int bits)
Definition: EventHeader.h:60
void set_user_id(int bits)
Definition: MTF7Header.h:34
void set_cppf(int bits)
Definition: EventHeader.h:65
void set_sp_ersv(int bits)
Definition: EventHeader.h:49
void set_osy(int bits)
Definition: EventHeader.h:58
void set_l1a(int bits)
Definition: EventHeader.h:44
void set_gem_crc(int bits)
Definition: EventHeader.h:68
void set_me2(int bits)
Definition: EventHeader.h:62
void set_rdy(int bits)
Definition: EventHeader.h:56
bool unpack(const Block &block, UnpackerCollections *coll) override
#define DEFINE_L1T_UNPACKER(type)
void set_wof(int bits)
Definition: EventHeader.h:59
uint16_t GetHexBits(uint16_t word, uint16_t lowBit, uint16_t highBit)
void set_tbin(int bits)
Definition: EventHeader.h:51
void set_l1a_BXN(int bits)
Definition: EventHeader.h:45
void amc(const amc::Header &h)
Definition: Block.h:88