CMS 3D CMS Logo

Block.h
Go to the documentation of this file.
1 #ifndef EventFilter_L1TRawToDigi_Block_h
2 #define EventFilter_L1TRawToDigi_Block_h
3 
4 #include <memory>
5 #include <vector>
6 
9 
10 namespace l1t {
11  enum block_t { MP7 = 0, CTP7, MTF7 };
12 
13  class BlockHeader {
14  public:
15  BlockHeader(unsigned int id, unsigned int size, unsigned int capID=0, unsigned int flags=0, block_t type=MP7) : id_(id), size_(size), capID_(capID), flags_(flags), type_(type) {};
16  // Create a MP7 block header: everything is contained in the raw uint32
17  BlockHeader(const uint32_t *data) : id_((data[0] >> ID_shift) & ID_mask), size_((data[0] >> size_shift) & size_mask), capID_((data[0] >> capID_shift) & capID_mask), flags_((data[0] >> flags_shift) & flags_mask), type_(MP7) {};
18 
19  bool operator<(const BlockHeader& o) const { return getID() < o.getID(); };
20 
21  unsigned int getID() const { return id_; };
22  unsigned int getSize() const { return size_; };
23  unsigned int getCapID() const { return capID_; };
24  unsigned int getFlags() const { return flags_; };
25  block_t getType() const { return type_; };
26 
27  uint32_t raw() const;
28 
29  private:
30  static constexpr unsigned CTP7_shift = 0;
31  static constexpr unsigned CTP7_mask = 0xffff;
32  static constexpr unsigned ID_shift = 24;
33  static constexpr unsigned ID_mask = 0xff;
34  static constexpr unsigned size_shift = 16;
35  static constexpr unsigned size_mask = 0xff;
36  static constexpr unsigned capID_shift = 8;
37  static constexpr unsigned capID_mask = 0xff;
38  static constexpr unsigned flags_shift = 0;
39  static constexpr unsigned flags_mask = 0xff;
40 
41  unsigned int id_;
42  unsigned int size_;
43  unsigned int capID_;
44  unsigned int flags_;
46  };
47 
48  class Block {
49  public:
50  Block(const BlockHeader& h, const uint32_t * payload_start, const uint32_t * payload_end) :
51  header_(h), payload_(payload_start, payload_end) {};
52  Block(unsigned int id, const std::vector<uint32_t>& payload, unsigned int capID=0, unsigned int flags=0, block_t type=MP7) :
53  header_(id, payload.size(), capID, flags, type), payload_(payload) {};
54 
55  bool operator<(const Block& o) const { return header() < o.header(); };
56 
57  inline unsigned int getSize() const { return payload_.size() + 1; };
58 
59  BlockHeader header() const { return header_; };
60  const std::vector<uint32_t>& payload() const { return payload_; };
61 
62  void amc(const amc::Header& h) { amc_ = h; };
63  amc::Header amc() const { return amc_; };
64 
65  BxBlocks getBxBlocks(unsigned int payloadWordsPerBx, bool bxHeader) const;
66  private:
69  std::vector<uint32_t> payload_;
70  };
71 
72  typedef std::vector<Block> Blocks;
73 
74  class Payload {
75  public:
76  Payload(const uint32_t * data, const uint32_t * end) : data_(data), end_(end), algo_(0), infra_(0) {};
77  virtual ~Payload() {};
78  virtual unsigned getAlgorithmFWVersion() const { return algo_; };
79  virtual unsigned getInfrastructureFWVersion() const { return infra_; };
80  virtual unsigned getHeaderSize() const = 0;
81  // Read header from data_ and advance data_ to point behind the
82  // header. Called by getBlock(), which also checks that data_ !=
83  // end_ before calling (assumes size of one 32 bit word).
84  virtual BlockHeader getHeader() = 0;
85  virtual std::unique_ptr<Block> getBlock();
86  protected:
87  const uint32_t * data_;
88  const uint32_t * end_;
89 
90  unsigned algo_;
91  unsigned infra_;
92  };
93 
94  class MP7Payload : public Payload {
95  public:
96  MP7Payload(const uint32_t * data, const uint32_t * end, bool legacy_mc=false);
97  unsigned getHeaderSize() const override { return 1; };
98  BlockHeader getHeader() override;
99  };
100 
101  class MTF7Payload : public Payload {
102  public:
103  MTF7Payload(const uint32_t * data, const uint32_t * end);
104  // Unused methods - we override getBlock() instead
105  unsigned getHeaderSize() const override { return 0; };
106  BlockHeader getHeader() override { return BlockHeader(nullptr); };
107  std::unique_ptr<Block> getBlock() override;
108  private:
109  // sizes in 16 bit words
110  static constexpr unsigned header_size = 12;
111  static constexpr unsigned counter_size = 4;
112  static constexpr unsigned trailer_size = 8;
113 
114  // maximum of the block length (64bits) and bit patterns of the
115  // first bits (of 16bit words)
116  static constexpr unsigned max_block_length_ = 3;
117  static const std::vector<unsigned int> block_patterns_;
118 
119  int count(unsigned int pattern, unsigned int length) const;
120  bool valid(unsigned int pattern) const;
121  };
122 
123  class CTP7Payload : public Payload {
124  public:
125  CTP7Payload(const uint32_t * data, const uint32_t * end, amc::Header amcHeader);
126  unsigned getHeaderSize() const override { return 2; };
127  BlockHeader getHeader() override;
128  std::unique_ptr<Block> getBlock() override;
129  private:
130  // FIXME check values
131  static constexpr unsigned size_mask = 0xff;
132  static constexpr unsigned size_shift = 16;
133 
134  unsigned size_;
135  unsigned capId_;
136  unsigned bx_per_l1a_;
137  unsigned calo_bxid_;
139  };
140 }
141 
142 #endif
size
Write out results.
type
Definition: HCALResponse.h:21
amc::Header amc() const
Definition: Block.h:63
std::vector< uint32_t > payload_
Definition: Block.h:69
static constexpr unsigned capID_shift
Definition: Block.h:36
const std::vector< uint32_t > & payload() const
Definition: Block.h:60
Definition: Block.h:11
Block(const BlockHeader &h, const uint32_t *payload_start, const uint32_t *payload_end)
Definition: Block.h:50
static constexpr unsigned capID_mask
Definition: Block.h:37
static constexpr unsigned flags_mask
Definition: Block.h:39
unsigned int getID() const
Definition: Block.h:21
FWCore Framework interface EventSetupRecordImplementation h
Helper function to determine trigger accepts.
static constexpr unsigned size_shift
Definition: Block.h:34
unsigned getHeaderSize() const override
Definition: Block.h:126
static constexpr unsigned flags_shift
Definition: Block.h:38
BlockHeader header() const
Definition: Block.h:59
block_t getType() const
Definition: Block.h:25
std::vector< Variable::Flags > flags
Definition: MVATrainer.cc:135
delete x;
Definition: CaloConfig.h:22
unsigned getHeaderSize() const override
Definition: Block.h:105
block_t type_
Definition: Block.h:45
const uint32_t * end_
Definition: Block.h:88
unsigned int flags_
Definition: Block.h:44
BlockHeader(const uint32_t *data)
Definition: Block.h:17
virtual ~Payload()
Definition: Block.h:77
#define constexpr
unsigned size_
Definition: Block.h:134
BlockHeader getHeader() override
Definition: Block.h:106
unsigned capId_
Definition: Block.h:135
virtual unsigned getInfrastructureFWVersion() const
Definition: Block.h:79
block_t
Definition: Block.h:11
virtual unsigned getAlgorithmFWVersion() const
Definition: Block.h:78
std::vector< Block > Blocks
Definition: Block.h:72
static constexpr unsigned ID_mask
Definition: Block.h:33
BlockHeader header_
Definition: Block.h:67
#define end
Definition: vmac.h:39
unsigned infra_
Definition: Block.h:91
unsigned int size_
Definition: Block.h:42
Block(unsigned int id, const std::vector< uint32_t > &payload, unsigned int capID=0, unsigned int flags=0, block_t type=MP7)
Definition: Block.h:52
static constexpr unsigned CTP7_mask
Definition: Block.h:31
unsigned int capID_
Definition: Block.h:43
const uint32_t * data_
Definition: Block.h:87
static constexpr unsigned size_mask
Definition: Block.h:35
std::vector< BxBlock > BxBlocks
Definition: BxBlock.h:68
unsigned calo_bxid_
Definition: Block.h:137
amc::Header amc_
Definition: Block.h:68
unsigned int getCapID() const
Definition: Block.h:23
unsigned bx_per_l1a_
Definition: Block.h:136
unsigned getHeaderSize() const override
Definition: Block.h:97
static constexpr unsigned CTP7_shift
Definition: Block.h:30
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:82
unsigned int id_
Definition: Block.h:41
bool operator<(const BlockHeader &o) const
Definition: Block.h:19
unsigned int getSize() const
Definition: Block.h:22
static constexpr unsigned ID_shift
Definition: Block.h:32
BlockHeader(unsigned int id, unsigned int size, unsigned int capID=0, unsigned int flags=0, block_t type=MP7)
Definition: Block.h:15
amc::Header amcHeader_
Definition: Block.h:138
uint32_t raw() const
Definition: Block.cc:28
void amc(const amc::Header &h)
Definition: Block.h:62
unsigned int getFlags() const
Definition: Block.h:24
unsigned int getSize() const
Definition: Block.h:57
unsigned algo_
Definition: Block.h:90
static const std::vector< unsigned int > block_patterns_
Definition: Block.h:117
Payload(const uint32_t *data, const uint32_t *end)
Definition: Block.h:76
bool operator<(const Block &o) const
Definition: Block.h:55