Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:04:37

0001 #ifndef DataFormats_L1Trigger_BxBlock_h
0002 #define DataFormats_L1Trigger_BxBlock_h
0003 
0004 #include <algorithm>
0005 #include <memory>
0006 #include <vector>
0007 #include <cmath>
0008 
0009 namespace l1t {
0010   class BxBlockHeader {
0011   public:
0012     BxBlockHeader() : id_(0), totalBx_(0), flags_(0){};
0013     BxBlockHeader(unsigned int id, unsigned int totalBx, unsigned int flags = 0)
0014         : id_(id), totalBx_(totalBx), flags_(flags){};
0015     // Create a BX header: everything is contained in the raw uint32
0016     BxBlockHeader(const uint32_t raw)
0017         : id_(((raw >> id_shift) & id_mask) / n_words),
0018           totalBx_(((raw >> totalBx_shift) & totalBx_mask) / n_words),
0019           flags_((raw >> flags_shift) & flags_mask){};
0020 
0021     bool operator<(const BxBlockHeader& o) const { return getBx() < o.getBx(); };
0022 
0023     inline int getBx() const {
0024       return (int)id_ + std::min(0, 1 - (int)totalBx_ % 2 - (int)std::floor(totalBx_ / 2.));
0025     };  // In case of an even totalBx_ the BX range should be like, e.g. -3 to +4
0026     inline unsigned int getId() const { return id_; };
0027     inline unsigned int getTotalBx() const { return totalBx_; };
0028     inline unsigned int getFlags() const { return flags_; };
0029 
0030     inline uint32_t raw() const {
0031       return (((id_ & id_mask) << id_shift) * n_words) | (((totalBx_ & totalBx_mask) << totalBx_shift) * n_words) |
0032              ((flags_ & flags_mask) << flags_shift);
0033     };
0034 
0035   private:
0036     static constexpr unsigned n_words = 6;  // every link transmits 6 32 bit words per bx
0037     static constexpr unsigned id_shift = 24;
0038     static constexpr unsigned id_mask = 0xff;
0039     static constexpr unsigned totalBx_shift = 16;
0040     static constexpr unsigned totalBx_mask = 0xff;
0041     static constexpr unsigned flags_shift = 0;
0042     static constexpr unsigned flags_mask = 0xffff;
0043 
0044     unsigned int id_;
0045     unsigned int totalBx_;
0046     unsigned int flags_;
0047   };
0048 
0049   class BxBlock {
0050   public:
0051     BxBlock(std::vector<uint32_t>::const_iterator bx_start, std::vector<uint32_t>::const_iterator bx_end)
0052         : header_(*bx_start), payload_(bx_start + 1, bx_end){};
0053     BxBlock(const BxBlockHeader& h,
0054             std::vector<uint32_t>::const_iterator payload_start,
0055             std::vector<uint32_t>::const_iterator payload_end)
0056         : header_(h), payload_(payload_start, payload_end){};
0057     BxBlock(unsigned int id,
0058             unsigned int totalBx,
0059             std::vector<uint32_t>::const_iterator payload_start,
0060             std::vector<uint32_t>::const_iterator payload_end,
0061             unsigned int flags = 0)
0062         : header_(id, totalBx, flags), payload_(payload_start, payload_end){};
0063     BxBlock(unsigned int id, unsigned int totalBx, const std::vector<uint32_t>& payload, unsigned int flags = 0)
0064         : header_(id, totalBx, flags), payload_(payload){};
0065     ~BxBlock(){};
0066 
0067     bool operator<(const BxBlock& o) const { return header() < o.header(); };
0068 
0069     inline unsigned int getSize() const { return payload_.size(); };
0070 
0071     BxBlockHeader header() const { return header_; };
0072     std::vector<uint32_t> payload() const { return payload_; };
0073 
0074   private:
0075     BxBlockHeader header_;
0076     std::vector<uint32_t> payload_;
0077   };
0078 
0079   typedef std::vector<BxBlock> BxBlocks;
0080 }  // namespace l1t
0081 
0082 #endif