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
amc::Packet::Packet
Packet(const uint64_t *d)
Definition: AMCSpec.h:130
amc::Trailer::getCRC
unsigned int getCRC() const
Definition: AMCSpec.h:108
amc::Packet::addPayload
void addPayload(const uint64_t *, unsigned int)
Definition: AMCSpec.cc:121
start
Definition: start.py:1
amc::Header::User_shift
static const unsigned int User_shift
Definition: AMCSpec.h:95
amc::BlockHeader::BlkNo_shift
static const unsigned int BlkNo_shift
Definition: AMCSpec.h:39
amc::Packet::finalize
void finalize(unsigned int lv1, unsigned int bx, bool legacy_mc=false, bool mtf7_mode=false)
Definition: AMCSpec.cc:125
amc::Trailer::writeCRC
static void writeCRC(const uint64_t *start, uint64_t *end)
Definition: AMCSpec.cc:94
amc::BlockHeader::BlockHeader
BlockHeader()
Definition: AMCSpec.h:15
amc::Trailer
Definition: AMCSpec.h:102
amc::Packet::trailer_
Trailer trailer_
Definition: AMCSpec.h:159
amc::Header
Definition: AMCSpec.h:59
amc::BlockHeader::getSegmented
unsigned int getSegmented() const
Definition: AMCSpec.h:32
amc::BlockHeader::BoardID_mask
static const unsigned int BoardID_mask
Definition: AMCSpec.h:44
l1GtPatternGenerator_cfi.bx
bx
Definition: l1GtPatternGenerator_cfi.py:18
amc::Header::Header
Header(const uint64_t *data)
Definition: AMCSpec.h:62
amc::Trailer::data_
uint64_t data_
Definition: AMCSpec.h:125
amc::Header::AmcNo_shift
static const unsigned int AmcNo_shift
Definition: AMCSpec.h:88
amc::Header::getLV1ID
unsigned int getLV1ID() const
Definition: AMCSpec.h:73
amc::Header::User_mask
static const unsigned int User_mask
Definition: AMCSpec.h:96
amc::Trailer::Trailer
Trailer()
Definition: AMCSpec.h:104
amc::Trailer::check
bool check(unsigned int crc, unsigned int lv1_id, unsigned int size, bool mtf7_mode=false) const
Definition: AMCSpec.cc:82
amc::Trailer::Size_mask
static const unsigned int Size_mask
Definition: AMCSpec.h:119
amc::Trailer::CRC_shift
static const unsigned int CRC_shift
Definition: AMCSpec.h:122
amc::Header::getUserData
unsigned int getUserData() const
Definition: AMCSpec.h:77
amc::split_block_size
static const unsigned int split_block_size
Definition: AMCSpec.h:9
amc::Packet::payload_
std::vector< uint64_t > payload_
Definition: AMCSpec.h:161
amc::BlockHeader::Valid_bit_shift
static const unsigned int Valid_bit_shift
Definition: AMCSpec.h:51
amc::Packet::header
Header header() const
Definition: AMCSpec.h:149
amc::Header::Size_mask
static const unsigned int Size_mask
Definition: AMCSpec.h:83
amc::BlockHeader::Size_mask
static const unsigned int Size_mask
Definition: AMCSpec.h:38
amc::Packet::blocks
unsigned int blocks() const
Definition: AMCSpec.h:152
amc::Header::LV1ID_shift
static const unsigned int LV1ID_shift
Definition: AMCSpec.h:86
amc::Header::Header
Header()
Definition: AMCSpec.h:61
amc::Header::AmcNo_mask
static const unsigned int AmcNo_mask
Definition: AMCSpec.h:89
amc::BlockHeader::getBlocks
unsigned int getBlocks() const
Definition: AMCSpec.cc:47
amc::BlockHeader::validCRC
unsigned int validCRC() const
Definition: AMCSpec.h:34
amc::BlockHeader::Segmented_bit_shift
static const unsigned int Segmented_bit_shift
Definition: AMCSpec.h:48
amc::Header::BX_shift
static const unsigned int BX_shift
Definition: AMCSpec.h:84
mps_fire.end
end
Definition: mps_fire.py:242
amc::Trailer::raw
uint64_t raw() const
Definition: AMCSpec.h:112
amc::Packet
Definition: AMCSpec.h:128
svgfig.load
def load(fileName)
Definition: svgfig.py:547
amc::Packet::header_
Header header_
Definition: AMCSpec.h:158
amc::BlockHeader::getMore
unsigned int getMore() const
Definition: AMCSpec.h:31
amc::BlockHeader::data_
uint64_t data_
Definition: AMCSpec.h:54
amc::Header::BoardID_mask
static const unsigned int BoardID_mask
Definition: AMCSpec.h:92
amc::BlockHeader::Present_bit_shift
static const unsigned int Present_bit_shift
Definition: AMCSpec.h:50
amc::Header::getOrbitNumber
unsigned int getOrbitNumber() const
Definition: AMCSpec.h:75
amc::BlockHeader::raw
uint64_t raw() const
Definition: AMCSpec.h:23
amc::BlockHeader::More_bit_shift
static const unsigned int More_bit_shift
Definition: AMCSpec.h:47
amc::Header::getBX
unsigned int getBX() const
Definition: AMCSpec.h:74
amc::Packet::block
std::vector< uint64_t > block(unsigned int id) const
Definition: AMCSpec.cc:143
amc::BlockHeader::BlockHeader
BlockHeader(const uint64_t *data)
Definition: AMCSpec.h:16
amc::BlockHeader::AmcNo_shift
static const unsigned int AmcNo_shift
Definition: AMCSpec.h:41
amc::Trailer::getSize
unsigned int getSize() const
Definition: AMCSpec.h:110
amc::Packet::blockHeader
BlockHeader blockHeader(unsigned int block=0) const
Definition: AMCSpec.h:148
amc::BlockHeader::Length_bit_shift
static const unsigned int Length_bit_shift
Definition: AMCSpec.h:46
amc::Header::OrN_mask
static const unsigned int OrN_mask
Definition: AMCSpec.h:94
amc::BlockHeader::getBlockSize
unsigned int getBlockSize() const
Definition: AMCSpec.cc:57
groupFilesInBlocks.block
block
Definition: groupFilesInBlocks.py:150
amc::Header::raw
std::vector< uint64_t > raw() const
Definition: AMCSpec.h:79
amc::BlockHeader::BlkNo_mask
static const unsigned int BlkNo_mask
Definition: AMCSpec.h:40
amc::BlockHeader::Enabled_bit_shift
static const unsigned int Enabled_bit_shift
Definition: AMCSpec.h:49
amc::Header::getBoardID
unsigned int getBoardID() const
Definition: AMCSpec.h:72
amc::BlockHeader::getAMCNumber
unsigned int getAMCNumber() const
Definition: AMCSpec.h:28
EnviromentSettings.user
user
Definition: EnviromentSettings.py:30
amc::Trailer::LV1ID_shift
static const unsigned int LV1ID_shift
Definition: AMCSpec.h:120
amc::Header::BoardID_shift
static const unsigned int BoardID_shift
Definition: AMCSpec.h:91
amc::BlockHeader::BoardID_shift
static const unsigned int BoardID_shift
Definition: AMCSpec.h:43
amc::Header::getAMCNumber
unsigned int getAMCNumber() const
Definition: AMCSpec.h:71
amc::BlockHeader::getBoardID
unsigned int getBoardID() const
Definition: AMCSpec.h:29
amc::Header::getSize
unsigned int getSize() const
Definition: AMCSpec.h:76
amc::Trailer::CRC_mask
static const unsigned int CRC_mask
Definition: AMCSpec.h:123
amc::Header::OrN_shift
static const unsigned int OrN_shift
Definition: AMCSpec.h:93
amc::Trailer::LV1ID_mask
static const unsigned int LV1ID_mask
Definition: AMCSpec.h:121
amc::Header::BX_mask
static const unsigned int BX_mask
Definition: AMCSpec.h:85
amc::BlockHeader::getSize
unsigned int getSize() const
Definition: AMCSpec.h:30
amc
Definition: AMCSpec.h:8
amc::BlockHeader::AmcNo_mask
static const unsigned int AmcNo_mask
Definition: AMCSpec.h:42
amc::Header::data1_
uint64_t data1_
Definition: AMCSpec.h:99
data
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:79
amc::Header::data0_
uint64_t data0_
Definition: AMCSpec.h:98
cond::uint64_t
unsigned long long uint64_t
Definition: Time.h:13
amc::Packet::block_header_
BlockHeader block_header_
Definition: AMCSpec.h:154
ztail.d
d
Definition: ztail.py:151
amc::Packet::trailer
Trailer trailer() const
Definition: AMCSpec.h:150
amc::Header::Size_shift
static const unsigned int Size_shift
Definition: AMCSpec.h:82
amc::BlockHeader::CRC_bit_shift
static const unsigned int CRC_bit_shift
Definition: AMCSpec.h:52
amc::Packet::data
std::unique_ptr< uint64_t[]> data()
Definition: AMCSpec.cc:154
amc::Trailer::Trailer
Trailer(const uint64_t *data)
Definition: AMCSpec.h:105
amc::Header::LV1ID_mask
static const unsigned int LV1ID_mask
Definition: AMCSpec.h:87
amc::Trailer::Size_shift
static const unsigned int Size_shift
Definition: AMCSpec.h:118
amc::BlockHeader::Size_shift
static const unsigned int Size_shift
Definition: AMCSpec.h:37
findQualityFiles.size
size
Write out results.
Definition: findQualityFiles.py:443
amc::Trailer::getLV1ID
unsigned int getLV1ID() const
Definition: AMCSpec.h:109
amc::BlockHeader
Definition: AMCSpec.h:13
amc::Packet::size
unsigned int size() const
Definition: AMCSpec.h:154