Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:15:09

0001 #ifndef EventFilter_L1TRawToDigi_AMC_SPEC__h
0002 #define EventFilter_L1TRawToDigi_AMC_SPEC__h
0003 
0004 #include <memory>
0005 #include <vector>
0006 #include <cstdint>
0007 
0008 namespace amc {
0009   static const unsigned int split_block_size = 0x1000;
0010 
0011   // The AMC header within an AMC13 payload block.  Should optimally only
0012   // be used when packing/unpacking AMC payloads into AMC13 blocks.
0013   class BlockHeader {
0014   public:
0015     BlockHeader() : data_(0){};
0016     BlockHeader(const uint64_t *data) : data_(data[0]){};
0017     // size is the total size of the AMC payload, not just of the
0018     // block
0019     BlockHeader(unsigned int amc_no, unsigned int board_id, unsigned int size, unsigned int block = 0);
0020 
0021     operator uint64_t() const { return data_; };
0022 
0023     inline uint64_t raw() const { return data_; };
0024 
0025     unsigned int getBlocks() const;
0026     unsigned int getBlockSize() const;
0027 
0028     inline unsigned int getAMCNumber() const { return (data_ >> AmcNo_shift) & AmcNo_mask; };
0029     inline unsigned int getBoardID() const { return (data_ >> BoardID_shift) & BoardID_mask; };
0030     inline unsigned int getSize() const { return (data_ >> Size_shift) & Size_mask; };
0031     inline unsigned int getMore() const { return (data_ >> More_bit_shift) & 1; };
0032     inline unsigned int getSegmented() const { return (data_ >> Segmented_bit_shift) & 1; };
0033 
0034     inline unsigned int validCRC() const { return (data_ >> CRC_bit_shift) & 1; };
0035 
0036   private:
0037     static const unsigned int Size_shift = 32;
0038     static const unsigned int Size_mask = 0xffffff;
0039     static const unsigned int BlkNo_shift = 20;
0040     static const unsigned int BlkNo_mask = 0xff;
0041     static const unsigned int AmcNo_shift = 16;
0042     static const unsigned int AmcNo_mask = 0xf;
0043     static const unsigned int BoardID_shift = 0;
0044     static const unsigned int BoardID_mask = 0xffff;
0045 
0046     static const unsigned int Length_bit_shift = 62;
0047     static const unsigned int More_bit_shift = 61;
0048     static const unsigned int Segmented_bit_shift = 60;
0049     static const unsigned int Enabled_bit_shift = 59;
0050     static const unsigned int Present_bit_shift = 58;
0051     static const unsigned int Valid_bit_shift = 57;
0052     static const unsigned int CRC_bit_shift = 56;
0053 
0054     uint64_t data_;
0055   };
0056 
0057   // The actual header attached to the AMC payload, also contained in the
0058   // AMC payload of an AMC13 packet/block.
0059   class Header {
0060   public:
0061     Header() : data0_(0), data1_(0){};
0062     Header(const uint64_t *data) : data0_(data[0]), data1_(data[1]){};
0063     Header(unsigned int amc_no,
0064            unsigned int lv1_id,
0065            unsigned int bx_id,
0066            unsigned int size,
0067            unsigned int or_n,
0068            unsigned int board_id,
0069            unsigned int user);
0070 
0071     inline unsigned int getAMCNumber() const { return (data0_ >> AmcNo_shift) & AmcNo_mask; };
0072     inline unsigned int getBoardID() const { return (data1_ >> BoardID_shift) & BoardID_mask; };
0073     inline unsigned int getLV1ID() const { return (data0_ >> LV1ID_shift) & LV1ID_mask; };
0074     inline unsigned int getBX() const { return (data0_ >> BX_shift) & BX_mask; };
0075     inline unsigned int getOrbitNumber() const { return (data1_ >> OrN_shift) & OrN_mask; };
0076     inline unsigned int getSize() const { return (data0_ >> Size_shift) & Size_mask; };
0077     inline unsigned int getUserData() const { return (data1_ >> User_shift) & User_mask; };
0078 
0079     std::vector<uint64_t> raw() const { return {data0_, data1_}; };
0080 
0081   private:
0082     static const unsigned int Size_shift = 0;
0083     static const unsigned int Size_mask = 0xfffff;
0084     static const unsigned int BX_shift = 20;
0085     static const unsigned int BX_mask = 0xfff;
0086     static const unsigned int LV1ID_shift = 32;
0087     static const unsigned int LV1ID_mask = 0xffffff;
0088     static const unsigned int AmcNo_shift = 56;
0089     static const unsigned int AmcNo_mask = 0xf;
0090 
0091     static const unsigned int BoardID_shift = 0;
0092     static const unsigned int BoardID_mask = 0xffff;
0093     static const unsigned int OrN_shift = 16;
0094     static const unsigned int OrN_mask = 0xffff;
0095     static const unsigned int User_shift = 32;
0096     static const unsigned int User_mask = 0xffffffff;
0097 
0098     uint64_t data0_;
0099     uint64_t data1_;
0100   };
0101 
0102   class Trailer {
0103   public:
0104     Trailer() : data_(0){};
0105     Trailer(const uint64_t *data) : data_(data[0]){};
0106     Trailer(unsigned int crc, unsigned int lv1_id, unsigned int size);
0107 
0108     inline unsigned int getCRC() const { return (data_ >> CRC_shift) & CRC_mask; };
0109     inline unsigned int getLV1ID() const { return (data_ >> LV1ID_shift) & LV1ID_mask; };
0110     inline unsigned int getSize() const { return (data_ >> Size_shift) & Size_mask; };
0111 
0112     uint64_t raw() const { return data_; }
0113     bool check(unsigned int crc, unsigned int lv1_id, unsigned int size, bool mtf7_mode = false) const;
0114 
0115     static void writeCRC(const uint64_t *start, uint64_t *end);
0116 
0117   private:
0118     static const unsigned int Size_shift = 0;
0119     static const unsigned int Size_mask = 0xfffff;
0120     static const unsigned int LV1ID_shift = 24;
0121     static const unsigned int LV1ID_mask = 0xff;
0122     static const unsigned int CRC_shift = 32;
0123     static const unsigned int CRC_mask = 0xffffffff;
0124 
0125     uint64_t data_;
0126   };
0127 
0128   class Packet {
0129   public:
0130     Packet(const uint64_t *d) : block_header_(d){};
0131     Packet(unsigned int amc,
0132            unsigned int board,
0133            unsigned int lv1id,
0134            unsigned int orbit,
0135            unsigned int bx,
0136            const std::vector<uint64_t> &load,
0137            unsigned int user = 0);
0138 
0139     // Add payload fragment from an AMC13 block to the AMC packet
0140     void addPayload(const uint64_t *, unsigned int);
0141     // To be called after the last payload addition.  Removes header
0142     // and trailer from the actual paylod.  Also performs
0143     // cross-checks for data consistency.
0144     void finalize(unsigned int lv1, unsigned int bx, bool legacy_mc = false, bool mtf7_mode = false);
0145 
0146     std::vector<uint64_t> block(unsigned int id) const;
0147     std::unique_ptr<uint64_t[]> data();
0148     BlockHeader blockHeader(unsigned int block = 0) const { return block_header_; };
0149     Header header() const { return header_; };
0150     Trailer trailer() const { return trailer_; };
0151 
0152     inline unsigned int blocks() const { return block_header_.getBlocks(); };
0153     // Returns the size of the payload _without_ the headers
0154     inline unsigned int size() const { return payload_.size() - 3; };
0155 
0156   private:
0157     BlockHeader block_header_;
0158     Header header_;
0159     Trailer trailer_;
0160 
0161     std::vector<uint64_t> payload_;
0162   };
0163 }  // namespace amc
0164 
0165 #endif