CMS 3D CMS Logo

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