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 TrailersBlockUnpacker : 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 TrailersBlockUnpacker::checkFormat(const Block& block) {
0035 auto payload = block.payload();
0036 int errors = 0;
0037
0038
0039 if (payload.size() != 8) {
0040 errors += 1;
0041 edm::LogError("L1T|EMTF") << "Payload size in 'AMC Data Trailer' 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 Trailer'";
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 Trailer'";
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 Trailer'";
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 Trailer'";
0060 }
0061 if (GetHexBits(payload[3], 16, 31) != 0) {
0062 errors += 1;
0063 edm::LogError("L1T|EMTF") << "Payload[3] has more than 16 bits in 'AMC Data Trailer'";
0064 }
0065 if (GetHexBits(payload[3], 16, 31) != 0) {
0066 errors += 1;
0067 edm::LogError("L1T|EMTF") << "Payload[3] has more than 16 bits in 'AMC Data Trailer'";
0068 }
0069 if (GetHexBits(payload[3], 16, 31) != 0) {
0070 errors += 1;
0071 edm::LogError("L1T|EMTF") << "Payload[3] has more than 16 bits in 'AMC Data Trailer'";
0072 }
0073 if (GetHexBits(payload[3], 16, 31) != 0) {
0074 errors += 1;
0075 edm::LogError("L1T|EMTF") << "Payload[3] has more than 16 bits in 'AMC Data Trailer'";
0076 }
0077
0078
0079 uint16_t TR1a = payload[0];
0080 uint16_t TR1b = payload[1];
0081 uint16_t TR1c = payload[2];
0082 uint16_t TR1d = payload[3];
0083 uint16_t TR2a = payload[4];
0084 uint16_t TR2b = payload[5];
0085 uint16_t TR2c = payload[6];
0086 uint16_t TR2d = payload[7];
0087
0088
0089 if (GetHexBits(TR1a, 12, 15) != 15) {
0090 errors += 1;
0091 edm::LogError("L1T|EMTF") << "Format identifier bits in TR1a are incorrect";
0092 }
0093 if (GetHexBits(TR1b, 12, 15) != 15) {
0094 errors += 1;
0095 edm::LogError("L1T|EMTF") << "Format identifier bits in TR1b are incorrect";
0096 }
0097 if (GetHexBits(TR1c, 12, 15) != 15) {
0098 errors += 1;
0099 edm::LogError("L1T|EMTF") << "Format identifier bits in TR1c are incorrect";
0100 }
0101 if (GetHexBits(TR1d, 12, 15) != 15) {
0102 errors += 1;
0103 edm::LogError("L1T|EMTF") << "Format identifier bits in TR1d are incorrect";
0104 }
0105 if (GetHexBits(TR2a, 12, 15) != 14) {
0106 errors += 1;
0107 edm::LogError("L1T|EMTF") << "Format identifier bits in TR2a are incorrect";
0108 }
0109 if (GetHexBits(TR2b, 12, 15) != 14) {
0110 errors += 1;
0111 edm::LogError("L1T|EMTF") << "Format identifier bits in TR2b are incorrect";
0112 }
0113 if (GetHexBits(TR2c, 12, 15) != 14) {
0114 errors += 1;
0115 edm::LogError("L1T|EMTF") << "Format identifier bits in TR2c are incorrect";
0116 }
0117 if (GetHexBits(TR2d, 12, 15) != 14) {
0118 errors += 1;
0119 edm::LogError("L1T|EMTF") << "Format identifier bits in TR2d are incorrect";
0120 }
0121
0122 return errors;
0123 }
0124
0125 bool TrailersBlockUnpacker::unpack(const Block& block, UnpackerCollections* coll) {
0126
0127
0128
0129
0130
0131 auto payload = block.payload();
0132
0133
0134 l1t::emtf::AMC13Trailer AMC13Trailer_;
0135 l1t::emtf::MTF7Trailer MTF7Trailer_;
0136 l1t::emtf::EventTrailer EventTrailer_;
0137 for (int err = 0; err < checkFormat(block); err++)
0138 EventTrailer_.add_format_error();
0139
0140
0141 uint16_t TR1a = payload[0];
0142 uint16_t TR1b = payload[1];
0143 uint16_t TR1c = payload[2];
0144 uint16_t TR1d = payload[3];
0145 uint16_t TR2a = payload[4];
0146 uint16_t TR2b = payload[5];
0147 uint16_t TR2c = payload[6];
0148 uint16_t TR2d = payload[7];
0149
0150
0151
0152 EMTFDaqOutCollection* res;
0153 res = static_cast<EMTFCollections*>(coll)->getEMTFDaqOuts();
0154 int iOut = res->size() - 1;
0155
0156
0157
0158
0159
0160 if ((res->at(iOut)).HasEventTrailer() == true) {
0161 (res->at(iOut)).add_format_error();
0162 edm::LogError("L1T|EMTF") << "Why is there already an EventTrailer object?";
0163 }
0164
0165 EventTrailer_.set_l1a(GetHexBits(TR1a, 0, 7));
0166 EventTrailer_.set_ddcsr_lf(GetHexBits(TR1a, 8, 11, TR1b, 8, 11));
0167
0168 EventTrailer_.set_lfff(GetHexBits(TR1b, 7, 7));
0169
0170
0171 EventTrailer_.set_mm(GetHexBits(TR1c, 0, 3));
0172 EventTrailer_.set_yy(GetHexBits(TR1c, 4, 7));
0173 EventTrailer_.set_bb(GetHexBits(TR1c, 8, 8));
0174
0175 EventTrailer_.set_spcsr_scc(GetHexBits(TR1d, 0, 11));
0176
0177 EventTrailer_.set_dd(GetHexBits(TR2a, 0, 4));
0178
0179 EventTrailer_.set_sp_padr(GetHexBits(TR2b, 0, 4));
0180 EventTrailer_.set_sp_ersv(GetHexBits(TR2b, 5, 7));
0181 EventTrailer_.set_sp_ladr(GetHexBits(TR2b, 8, 11));
0182
0183 EventTrailer_.set_crc22(GetHexBits(TR2c, 0, 10, TR2d, 0, 10));
0184 EventTrailer_.set_lp(GetHexBits(TR2c, 11, 11));
0185 EventTrailer_.set_hp(GetHexBits(TR2d, 11, 11));
0186
0187
0188
0189 (res->at(iOut)).set_EventTrailer(EventTrailer_);
0190
0191
0192
0193
0194
0195 if ((res->at(iOut)).HasMTF7Trailer() == true) {
0196 (res->at(iOut)).add_format_error();
0197 edm::LogError("L1T|EMTF") << "Why is there already an MTF7Trailer object?";
0198 }
0199
0200
0201
0202
0203
0204
0205
0206 (res->at(iOut)).set_MTF7Trailer(MTF7Trailer_);
0207
0208
0209
0210
0211
0212 if ((res->at(iOut)).HasAMC13Trailer() == true) {
0213 (res->at(iOut)).add_format_error();
0214 edm::LogError("L1T|EMTF") << "Why is there already an AMC13Trailer object?";
0215 }
0216
0217
0218
0219
0220
0221
0222
0223
0224
0225
0226
0227
0228
0229
0230 (res->at(iOut)).set_AMC13Trailer(AMC13Trailer_);
0231
0232
0233 return true;
0234
0235 }
0236
0237
0238
0239
0240
0241
0242 }
0243 }
0244 }
0245
0246 DEFINE_L1T_UNPACKER(l1t::stage2::emtf::TrailersBlockUnpacker);
0247