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 
8 
9 namespace l1t {
10  enum block_t { MP7 = 0, CTP7, MTF7 };
11 
12  class BlockHeader {
13  public:
14  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) {};
15  // Create a MP7 block header: everything is contained in the raw uint32
16  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) {};
17  // Create a CTP7 block header: size is contained in the general CTP7 header
18  BlockHeader(const uint32_t *data, unsigned int size) : id_((data[0] >> CTP7_shift) & CTP7_mask), size_(size), capID_(0), flags_(0), type_(CTP7) {};
19 
20  bool operator<(const BlockHeader& o) const { return getID() < o.getID(); };
21 
22  unsigned int getID() const { return id_; };
23  unsigned int getSize() const { return size_; };
24  unsigned int getCapID() const { return capID_; };
25  unsigned int getFlags() const { return flags_; };
26  block_t getType() const { return type_; };
27 
28  uint32_t raw(block_t type=MP7) const;
29 
30  private:
31  static const unsigned int CTP7_shift = 0;
32  static const unsigned int CTP7_mask = 0xffff;
33  static const unsigned int ID_shift = 24;
34  static const unsigned int ID_mask = 0xff;
35  static const unsigned int size_shift = 16;
36  static const unsigned int size_mask = 0xff;
37  static const unsigned int capID_shift = 8;
38  static const unsigned int capID_mask = 0xff;
39  static const unsigned int flags_shift = 0;
40  static const unsigned int flags_mask = 0xff;
41 
42  unsigned int id_;
43  unsigned int size_;
44  unsigned int capID_;
45  unsigned int flags_;
47  };
48 
49  class Block {
50  public:
51  Block(const BlockHeader& h, const uint32_t * payload_start, const uint32_t * payload_end) :
52  header_(h), payload_(payload_start, payload_end) {};
53  Block(unsigned int id, const std::vector<uint32_t>& payload, unsigned int capID=0, block_t type=MP7) :
54  header_(id, payload.size(), capID, type), payload_(payload) {};
55 
56  bool operator<(const Block& o) const { return header() < o.header(); };
57 
58  inline unsigned int getSize() const { return payload_.size() + 1; };
59 
60  BlockHeader header() const { return header_; };
61  std::vector<uint32_t> payload() const { return payload_; };
62 
63  void amc(const amc::Header& h) { amc_ = h; };
64  amc::Header amc() const { return amc_; };
65 
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  virtual unsigned getHeaderSize() const override { return 1; };
98  virtual 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  virtual unsigned getHeaderSize() const override { return 0; };
106  virtual BlockHeader getHeader() override { return BlockHeader(0); };
107  virtual std::unique_ptr<Block> getBlock() override;
108  private:
109  // sizes in 16 bit words
110  static const unsigned int header_size = 12;
111  static const unsigned int counter_size = 4;
112  static const unsigned int trailer_size = 8;
113 
114  // maximum of the block length (64bits) and bit patterns of the
115  // first bits (of 16bit words)
116  static const unsigned int 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);
126  virtual unsigned getHeaderSize() const override { return 2; };
127  virtual BlockHeader getHeader() override;
128  private:
129  // FIXME check values
130  static const unsigned int size_mask = 0xff;
131  static const unsigned int size_shift = 16;
132 
133  unsigned size_;
134  };
135 }
136 
137 #endif
size
Write out results.
uint32_t raw(block_t type=MP7) const
Definition: Block.cc:28
type
Definition: HCALResponse.h:21
static const unsigned int capID_mask
Definition: Block.h:38
std::vector< uint32_t > payload_
Definition: Block.h:69
static const unsigned int CTP7_mask
Definition: Block.h:32
Definition: Block.h:10
Block(const BlockHeader &h, const uint32_t *payload_start, const uint32_t *payload_end)
Definition: Block.h:51
unsigned int getID() const
Definition: Block.h:22
FWCore Framework interface EventSetupRecordImplementation h
Helper function to determine trigger accepts.
std::vector< l1t::Jet >::iterator end_
BlockHeader header() const
Definition: Block.h:60
block_t getType() const
Definition: Block.h:26
std::vector< Variable::Flags > flags
Definition: MVATrainer.cc:135
virtual BlockHeader getHeader() override
Definition: Block.h:106
delete x;
Definition: CaloConfig.h:22
virtual unsigned getHeaderSize() const override
Definition: Block.h:97
static const unsigned int ID_shift
Definition: Block.h:33
block_t type_
Definition: Block.h:46
const uint32_t * end_
Definition: Block.h:88
unsigned int flags_
Definition: Block.h:45
std::vector< uint32_t > payload() const
Definition: Block.h:61
static const unsigned int ID_mask
Definition: Block.h:34
BlockHeader(const uint32_t *data)
Definition: Block.h:16
virtual ~Payload()
Definition: Block.h:77
unsigned size_
Definition: Block.h:133
virtual unsigned getHeaderSize() const override
Definition: Block.h:105
Block(unsigned int id, const std::vector< uint32_t > &payload, unsigned int capID=0, block_t type=MP7)
Definition: Block.h:53
payload
payload postfix for testing
virtual unsigned getInfrastructureFWVersion() const
Definition: Block.h:79
block_t
Definition: Block.h:10
virtual unsigned getAlgorithmFWVersion() const
Definition: Block.h:78
double amc
Definition: hdecay.h:20
std::vector< Block > Blocks
Definition: Block.h:72
BlockHeader header_
Definition: Block.h:64
static const unsigned int size_mask
Definition: Block.h:36
#define end
Definition: vmac.h:37
unsigned infra_
Definition: Block.h:91
unsigned int size_
Definition: Block.h:43
unsigned int capID_
Definition: Block.h:44
const uint32_t * data_
Definition: Block.h:87
amc::Header amc_
Definition: Block.h:68
unsigned int getCapID() const
Definition: Block.h:24
static const unsigned int CTP7_shift
Definition: Block.h:31
static const unsigned int flags_mask
Definition: Block.h:40
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:82
unsigned int id_
Definition: Block.h:42
bool operator<(const BlockHeader &o) const
Definition: Block.h:20
unsigned int getSize() const
Definition: Block.h:23
BlockHeader(unsigned int id, unsigned int size, unsigned int capID=0, unsigned int flags=0, block_t type=MP7)
Definition: Block.h:14
static const unsigned int capID_shift
Definition: Block.h:37
BlockHeader(const uint32_t *data, unsigned int size)
Definition: Block.h:18
static const unsigned int size_shift
Definition: Block.h:35
void amc(const amc::Header &h)
Definition: Block.h:63
unsigned int getFlags() const
Definition: Block.h:25
static const unsigned int flags_shift
Definition: Block.h:39
unsigned int getSize() const
Definition: Block.h:58
virtual unsigned getHeaderSize() const override
Definition: Block.h:126
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:56