CMS 3D CMS Logo

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