CMS 3D CMS Logo

EMTFBlockHeaders.cc
Go to the documentation of this file.
2 
3 #include "EMTFCollections.h"
4 #include "EMTFUnpackerTools.h"
5 #include "EMTFBlockHeaders.h"
6 
7 namespace l1t {
8  namespace stage2 {
9  namespace emtf {
10 
12 
13  auto payload = block.payload();
14  int errors = 0;
15 
16  //Check the number of 16-bit words
17  if(payload.size() != 12) { errors += 1; edm::LogError("L1T|EMTF") << "Payload size in 'AMC Data Header' is different than expected"; }
18 
19  //Check that each word is 16 bits
20  if(GetHexBits(payload[0], 16, 31) != 0) { errors += 1; edm::LogError("L1T|EMTF") << "Payload[0] has more than 16 bits in 'AMC Data Header'"; }
21  if(GetHexBits(payload[1], 16, 31) != 0) { errors += 1; edm::LogError("L1T|EMTF") << "Payload[1] has more than 16 bits in 'AMC Data Header'"; }
22  if(GetHexBits(payload[2], 16, 31) != 0) { errors += 1; edm::LogError("L1T|EMTF") << "Payload[2] has more than 16 bits in 'AMC Data Header'"; }
23  if(GetHexBits(payload[3], 16, 31) != 0) { errors += 1; edm::LogError("L1T|EMTF") << "Payload[3] has more than 16 bits in 'AMC Data Header'"; }
24  if(GetHexBits(payload[4], 16, 31) != 0) { errors += 1; edm::LogError("L1T|EMTF") << "Payload[4] has more than 16 bits in 'AMC Data Header'"; }
25  if(GetHexBits(payload[5], 16, 31) != 0) { errors += 1; edm::LogError("L1T|EMTF") << "Payload[5] has more than 16 bits in 'AMC Data Header'"; }
26  if(GetHexBits(payload[6], 16, 31) != 0) { errors += 1; edm::LogError("L1T|EMTF") << "Payload[6] has more than 16 bits in 'AMC Data Header'"; }
27  if(GetHexBits(payload[7], 16, 31) != 0) { errors += 1; edm::LogError("L1T|EMTF") << "Payload[7] has more than 16 bits in 'AMC Data Header'"; }
28  if(GetHexBits(payload[8], 16, 31) != 0) { errors += 1; edm::LogError("L1T|EMTF") << "Payload[8] has more than 16 bits in 'AMC Data Header'"; }
29  if(GetHexBits(payload[9], 16, 31) != 0) { errors += 1; edm::LogError("L1T|EMTF") << "Payload[9] has more than 16 bits in 'AMC Data Header'"; }
30  if(GetHexBits(payload[10], 16, 31) != 0) { errors += 1; edm::LogError("L1T|EMTF") << "Payload[10] has more than 16 bits in 'AMC Data Header'"; }
31  if(GetHexBits(payload[11], 16, 31) != 0) { errors += 1; edm::LogError("L1T|EMTF") << "Payload[11] has more than 16 bits in 'AMC Data Header'"; }
32 
33  uint16_t HD1a = payload[0];
34  uint16_t HD1b = payload[1];
35  uint16_t HD1c = payload[2];
36  uint16_t HD1d = payload[3];
37  uint16_t HD2a = payload[4];
38  uint16_t HD2b = payload[5];
39  uint16_t HD2c = payload[6];
40  uint16_t HD2d = payload[7];
41  uint16_t HD3a = payload[8];
42  uint16_t HD3b = payload[9];
43  uint16_t HD3c = payload[10];
44  uint16_t HD3d = payload[11];
45 
46  //Check Format
47  if(GetHexBits(HD1a, 12, 15) != 9) { errors += 1; edm::LogError("L1T|EMTF") << "Format identifier bits in HD1a are incorrect"; }
48  if(GetHexBits(HD1b, 12, 15) != 9) { errors += 1; edm::LogError("L1T|EMTF") << "Format identifier bits in HD1b are incorrect"; }
49  if(GetHexBits(HD1c, 12, 15) != 9) { errors += 1; edm::LogError("L1T|EMTF") << "Format identifier bits in HD1c are incorrect"; }
50  if(GetHexBits(HD1c, 0, 11) != 0) { errors += 1; edm::LogError("L1T|EMTF") << "Format identifier bits in HD1c are incorrect"; }
51  if(GetHexBits(HD1d, 12, 15) != 9) { errors += 1; edm::LogError("L1T|EMTF") << "Format identifier bits in HD1d are incorrect"; }
52  if(GetHexBits(HD2a, 12, 15) != 10) { errors += 1; edm::LogError("L1T|EMTF") << "Format identifier bits in HD2a are incorrect"; }
53  if(GetHexBits(HD2a, 0, 11) != 0) { errors += 1; edm::LogError("L1T|EMTF") << "Format identifier bits in HD2a are incorrect"; }
54  if(GetHexBits(HD2b, 12, 15) != 10) { errors += 1; edm::LogError("L1T|EMTF") << "Format identifier bits in HD2b are incorrect"; }
55  if(GetHexBits(HD2c, 12, 15) != 10) { errors += 1; edm::LogError("L1T|EMTF") << "Format identifier bits in HD2c are incorrect"; }
56  if(GetHexBits(HD2c, 11, 11) != 0) { errors += 1; edm::LogError("L1T|EMTF") << "Format identifier bits in HD2c are incorrect"; }
57  if(GetHexBits(HD2d, 12, 15) != 10) { errors += 1; edm::LogError("L1T|EMTF") << "Format identifier bits in HD2d are incorrect"; }
58  if(GetHexBits(HD3a, 9, 14) != 0) { errors += 1; edm::LogError("L1T|EMTF") << "Format identifier bits in HD3a are incorrect"; }
59  if(GetHexBits(HD3a, 15, 15) != 1) { errors += 1; edm::LogError("L1T|EMTF") << "Format identifier bits in HD3a are incorrect"; }
60  if(GetHexBits(HD3b, 11, 15) != 0) { errors += 1; edm::LogError("L1T|EMTF") << "Format identifier bits in HD3b are incorrect"; }
61  if(GetHexBits(HD3c, 11, 15) != 0) { errors += 1; edm::LogError("L1T|EMTF") << "Format identifier bits in HD3c are incorrect"; }
62  if(GetHexBits(HD3d, 11, 15) != 0) { errors += 1; edm::LogError("L1T|EMTF") << "Format identifier bits in HD3d are incorrect"; }
63 
64  return errors;
65 
66  }
67 
68 
70 
71  // std::cout << "Inside EMTFBlockHeaders.cc: unpack" << std::endl;
72 
73  // Get the payload for this block, made up of 16-bit words (0xffff)
74  // Format defined in MTF7Payload::getBlock() in src/Block.cc
75  // payload[0] = bits 0-15, payload[1] = 16-31, payload[3] = 32-47, etc.
76  auto payload = block.payload();
77 
78  // Check Format of Payload
79  l1t::emtf::AMC13Header AMC13Header_;
80  l1t::emtf::MTF7Header MTF7Header_;
81  l1t::emtf::EventHeader EventHeader_;
82  for (int err = 0; err < checkFormat(block); err++) EventHeader_.add_format_error();
83 
84  // Assign payload to 16-bit words
85  uint16_t HD1a = payload[0];
86  uint16_t HD1b = payload[1];
87  // uint16_t HD1c = payload[2];
88  uint16_t HD1d = payload[3];
89  // uint16_t HD2a = payload[4];
90  uint16_t HD2b = payload[5];
91  uint16_t HD2c = payload[6];
92  uint16_t HD2d = payload[7];
93  uint16_t HD3a = payload[8];
94  uint16_t HD3b = payload[9];
95  uint16_t HD3c = payload[10];
96  uint16_t HD3d = payload[11];
97 
98  // res is a pointer to a collection of EMTFDaqOut class objects
99  // There is one EMTFDaqOut for each MTF7 (60 deg. sector) in the event
101  res = static_cast<EMTFCollections*>(coll)->getEMTFDaqOuts();
102 
103  EMTFDaqOut EMTFDaqOut_;
104  res->push_back(EMTFDaqOut_);
105  int iOut = res->size() - 1;
106 
108  // Unpack the AMC13 header information
110 
111  if ( (res->at(iOut)).HasAMC13Header() == true )
112  { (res->at(iOut)).add_format_error(); edm::LogError("L1T|EMTF") << "Why is there already an AMC13Header object?"; goto write_AMC13; }
113 
114  // TODO: Write functions in interface/AMC13Spec.h (as in AMCSpec.h) to extract all AMC13 header and trailer info
115  // TODO: Edit interface/Block.h to have a amc13() function similar to amc()
116 
117  // AMC13Header_.set_orn( block.amc13().get() ) { orn = bits; };
118  // AMC13Header_.set_lv1_id( block.amc13().get() ) { lv1_id = bits; };
119  // AMC13Header_.set_bx_id( block.amc13().get() ) { bx_id = bits; };
120  // AMC13Header_.set_source_id( block.amc13().get() ) { source_id = bits; };
121  // AMC13Header_.set_evt_ty( block.amc13().get() ) { evt_ty = bits; };
122  // AMC13Header_.set_fov( block.amc13().get() ) { fov = bits; };
123  // AMC13Header_.set_ufov( block.amc13().get() ) { ufov = bits; };
124  // AMC13Header_.set_res( block.amc13().get() ) { res = bits; };
125  // AMC13Header_.set_namc( block.amc13().get() ) { namc = bits; };
126  // AMC13Header_.set_h( block.amc13().get() ) { h = bits; };
127  // AMC13Header_.set_x( block.amc13().get() ) { x = bits; };
128  // AMC13Header_.set_dataword(uint64_t bits) { dataword = bits; };
129 
130  write_AMC13:
131 
132  (res->at(iOut)).set_AMC13Header(AMC13Header_);
133 
135  // Unpack the MTF7 header information
137 
138  if ( (res->at(iOut)).HasMTF7Header() == true )
139  { (res->at(iOut)).add_format_error(); edm::LogError("L1T|EMTF") << "Why is there already an MTF7Header object?"; goto write_MTF7; }
140 
141  // AMC header info defined in interface/AMCSpec.h
142  MTF7Header_.set_amc_number ( block.amc().getAMCNumber() );
143  MTF7Header_.set_bx_id ( block.amc().getBX() );
144  MTF7Header_.set_orbit_number ( block.amc().getOrbitNumber() );
145  MTF7Header_.set_board_id ( block.amc().getBoardID() );
146  MTF7Header_.set_lv1_id ( block.amc().getLV1ID() );
147  MTF7Header_.set_data_length ( block.amc().getSize() );
148  MTF7Header_.set_user_id ( block.amc().getUserData() );
149  // MTF7Header_.set_dataword(uint64_t bits) { dataword = bits; };
150 
151  write_MTF7:
152 
153  (res->at(iOut)).set_MTF7Header(MTF7Header_);
154 
156  // Unpack the Event Record header information
158 
159  if ( (res->at(iOut)).HasEventHeader() == true )
160  { (res->at(iOut)).add_format_error(); edm::LogError("L1T|EMTF") << "Why is there already an EventHeader object?"; goto write_Event; }
161  if (EventHeader_.Format_Errors() > 0) goto write_Event;
162 
163  EventHeader_.set_l1a ( GetHexBits(HD1a, 0, 11, HD1b, 0, 11) );
164  EventHeader_.set_l1a_BXN ( GetHexBits(HD1d, 0, 11) );
165  EventHeader_.set_sp_TS ( GetHexBits(HD2b, 8, 11) );
166  EventHeader_.set_endcap ( GetHexBits(HD2b, 11, 11) ? -1 : 1 );
167  EventHeader_.set_sector ( GetHexBits(HD2b, 8, 10) + 1 );
168  EventHeader_.set_sp_ersv ( GetHexBits(HD2b, 5, 7) );
169  EventHeader_.set_sp_addr ( GetHexBits(HD2b, 0, 4) );
170  EventHeader_.set_tbin ( GetHexBits(HD2c, 8, 10) );
171  EventHeader_.set_ddm ( GetHexBits(HD2c, 7, 7) );
172  EventHeader_.set_spa ( GetHexBits(HD2c, 6, 6) );
173  EventHeader_.set_rpca ( GetHexBits(HD2c, 5, 5) );
174  EventHeader_.set_skip ( GetHexBits(HD2c, 4, 4) );
175  EventHeader_.set_rdy ( GetHexBits(HD2c, 3, 3) );
176  EventHeader_.set_bsy ( GetHexBits(HD2c, 2, 2) );
177  EventHeader_.set_osy ( GetHexBits(HD2c, 1, 1) );
178  EventHeader_.set_wof ( GetHexBits(HD2c, 0, 0) );
179  EventHeader_.set_me1a ( GetHexBits(HD2d, 0, 11) );
180  EventHeader_.set_me1b ( GetHexBits(HD3a, 0, 8) );
181  EventHeader_.set_me2 ( GetHexBits(HD3b, 0, 10) );
182  EventHeader_.set_me3 ( GetHexBits(HD3c, 0, 10) );
183  EventHeader_.set_me4 ( GetHexBits(HD3d, 0, 10) );
184  // EventHeader_.set_dataword(uint64_t bits) { dataword = bits; };
185 
186  write_Event:
187 
188  (res->at(iOut)).set_EventHeader(EventHeader_);
189 
190  // Finished with unpacking headers
191  return true;
192 
193  } // End bool HeadersBlockUnpacker::unpack
194 
195  // bool HeadersBlockPacker::pack(const Block& block, UnpackerCollections *coll) {
196  // std::cout << "Inside HeadersBlockPacker::pack" << std::endl;
197  // return true;
198  // } // End bool HeadersBlockPacker::pack
199 
200  } // End namespace emtf
201  } // End namespace stage2
202 } // End namespace l1t
203 
205 // DEFINE_L1T_PACKER(l1t::stage2::HeadersBlockPacker);
void set_endcap(int bits)
Definition: EventHeader.h:34
void set_lv1_id(int bits)
Definition: MTF7Header.h:35
void set_sp_TS(int bits)
Definition: EventHeader.h:33
void set_orbit_number(int bits)
Definition: MTF7Header.h:33
void set_skip(int bits)
Definition: EventHeader.h:42
void set_amc_number(int bits)
Definition: MTF7Header.h:31
Definition: Event.h:15
delete x;
Definition: CaloConfig.h:22
void set_me3(int bits)
Definition: EventHeader.h:50
void set_bsy(int bits)
Definition: EventHeader.h:44
std::vector< uint32_t > payload() const
Definition: Block.h:62
Definition: Electron.h:4
void set_me4(int bits)
Definition: EventHeader.h:51
void set_sector(int bits)
Definition: EventHeader.h:35
void set_data_length(int bits)
Definition: MTF7Header.h:36
payload
payload postfix for testing
virtual int checkFormat(const Block &block)
void set_bx_id(int bits)
Definition: MTF7Header.h:32
int Format_Errors() const
Definition: EventHeader.h:76
void set_rpca(int bits)
Definition: EventHeader.h:41
void set_me1b(int bits)
Definition: EventHeader.h:48
void set_board_id(int bits)
Definition: MTF7Header.h:34
void set_spa(int bits)
Definition: EventHeader.h:40
void set_ddm(int bits)
Definition: EventHeader.h:39
void set_sp_addr(int bits)
Definition: EventHeader.h:37
std::vector< EMTFDaqOut > EMTFDaqOutCollection
Definition: EMTFDaqOut.h:130
void set_me1a(int bits)
Definition: EventHeader.h:47
void set_user_id(int bits)
Definition: MTF7Header.h:37
JetCorrectorParametersCollection coll
Definition: classes.h:10
void set_sp_ersv(int bits)
Definition: EventHeader.h:36
void set_osy(int bits)
Definition: EventHeader.h:45
void set_l1a(int bits)
Definition: EventHeader.h:31
void set_me2(int bits)
Definition: EventHeader.h:49
void set_rdy(int bits)
Definition: EventHeader.h:43
virtual bool unpack(const Block &block, UnpackerCollections *coll) override
#define DEFINE_L1T_UNPACKER(type)
Definition: errors.py:1
void set_wof(int bits)
Definition: EventHeader.h:46
uint16_t GetHexBits(uint16_t word, uint16_t lowBit, uint16_t highBit)
void set_tbin(int bits)
Definition: EventHeader.h:38
void set_l1a_BXN(int bits)
Definition: EventHeader.h:32
void amc(const amc::Header &h)
Definition: Block.h:64