File indexing completed on 2024-09-07 04:36:14
0001
0002
0003 #include "EventFilter/L1TRawToDigi/plugins/UnpackerFactory.h"
0004
0005 #include "EMTFCollections.h"
0006 #include "EMTFUnpackerTools.h"
0007
0008
0009 namespace l1t {
0010 namespace stage2 {
0011 namespace emtf {
0012
0013 class HeadersBlockUnpacker : public Unpacker {
0014 public:
0015 virtual int checkFormat(const Block& block);
0016 bool unpack(const Block& block,
0017 UnpackerCollections* coll) override;
0018
0019 };
0020
0021
0022
0023
0024
0025
0026 }
0027 }
0028 }
0029
0030 namespace l1t {
0031 namespace stage2 {
0032 namespace emtf {
0033
0034 int HeadersBlockUnpacker::checkFormat(const Block& block) {
0035 auto payload = block.payload();
0036 int errors = 0;
0037
0038
0039 if (payload.size() != 12) {
0040 errors += 1;
0041 edm::LogError("L1T|EMTF") << "Payload size in 'AMC Data Header' is different than expected";
0042 }
0043
0044
0045 if (GetHexBits(payload[0], 16, 31) != 0) {
0046 errors += 1;
0047 edm::LogError("L1T|EMTF") << "Payload[0] has more than 16 bits in 'AMC Data Header'";
0048 }
0049 if (GetHexBits(payload[1], 16, 31) != 0) {
0050 errors += 1;
0051 edm::LogError("L1T|EMTF") << "Payload[1] has more than 16 bits in 'AMC Data Header'";
0052 }
0053 if (GetHexBits(payload[2], 16, 31) != 0) {
0054 errors += 1;
0055 edm::LogError("L1T|EMTF") << "Payload[2] has more than 16 bits in 'AMC Data Header'";
0056 }
0057 if (GetHexBits(payload[3], 16, 31) != 0) {
0058 errors += 1;
0059 edm::LogError("L1T|EMTF") << "Payload[3] has more than 16 bits in 'AMC Data Header'";
0060 }
0061 if (GetHexBits(payload[4], 16, 31) != 0) {
0062 errors += 1;
0063 edm::LogError("L1T|EMTF") << "Payload[4] has more than 16 bits in 'AMC Data Header'";
0064 }
0065 if (GetHexBits(payload[5], 16, 31) != 0) {
0066 errors += 1;
0067 edm::LogError("L1T|EMTF") << "Payload[5] has more than 16 bits in 'AMC Data Header'";
0068 }
0069 if (GetHexBits(payload[6], 16, 31) != 0) {
0070 errors += 1;
0071 edm::LogError("L1T|EMTF") << "Payload[6] has more than 16 bits in 'AMC Data Header'";
0072 }
0073 if (GetHexBits(payload[7], 16, 31) != 0) {
0074 errors += 1;
0075 edm::LogError("L1T|EMTF") << "Payload[7] has more than 16 bits in 'AMC Data Header'";
0076 }
0077 if (GetHexBits(payload[8], 16, 31) != 0) {
0078 errors += 1;
0079 edm::LogError("L1T|EMTF") << "Payload[8] has more than 16 bits in 'AMC Data Header'";
0080 }
0081 if (GetHexBits(payload[9], 16, 31) != 0) {
0082 errors += 1;
0083 edm::LogError("L1T|EMTF") << "Payload[9] has more than 16 bits in 'AMC Data Header'";
0084 }
0085 if (GetHexBits(payload[10], 16, 31) != 0) {
0086 errors += 1;
0087 edm::LogError("L1T|EMTF") << "Payload[10] has more than 16 bits in 'AMC Data Header'";
0088 }
0089 if (GetHexBits(payload[11], 16, 31) != 0) {
0090 errors += 1;
0091 edm::LogError("L1T|EMTF") << "Payload[11] has more than 16 bits in 'AMC Data Header'";
0092 }
0093
0094 uint16_t HD1a = payload[0];
0095 uint16_t HD1b = payload[1];
0096 uint16_t HD1c = payload[2];
0097 uint16_t HD1d = payload[3];
0098 uint16_t HD2a = payload[4];
0099 uint16_t HD2b = payload[5];
0100 uint16_t HD2c = payload[6];
0101 uint16_t HD2d = payload[7];
0102 uint16_t HD3a = payload[8];
0103 uint16_t HD3b = payload[9];
0104 uint16_t HD3c = payload[10];
0105 uint16_t HD3d = payload[11];
0106
0107
0108 if (GetHexBits(HD1a, 12, 15) != 9) {
0109 errors += 1;
0110 edm::LogError("L1T|EMTF") << "Format identifier bits in HD1a are incorrect";
0111 }
0112 if (GetHexBits(HD1b, 12, 15) != 9) {
0113 errors += 1;
0114 edm::LogError("L1T|EMTF") << "Format identifier bits in HD1b are incorrect";
0115 }
0116 if (GetHexBits(HD1c, 12, 15) != 9) {
0117 errors += 1;
0118 edm::LogError("L1T|EMTF") << "Format identifier bits in HD1c are incorrect";
0119 }
0120 if (GetHexBits(HD1d, 12, 15) != 9) {
0121 errors += 1;
0122 edm::LogError("L1T|EMTF") << "Format identifier bits in HD1d are incorrect";
0123 }
0124 if (GetHexBits(HD2a, 12, 15) != 10) {
0125 errors += 1;
0126 edm::LogError("L1T|EMTF") << "Format identifier bits in HD2a are incorrect";
0127 }
0128 if (GetHexBits(HD2b, 12, 15) != 10) {
0129 errors += 1;
0130 edm::LogError("L1T|EMTF") << "Format identifier bits in HD2b are incorrect";
0131 }
0132 if (GetHexBits(HD2c, 12, 15) != 10) {
0133 errors += 1;
0134 edm::LogError("L1T|EMTF") << "Format identifier bits in HD2c are incorrect";
0135 }
0136 if (GetHexBits(HD2d, 12, 15) != 10) {
0137 errors += 1;
0138 edm::LogError("L1T|EMTF") << "Format identifier bits in HD2d are incorrect";
0139 }
0140 if (GetHexBits(HD3a, 15, 15) != 1) {
0141 errors += 1;
0142 edm::LogError("L1T|EMTF") << "Format identifier bits in HD3a are incorrect";
0143 }
0144 if (GetHexBits(HD3b, 15, 15) != 0) {
0145 errors += 1;
0146 edm::LogError("L1T|EMTF") << "Format identifier bits in HD3b are incorrect";
0147 }
0148 if (GetHexBits(HD3c, 15, 15) != 0) {
0149 errors += 1;
0150 edm::LogError("L1T|EMTF") << "Format identifier bits in HD3c are incorrect";
0151 }
0152 if (GetHexBits(HD3d, 15, 15) != 0) {
0153 errors += 1;
0154 edm::LogError("L1T|EMTF") << "Format identifier bits in HD3d are incorrect";
0155 }
0156
0157 return errors;
0158 }
0159
0160 bool HeadersBlockUnpacker::unpack(const Block& block, UnpackerCollections* coll) {
0161
0162
0163
0164
0165
0166 auto payload = block.payload();
0167
0168
0169 l1t::emtf::AMC13Header AMC13Header_;
0170 l1t::emtf::MTF7Header MTF7Header_;
0171 l1t::emtf::EventHeader EventHeader_;
0172 for (int err = 0; err < checkFormat(block); err++)
0173 EventHeader_.add_format_error();
0174
0175
0176 uint16_t HD1a = payload[0];
0177 uint16_t HD1b = payload[1];
0178
0179 uint16_t HD1d = payload[3];
0180 uint16_t HD2a = payload[4];
0181 uint16_t HD2b = payload[5];
0182 uint16_t HD2c = payload[6];
0183 uint16_t HD2d = payload[7];
0184 uint16_t HD3a = payload[8];
0185 uint16_t HD3b = payload[9];
0186 uint16_t HD3c = payload[10];
0187 uint16_t HD3d = payload[11];
0188
0189
0190
0191 EMTFDaqOutCollection* res;
0192 res = static_cast<EMTFCollections*>(coll)->getEMTFDaqOuts();
0193
0194 EMTFDaqOut EMTFDaqOut_;
0195 res->push_back(EMTFDaqOut_);
0196 int iOut = res->size() - 1;
0197
0198
0199
0200
0201
0202 if ((res->at(iOut)).HasAMC13Header() == true) {
0203 (res->at(iOut)).add_format_error();
0204 edm::LogError("L1T|EMTF") << "Why is there already an AMC13Header object?";
0205 goto write_AMC13;
0206 }
0207
0208
0209
0210
0211
0212
0213
0214
0215
0216
0217
0218
0219
0220
0221
0222
0223
0224 write_AMC13:
0225
0226 (res->at(iOut)).set_AMC13Header(AMC13Header_);
0227
0228
0229
0230
0231
0232 if ((res->at(iOut)).HasMTF7Header() == true) {
0233 (res->at(iOut)).add_format_error();
0234 edm::LogError("L1T|EMTF") << "Why is there already an MTF7Header object?";
0235 goto write_MTF7;
0236 }
0237
0238
0239 MTF7Header_.set_amc_number(block.amc().getAMCNumber());
0240 MTF7Header_.set_bx_id(block.amc().getBX());
0241 MTF7Header_.set_orbit_number(block.amc().getOrbitNumber());
0242 MTF7Header_.set_board_id(block.amc().getBoardID());
0243 MTF7Header_.set_lv1_id(block.amc().getLV1ID());
0244 MTF7Header_.set_data_length(block.amc().getSize());
0245 MTF7Header_.set_user_id(block.amc().getUserData());
0246
0247
0248 write_MTF7:
0249
0250 (res->at(iOut)).set_MTF7Header(MTF7Header_);
0251
0252
0253
0254
0255
0256 if ((res->at(iOut)).HasEventHeader() == true) {
0257 (res->at(iOut)).add_format_error();
0258 edm::LogError("L1T|EMTF") << "Why is there already an EventHeader object?";
0259 goto write_Event;
0260 }
0261 if (EventHeader_.Format_errors() > 0)
0262 goto write_Event;
0263
0264 EventHeader_.set_l1a(GetHexBits(HD1a, 0, 11, HD1b, 0, 11));
0265 EventHeader_.set_l1a_BXN(GetHexBits(HD1d, 0, 11));
0266 EventHeader_.set_sp_TS(GetHexBits(HD2b, 8, 11));
0267 EventHeader_.set_endcap(GetHexBits(HD2b, 11, 11) ? -1 : 1);
0268 EventHeader_.set_sector(GetHexBits(HD2b, 8, 10) + 1);
0269 EventHeader_.set_sp_ersv(GetHexBits(HD2b, 5, 7));
0270 EventHeader_.set_sp_addr(GetHexBits(HD2b, 0, 4));
0271 EventHeader_.set_tbin(GetHexBits(HD2c, 8, 10));
0272 EventHeader_.set_ddm(GetHexBits(HD2c, 7, 7));
0273 EventHeader_.set_spa(GetHexBits(HD2c, 6, 6));
0274 EventHeader_.set_rpca(GetHexBits(HD2c, 5, 5));
0275 EventHeader_.set_skip(GetHexBits(HD2c, 4, 4));
0276 EventHeader_.set_rdy(GetHexBits(HD2c, 3, 3));
0277 EventHeader_.set_bsy(GetHexBits(HD2c, 2, 2));
0278 EventHeader_.set_osy(GetHexBits(HD2c, 1, 1));
0279 EventHeader_.set_wof(GetHexBits(HD2c, 0, 0));
0280 EventHeader_.set_me1a(GetHexBits(HD2d, 0, 11));
0281 EventHeader_.set_me1b(GetHexBits(HD3a, 0, 8));
0282 EventHeader_.set_me2(GetHexBits(HD3b, 0, 10));
0283 EventHeader_.set_me3(GetHexBits(HD3c, 0, 10));
0284 EventHeader_.set_me4(GetHexBits(HD3d, 0, 10));
0285 EventHeader_.set_cppf(GetHexBits(HD3a, 11, 14, HD3b, 11, 13));
0286 EventHeader_.set_cppf_crc(GetHexBits(HD3c, 11, 14, HD3d, 11, 13));
0287 EventHeader_.set_gem(GetHexBits(HD2a, 0, 6));
0288 EventHeader_.set_gem_crc(GetHexBits(HD2a, 7, 11, HD3a, 9, 10));
0289
0290
0291 write_Event:
0292
0293 (res->at(iOut)).set_EventHeader(EventHeader_);
0294
0295
0296 return true;
0297
0298 }
0299
0300
0301
0302
0303
0304
0305 }
0306 }
0307 }
0308
0309 DEFINE_L1T_UNPACKER(l1t::stage2::emtf::HeadersBlockUnpacker);
0310