CMS 3D CMS Logo

EMTFBlockTrailers.cc
Go to the documentation of this file.
2 
3 #include "EMTFCollections.h"
4 #include "EMTFUnpackerTools.h"
5 #include "EMTFBlockTrailers.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() != 8) { errors += 1; edm::LogError("L1T|EMTF") << "Payload size in 'AMC Data Trailer' 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 Trailer'"; }
21  if(GetHexBits(payload[1], 16, 31) != 0) { errors += 1; edm::LogError("L1T|EMTF") << "Payload[1] has more than 16 bits in 'AMC Data Trailer'"; }
22  if(GetHexBits(payload[2], 16, 31) != 0) { errors += 1; edm::LogError("L1T|EMTF") << "Payload[2] has more than 16 bits in 'AMC Data Trailer'"; }
23  if(GetHexBits(payload[3], 16, 31) != 0) { errors += 1; edm::LogError("L1T|EMTF") << "Payload[3] has more than 16 bits in 'AMC Data Trailer'"; }
24  if(GetHexBits(payload[3], 16, 31) != 0) { errors += 1; edm::LogError("L1T|EMTF") << "Payload[3] has more than 16 bits in 'AMC Data Trailer'"; }
25  if(GetHexBits(payload[3], 16, 31) != 0) { errors += 1; edm::LogError("L1T|EMTF") << "Payload[3] has more than 16 bits in 'AMC Data Trailer'"; }
26  if(GetHexBits(payload[3], 16, 31) != 0) { errors += 1; edm::LogError("L1T|EMTF") << "Payload[3] has more than 16 bits in 'AMC Data Trailer'"; }
27  if(GetHexBits(payload[3], 16, 31) != 0) { errors += 1; edm::LogError("L1T|EMTF") << "Payload[3] has more than 16 bits in 'AMC Data Trailer'"; }
28 
29  // Assign payload to 16-bit words
30  uint16_t TR1a = payload[0];
31  uint16_t TR1b = payload[1];
32  uint16_t TR1c = payload[2];
33  uint16_t TR1d = payload[3];
34  uint16_t TR2a = payload[4];
35  uint16_t TR2b = payload[5];
36  uint16_t TR2c = payload[6];
37  uint16_t TR2d = payload[7];
38 
39  //Check Format
40  if(GetHexBits(TR1a, 12, 15) != 15) { errors += 1; edm::LogError("L1T|EMTF") << "Format identifier bits in TR1a are incorrect"; }
41  if(GetHexBits(TR1b, 12, 15) != 15) { errors += 1; edm::LogError("L1T|EMTF") << "Format identifier bits in TR1b are incorrect"; }
42  if(GetHexBits(TR1b, 0, 3) != 15) { errors += 1; edm::LogError("L1T|EMTF") << "Format identifier bits in TR1b are incorrect"; }
43  if(GetHexBits(TR1b, 4, 6) != 7) { errors += 1; edm::LogError("L1T|EMTF") << "Format identifier bits in TR1b are incorrect"; }
44  if(GetHexBits(TR1c, 9, 11) != 0) { errors += 1; edm::LogError("L1T|EMTF") << "Format identifier bits in TR1c are incorrect"; }
45  // FIXME: we are consistently reading GetHexBits(TR1c, 12, 15) == 14 - AWB 10.02.16
46  // if(GetHexBits(TR1c, 12, 15) != 15) { errors += 1; edm::LogError("L1T|EMTF") << "Format identifier bits in TR1c are incorrect"; }
47  if(GetHexBits(TR1d, 12, 15) != 15) { errors += 1; edm::LogError("L1T|EMTF") << "Format identifier bits in TR1d are incorrect"; }
48  // FIXME: we are consistently reading GetHexBits(TR2a, 5, 11) == 18 - AWB 10.02.16
49  // if(GetHexBits(TR2a, 5, 11) != 0) { errors += 1; edm::LogError("L1T|EMTF") << "Format identifier bits in TR2a are incorrect"; }
50  if(GetHexBits(TR2a, 12, 15) != 14) { errors += 1; edm::LogError("L1T|EMTF") << "Format identifier bits in TR2a are incorrect"; }
51  if(GetHexBits(TR2b, 12, 15) != 14) { errors += 1; edm::LogError("L1T|EMTF") << "Format identifier bits in TR2b are incorrect"; }
52  if(GetHexBits(TR2c, 12, 15) != 14) { errors += 1; edm::LogError("L1T|EMTF") << "Format identifier bits in TR2c are incorrect"; }
53  if(GetHexBits(TR2d, 12, 15) != 14) { errors += 1; edm::LogError("L1T|EMTF") << "Format identifier bits in TR2d are incorrect"; }
54 
55  return errors;
56 
57  }
58 
60 
61  // std::cout << "Inside EMTFBlockTrailers.cc: unpack" << std::endl;
62 
63  // Get the payload for this block, made up of 16-bit words (0xffff)
64  // Format defined in MTF7Payload::getBlock() in src/Block.cc
65  // payload[0] = bits 0-15, payload[1] = 16-31, payload[3] = 32-47, etc.
66  auto payload = block.payload();
67 
68 
69  // Check Format of Payload
70  l1t::emtf::AMC13Trailer AMC13Trailer_;
71  l1t::emtf::MTF7Trailer MTF7Trailer_;
72  l1t::emtf::EventTrailer EventTrailer_;
73  for (int err = 0; err < checkFormat(block); err++) EventTrailer_.add_format_error();
74 
75  // Assign payload to 16-bit words
76  uint16_t TR1a = payload[0];
77  uint16_t TR1b = payload[1];
78  uint16_t TR1c = payload[2];
79  uint16_t TR1d = payload[3];
80  uint16_t TR2a = payload[4];
81  uint16_t TR2b = payload[5];
82  uint16_t TR2c = payload[6];
83  uint16_t TR2d = payload[7];
84 
85  // res is a pointer to a collection of EMTFDaqOut class objects
86  // There is one EMTFDaqOut for each MTF7 (60 deg. sector) in the event
88  res = static_cast<EMTFCollections*>(coll)->getEMTFDaqOuts();
89  int iOut = res->size() - 1;
90 
92  // Unpack the Event Record trailer information
94 
95  if ( (res->at(iOut)).HasEventTrailer() == true )
96  { (res->at(iOut)).add_format_error(); edm::LogError("L1T|EMTF") << "Why is there already an EventTrailer object?"; goto write_Event; }
97  if (EventTrailer_.Format_Errors() > 0) goto write_Event;
98 
99  EventTrailer_.set_l1a ( GetHexBits(TR1a, 0, 7) );
100  EventTrailer_.set_ddcsr_lf ( GetHexBits(TR1a, 8, 11, TR1b, 8, 11) );
101 
102  EventTrailer_.set_lfff ( GetHexBits(TR1b, 7, 7) );
103 
104  // EventTrailer_.set_ddcsr_bid ( GetHexBits(TR2a, 0, 4, TR1c, 0, 8) ); // Probably incorrect
105  EventTrailer_.set_mm ( GetHexBits(TR1c, 0, 3) );
106  EventTrailer_.set_yy ( GetHexBits(TR1c, 4, 7) );
107  EventTrailer_.set_bb ( GetHexBits(TR1c, 8, 8) );
108 
109  EventTrailer_.set_spcsr_scc ( GetHexBits(TR1d, 0, 11) );
110 
111  EventTrailer_.set_dd ( GetHexBits(TR2a, 0, 4) );
112 
113  EventTrailer_.set_sp_padr ( GetHexBits(TR2b, 0, 4) );
114  EventTrailer_.set_sp_ersv ( GetHexBits(TR2b, 5, 7) );
115  EventTrailer_.set_sp_ladr ( GetHexBits(TR2b, 8, 11) );
116 
117  EventTrailer_.set_crc22 ( GetHexBits(TR2c, 0, 10, TR2d, 0, 10) );
118  EventTrailer_.set_lp ( GetHexBits(TR2c, 11, 11) );
119  EventTrailer_.set_hp ( GetHexBits(TR2d, 11, 11) );
120 
121  // EventTrailer_.set_dataword(uint64_t bits) { dataword = bits; };
122 
123  write_Event:
124 
125  (res->at(iOut)).set_EventTrailer(EventTrailer_);
126 
128  // Unpack the MTF7 trailer information
130 
131  if ( (res->at(iOut)).HasMTF7Trailer() == true )
132  { (res->at(iOut)).add_format_error(); edm::LogError("L1T|EMTF") << "Why is there already an MTF7Trailer object?"; goto write_MTF7; }
133 
134  // // AMC trailer info defined in interface/AMCSpec.h ... but not implemented in interface/Block.h?
135  // MTF7Trailer_.set_crc_32( GetHexBits(payload[], , ) );
136  // MTF7Trailer_.set_lv1_id( GetHexBits(payload[], , ) );
137  // MTF7Trailer_.set_data_length( GetHexBits(payload[], , ) );
138  // MTF7Trailer_.set_dataword(uint64_t bits) { dataword = bits; };
139 
140  write_MTF7:
141 
142  (res->at(iOut)).set_MTF7Trailer(MTF7Trailer_);
143 
145  // Unpack the AMC13 trailer information
147 
148  if ( (res->at(iOut)).HasAMC13Trailer() == true )
149  { (res->at(iOut)).add_format_error(); edm::LogError("L1T|EMTF") << "Why is there already an AMC13Trailer object?"; goto write_AMC13; }
150 
151  // TODO: Write functions in interface/AMC13Spec.h (as in AMCSpec.h) to extract all AMC13 header and trailer info
152  // TODO: Edit interface/Block.h to have a amc13() function similar to amc()
153 
154  // AMC13Trailer_.set_evt_lgth( GetHexBits(payload[], , ) );
155  // AMC13Trailer_.set_crc16( GetHexBits(payload[], , ) );
156  // AMC13Trailer_.set_evt_stat( GetHexBits(payload[], , ) );
157  // AMC13Trailer_.set_tts( GetHexBits(payload[], , ) );
158  // AMC13Trailer_.set_c( GetHexBits(payload[], , ) );
159  // AMC13Trailer_.set_f( GetHexBits(payload[], , ) );
160  // AMC13Trailer_.set_t( GetHexBits(payload[], , ) );
161  // AMC13Trailer_.set_r( GetHexBits(payload[], , ) );
162  // AMC13Trailer_.set_dataword(uint64_t bits) { dataword = bits; };
163 
164  write_AMC13:
165 
166  (res->at(iOut)).set_AMC13Trailer(AMC13Trailer_);
167 
168  // Finished with unpacking trailers
169  return true;
170 
171  } // End bool TrailersBlockUnpacker::unpack
172 
173  // bool TrailersBlockPacker::pack(const Block& block, UnpackerCollections *coll) {
174  // std::cout << "Inside TrailersBlockPacker::pack" << std::endl;
175  // return true;
176  // } // End bool TrailersBlockPacker::pack
177 
178  } // End namespace emtf
179  } // End namespace stage2
180 } // End namespace l1t
181 
183 // DEFINE_L1T_PACKER(l1t::stage2::TrailersBlockPacker);
void set_spcsr_scc(int bits)
Definition: EventTrailer.h:33
void set_mm(int bits)
Definition: EventTrailer.h:36
void set_lp(int bits)
Definition: EventTrailer.h:29
void set_ddcsr_lf(int bits)
Definition: EventTrailer.h:32
Definition: Event.h:15
delete x;
Definition: CaloConfig.h:22
std::vector< uint32_t > payload() const
Definition: Block.h:61
Definition: Electron.h:4
virtual int checkFormat(const Block &block)
payload
payload postfix for testing
std::vector< EMTFDaqOut > EMTFDaqOutCollection
Definition: EMTFDaqOut.h:130
void set_yy(int bits)
Definition: EventTrailer.h:35
void set_hp(int bits)
Definition: EventTrailer.h:30
JetCorrectorParametersCollection coll
Definition: classes.h:10
int Format_Errors() const
Definition: EventTrailer.h:61
virtual bool unpack(const Block &block, UnpackerCollections *coll) override
void set_sp_ladr(int bits)
Definition: EventTrailer.h:38
void set_sp_padr(int bits)
Definition: EventTrailer.h:40
#define DEFINE_L1T_UNPACKER(type)
void set_crc22(int bits)
Definition: EventTrailer.h:28
void set_bb(int bits)
Definition: EventTrailer.h:42
Definition: errors.py:1
uint16_t GetHexBits(uint16_t word, uint16_t lowBit, uint16_t highBit)
void set_lfff(int bits)
Definition: EventTrailer.h:41
void set_sp_ersv(int bits)
Definition: EventTrailer.h:39
void set_l1a(int bits)
Definition: EventTrailer.h:34
void set_dd(int bits)
Definition: EventTrailer.h:37