CMS 3D CMS Logo

AMCSpec.h
Go to the documentation of this file.
1 #ifndef EventFilter_L1TRawToDigi_AMC_SPEC__h
2 #define EventFilter_L1TRawToDigi_AMC_SPEC__h
3 
4 #include <memory>
5 #include <vector>
6 #include <cstdint>
7 
8 namespace amc {
9  static const unsigned int split_block_size = 0x1000;
10 
11  // The AMC header within an AMC13 payload block. Should optimally only
12  // be used when packing/unpacking AMC payloads into AMC13 blocks.
13  class BlockHeader {
14  public:
15  BlockHeader() : data_(0) {}
16  BlockHeader(const uint64_t *data) : data_(data[0]) {}
17  // size is the total size of the AMC payload, not just of the
18  // block
19  BlockHeader(unsigned int amc_no, unsigned int board_id, unsigned int size, unsigned int block = 0);
20 
21  operator uint64_t() const { return data_; };
22 
23  inline uint64_t raw() const { return data_; };
24 
25  unsigned int getBlocks() const;
26  unsigned int getBlockSize() const;
27 
28  inline unsigned int getAMCNumber() const { return (data_ >> AmcNo_shift) & AmcNo_mask; };
29  inline unsigned int getBoardID() const { return (data_ >> BoardID_shift) & BoardID_mask; };
30  inline unsigned int getSize() const { return (data_ >> Size_shift) & Size_mask; };
31  inline unsigned int getMore() const { return (data_ >> More_bit_shift) & 1; };
32  inline unsigned int getSegmented() const { return (data_ >> Segmented_bit_shift) & 1; };
33 
34  inline unsigned int validCRC() const { return (data_ >> CRC_bit_shift) & 1; };
35 
36  private:
37  static const unsigned int Size_shift = 32;
38  static const unsigned int Size_mask = 0xffffff;
39  static const unsigned int BlkNo_shift = 20;
40  static const unsigned int BlkNo_mask = 0xff;
41  static const unsigned int AmcNo_shift = 16;
42  static const unsigned int AmcNo_mask = 0xf;
43  static const unsigned int BoardID_shift = 0;
44  static const unsigned int BoardID_mask = 0xffff;
45 
46  static const unsigned int Length_bit_shift = 62;
47  static const unsigned int More_bit_shift = 61;
48  static const unsigned int Segmented_bit_shift = 60;
49  static const unsigned int Enabled_bit_shift = 59;
50  static const unsigned int Present_bit_shift = 58;
51  static const unsigned int Valid_bit_shift = 57;
52  static const unsigned int CRC_bit_shift = 56;
53 
55  };
56 
57  // The actual header attached to the AMC payload, also contained in the
58  // AMC payload of an AMC13 packet/block.
59  class Header {
60  public:
61  Header() : data0_(0), data1_(0) {}
62  Header(const uint64_t *data) : data0_(data[0]), data1_(data[1]) {}
63  Header(unsigned int amc_no,
64  unsigned int lv1_id,
65  unsigned int bx_id,
66  unsigned int size,
67  unsigned int or_n,
68  unsigned int board_id,
69  unsigned int user);
70 
71  inline unsigned int getAMCNumber() const { return (data0_ >> AmcNo_shift) & AmcNo_mask; };
72  inline unsigned int getBoardID() const { return (data1_ >> BoardID_shift) & BoardID_mask; };
73  inline unsigned int getLV1ID() const { return (data0_ >> LV1ID_shift) & LV1ID_mask; };
74  inline unsigned int getBX() const { return (data0_ >> BX_shift) & BX_mask; };
75  inline unsigned int getOrbitNumber() const { return (data1_ >> OrN_shift) & OrN_mask; };
76  inline unsigned int getSize() const { return (data0_ >> Size_shift) & Size_mask; };
77  inline unsigned int getUserData() const { return (data1_ >> User_shift) & User_mask; };
78 
79  std::vector<uint64_t> raw() const { return {data0_, data1_}; };
80 
81  private:
82  static const unsigned int Size_shift = 0;
83  static const unsigned int Size_mask = 0xfffff;
84  static const unsigned int BX_shift = 20;
85  static const unsigned int BX_mask = 0xfff;
86  static const unsigned int LV1ID_shift = 32;
87  static const unsigned int LV1ID_mask = 0xffffff;
88  static const unsigned int AmcNo_shift = 56;
89  static const unsigned int AmcNo_mask = 0xf;
90 
91  static const unsigned int BoardID_shift = 0;
92  static const unsigned int BoardID_mask = 0xffff;
93  static const unsigned int OrN_shift = 16;
94  static const unsigned int OrN_mask = 0xffff;
95  static const unsigned int User_shift = 32;
96  static const unsigned int User_mask = 0xffffffff;
97 
100  };
101 
102  class Trailer {
103  public:
104  Trailer() : data_(0) {}
105  Trailer(const uint64_t *data) : data_(data[0]) {}
106  Trailer(unsigned int crc, unsigned int lv1_id, unsigned int size);
107 
108  inline unsigned int getCRC() const { return (data_ >> CRC_shift) & CRC_mask; };
109  inline unsigned int getLV1ID() const { return (data_ >> LV1ID_shift) & LV1ID_mask; };
110  inline unsigned int getSize() const { return (data_ >> Size_shift) & Size_mask; };
111 
112  uint64_t raw() const { return data_; }
113  bool check(unsigned int crc, unsigned int lv1_id, unsigned int size, bool mtf7_mode = false) const;
114 
115  static void writeCRC(const uint64_t *start, uint64_t *end);
116 
117  private:
118  static const unsigned int Size_shift = 0;
119  static const unsigned int Size_mask = 0xfffff;
120  static const unsigned int LV1ID_shift = 24;
121  static const unsigned int LV1ID_mask = 0xff;
122  static const unsigned int CRC_shift = 32;
123  static const unsigned int CRC_mask = 0xffffffff;
124 
126  };
127 
128  class Packet {
129  public:
131  Packet(unsigned int amc,
132  unsigned int board,
133  unsigned int lv1id,
134  unsigned int orbit,
135  unsigned int bx,
136  const std::vector<uint64_t> &load,
137  unsigned int user = 0);
138 
139  // Add payload fragment from an AMC13 block to the AMC packet
140  void addPayload(const uint64_t *, unsigned int);
141  // To be called after the last payload addition. Removes header
142  // and trailer from the actual paylod. Also performs
143  // cross-checks for data consistency.
144  void finalize(unsigned int lv1, unsigned int bx, bool legacy_mc = false, bool mtf7_mode = false);
145 
146  std::vector<uint64_t> block(unsigned int id) const;
147  std::unique_ptr<uint64_t[]> data();
148  BlockHeader blockHeader(unsigned int block = 0) const { return block_header_; };
149  Header header() const { return header_; };
150  Trailer trailer() const { return trailer_; };
151 
152  inline unsigned int blocks() const { return block_header_.getBlocks(); };
153  // Returns the size of the payload _without_ the headers
154  inline unsigned int size() const { return payload_.size() - 3; };
155 
156  private:
160 
161  std::vector<uint64_t> payload_;
162  };
163 } // namespace amc
164 
165 #endif
Definition: start.py:1
static const unsigned int Size_mask
Definition: AMCSpec.h:119
static const unsigned int AmcNo_mask
Definition: AMCSpec.h:89
static const unsigned int CRC_mask
Definition: AMCSpec.h:123
static const unsigned int BoardID_mask
Definition: AMCSpec.h:44
uint64_t data_
Definition: AMCSpec.h:125
static const unsigned int BX_mask
Definition: AMCSpec.h:85
static const unsigned int BoardID_shift
Definition: AMCSpec.h:91
BlockHeader blockHeader(unsigned int block=0) const
Definition: AMCSpec.h:148
static const unsigned int Size_shift
Definition: AMCSpec.h:37
static const unsigned int CRC_bit_shift
Definition: AMCSpec.h:52
unsigned int getLV1ID() const
Definition: AMCSpec.h:109
static void writeCRC(const uint64_t *start, uint64_t *end)
Definition: AMCSpec.cc:94
static const unsigned int Size_shift
Definition: AMCSpec.h:82
unsigned int getCRC() const
Definition: AMCSpec.h:108
BlockHeader block_header_
Definition: AMCSpec.h:154
static const unsigned int Size_mask
Definition: AMCSpec.h:83
unsigned int getBoardID() const
Definition: AMCSpec.h:72
static const unsigned int LV1ID_mask
Definition: AMCSpec.h:87
unsigned int getAMCNumber() const
Definition: AMCSpec.h:71
unsigned int getBlocks() const
Definition: AMCSpec.cc:47
static const unsigned int CRC_shift
Definition: AMCSpec.h:122
unsigned int validCRC() const
Definition: AMCSpec.h:34
static const unsigned int Segmented_bit_shift
Definition: AMCSpec.h:48
std::vector< uint64_t > raw() const
Definition: AMCSpec.h:79
static const unsigned int Present_bit_shift
Definition: AMCSpec.h:50
uint64_t raw() const
Definition: AMCSpec.h:112
static const unsigned int AmcNo_shift
Definition: AMCSpec.h:41
static const unsigned int BlkNo_shift
Definition: AMCSpec.h:39
void addPayload(const uint64_t *, unsigned int)
Definition: AMCSpec.cc:121
Trailer trailer() const
Definition: AMCSpec.h:150
void finalize(unsigned int lv1, unsigned int bx, bool legacy_mc=false, bool mtf7_mode=false)
Definition: AMCSpec.cc:125
static const unsigned int OrN_mask
Definition: AMCSpec.h:94
static const unsigned int LV1ID_shift
Definition: AMCSpec.h:86
static const unsigned int Valid_bit_shift
Definition: AMCSpec.h:51
bool check(unsigned int crc, unsigned int lv1_id, unsigned int size, bool mtf7_mode=false) const
Definition: AMCSpec.cc:82
static const unsigned int BlkNo_mask
Definition: AMCSpec.h:40
unsigned int blocks() const
Definition: AMCSpec.h:152
static const unsigned int LV1ID_shift
Definition: AMCSpec.h:120
static const unsigned int Size_mask
Definition: AMCSpec.h:38
static const unsigned int AmcNo_shift
Definition: AMCSpec.h:88
unsigned int getUserData() const
Definition: AMCSpec.h:77
static const unsigned int split_block_size
Definition: AMCSpec.h:9
static const unsigned int BX_shift
Definition: AMCSpec.h:84
unsigned int getMore() const
Definition: AMCSpec.h:31
static const unsigned int User_shift
Definition: AMCSpec.h:95
d
Definition: ztail.py:151
unsigned int getAMCNumber() const
Definition: AMCSpec.h:28
uint64_t data1_
Definition: AMCSpec.h:99
unsigned int getBX() const
Definition: AMCSpec.h:74
static const unsigned int More_bit_shift
Definition: AMCSpec.h:47
static const unsigned int BoardID_mask
Definition: AMCSpec.h:92
Trailer trailer_
Definition: AMCSpec.h:159
uint64_t data_
Definition: AMCSpec.h:54
static const unsigned int AmcNo_mask
Definition: AMCSpec.h:42
uint64_t raw() const
Definition: AMCSpec.h:23
static const unsigned int LV1ID_mask
Definition: AMCSpec.h:121
static const unsigned int BoardID_shift
Definition: AMCSpec.h:43
unsigned long long uint64_t
Definition: Time.h:13
unsigned int getBoardID() const
Definition: AMCSpec.h:29
def load(fileName)
Definition: svgfig.py:547
unsigned int getSize() const
Definition: AMCSpec.h:30
static const unsigned int User_mask
Definition: AMCSpec.h:96
unsigned int getSize() const
Definition: AMCSpec.h:76
BlockHeader(const uint64_t *data)
Definition: AMCSpec.h:16
unsigned int getOrbitNumber() const
Definition: AMCSpec.h:75
unsigned int getSize() const
Definition: AMCSpec.h:110
static const unsigned int OrN_shift
Definition: AMCSpec.h:93
Header header_
Definition: AMCSpec.h:158
static const unsigned int Length_bit_shift
Definition: AMCSpec.h:46
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:80
Header header() const
Definition: AMCSpec.h:149
std::unique_ptr< uint64_t[]> data()
Definition: AMCSpec.cc:154
Trailer(const uint64_t *data)
Definition: AMCSpec.h:105
static const unsigned int Size_shift
Definition: AMCSpec.h:118
std::vector< uint64_t > block(unsigned int id) const
Definition: AMCSpec.cc:143
static const unsigned int Enabled_bit_shift
Definition: AMCSpec.h:49
unsigned int getSegmented() const
Definition: AMCSpec.h:32
unsigned int size() const
Definition: AMCSpec.h:154
unsigned int getLV1ID() const
Definition: AMCSpec.h:73
Packet(const uint64_t *d)
Definition: AMCSpec.h:130
Definition: AMCSpec.h:8
unsigned int getBlockSize() const
Definition: AMCSpec.cc:57
Header(const uint64_t *data)
Definition: AMCSpec.h:62
std::vector< uint64_t > payload_
Definition: AMCSpec.h:161
uint64_t data0_
Definition: AMCSpec.h:98