test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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 <stdint.h>
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, unsigned int lv1_id, unsigned int bx_id, unsigned int size,
64  unsigned int or_n, unsigned int board_id, unsigned int user);
65 
66  inline unsigned int getAMCNumber() const { return (data0_ >> AmcNo_shift) & AmcNo_mask; };
67  inline unsigned int getBoardID() const { return (data1_ >> BoardID_shift) & BoardID_mask; };
68  inline unsigned int getLV1ID() const { return (data0_ >> LV1ID_shift) & LV1ID_mask; };
69  inline unsigned int getBX() const { return (data0_ >> BX_shift) & BX_mask; };
70  inline unsigned int getOrbitNumber() const { return (data1_ >> OrN_shift) & OrN_mask; };
71  inline unsigned int getSize() const { return (data0_ >> Size_shift) & Size_mask; };
72  inline unsigned int getUserData() const { return (data1_ >> User_shift) & User_mask; };
73 
74  std::vector<uint64_t> raw() const { return {data0_, data1_}; };
75 
76  private:
77  static const unsigned int Size_shift = 0;
78  static const unsigned int Size_mask = 0xfffff;
79  static const unsigned int BX_shift = 20;
80  static const unsigned int BX_mask = 0xfff;
81  static const unsigned int LV1ID_shift = 32;
82  static const unsigned int LV1ID_mask = 0xffffff;
83  static const unsigned int AmcNo_shift = 56;
84  static const unsigned int AmcNo_mask = 0xf;
85 
86  static const unsigned int BoardID_shift = 0;
87  static const unsigned int BoardID_mask = 0xffff;
88  static const unsigned int OrN_shift = 16;
89  static const unsigned int OrN_mask = 0xffff;
90  static const unsigned int User_shift = 32;
91  static const unsigned int User_mask = 0xffffffff;
92 
95  };
96 
97  class Trailer {
98  public:
99  Trailer() : data_(0) {};
100  Trailer(const uint64_t *data) : data_(data[0]) {};
101  Trailer(unsigned int crc, unsigned int lv1_id, unsigned int size);
102 
103  inline unsigned int getCRC() const { return (data_ >> CRC_shift) & CRC_mask; };
104  inline unsigned int getLV1ID() const { return (data_ >> LV1ID_shift) & LV1ID_mask; };
105  inline unsigned int getSize() const { return (data_ >> Size_shift) & Size_mask; };
106 
107  uint64_t raw() const { return data_; }
108  bool check(unsigned int crc, unsigned int lv1_id, unsigned int size, bool mtf7_mode=false) const;
109 
110  static void writeCRC(const uint64_t *start, uint64_t *end);
111 
112  private:
113  static const unsigned int Size_shift = 0;
114  static const unsigned int Size_mask = 0xfffff;
115  static const unsigned int LV1ID_shift = 24;
116  static const unsigned int LV1ID_mask = 0xff;
117  static const unsigned int CRC_shift = 32;
118  static const unsigned int CRC_mask = 0xffffffff;
119 
121  };
122 
123  class Packet {
124  public:
125  Packet(const uint64_t* d) : block_header_(d) {};
126  Packet(unsigned int amc, unsigned int board, unsigned int lv1id, unsigned int orbit, unsigned int bx, const std::vector<uint64_t>& load);
127 
128  // Add payload fragment from an AMC13 block to the AMC packet
129  void addPayload(const uint64_t*, unsigned int);
130  // To be called after the last payload addition. Removes header
131  // and trailer from the actual paylod. Also performs
132  // cross-checks for data consistency.
133  void finalize(unsigned int lv1, unsigned int bx, bool legacy_mc=false, bool mtf7_mode=false);
134 
135  std::vector<uint64_t> block(unsigned int id) const;
136  std::unique_ptr<uint64_t[]> data();
137  BlockHeader blockHeader(unsigned int block=0) const { return block_header_; };
138  Header header() const { return header_; };
139  Trailer trailer() const { return trailer_; };
140 
141  inline unsigned int blocks() const { return block_header_.getBlocks(); };
142  // Returns the size of the payload _without_ the headers
143  inline unsigned int size() const { return payload_.size() - 3; };
144 
145  private:
149 
150  std::vector<uint64_t> payload_;
151  };
152 }
153 
154 #endif
static const unsigned int Size_mask
Definition: AMCSpec.h:114
unsigned int getLV1ID() const
Definition: AMCSpec.h:104
static const unsigned int AmcNo_mask
Definition: AMCSpec.h:84
static const unsigned int CRC_mask
Definition: AMCSpec.h:118
static const unsigned int BoardID_mask
Definition: AMCSpec.h:44
tuple start
Check for commandline option errors.
Definition: dqm_diff.py:58
uint64_t data_
Definition: AMCSpec.h:120
uint64_t raw() const
Definition: AMCSpec.h:23
static const unsigned int BX_mask
Definition: AMCSpec.h:80
static const unsigned int BoardID_shift
Definition: AMCSpec.h:86
static const unsigned int Size_shift
Definition: AMCSpec.h:37
static const unsigned int CRC_bit_shift
Definition: AMCSpec.h:52
unsigned int getSize() const
Definition: AMCSpec.h:105
unsigned int getAMCNumber() const
Definition: AMCSpec.h:66
static void writeCRC(const uint64_t *start, uint64_t *end)
Definition: AMCSpec.cc:118
unsigned int getBX() const
Definition: AMCSpec.h:69
unsigned int getCRC() const
Definition: AMCSpec.h:103
static const unsigned int Size_shift
Definition: AMCSpec.h:77
BlockHeader block_header_
Definition: AMCSpec.h:143
static const unsigned int Size_mask
Definition: AMCSpec.h:78
uint64_t raw() const
Definition: AMCSpec.h:107
static const unsigned int LV1ID_mask
Definition: AMCSpec.h:82
unsigned int getMore() const
Definition: AMCSpec.h:31
std::vector< uint64_t > block(unsigned int id) const
Definition: AMCSpec.cc:167
unsigned int getAMCNumber() const
Definition: AMCSpec.h:28
static const unsigned int CRC_shift
Definition: AMCSpec.h:117
static const unsigned int Segmented_bit_shift
Definition: AMCSpec.h:48
static const unsigned int Present_bit_shift
Definition: AMCSpec.h:50
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:142
tuple d
Definition: ztail.py:151
void finalize(unsigned int lv1, unsigned int bx, bool legacy_mc=false, bool mtf7_mode=false)
Definition: AMCSpec.cc:148
static const unsigned int OrN_mask
Definition: AMCSpec.h:89
static const unsigned int LV1ID_shift
Definition: AMCSpec.h:81
static const unsigned int Valid_bit_shift
Definition: AMCSpec.h:51
double amc
Definition: hdecay.h:20
std::vector< uint64_t > raw() const
Definition: AMCSpec.h:74
static const unsigned int BlkNo_mask
Definition: AMCSpec.h:40
unsigned int getBlocks() const
Definition: AMCSpec.cc:54
static const unsigned int LV1ID_shift
Definition: AMCSpec.h:115
def load
Definition: svgfig.py:546
static const unsigned int Size_mask
Definition: AMCSpec.h:38
static const unsigned int AmcNo_shift
Definition: AMCSpec.h:83
static const unsigned int split_block_size
Definition: AMCSpec.h:9
static const unsigned int BX_shift
Definition: AMCSpec.h:79
#define end
Definition: vmac.h:37
static const unsigned int User_shift
Definition: AMCSpec.h:90
BlockHeader blockHeader(unsigned int block=0) const
Definition: AMCSpec.h:137
uint64_t data1_
Definition: AMCSpec.h:94
static const unsigned int More_bit_shift
Definition: AMCSpec.h:47
static const unsigned int BoardID_mask
Definition: AMCSpec.h:87
Trailer trailer_
Definition: AMCSpec.h:148
unsigned int getBlockSize() const
Definition: AMCSpec.cc:66
uint64_t data_
Definition: AMCSpec.h:54
Trailer trailer() const
Definition: AMCSpec.h:139
static const unsigned int AmcNo_mask
Definition: AMCSpec.h:42
unsigned int size() const
Definition: AMCSpec.h:143
static const unsigned int LV1ID_mask
Definition: AMCSpec.h:116
static const unsigned int BoardID_shift
Definition: AMCSpec.h:43
unsigned long long uint64_t
Definition: Time.h:15
unsigned int getSize() const
Definition: AMCSpec.h:30
Header header() const
Definition: AMCSpec.h:138
unsigned int getOrbitNumber() const
Definition: AMCSpec.h:70
unsigned int getSize() const
Definition: AMCSpec.h:71
static const unsigned int User_mask
Definition: AMCSpec.h:91
BlockHeader(const uint64_t *data)
Definition: AMCSpec.h:16
unsigned int getBoardID() const
Definition: AMCSpec.h:29
static const unsigned int OrN_shift
Definition: AMCSpec.h:88
unsigned int getUserData() const
Definition: AMCSpec.h:72
Header header_
Definition: AMCSpec.h:147
static const unsigned int Length_bit_shift
Definition: AMCSpec.h:46
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:82
std::unique_ptr< uint64_t[]> data()
Definition: AMCSpec.cc:179
Trailer(const uint64_t *data)
Definition: AMCSpec.h:100
unsigned int validCRC() const
Definition: AMCSpec.h:34
static const unsigned int Size_shift
Definition: AMCSpec.h:113
unsigned int getBoardID() const
Definition: AMCSpec.h:67
unsigned int getSegmented() const
Definition: AMCSpec.h:32
static const unsigned int Enabled_bit_shift
Definition: AMCSpec.h:49
bool check(unsigned int crc, unsigned int lv1_id, unsigned int size, bool mtf7_mode=false) const
Definition: AMCSpec.cc:102
Packet(const uint64_t *d)
Definition: AMCSpec.h:125
unsigned int getLV1ID() const
Definition: AMCSpec.h:68
Header(const uint64_t *data)
Definition: AMCSpec.h:62
unsigned int blocks() const
Definition: AMCSpec.h:141
tuple size
Write out results.
std::vector< uint64_t > payload_
Definition: AMCSpec.h:150
uint64_t data0_
Definition: AMCSpec.h:93