Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 #ifndef EventFilter_L1TRawToDigi_Block_h
0002 #define EventFilter_L1TRawToDigi_Block_h
0003 
0004 #include <memory>
0005 #include <vector>
0006 
0007 #include "EventFilter/L1TRawToDigi/interface/AMCSpec.h"
0008 #include "DataFormats/L1Trigger/interface/BxBlock.h"
0009 
0010 namespace l1t {
0011   enum block_t { MP7 = 0, CTP7, MTF7 };
0012   namespace mtf7 {
0013     enum mtf7_block_t {
0014       // The "0b" prefix indicates binary; the block header id is stored in decimal.
0015       // Bits are the left-most bit (D15) of every 16-bit word in the format document.
0016       // Bottom-to-top in the document maps to left-to-right in each of the bit pattern.
0017       EvHd = 0b000111111111,  ///< Event Record Header   : block->header().getID() = 511
0018       CnBlk = 0b0010,         ///< Block of Counters     : block->header().getID() = 2
0019       ME = 0b0011,            ///< ME Data Record        : block->header().getID() = 3
0020       RPC = 0b0100,           ///< RPC Data Record       : block->header().getID() = 4
0021       GEM = 0b0111,           ///< GEM Data Record       : block->header().getID() = 7
0022       // FIXME, not currently defined... guess? JS - 01.07.20
0023       ME0 = 0b0110,        ///< ME0 Data Record       : block->header().getID() = 6
0024       SPOut = 0b01100101,  ///< SP Output Data Record : block->header().getID() = 101
0025       EvTr = 0b11111111    ///< Event Record Trailer  : block->header().getID() = 255
0026     };
0027   }
0028 
0029   class BlockHeader {
0030   public:
0031     BlockHeader(unsigned int id, unsigned int size, unsigned int capID = 0, unsigned int flags = 0, block_t type = MP7)
0032         : id_(id), size_(size), capID_(capID), flags_(flags), type_(type){};
0033     // Create a MP7 block header: everything is contained in the raw uint32
0034     BlockHeader(const uint32_t* data)
0035         : id_((data[0] >> ID_shift) & ID_mask),
0036           size_((data[0] >> size_shift) & size_mask),
0037           capID_((data[0] >> capID_shift) & capID_mask),
0038           flags_((data[0] >> flags_shift) & flags_mask),
0039           type_(MP7){};
0040 
0041     bool operator<(const BlockHeader& o) const { return getID() < o.getID(); };
0042 
0043     unsigned int getID() const { return id_; };
0044     unsigned int getSize() const { return size_; };
0045     unsigned int getCapID() const { return capID_; };
0046     unsigned int getFlags() const { return flags_; };
0047     block_t getType() const { return type_; };
0048 
0049     uint32_t raw() const;
0050 
0051   private:
0052     static constexpr unsigned CTP7_shift = 0;
0053     static constexpr unsigned CTP7_mask = 0xffff;
0054     static constexpr unsigned ID_shift = 24;
0055     static constexpr unsigned ID_mask = 0xff;
0056     static constexpr unsigned size_shift = 16;
0057     static constexpr unsigned size_mask = 0xff;
0058     static constexpr unsigned capID_shift = 8;
0059     static constexpr unsigned capID_mask = 0xff;
0060     static constexpr unsigned flags_shift = 0;
0061     static constexpr unsigned flags_mask = 0xff;
0062 
0063     unsigned int id_;
0064     unsigned int size_;
0065     unsigned int capID_;
0066     unsigned int flags_;
0067     block_t type_;
0068   };
0069 
0070   class Block {
0071   public:
0072     Block(const BlockHeader& h, const uint32_t* payload_start, const uint32_t* payload_end)
0073         : header_(h), payload_(payload_start, payload_end){};
0074     Block(unsigned int id,
0075           const std::vector<uint32_t>& payload,
0076           unsigned int capID = 0,
0077           unsigned int flags = 0,
0078           block_t type = MP7)
0079         : header_(id, payload.size(), capID, flags, type), payload_(payload){};
0080 
0081     bool operator<(const Block& o) const { return header() < o.header(); };
0082 
0083     inline unsigned int getSize() const { return payload_.size() + 1; };
0084 
0085     BlockHeader header() const { return header_; };
0086     const std::vector<uint32_t>& payload() const { return payload_; };
0087 
0088     void amc(const amc::Header& h) { amc_ = h; };
0089     amc::Header amc() const { return amc_; };
0090 
0091     BxBlocks getBxBlocks(unsigned int payloadWordsPerBx, bool bxHeader) const;
0092 
0093   private:
0094     BlockHeader header_;
0095     amc::Header amc_;
0096     std::vector<uint32_t> payload_;
0097   };
0098 
0099   typedef std::vector<Block> Blocks;
0100 
0101   class Payload {
0102   public:
0103     Payload(const uint32_t* data, const uint32_t* end) : data_(data), end_(end), algo_(0), infra_(0){};
0104     virtual ~Payload(){};
0105     virtual unsigned getAlgorithmFWVersion() const { return algo_; };
0106     virtual unsigned getInfrastructureFWVersion() const { return infra_; };
0107     virtual unsigned getHeaderSize() const = 0;
0108     // Read header from data_ and advance data_ to point behind the
0109     // header.  Called by getBlock(), which also checks that data_ !=
0110     // end_ before calling (assumes size of one 32 bit word).
0111     virtual BlockHeader getHeader() = 0;
0112     virtual std::unique_ptr<Block> getBlock();
0113 
0114   protected:
0115     const uint32_t* data_;
0116     const uint32_t* end_;
0117 
0118     unsigned algo_;
0119     unsigned infra_;
0120   };
0121 
0122   class MP7Payload : public Payload {
0123   public:
0124     MP7Payload(const uint32_t* data, const uint32_t* end, bool legacy_mc = false);
0125     unsigned getHeaderSize() const override { return 1; };
0126     BlockHeader getHeader() override;
0127   };
0128 
0129   class MTF7Payload : public Payload {
0130   public:
0131     MTF7Payload(const uint32_t* data, const uint32_t* end);
0132     // Unused methods - we override getBlock() instead
0133     unsigned getHeaderSize() const override { return 0; };
0134     BlockHeader getHeader() override { return BlockHeader(nullptr); };
0135     std::unique_ptr<Block> getBlock() override;
0136 
0137   private:
0138     // sizes in 16 bit words
0139     static constexpr unsigned header_size = 12;
0140     static constexpr unsigned counter_size = 4;
0141     static constexpr unsigned trailer_size = 8;
0142 
0143     /// Start of the EMTF DAQ payload, in number of 64-bit words
0144     static constexpr unsigned DAQ_PAYLOAD_OFFSET = 4;
0145     /// Maximum number of BX per MTF7 payload
0146     static constexpr unsigned MAX_BX_PER_PAYLOAD = 8;
0147     /// Maximum number of CSC words per MTF7 payload per bx: 9 links/sectors, 6 stations, 2 LCTs
0148     static constexpr unsigned ME_MAX_PER_BX = 108;
0149     /// Maximum number of RPC words per MTF7 payload per bx: 7 links/sectors, 6 stations, 2 segments
0150     static constexpr unsigned RPC_MAX_PER_BX = 84;
0151     /// Maximum number of GE1/1 words per MTF7 payload per bx: 7 GE1/1 links, 2 layers, 8 clusters
0152     static constexpr unsigned GE11_MAX_PER_BX = 112;
0153     /// TODO: Maximum number of GE2/1 words per MTF7 payload per bx: ?? GE2/1 links, 2 layers, ?? clusters
0154     static constexpr unsigned GE21_MAX_PER_BX = 0;
0155     /// TODO: Maximum number of ME0 words per MTF7 payload per bx: ?? ME0 links, ?? layers, ?? clusters
0156     static constexpr unsigned ME0_MAX_PER_BX = 0;
0157     /// Maximum number of SPz words per MTF7 payload per bx: 3 tracks, 2 words per track
0158     static constexpr unsigned SP_MAX_PER_BX = 6;
0159     /// Maximum number of 64-bit words in the EMTF payload
0160     static constexpr unsigned PAYLOAD_MAX_SIZE =
0161         MAX_BX_PER_PAYLOAD *
0162             (ME_MAX_PER_BX + RPC_MAX_PER_BX + GE11_MAX_PER_BX + GE21_MAX_PER_BX + ME0_MAX_PER_BX + SP_MAX_PER_BX) +
0163         (trailer_size / 4);
0164 
0165     static constexpr unsigned max_block_length_ = 3;         ///< maximum of the block length (64bits)
0166     static const std::vector<unsigned int> block_patterns_;  ///< bit patterns of the first bits (of 16bit words)
0167 
0168     int count(unsigned int pattern, unsigned int length) const;
0169     bool valid(unsigned int pattern) const;
0170   };
0171 
0172   class CTP7Payload : public Payload {
0173   public:
0174     CTP7Payload(const uint32_t* data, const uint32_t* end, amc::Header amcHeader);
0175     unsigned getHeaderSize() const override { return 2; };
0176     BlockHeader getHeader() override;
0177     std::unique_ptr<Block> getBlock() override;
0178 
0179   private:
0180     // FIXME check values
0181     static constexpr unsigned size_mask = 0xff;
0182     static constexpr unsigned size_shift = 16;
0183 
0184     unsigned size_;
0185     unsigned capId_;
0186     unsigned bx_per_l1a_;
0187     unsigned calo_bxid_;
0188     amc::Header amcHeader_;
0189   };
0190 }  // namespace l1t
0191 
0192 #endif