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) : id_(id), totalBx_(totalBx), flags_(flags) {};
14  // Create a BX header: everything is contained in the raw uint32
15  BxBlockHeader(const uint32_t raw) : id_(((raw >> id_shift) & id_mask) / n_words)
16  , totalBx_(((raw >> totalBx_shift) & totalBx_mask) / n_words)
17  , flags_((raw >> flags_shift) & flags_mask) {};
18 
19  bool operator<(const BxBlockHeader& o) const { return getBx() < o.getBx(); };
20 
21  inline int getBx() const { return (int)id_ + std::min(0, 1 - (int)totalBx_%2 - (int)std::floor(totalBx_/2.)); }; // In case of an even totalBx_ the BX range should be like, e.g. -3 to +4
22  inline unsigned int getId() const { return id_; };
23  inline unsigned int getTotalBx() const { return totalBx_; };
24  inline unsigned int getFlags() const { return flags_; };
25 
26  inline uint32_t raw() const { return (((id_ & id_mask) << id_shift) * n_words)
28  | ((flags_ & flags_mask) << flags_shift); };
29 
30  private:
31  static constexpr unsigned n_words = 6; // every link transmits 6 32 bit words per bx
32  static constexpr unsigned id_shift = 24;
33  static constexpr unsigned id_mask = 0xff;
34  static constexpr unsigned totalBx_shift = 16;
35  static constexpr unsigned totalBx_mask = 0xff;
36  static constexpr unsigned flags_shift = 0;
37  static constexpr unsigned flags_mask = 0xffff;
38 
39  unsigned int id_;
40  unsigned int totalBx_;
41  unsigned int flags_;
42  };
43 
44  class BxBlock {
45  public:
46  BxBlock(std::vector<uint32_t>::const_iterator bx_start, std::vector<uint32_t>::const_iterator bx_end) :
47  header_(*bx_start), payload_(bx_start+1, bx_end) {};
48  BxBlock(const BxBlockHeader& h, std::vector<uint32_t>::const_iterator payload_start, std::vector<uint32_t>::const_iterator payload_end) :
49  header_(h), payload_(payload_start, payload_end) {};
50  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) :
51  header_(id, totalBx, flags), payload_(payload_start, payload_end) {};
52  BxBlock(unsigned int id, unsigned int totalBx, const std::vector<uint32_t>& payload, unsigned int flags=0) :
53  header_(id, totalBx, flags), payload_(payload) {};
54  ~BxBlock() {};
55 
56  bool operator<(const BxBlock& o) const { return header() < o.header(); };
57 
58  inline unsigned int getSize() const { return payload_.size(); };
59 
60  BxBlockHeader header() const { return header_; };
61  std::vector<uint32_t> payload() const { return payload_; };
62 
63  private:
64  BxBlockHeader header_;
65  std::vector<uint32_t> payload_;
66  };
67 
68  typedef std::vector<BxBlock> BxBlocks;
69 }
70 
71 #endif
FWCore Framework interface EventSetupRecordImplementation h
Helper function to determine trigger accepts.
static constexpr unsigned flags_mask
Definition: BxBlock.h:37
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:50
BxBlock(unsigned int id, unsigned int totalBx, const std::vector< uint32_t > &payload, unsigned int flags=0)
Definition: BxBlock.h:52
BxBlockHeader(const uint32_t raw)
Definition: BxBlock.h:15
BxBlockHeader(unsigned int id, unsigned int totalBx, unsigned int flags=0)
Definition: BxBlock.h:13
unsigned int flags_
Definition: BxBlock.h:41
std::vector< Variable::Flags > flags
Definition: MVATrainer.cc:135
static constexpr unsigned n_words
Definition: BxBlock.h:31
BxBlock(std::vector< uint32_t >::const_iterator bx_start, std::vector< uint32_t >::const_iterator bx_end)
Definition: BxBlock.h:46
delete x;
Definition: CaloConfig.h:22
static constexpr unsigned id_mask
Definition: BxBlock.h:33
BxBlock(const BxBlockHeader &h, std::vector< uint32_t >::const_iterator payload_start, std::vector< uint32_t >::const_iterator payload_end)
Definition: BxBlock.h:48
#define constexpr
unsigned int totalBx_
Definition: BxBlock.h:40
unsigned int getTotalBx() const
Definition: BxBlock.h:23
unsigned int getSize() const
Definition: BxBlock.h:58
T min(T a, T b)
Definition: MathUtil.h:58
static constexpr unsigned id_shift
Definition: BxBlock.h:32
bool operator<(const BxBlock &o) const
Definition: BxBlock.h:56
unsigned int getId() const
Definition: BxBlock.h:22
BxBlockHeader header() const
Definition: BxBlock.h:60
static constexpr unsigned flags_shift
Definition: BxBlock.h:36
static constexpr unsigned totalBx_mask
Definition: BxBlock.h:35
std::vector< BxBlock > BxBlocks
Definition: BxBlock.h:68
int getBx() const
Definition: BxBlock.h:21
static constexpr unsigned totalBx_shift
Definition: BxBlock.h:34
unsigned int id_
Definition: BxBlock.h:39
std::vector< uint32_t > payload_
Definition: BxBlock.h:65
std::vector< uint32_t > payload() const
Definition: BxBlock.h:61
bool operator<(const BxBlockHeader &o) const
Definition: BxBlock.h:19
unsigned int getFlags() const
Definition: BxBlock.h:24
uint32_t raw() const
Definition: BxBlock.h:26