CMS 3D CMS Logo

BxBlock.h
Go to the documentation of this file.
1 #ifndef DataFormats_L1Trigger_BxBlock_h
2 #define DataFormats_L1Trigger_BxBlock_h
3 
4 #include <algorithm>
5 #include <memory>
6 #include <vector>
7 #include <cmath>
8 
9 namespace l1t {
10  class BxBlockHeader {
11  public:
12  BxBlockHeader() : id_(0), totalBx_(0), flags_(0){};
13  BxBlockHeader(unsigned int id, unsigned int totalBx, unsigned int flags = 0)
14  : id_(id), totalBx_(totalBx), flags_(flags){};
15  // Create a BX header: everything is contained in the raw uint32
16  BxBlockHeader(const uint32_t raw)
17  : id_(((raw >> id_shift) & id_mask) / n_words),
19  flags_((raw >> flags_shift) & flags_mask){};
20 
21  bool operator<(const BxBlockHeader& o) const { return getBx() < o.getBx(); };
22 
23  inline int getBx() const {
24  return (int)id_ + std::min(0, 1 - (int)totalBx_ % 2 - (int)std::floor(totalBx_ / 2.));
25  }; // In case of an even totalBx_ the BX range should be like, e.g. -3 to +4
26  inline unsigned int getId() const { return id_; };
27  inline unsigned int getTotalBx() const { return totalBx_; };
28  inline unsigned int getFlags() const { return flags_; };
29 
30  inline uint32_t raw() const {
31  return (((id_ & id_mask) << id_shift) * n_words) | (((totalBx_ & totalBx_mask) << totalBx_shift) * n_words) |
32  ((flags_ & flags_mask) << flags_shift);
33  };
34 
35  private:
36  static constexpr unsigned n_words = 6; // every link transmits 6 32 bit words per bx
37  static constexpr unsigned id_shift = 24;
38  static constexpr unsigned id_mask = 0xff;
39  static constexpr unsigned totalBx_shift = 16;
40  static constexpr unsigned totalBx_mask = 0xff;
41  static constexpr unsigned flags_shift = 0;
42  static constexpr unsigned flags_mask = 0xffff;
43 
44  unsigned int id_;
45  unsigned int totalBx_;
46  unsigned int flags_;
47  };
48 
49  class BxBlock {
50  public:
51  BxBlock(std::vector<uint32_t>::const_iterator bx_start, std::vector<uint32_t>::const_iterator bx_end)
52  : header_(*bx_start), payload_(bx_start + 1, bx_end){};
54  std::vector<uint32_t>::const_iterator payload_start,
55  std::vector<uint32_t>::const_iterator payload_end)
56  : header_(h), payload_(payload_start, payload_end){};
57  BxBlock(unsigned int id,
58  unsigned int totalBx,
59  std::vector<uint32_t>::const_iterator payload_start,
60  std::vector<uint32_t>::const_iterator payload_end,
61  unsigned int flags = 0)
62  : header_(id, totalBx, flags), payload_(payload_start, payload_end){};
63  BxBlock(unsigned int id, unsigned int totalBx, const std::vector<uint32_t>& payload, unsigned int flags = 0)
64  : header_(id, totalBx, flags), payload_(payload){};
65  ~BxBlock(){};
66 
67  bool operator<(const BxBlock& o) const { return header() < o.header(); };
68 
69  inline unsigned int getSize() const { return payload_.size(); };
70 
71  BxBlockHeader header() const { return header_; };
72  std::vector<uint32_t> payload() const { return payload_; };
73 
74  private:
76  std::vector<uint32_t> payload_;
77  };
78 
79  typedef std::vector<BxBlock> BxBlocks;
80 } // namespace l1t
81 
82 #endif
l1t::BxBlockHeader::flags_
unsigned int flags_
Definition: BxBlock.h:46
l1t::BxBlock::header
BxBlockHeader header() const
Definition: BxBlock.h:71
l1t::BxBlock::BxBlock
BxBlock(unsigned int id, unsigned int totalBx, const std::vector< uint32_t > &payload, unsigned int flags=0)
Definition: BxBlock.h:63
min
T min(T a, T b)
Definition: MathUtil.h:58
l1t::BxBlockHeader::totalBx_shift
static constexpr unsigned totalBx_shift
Definition: BxBlock.h:39
l1t::BxBlock::operator<
bool operator<(const BxBlock &o) const
Definition: BxBlock.h:67
l1t::BxBlockHeader::raw
uint32_t raw() const
Definition: BxBlock.h:30
l1t::BxBlock::payload
std::vector< uint32_t > payload() const
Definition: BxBlock.h:72
EcalTangentSkim_cfg.o
o
Definition: EcalTangentSkim_cfg.py:42
l1t::BxBlockHeader::BxBlockHeader
BxBlockHeader(const uint32_t raw)
Definition: BxBlock.h:16
l1t::BxBlockHeader::flags_mask
static constexpr unsigned flags_mask
Definition: BxBlock.h:42
l1t::BxBlockHeader::getFlags
unsigned int getFlags() const
Definition: BxBlock.h:28
l1t::BxBlockHeader::getTotalBx
unsigned int getTotalBx() const
Definition: BxBlock.h:27
l1t::BxBlockHeader::id_shift
static constexpr unsigned id_shift
Definition: BxBlock.h:37
l1t::BxBlock::BxBlock
BxBlock(unsigned int id, unsigned int totalBx, std::vector< uint32_t >::const_iterator payload_start, std::vector< uint32_t >::const_iterator payload_end, unsigned int flags=0)
Definition: BxBlock.h:57
l1t::BxBlock::~BxBlock
~BxBlock()
Definition: BxBlock.h:65
l1t::BxBlockHeader::flags_shift
static constexpr unsigned flags_shift
Definition: BxBlock.h:41
h
l1t::BxBlockHeader::getBx
int getBx() const
Definition: BxBlock.h:23
l1t::BxBlockHeader::totalBx_mask
static constexpr unsigned totalBx_mask
Definition: BxBlock.h:40
l1t::BxBlockHeader::BxBlockHeader
BxBlockHeader()
Definition: BxBlock.h:12
l1t::BxBlockHeader::n_words
static constexpr unsigned n_words
Definition: BxBlock.h:36
l1t::BxBlock::header_
BxBlockHeader header_
Definition: BxBlock.h:72
l1t
delete x;
Definition: CaloConfig.h:22
l1t::BxBlock::BxBlock
BxBlock(const BxBlockHeader &h, std::vector< uint32_t >::const_iterator payload_start, std::vector< uint32_t >::const_iterator payload_end)
Definition: BxBlock.h:53
l1t::BxBlockHeader::totalBx_
unsigned int totalBx_
Definition: BxBlock.h:45
l1t::BxBlockHeader::id_
unsigned int id_
Definition: BxBlock.h:44
l1t::BxBlock::payload_
std::vector< uint32_t > payload_
Definition: BxBlock.h:76
l1t::BxBlock
Definition: BxBlock.h:49
l1t::BxBlockHeader::getId
unsigned int getId() const
Definition: BxBlock.h:26
l1t::BxBlockHeader::operator<
bool operator<(const BxBlockHeader &o) const
Definition: BxBlock.h:21
l1t::BxBlock::getSize
unsigned int getSize() const
Definition: BxBlock.h:69
triggerObjects_cff.id
id
Definition: triggerObjects_cff.py:29
l1t::BxBlockHeader::id_mask
static constexpr unsigned id_mask
Definition: BxBlock.h:38
HLT_FULL_cff.flags
flags
Definition: HLT_FULL_cff.py:13150
l1t::BxBlockHeader
Definition: BxBlock.h:10
l1t::BxBlock::BxBlock
BxBlock(std::vector< uint32_t >::const_iterator bx_start, std::vector< uint32_t >::const_iterator bx_end)
Definition: BxBlock.h:51
l1t::BxBlockHeader::BxBlockHeader
BxBlockHeader(unsigned int id, unsigned int totalBx, unsigned int flags=0)
Definition: BxBlock.h:13
l1t::BxBlocks
std::vector< BxBlock > BxBlocks
Definition: BxBlock.h:79