CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
Block.h
Go to the documentation of this file.
1 #ifndef Block_h
2 #define 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, block_t type=MP7) : id_(id), size_(size), capID_(capID), 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), 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), 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  block_t getType() const { return type_; };
26 
27  uint32_t raw(block_t type=MP7) const;
28 
29  private:
30  static const unsigned int CTP7_shift = 0;
31  static const unsigned int CTP7_mask = 0xffff;
32  static const unsigned int ID_shift = 24;
33  static const unsigned int ID_mask = 0xff;
34  static const unsigned int size_shift = 16;
35  static const unsigned int size_mask = 0xff;
36  static const unsigned int capID_shift = 8;
37  static const unsigned int capID_mask = 0xff;
38 
39  unsigned int id_;
40  unsigned int size_;
41  unsigned int capID_;
43  };
44 
45  class Block {
46  public:
47  Block(const BlockHeader& h, const uint32_t * payload_start, const uint32_t * payload_end) :
48  header_(h), payload_(payload_start, payload_end) {};
49  Block(unsigned int id, const std::vector<uint32_t>& payload, unsigned int capID=0, block_t type=MP7) :
50  header_(id, payload.size(), capID, type), payload_(payload) {};
51 
52  bool operator<(const Block& o) const { return header() < o.header(); };
53 
54  inline unsigned int getSize() const { return payload_.size() + 1; };
55 
56  BlockHeader header() const { return header_; };
57  std::vector<uint32_t> payload() const { return payload_; };
58 
59  void amc(const amc::Header& h) { amc_ = h; };
60  amc::Header amc() const { return amc_; };
61 
62  private:
65  std::vector<uint32_t> payload_;
66  };
67 
68  typedef std::vector<Block> Blocks;
69 
70  class Payload {
71  public:
72  Payload(const uint32_t * data, const uint32_t * end) : data_(data), end_(end), algo_(0), infra_(0) {};
73 
74  virtual unsigned getAlgorithmFWVersion() const { return algo_; };
75  virtual unsigned getInfrastructureFWVersion() const { return infra_; };
76  virtual unsigned getHeaderSize() const = 0;
77  // Read header from data_ and advance data_ to point behind the
78  // header. Called by getBlock(), which also checks that data_ !=
79  // end_ before calling (assumes size of one 32 bit word).
80  virtual BlockHeader getHeader() = 0;
81  virtual std::auto_ptr<Block> getBlock();
82  protected:
83  const uint32_t * data_;
84  const uint32_t * end_;
85 
86  unsigned algo_;
87  unsigned infra_;
88  };
89 
90  class MP7Payload : public Payload {
91  public:
92  MP7Payload(const uint32_t * data, const uint32_t * end, bool legacy_mc=false);
93  virtual unsigned getHeaderSize() const override { return 1; };
94  virtual BlockHeader getHeader() override;
95  };
96 
97  class MTF7Payload : public Payload {
98  public:
99  MTF7Payload(const uint32_t * data, const uint32_t * end);
100  // Unused methods - we override getBlock() instead
101  virtual unsigned getHeaderSize() const override { return 0; };
102  virtual BlockHeader getHeader() override { return BlockHeader(0); };
103  virtual std::auto_ptr<Block> getBlock() override;
104  private:
105  // sizes in 16 bit words
106  static const unsigned int header_size = 12;
107  static const unsigned int counter_size = 4;
108  static const unsigned int trailer_size = 8;
109 
110  // maximum of the block length (64bits) and bit patterns of the
111  // first bits (of 16bit words)
112  static const unsigned int max_block_length_ = 3;
113  static const std::vector<unsigned int> block_patterns_;
114 
115  int count(unsigned int pattern, unsigned int length) const;
116  bool valid(unsigned int pattern) const;
117  };
118 
119  class CTP7Payload : public Payload {
120  public:
121  CTP7Payload(const uint32_t * data, const uint32_t * end);
122  virtual unsigned getHeaderSize() const override { return 2; };
123  virtual BlockHeader getHeader() override;
124  private:
125  // FIXME check values
126  static const unsigned int size_mask = 0xff;
127  static const unsigned int size_shift = 16;
128 
129  unsigned size_;
130  };
131 }
132 
133 #endif
virtual unsigned getHeaderSize() const override
Definition: Block.h:93
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:37
static const unsigned int size_shift
Definition: Block.h:127
virtual BlockHeader getHeader() override
Definition: Block.cc:188
amc::Header amc() const
Definition: Block.h:60
std::vector< uint32_t > payload_
Definition: Block.h:65
static const unsigned int CTP7_mask
Definition: Block.h:31
MP7Payload(const uint32_t *data, const uint32_t *end, bool legacy_mc=false)
Definition: Block.cc:72
Definition: Block.h:10
Block(const BlockHeader &h, const uint32_t *payload_start, const uint32_t *payload_end)
Definition: Block.h:47
virtual std::auto_ptr< Block > getBlock()
Definition: Block.cc:43
BlockHeader(unsigned int id, unsigned int size, unsigned int capID=0, block_t type=MP7)
Definition: Block.h:14
unsigned int getID() const
Definition: Block.h:22
FWCore Framework interface EventSetupRecordImplementation h
Helper function to determine trigger accepts.
virtual std::auto_ptr< Block > getBlock() override
Definition: Block.cc:147
static const unsigned int trailer_size
Definition: Block.h:108
BlockHeader header() const
Definition: Block.h:56
block_t getType() const
Definition: Block.h:25
virtual BlockHeader getHeader() override
Definition: Block.h:102
int count(unsigned int pattern, unsigned int length) const
Definition: Block.cc:124
static const unsigned int ID_shift
Definition: Block.h:32
block_t type_
Definition: Block.h:42
const uint32_t * end_
Definition: Block.h:84
std::vector< uint32_t > payload() const
Definition: Block.h:57
static const unsigned int ID_mask
Definition: Block.h:33
BlockHeader(const uint32_t *data)
Definition: Block.h:16
unsigned size_
Definition: Block.h:129
virtual BlockHeader getHeader()=0
Block(unsigned int id, const std::vector< uint32_t > &payload, unsigned int capID=0, block_t type=MP7)
Definition: Block.h:49
virtual unsigned getInfrastructureFWVersion() const
Definition: Block.h:75
block_t
Definition: Block.h:10
virtual unsigned getAlgorithmFWVersion() const
Definition: Block.h:74
virtual unsigned getHeaderSize() const override
Definition: Block.h:101
CTP7Payload(const uint32_t *data, const uint32_t *end)
Definition: Block.cc:180
static const unsigned int counter_size
Definition: Block.h:107
bool valid(unsigned int pattern) const
Definition: Block.cc:137
std::vector< Block > Blocks
Definition: Block.h:68
virtual unsigned getHeaderSize() const =0
BlockHeader header_
Definition: Block.h:60
static const unsigned int size_mask
Definition: Block.h:35
#define end
Definition: vmac.h:37
unsigned infra_
Definition: Block.h:87
unsigned int size_
Definition: Block.h:40
MTF7Payload(const uint32_t *data, const uint32_t *end)
Definition: Block.cc:95
unsigned int capID_
Definition: Block.h:41
const uint32_t * data_
Definition: Block.h:83
amc::Header amc_
Definition: Block.h:64
unsigned int getCapID() const
Definition: Block.h:24
virtual BlockHeader getHeader() override
Definition: Block.cc:88
static const unsigned int size_mask
Definition: Block.h:126
static const unsigned int CTP7_shift
Definition: Block.h:30
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:82
unsigned int id_
Definition: Block.h:39
virtual unsigned getHeaderSize() const override
Definition: Block.h:122
static const unsigned int header_size
Definition: Block.h:106
bool operator<(const BlockHeader &o) const
Definition: Block.h:20
unsigned int getSize() const
Definition: Block.h:23
static const unsigned int capID_shift
Definition: Block.h:36
static const unsigned int max_block_length_
Definition: Block.h:112
BlockHeader(const uint32_t *data, unsigned int size)
Definition: Block.h:18
static const unsigned int size_shift
Definition: Block.h:34
void amc(const amc::Header &h)
Definition: Block.h:59
unsigned int getSize() const
Definition: Block.h:54
tuple size
Write out results.
unsigned algo_
Definition: Block.h:86
static const std::vector< unsigned int > block_patterns_
Definition: Block.h:113
Payload(const uint32_t *data, const uint32_t *end)
Definition: Block.h:72
bool operator<(const Block &o) const
Definition: Block.h:52