Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:26:04

0001 // Code to unpack the AMC13 trailer, "AMC data trailer", and "Event Record Trailer"
0002 
0003 #include "EventFilter/L1TRawToDigi/plugins/UnpackerFactory.h"
0004 
0005 #include "EMTFCollections.h"
0006 #include "EMTFUnpackerTools.h"
0007 
0008 // This is the "header" - no EMTFBlockTrailers.h file is needed
0009 namespace l1t {
0010   namespace stage2 {
0011     namespace emtf {
0012 
0013       class TrailersBlockUnpacker : public Unpacker {  // "TrailersBlockUnpacker" inherits from "Unpacker"
0014       public:
0015         virtual int checkFormat(const Block& block);
0016         bool unpack(const Block& block,
0017                     UnpackerCollections* coll) override;  // Apparently it's always good to use override in C++
0018         // virtual bool packBlock(const Block& block, UnpackerCollections *coll) override;
0019       };
0020 
0021       // class TrailersBlockPacker : public Packer { // "TrailersBlockPacker" inherits from "Packer"
0022       // public:
0023       //    virtual bool unpack(const Block& block, UnpackerCollections *coll) override; // Apparently it's always good to use override in C++
0024       // };
0025 
0026     }  // namespace emtf
0027   }    // namespace stage2
0028 }  // namespace l1t
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         //Check the number of 16-bit words
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         //Check that each word is 16 bits
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         // Assign payload to 16-bit words
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         //Check Format
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         // std::cout << "Inside EMTFBlockTrailers.cc: unpack" << std::endl;
0127 
0128         // Get the payload for this block, made up of 16-bit words (0xffff)
0129         // Format defined in MTF7Payload::getBlock() in src/Block.cc
0130         // payload[0] = bits 0-15, payload[1] = 16-31, payload[3] = 32-47, etc.
0131         auto payload = block.payload();
0132 
0133         // Check Format of Payload
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         // Assign payload to 16-bit words
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         // res is a pointer to a collection of EMTFDaqOut class objects
0151         // There is one EMTFDaqOut for each MTF7 (60 deg. sector) in the event
0152         EMTFDaqOutCollection* res;
0153         res = static_cast<EMTFCollections*>(coll)->getEMTFDaqOuts();
0154         int iOut = res->size() - 1;
0155 
0156         /////////////////////////////////////////////
0157         // Unpack the Event Record trailer information
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         // EventTrailer_.set_ddcsr_bid ( GetHexBits(TR2a,  0,  4, TR1c,  0, 8) ); // Probably incorrect
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         // EventTrailer_.set_dataword(uint64_t bits)  { dataword = bits;  };
0188 
0189         (res->at(iOut)).set_EventTrailer(EventTrailer_);
0190 
0191         /////////////////////////////////////
0192         // Unpack the MTF7 trailer information
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         // // AMC trailer info defined in interface/AMCSpec.h ... but not implemented in interface/Block.h?
0201         // MTF7Trailer_.set_crc_32( GetHexBits(payload[], , ) );
0202         // MTF7Trailer_.set_lv1_id( GetHexBits(payload[], , ) );
0203         // MTF7Trailer_.set_data_length( GetHexBits(payload[], , ) );
0204         // MTF7Trailer_.set_dataword(uint64_t bits)  { dataword = bits;    };
0205 
0206         (res->at(iOut)).set_MTF7Trailer(MTF7Trailer_);
0207 
0208         //////////////////////////////////////
0209         // Unpack the AMC13 trailer information
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         // TODO: Write functions in interface/AMC13Spec.h (as in AMCSpec.h) to extract all AMC13 header and trailer info
0218         // TODO: Edit interface/Block.h to have a amc13() function similar to amc()
0219 
0220         // AMC13Trailer_.set_evt_lgth( GetHexBits(payload[], , ) );
0221         // AMC13Trailer_.set_crc16( GetHexBits(payload[], , ) );
0222         // AMC13Trailer_.set_evt_stat( GetHexBits(payload[], , ) );
0223         // AMC13Trailer_.set_tts( GetHexBits(payload[], , ) );
0224         // AMC13Trailer_.set_c( GetHexBits(payload[], , ) );
0225         // AMC13Trailer_.set_f( GetHexBits(payload[], , ) );
0226         // AMC13Trailer_.set_t( GetHexBits(payload[], , ) );
0227         // AMC13Trailer_.set_r( GetHexBits(payload[], , ) );
0228         // AMC13Trailer_.set_dataword(uint64_t bits)  { dataword = bits; };
0229 
0230         (res->at(iOut)).set_AMC13Trailer(AMC13Trailer_);
0231 
0232         // Finished with unpacking trailers
0233         return true;
0234 
0235       }  // End bool TrailersBlockUnpacker::unpack
0236 
0237       // bool TrailersBlockPacker::pack(const Block& block, UnpackerCollections *coll) {
0238       //    std::cout << "Inside TrailersBlockPacker::pack" << std::endl;
0239       //    return true;
0240       // } // End bool TrailersBlockPacker::pack
0241 
0242     }  // End namespace emtf
0243   }    // End namespace stage2
0244 }  // End namespace l1t
0245 
0246 DEFINE_L1T_UNPACKER(l1t::stage2::emtf::TrailersBlockUnpacker);
0247 // DEFINE_L1T_PACKER(l1t::stage2::TrailersBlockPacker);