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 <memory>
5 #include <vector>
6 #include <cmath>
7 
8 namespace l1t {
9  class BxBlockHeader {
10  public:
11  BxBlockHeader() : id_(0), totalBx_(0), flags_(0) {};
12  BxBlockHeader(unsigned int id, unsigned int totalBx, unsigned int flags=0) : id_(id), totalBx_(totalBx), flags_(flags) {};
13  // Create a BX header: everything is contained in the raw uint32
14  BxBlockHeader(const uint32_t raw) : id_(((raw >> id_shift) & id_mask) / n_words)
15  , totalBx_(((raw >> totalBx_shift) & totalBx_mask) / n_words)
16  , flags_((raw >> flags_shift) & flags_mask) {};
17 
18  bool operator<(const BxBlockHeader& o) const { return getBx() < o.getBx(); };
19 
20  inline int getBx() const { return (int)id_ - (int)std::floor(totalBx_/2.); };
21  inline unsigned int getId() const { return id_; };
22  inline unsigned int getTotalBx() const { return totalBx_; };
23  inline unsigned int getFlags() const { return flags_; };
24 
25  inline uint32_t raw() const { return (((id_ & id_mask) << id_shift) * n_words)
27  | ((flags_ & flags_mask) << flags_shift); };
28 
29  private:
30  static constexpr unsigned n_words = 6; // every link transmits 6 32 bit words per bx
31  static constexpr unsigned id_shift = 24;
32  static constexpr unsigned id_mask = 0xff;
33  static constexpr unsigned totalBx_shift = 16;
34  static constexpr unsigned totalBx_mask = 0xff;
35  static constexpr unsigned flags_shift = 0;
36  static constexpr unsigned flags_mask = 0xffff;
37 
38  unsigned int id_;
39  unsigned int totalBx_;
40  unsigned int flags_;
41  };
42 
43  class BxBlock {
44  public:
45  BxBlock(std::vector<uint32_t>::const_iterator bx_start, std::vector<uint32_t>::const_iterator bx_end) :
46  header_(*bx_start), payload_(bx_start+1, bx_end) {};
47  BxBlock(const BxBlockHeader& h, std::vector<uint32_t>::const_iterator payload_start, std::vector<uint32_t>::const_iterator payload_end) :
48  header_(h), payload_(payload_start, payload_end) {};
49  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) :
50  header_(id, totalBx, flags), payload_(payload_start, payload_end) {};
51  BxBlock(unsigned int id, unsigned int totalBx, const std::vector<uint32_t>& payload, unsigned int flags=0) :
52  header_(id, totalBx, flags), payload_(payload) {};
53  ~BxBlock() {};
54 
55  bool operator<(const BxBlock& o) const { return header() < o.header(); };
56 
57  inline unsigned int getSize() const { return payload_.size(); };
58 
59  BxBlockHeader header() const { return header_; };
60  std::vector<uint32_t> payload() const { return payload_; };
61 
62  private:
63  BxBlockHeader header_;
64  std::vector<uint32_t> payload_;
65  };
66 
67  typedef std::vector<BxBlock> BxBlocks;
68 }
69 
70 #endif
static constexpr unsigned flags_mask
Definition: BxBlock.h:36
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:49
BxBlock(unsigned int id, unsigned int totalBx, const std::vector< uint32_t > &payload, unsigned int flags=0)
Definition: BxBlock.h:51
BxBlockHeader(const uint32_t raw)
Definition: BxBlock.h:14
BxBlockHeader(unsigned int id, unsigned int totalBx, unsigned int flags=0)
Definition: BxBlock.h:12
unsigned int flags_
Definition: BxBlock.h:40
std::vector< Variable::Flags > flags
Definition: MVATrainer.cc:135
static constexpr unsigned n_words
Definition: BxBlock.h:30
BxBlock(std::vector< uint32_t >::const_iterator bx_start, std::vector< uint32_t >::const_iterator bx_end)
Definition: BxBlock.h:45
delete x;
Definition: CaloConfig.h:22
static constexpr unsigned id_mask
Definition: BxBlock.h:32
BxBlock(const BxBlockHeader &h, std::vector< uint32_t >::const_iterator payload_start, std::vector< uint32_t >::const_iterator payload_end)
Definition: BxBlock.h:47
#define constexpr
unsigned int totalBx_
Definition: BxBlock.h:39
payload
payload postfix for testing
unsigned int getTotalBx() const
Definition: BxBlock.h:22
unsigned int getSize() const
Definition: BxBlock.h:57
static constexpr unsigned id_shift
Definition: BxBlock.h:31
bool operator<(const BxBlock &o) const
Definition: BxBlock.h:55
unsigned int getId() const
Definition: BxBlock.h:21
BxBlockHeader header() const
Definition: BxBlock.h:59
static constexpr unsigned flags_shift
Definition: BxBlock.h:35
static constexpr unsigned totalBx_mask
Definition: BxBlock.h:34
std::vector< BxBlock > BxBlocks
Definition: BxBlock.h:67
int getBx() const
Definition: BxBlock.h:20
static constexpr unsigned totalBx_shift
Definition: BxBlock.h:33
unsigned int id_
Definition: BxBlock.h:38
std::vector< uint32_t > payload_
Definition: BxBlock.h:64
std::vector< uint32_t > payload() const
Definition: BxBlock.h:60
bool operator<(const BxBlockHeader &o) const
Definition: BxBlock.h:18
unsigned int getFlags() const
Definition: BxBlock.h:23
uint32_t raw() const
Definition: BxBlock.h:25