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,
17  UnpackerCollections* coll) override; // Apparently it's always good to use override in C++
18  // virtual bool packBlock(const Block& block, UnpackerCollections *coll) override;
19  };
20 
21  // class TrailersBlockPacker : public Packer { // "TrailersBlockPacker" inherits from "Packer"
22  // public:
23  // virtual bool unpack(const Block& block, UnpackerCollections *coll) override; // Apparently it's always good to use override in C++
24  // };
25 
26  } // namespace emtf
27  } // namespace stage2
28 } // namespace l1t
29 
30 namespace l1t {
31  namespace stage2 {
32  namespace emtf {
33 
35  auto payload = block.payload();
36  int errors = 0;
37 
38  //Check the number of 16-bit words
39  if (payload.size() != 8) {
40  errors += 1;
41  edm::LogError("L1T|EMTF") << "Payload size in 'AMC Data Trailer' is different than expected";
42  }
43 
44  //Check that each word is 16 bits
45  if (GetHexBits(payload[0], 16, 31) != 0) {
46  errors += 1;
47  edm::LogError("L1T|EMTF") << "Payload[0] has more than 16 bits in 'AMC Data Trailer'";
48  }
49  if (GetHexBits(payload[1], 16, 31) != 0) {
50  errors += 1;
51  edm::LogError("L1T|EMTF") << "Payload[1] has more than 16 bits in 'AMC Data Trailer'";
52  }
53  if (GetHexBits(payload[2], 16, 31) != 0) {
54  errors += 1;
55  edm::LogError("L1T|EMTF") << "Payload[2] has more than 16 bits in 'AMC Data Trailer'";
56  }
57  if (GetHexBits(payload[3], 16, 31) != 0) {
58  errors += 1;
59  edm::LogError("L1T|EMTF") << "Payload[3] has more than 16 bits in 'AMC Data Trailer'";
60  }
61  if (GetHexBits(payload[3], 16, 31) != 0) {
62  errors += 1;
63  edm::LogError("L1T|EMTF") << "Payload[3] has more than 16 bits in 'AMC Data Trailer'";
64  }
65  if (GetHexBits(payload[3], 16, 31) != 0) {
66  errors += 1;
67  edm::LogError("L1T|EMTF") << "Payload[3] has more than 16 bits in 'AMC Data Trailer'";
68  }
69  if (GetHexBits(payload[3], 16, 31) != 0) {
70  errors += 1;
71  edm::LogError("L1T|EMTF") << "Payload[3] has more than 16 bits in 'AMC Data Trailer'";
72  }
73  if (GetHexBits(payload[3], 16, 31) != 0) {
74  errors += 1;
75  edm::LogError("L1T|EMTF") << "Payload[3] has more than 16 bits in 'AMC Data Trailer'";
76  }
77 
78  // Assign payload to 16-bit words
79  uint16_t TR1a = payload[0];
80  uint16_t TR1b = payload[1];
81  uint16_t TR1c = payload[2];
82  uint16_t TR1d = payload[3];
83  uint16_t TR2a = payload[4];
84  uint16_t TR2b = payload[5];
85  uint16_t TR2c = payload[6];
86  uint16_t TR2d = payload[7];
87 
88  //Check Format
89  if (GetHexBits(TR1a, 12, 15) != 15) {
90  errors += 1;
91  edm::LogError("L1T|EMTF") << "Format identifier bits in TR1a are incorrect";
92  }
93  if (GetHexBits(TR1b, 12, 15) != 15) {
94  errors += 1;
95  edm::LogError("L1T|EMTF") << "Format identifier bits in TR1b are incorrect";
96  }
97  if (GetHexBits(TR1c, 12, 15) != 15) {
98  errors += 1;
99  edm::LogError("L1T|EMTF") << "Format identifier bits in TR1c are incorrect";
100  }
101  if (GetHexBits(TR1d, 12, 15) != 15) {
102  errors += 1;
103  edm::LogError("L1T|EMTF") << "Format identifier bits in TR1d are incorrect";
104  }
105  if (GetHexBits(TR2a, 12, 15) != 14) {
106  errors += 1;
107  edm::LogError("L1T|EMTF") << "Format identifier bits in TR2a are incorrect";
108  }
109  if (GetHexBits(TR2b, 12, 15) != 14) {
110  errors += 1;
111  edm::LogError("L1T|EMTF") << "Format identifier bits in TR2b are incorrect";
112  }
113  if (GetHexBits(TR2c, 12, 15) != 14) {
114  errors += 1;
115  edm::LogError("L1T|EMTF") << "Format identifier bits in TR2c are incorrect";
116  }
117  if (GetHexBits(TR2d, 12, 15) != 14) {
118  errors += 1;
119  edm::LogError("L1T|EMTF") << "Format identifier bits in TR2d are incorrect";
120  }
121 
122  return errors;
123  }
124 
126  // std::cout << "Inside EMTFBlockTrailers.cc: unpack" << std::endl;
127 
128  // Get the payload for this block, made up of 16-bit words (0xffff)
129  // Format defined in MTF7Payload::getBlock() in src/Block.cc
130  // payload[0] = bits 0-15, payload[1] = 16-31, payload[3] = 32-47, etc.
131  auto payload = block.payload();
132 
133  // Check Format of Payload
134  l1t::emtf::AMC13Trailer AMC13Trailer_;
135  l1t::emtf::MTF7Trailer MTF7Trailer_;
136  l1t::emtf::EventTrailer EventTrailer_;
137  for (int err = 0; err < checkFormat(block); err++)
138  EventTrailer_.add_format_error();
139 
140  // Assign payload to 16-bit words
141  uint16_t TR1a = payload[0];
142  uint16_t TR1b = payload[1];
143  uint16_t TR1c = payload[2];
144  uint16_t TR1d = payload[3];
145  uint16_t TR2a = payload[4];
146  uint16_t TR2b = payload[5];
147  uint16_t TR2c = payload[6];
148  uint16_t TR2d = payload[7];
149 
150  // res is a pointer to a collection of EMTFDaqOut class objects
151  // There is one EMTFDaqOut for each MTF7 (60 deg. sector) in the event
153  res = static_cast<EMTFCollections*>(coll)->getEMTFDaqOuts();
154  int iOut = res->size() - 1;
155 
157  // Unpack the Event Record trailer information
159 
160  if ((res->at(iOut)).HasEventTrailer() == true) {
161  (res->at(iOut)).add_format_error();
162  edm::LogError("L1T|EMTF") << "Why is there already an EventTrailer object?";
163  }
164 
165  EventTrailer_.set_l1a(GetHexBits(TR1a, 0, 7));
166  EventTrailer_.set_ddcsr_lf(GetHexBits(TR1a, 8, 11, TR1b, 8, 11));
167 
168  EventTrailer_.set_lfff(GetHexBits(TR1b, 7, 7));
169 
170  // EventTrailer_.set_ddcsr_bid ( GetHexBits(TR2a, 0, 4, TR1c, 0, 8) ); // Probably incorrect
171  EventTrailer_.set_mm(GetHexBits(TR1c, 0, 3));
172  EventTrailer_.set_yy(GetHexBits(TR1c, 4, 7));
173  EventTrailer_.set_bb(GetHexBits(TR1c, 8, 8));
174 
175  EventTrailer_.set_spcsr_scc(GetHexBits(TR1d, 0, 11));
176 
177  EventTrailer_.set_dd(GetHexBits(TR2a, 0, 4));
178 
179  EventTrailer_.set_sp_padr(GetHexBits(TR2b, 0, 4));
180  EventTrailer_.set_sp_ersv(GetHexBits(TR2b, 5, 7));
181  EventTrailer_.set_sp_ladr(GetHexBits(TR2b, 8, 11));
182 
183  EventTrailer_.set_crc22(GetHexBits(TR2c, 0, 10, TR2d, 0, 10));
184  EventTrailer_.set_lp(GetHexBits(TR2c, 11, 11));
185  EventTrailer_.set_hp(GetHexBits(TR2d, 11, 11));
186 
187  // EventTrailer_.set_dataword(uint64_t bits) { dataword = bits; };
188 
189  (res->at(iOut)).set_EventTrailer(EventTrailer_);
190 
192  // Unpack the MTF7 trailer information
194 
195  if ((res->at(iOut)).HasMTF7Trailer() == true) {
196  (res->at(iOut)).add_format_error();
197  edm::LogError("L1T|EMTF") << "Why is there already an MTF7Trailer object?";
198  }
199 
200  // // AMC trailer info defined in interface/AMCSpec.h ... but not implemented in interface/Block.h?
201  // MTF7Trailer_.set_crc_32( GetHexBits(payload[], , ) );
202  // MTF7Trailer_.set_lv1_id( GetHexBits(payload[], , ) );
203  // MTF7Trailer_.set_data_length( GetHexBits(payload[], , ) );
204  // MTF7Trailer_.set_dataword(uint64_t bits) { dataword = bits; };
205 
206  (res->at(iOut)).set_MTF7Trailer(MTF7Trailer_);
207 
209  // Unpack the AMC13 trailer information
211 
212  if ((res->at(iOut)).HasAMC13Trailer() == true) {
213  (res->at(iOut)).add_format_error();
214  edm::LogError("L1T|EMTF") << "Why is there already an AMC13Trailer object?";
215  }
216 
217  // TODO: Write functions in interface/AMC13Spec.h (as in AMCSpec.h) to extract all AMC13 header and trailer info
218  // TODO: Edit interface/Block.h to have a amc13() function similar to amc()
219 
220  // AMC13Trailer_.set_evt_lgth( GetHexBits(payload[], , ) );
221  // AMC13Trailer_.set_crc16( GetHexBits(payload[], , ) );
222  // AMC13Trailer_.set_evt_stat( GetHexBits(payload[], , ) );
223  // AMC13Trailer_.set_tts( GetHexBits(payload[], , ) );
224  // AMC13Trailer_.set_c( GetHexBits(payload[], , ) );
225  // AMC13Trailer_.set_f( GetHexBits(payload[], , ) );
226  // AMC13Trailer_.set_t( GetHexBits(payload[], , ) );
227  // AMC13Trailer_.set_r( GetHexBits(payload[], , ) );
228  // AMC13Trailer_.set_dataword(uint64_t bits) { dataword = bits; };
229 
230  (res->at(iOut)).set_AMC13Trailer(AMC13Trailer_);
231 
232  // Finished with unpacking trailers
233  return true;
234 
235  } // End bool TrailersBlockUnpacker::unpack
236 
237  // bool TrailersBlockPacker::pack(const Block& block, UnpackerCollections *coll) {
238  // std::cout << "Inside TrailersBlockPacker::pack" << std::endl;
239  // return true;
240  // } // End bool TrailersBlockPacker::pack
241 
242  } // End namespace emtf
243  } // End namespace stage2
244 } // End namespace l1t
245 
247 // DEFINE_L1T_PACKER(l1t::stage2::TrailersBlockPacker);
l1t::EMTFDaqOutCollection
std::vector< EMTFDaqOut > EMTFDaqOutCollection
Definition: EMTFDaqOut.h:179
l1t::stage2::emtf::TrailersBlockUnpacker
Definition: EMTFBlockTrailers.cc:13
l1t::emtf::EventTrailer::set_sp_padr
void set_sp_padr(int bits)
Definition: EventTrailer.h:46
l1t::emtf::EventTrailer::set_l1a
void set_l1a(int bits)
Definition: EventTrailer.h:40
EMTFCollections.h
l1t::emtf::EventTrailer::set_mm
void set_mm(int bits)
Definition: EventTrailer.h:42
l1t::emtf::AMC13Trailer
Definition: AMC13Trailer.h:11
l1t::emtf::EventTrailer::set_hp
void set_hp(int bits)
Definition: EventTrailer.h:36
errors
Definition: errors.py:1
emtf
Definition: Event.h:15
UnpackerFactory.h
jets_cff.payload
payload
Definition: jets_cff.py:32
l1t::emtf::MTF7Trailer
Definition: MTF7Trailer.h:11
l1t::Unpacker
Definition: Unpacker.h:11
l1t::stage2::emtf::TrailersBlockUnpacker::unpack
bool unpack(const Block &block, UnpackerCollections *coll) override
Definition: EMTFBlockTrailers.cc:125
l1t::emtf::EventTrailer::set_ddcsr_lf
void set_ddcsr_lf(int bits)
Definition: EventTrailer.h:38
l1t::emtf::EventTrailer::set_crc22
void set_crc22(int bits)
Definition: EventTrailer.h:34
l1t::emtf::EventTrailer
Definition: EventTrailer.h:9
l1t
delete x;
Definition: CaloConfig.h:22
l1t::stage2::emtf::TrailersBlockUnpacker::checkFormat
virtual int checkFormat(const Block &block)
Definition: EMTFBlockTrailers.cc:34
l1t::emtf::EventTrailer::set_bb
void set_bb(int bits)
Definition: EventTrailer.h:48
l1t::emtf::EventTrailer::set_lfff
void set_lfff(int bits)
Definition: EventTrailer.h:47
groupFilesInBlocks.block
block
Definition: groupFilesInBlocks.py:150
edm::LogError
Log< level::Error, false > LogError
Definition: MessageLogger.h:123
submitPVResolutionJobs.err
err
Definition: submitPVResolutionJobs.py:85
l1t::emtf::EventTrailer::set_dd
void set_dd(int bits)
Definition: EventTrailer.h:43
res
Definition: Electron.h:6
SiStripSourceConfigTier0_cff.stage2
stage2
Definition: SiStripSourceConfigTier0_cff.py:71
l1t::emtf::EventTrailer::set_lp
void set_lp(int bits)
Definition: EventTrailer.h:35
l1t::emtf::EventTrailer::add_format_error
void add_format_error()
Definition: EventTrailer.h:49
EMTFUnpackerTools.h
l1t::UnpackerCollections
Definition: UnpackerCollections.h:9
l1t::emtf::EventTrailer::set_yy
void set_yy(int bits)
Definition: EventTrailer.h:41
l1t::emtf::EventTrailer::set_sp_ladr
void set_sp_ladr(int bits)
Definition: EventTrailer.h:44
l1t::emtf::EventTrailer::set_sp_ersv
void set_sp_ersv(int bits)
Definition: EventTrailer.h:45
DEFINE_L1T_UNPACKER
#define DEFINE_L1T_UNPACKER(type)
Definition: UnpackerFactory.h:23
l1t::emtf::EventTrailer::set_spcsr_scc
void set_spcsr_scc(int bits)
Definition: EventTrailer.h:39
l1t::Block
Definition: Block.h:70
l1t::stage2::emtf::GetHexBits
uint16_t GetHexBits(uint16_t word, uint16_t lowBit, uint16_t highBit)
Definition: EMTFUnpackerTools.h:45
debug_messages_cfi.errors
errors
Definition: debug_messages_cfi.py:54