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  namespace mtf7 {
13  enum mtf7_block_t {
14  // The "0b" prefix indicates binary; the block header id is stored in decimal.
15  // Bits are the left-most bit (D15) of every 16-bit word in the format document.
16  // Bottom-to-top in the document maps to left-to-right in each of the bit pattern.
17  EvHd = 0b000111111111,
18  CnBlk = 0b0010,
19  ME = 0b0011,
20  RPC = 0b0100,
21  GEM = 0b0111,
22  // FIXME, not currently defined... guess? JS - 01.07.20
23  ME0 = 0b0110,
24  SPOut = 0b01100101,
25  EvTr = 0b11111111
26  };
27  }
28 
29  class BlockHeader {
30  public:
31  BlockHeader(unsigned int id, unsigned int size, unsigned int capID = 0, unsigned int flags = 0, block_t type = MP7)
32  : id_(id), size_(size), capID_(capID), flags_(flags), type_(type){};
33  // Create a MP7 block header: everything is contained in the raw uint32
34  BlockHeader(const uint32_t* data)
35  : id_((data[0] >> ID_shift) & ID_mask),
36  size_((data[0] >> size_shift) & size_mask),
37  capID_((data[0] >> capID_shift) & capID_mask),
38  flags_((data[0] >> flags_shift) & flags_mask),
39  type_(MP7){};
40 
41  bool operator<(const BlockHeader& o) const { return getID() < o.getID(); };
42 
43  unsigned int getID() const { return id_; };
44  unsigned int getSize() const { return size_; };
45  unsigned int getCapID() const { return capID_; };
46  unsigned int getFlags() const { return flags_; };
47  block_t getType() const { return type_; };
48 
49  uint32_t raw() const;
50 
51  private:
52  static constexpr unsigned CTP7_shift = 0;
53  static constexpr unsigned CTP7_mask = 0xffff;
54  static constexpr unsigned ID_shift = 24;
55  static constexpr unsigned ID_mask = 0xff;
56  static constexpr unsigned size_shift = 16;
57  static constexpr unsigned size_mask = 0xff;
58  static constexpr unsigned capID_shift = 8;
59  static constexpr unsigned capID_mask = 0xff;
60  static constexpr unsigned flags_shift = 0;
61  static constexpr unsigned flags_mask = 0xff;
62 
63  unsigned int id_;
64  unsigned int size_;
65  unsigned int capID_;
66  unsigned int flags_;
68  };
69 
70  class Block {
71  public:
72  Block(const BlockHeader& h, const uint32_t* payload_start, const uint32_t* payload_end)
73  : header_(h), payload_(payload_start, payload_end){};
74  Block(unsigned int id,
75  const std::vector<uint32_t>& payload,
76  unsigned int capID = 0,
77  unsigned int flags = 0,
78  block_t type = MP7)
79  : header_(id, payload.size(), capID, flags, type), payload_(payload){};
80 
81  bool operator<(const Block& o) const { return header() < o.header(); };
82 
83  inline unsigned int getSize() const { return payload_.size() + 1; };
84 
85  BlockHeader header() const { return header_; };
86  const std::vector<uint32_t>& payload() const { return payload_; };
87 
88  void amc(const amc::Header& h) { amc_ = h; };
89  amc::Header amc() const { return amc_; };
90 
91  BxBlocks getBxBlocks(unsigned int payloadWordsPerBx, bool bxHeader) const;
92 
93  private:
96  std::vector<uint32_t> payload_;
97  };
98 
99  typedef std::vector<Block> Blocks;
100 
101  class Payload {
102  public:
103  Payload(const uint32_t* data, const uint32_t* end) : data_(data), end_(end), algo_(0), infra_(0){};
104  virtual ~Payload(){};
105  virtual unsigned getAlgorithmFWVersion() const { return algo_; };
106  virtual unsigned getInfrastructureFWVersion() const { return infra_; };
107  virtual unsigned getHeaderSize() const = 0;
108  // Read header from data_ and advance data_ to point behind the
109  // header. Called by getBlock(), which also checks that data_ !=
110  // end_ before calling (assumes size of one 32 bit word).
111  virtual BlockHeader getHeader() = 0;
112  virtual std::unique_ptr<Block> getBlock();
113 
114  protected:
115  const uint32_t* data_;
116  const uint32_t* end_;
117 
118  unsigned algo_;
119  unsigned infra_;
120  };
121 
122  class MP7Payload : public Payload {
123  public:
124  MP7Payload(const uint32_t* data, const uint32_t* end, bool legacy_mc = false);
125  unsigned getHeaderSize() const override { return 1; };
126  BlockHeader getHeader() override;
127  };
128 
129  class MTF7Payload : public Payload {
130  public:
131  MTF7Payload(const uint32_t* data, const uint32_t* end);
132  // Unused methods - we override getBlock() instead
133  unsigned getHeaderSize() const override { return 0; };
134  BlockHeader getHeader() override { return BlockHeader(nullptr); };
135  std::unique_ptr<Block> getBlock() override;
136 
137  private:
138  // sizes in 16 bit words
139  static constexpr unsigned header_size = 12;
140  static constexpr unsigned counter_size = 4;
141  static constexpr unsigned trailer_size = 8;
142 
144  static constexpr unsigned DAQ_PAYLOAD_OFFSET = 4;
146  static constexpr unsigned MAX_BX_PER_PAYLOAD = 8;
148  static constexpr unsigned ME_MAX_PER_BX = 108;
150  static constexpr unsigned RPC_MAX_PER_BX = 84;
152  static constexpr unsigned GE11_MAX_PER_BX = 112;
154  static constexpr unsigned GE21_MAX_PER_BX = 0;
156  static constexpr unsigned ME0_MAX_PER_BX = 0;
158  static constexpr unsigned SP_MAX_PER_BX = 6;
160  static constexpr unsigned PAYLOAD_MAX_SIZE =
163  (trailer_size / 4);
164 
165  static constexpr unsigned max_block_length_ = 3;
166  static const std::vector<unsigned int> block_patterns_;
167 
168  int count(unsigned int pattern, unsigned int length) const;
169  bool valid(unsigned int pattern) const;
170  };
171 
172  class CTP7Payload : public Payload {
173  public:
174  CTP7Payload(const uint32_t* data, const uint32_t* end, amc::Header amcHeader);
175  unsigned getHeaderSize() const override { return 2; };
176  BlockHeader getHeader() override;
177  std::unique_ptr<Block> getBlock() override;
178 
179  private:
180  // FIXME check values
181  static constexpr unsigned size_mask = 0xff;
182  static constexpr unsigned size_shift = 16;
183 
184  unsigned size_;
185  unsigned capId_;
186  unsigned bx_per_l1a_;
187  unsigned calo_bxid_;
189  unsigned slot7_card_;
191  };
192 } // namespace l1t
193 
194 #endif
unsigned getHeaderSize() const override
Definition: Block.h:175
size
Write out results.
GEM Data Record : block->header().getID() = 7.
Definition: Block.h:21
amc::Header amc() const
Definition: Block.h:89
BlockHeader getHeader() override
Definition: Block.cc:224
Block of Counters : block->header().getID() = 2.
Definition: Block.h:18
std::vector< uint32_t > payload_
Definition: Block.h:96
static constexpr unsigned capID_shift
Definition: Block.h:58
MP7Payload(const uint32_t *data, const uint32_t *end, bool legacy_mc=false)
Definition: Block.cc:91
Definition: Block.h:11
Block(const BlockHeader &h, const uint32_t *payload_start, const uint32_t *payload_end)
Definition: Block.h:72
static constexpr unsigned capID_mask
Definition: Block.h:59
static constexpr unsigned flags_mask
Definition: Block.h:61
static constexpr unsigned size_shift
Definition: Block.h:56
unsigned int getID() const
Definition: Block.h:43
static constexpr unsigned max_block_length_
maximum of the block length (64bits)
Definition: Block.h:165
static constexpr unsigned size_mask
Definition: Block.h:181
Event Record Header : block->header().getID() = 511.
Definition: Block.h:17
bool valid(unsigned int pattern) const
Definition: Block.cc:165
static constexpr unsigned flags_shift
Definition: Block.h:60
static constexpr unsigned header_size
Definition: Block.h:139
delete x;
Definition: CaloConfig.h:22
block_t type_
Definition: Block.h:67
const uint32_t * end_
Definition: Block.h:116
unsigned int flags_
Definition: Block.h:66
virtual std::unique_ptr< Block > getBlock()
Definition: Block.cc:64
BlockHeader(const uint32_t *data)
Definition: Block.h:34
virtual ~Payload()
Definition: Block.h:104
static constexpr unsigned ME0_MAX_PER_BX
TODO: Maximum number of ME0 words per MTF7 payload per bx: ?? ME0 links, ?? layers, ?? clusters.
Definition: Block.h:156
unsigned size_
Definition: Block.h:184
SP Output Data Record : block->header().getID() = 101.
Definition: Block.h:24
BlockHeader getHeader() override
Definition: Block.h:134
unsigned six_hcal_feature_bits_
Definition: Block.h:188
unsigned capId_
Definition: Block.h:185
Definition: ME.h:11
virtual BlockHeader getHeader()=0
Event Record Trailer : block->header().getID() = 255.
Definition: Block.h:25
static constexpr unsigned GE11_MAX_PER_BX
Maximum number of GE1/1 words per MTF7 payload per bx: 7 GE1/1 links, 2 layers, 8 clusters...
Definition: Block.h:152
static constexpr unsigned counter_size
Definition: Block.h:140
unsigned int getSize() const
Definition: Block.h:44
block_t
Definition: Block.h:11
static constexpr unsigned MAX_BX_PER_PAYLOAD
Maximum number of BX per MTF7 payload.
Definition: Block.h:146
std::vector< Block > Blocks
Definition: Block.h:99
virtual unsigned getHeaderSize() const =0
static constexpr unsigned ID_mask
Definition: Block.h:55
unsigned getHeaderSize() const override
Definition: Block.h:133
BlockHeader header_
Definition: Block.h:94
static constexpr unsigned PAYLOAD_MAX_SIZE
Maximum number of 64-bit words in the EMTF payload.
Definition: Block.h:160
unsigned infra_
Definition: Block.h:119
BxBlocks getBxBlocks(unsigned int payloadWordsPerBx, bool bxHeader) const
Definition: Block.cc:40
unsigned int getCapID() const
Definition: Block.h:45
unsigned int size_
Definition: Block.h:64
bool operator<(const BlockHeader &o) const
Definition: Block.h:41
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:74
static constexpr unsigned CTP7_mask
Definition: Block.h:53
MTF7Payload(const uint32_t *data, const uint32_t *end)
Definition: Block.cc:111
unsigned int capID_
Definition: Block.h:65
mtf7_block_t
Definition: Block.h:13
const uint32_t * data_
Definition: Block.h:115
static constexpr unsigned size_mask
Definition: Block.h:57
unsigned getHeaderSize() const override
Definition: Block.h:125
std::vector< BxBlock > BxBlocks
Definition: BxBlock.h:79
block_t getType() const
Definition: Block.h:47
unsigned calo_bxid_
Definition: Block.h:187
unsigned slot7_card_
Definition: Block.h:189
unsigned int getFlags() const
Definition: Block.h:46
amc::Header amc_
Definition: Block.h:95
CTP7Payload(const uint32_t *data, const uint32_t *end, amc::Header amcHeader)
Definition: Block.cc:205
BlockHeader getHeader() override
Definition: Block.cc:105
static constexpr unsigned trailer_size
Definition: Block.h:141
BlockHeader header() const
Definition: Block.h:85
bool operator<(const Block &o) const
Definition: Block.h:81
static constexpr unsigned SP_MAX_PER_BX
Maximum number of SPz words per MTF7 payload per bx: 3 tracks, 2 words per track. ...
Definition: Block.h:158
ME0 Data Record : block->header().getID() = 6.
Definition: Block.h:23
unsigned bx_per_l1a_
Definition: Block.h:186
unsigned int getSize() const
Definition: Block.h:83
static constexpr unsigned CTP7_shift
Definition: Block.h:52
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:80
unsigned int id_
Definition: Block.h:63
uint32_t raw() const
Definition: Block.cc:23
std::unique_ptr< Block > getBlock() override
Definition: Block.cc:236
RPC Data Record : block->header().getID() = 4.
Definition: Block.h:20
static constexpr unsigned ID_shift
Definition: Block.h:54
BlockHeader(unsigned int id, unsigned int size, unsigned int capID=0, unsigned int flags=0, block_t type=MP7)
Definition: Block.h:31
amc::Header amcHeader_
Definition: Block.h:190
static constexpr unsigned ME_MAX_PER_BX
Maximum number of CSC words per MTF7 payload per bx: 9 links/sectors, 6 stations, 2 LCTs...
Definition: Block.h:148
virtual unsigned getAlgorithmFWVersion() const
Definition: Block.h:105
The Signals That Services Can Subscribe To This is based on ActivityRegistry h
Helper function to determine trigger accepts.
Definition: Activities.doc:4
void amc(const amc::Header &h)
Definition: Block.h:88
const std::vector< uint32_t > & payload() const
Definition: Block.h:86
static constexpr unsigned DAQ_PAYLOAD_OFFSET
Start of the EMTF DAQ payload, in number of 64-bit words.
Definition: Block.h:144
static constexpr unsigned RPC_MAX_PER_BX
Maximum number of RPC words per MTF7 payload per bx: 7 links/sectors, 6 stations, 2 segments...
Definition: Block.h:150
int count(unsigned int pattern, unsigned int length) const
Definition: Block.cc:154
virtual unsigned getInfrastructureFWVersion() const
Definition: Block.h:106
static constexpr unsigned size_shift
Definition: Block.h:182
unsigned algo_
Definition: Block.h:118
static const std::vector< unsigned int > block_patterns_
bit patterns of the first bits (of 16bit words)
Definition: Block.h:166
Payload(const uint32_t *data, const uint32_t *end)
Definition: Block.h:103
std::unique_ptr< Block > getBlock() override
Definition: Block.cc:173
static constexpr unsigned GE21_MAX_PER_BX
TODO: Maximum number of GE2/1 words per MTF7 payload per bx: ?? GE2/1 links, 2 layers, ?? clusters.
Definition: Block.h:154