CMS 3D CMS Logo

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