CMS 3D CMS Logo

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
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
static constexpr unsigned flags_mask
Definition: BxBlock.h:42
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
BxBlock(unsigned int id, unsigned int totalBx, const std::vector< uint32_t > &payload, unsigned int flags=0)
Definition: BxBlock.h:63
BxBlockHeader(const uint32_t raw)
Definition: BxBlock.h:16
BxBlockHeader(unsigned int id, unsigned int totalBx, unsigned int flags=0)
Definition: BxBlock.h:13
unsigned int flags_
Definition: BxBlock.h:46
unsigned int getFlags() const
Definition: BxBlock.h:28
static constexpr unsigned n_words
Definition: BxBlock.h:36
BxBlock(std::vector< uint32_t >::const_iterator bx_start, std::vector< uint32_t >::const_iterator bx_end)
Definition: BxBlock.h:51
delete x;
Definition: CaloConfig.h:22
static constexpr unsigned id_mask
Definition: BxBlock.h:38
BxBlock(const BxBlockHeader &h, std::vector< uint32_t >::const_iterator payload_start, std::vector< uint32_t >::const_iterator payload_end)
Definition: BxBlock.h:53
unsigned int totalBx_
Definition: BxBlock.h:45
bool operator<(const BxBlockHeader &o) const
Definition: BxBlock.h:21
bool operator<(const BxBlock &o) const
Definition: BxBlock.h:67
static constexpr unsigned id_shift
Definition: BxBlock.h:37
unsigned int getTotalBx() const
Definition: BxBlock.h:27
BxBlockHeader header() const
Definition: BxBlock.h:71
static constexpr unsigned flags_shift
Definition: BxBlock.h:41
static constexpr unsigned totalBx_mask
Definition: BxBlock.h:40
unsigned int getId() const
Definition: BxBlock.h:26
std::vector< BxBlock > BxBlocks
Definition: BxBlock.h:79
uint32_t raw() const
Definition: BxBlock.h:30
static constexpr unsigned totalBx_shift
Definition: BxBlock.h:39
unsigned int getSize() const
Definition: BxBlock.h:69
unsigned int id_
Definition: BxBlock.h:44
int getBx() const
Definition: BxBlock.h:23
std::vector< uint32_t > payload() const
Definition: BxBlock.h:72
std::vector< uint32_t > payload_
Definition: BxBlock.h:76
The Signals That Services Can Subscribe To This is based on ActivityRegistry h
Helper function to determine trigger accepts.
Definition: Activities.doc:4
BxBlockHeader header_
Definition: BxBlock.h:72