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 };
11 
12  class BlockHeader {
13  public:
14  BlockHeader(unsigned int id, unsigned int size, block_t type=MP7) : id_(id), size_(size), 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), 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), 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  block_t getType() const { return type_; };
25 
26  uint32_t raw(block_t type=MP7) const;
27 
28  private:
29  static const unsigned int CTP7_shift = 0;
30  static const unsigned int CTP7_mask = 0xffff;
31  static const unsigned int ID_shift = 24;
32  static const unsigned int ID_mask = 0xff;
33  static const unsigned int size_shift = 16;
34  static const unsigned int size_mask = 0xff;
35 
36  unsigned int id_;
37  unsigned int size_;
39  };
40 
41  class Block {
42  public:
43  Block(const BlockHeader& h, const uint32_t * payload_start, const uint32_t * payload_end) :
44  header_(h), payload_(payload_start, payload_end) {};
45  Block(unsigned int id, const std::vector<uint32_t>& payload, block_t type=MP7) :
46  header_(id, payload.size(), type), payload_(payload) {};
47 
48  bool operator<(const Block& o) const { return header() < o.header(); };
49 
50  inline unsigned int getSize() const { return payload_.size() + 1; };
51 
52  BlockHeader header() const { return header_; };
53  std::vector<uint32_t> payload() const { return payload_; };
54 
55  void amc(const amc::Header& h) { amc_ = h; };
56  amc::Header amc() const { return amc_; };
57 
58  private:
61  std::vector<uint32_t> payload_;
62  };
63 
64  typedef std::vector<Block> Blocks;
65 
66  class Payload {
67  public:
68  Payload(const uint32_t * data, const uint32_t * end) : data_(data), end_(end), fw_(0) {};
69 
70  unsigned getFirmwareId() const { return fw_; };
71  virtual unsigned getHeaderSize() const = 0;
72  // Read header from data_ and advance data_ to point behind the
73  // header. Called by getBlock(), which also checks that data_ !=
74  // end_ before calling (assumes size of one 32 bit word).
75  virtual BlockHeader getHeader() = 0;
76  std::auto_ptr<Block> getBlock();
77  protected:
78  const uint32_t * data_;
79  const uint32_t * end_;
80 
81  unsigned fw_;
82  };
83 
84  class MP7Payload : public Payload {
85  public:
86  MP7Payload(const uint32_t * data, const uint32_t * end);
87  virtual unsigned getHeaderSize() const override { return 1; };
88  virtual BlockHeader getHeader() override;
89  };
90 
91  class CTP7Payload : public Payload {
92  public:
93  CTP7Payload(const uint32_t * data, const uint32_t * end);
94  virtual unsigned getHeaderSize() const override { return 2; };
95  virtual BlockHeader getHeader() override;
96  private:
97  // FIXME check values
98  static const unsigned int size_mask = 0xff;
99  static const unsigned int size_shift = 16;
100 
101  unsigned size_;
102  };
103 }
104 
105 #endif
virtual unsigned getHeaderSize() const override
Definition: Block.h:87
uint32_t raw(block_t type=MP7) const
Definition: Block.cc:9
type
Definition: HCALResponse.h:21
static const unsigned int size_shift
Definition: Block.h:99
virtual BlockHeader getHeader() override
Definition: Block.cc:63
amc::Header amc() const
Definition: Block.h:56
std::vector< uint32_t > payload_
Definition: Block.h:61
static const unsigned int CTP7_mask
Definition: Block.h:30
Block(const BlockHeader &h, const uint32_t *payload_start, const uint32_t *payload_end)
Definition: Block.h:43
std::auto_ptr< Block > getBlock()
Definition: Block.cc:20
unsigned fw_
Definition: Block.h:81
unsigned int getID() const
Definition: Block.h:22
Definition: Block.h:10
BlockHeader header() const
Definition: Block.h:52
block_t getType() const
Definition: Block.h:24
static const unsigned int ID_shift
Definition: Block.h:31
block_t type_
Definition: Block.h:38
const uint32_t * end_
Definition: Block.h:79
std::vector< uint32_t > payload() const
Definition: Block.h:53
static const unsigned int ID_mask
Definition: Block.h:32
BlockHeader(const uint32_t *data)
Definition: Block.h:16
unsigned size_
Definition: Block.h:101
virtual BlockHeader getHeader()=0
block_t
Definition: Block.h:10
CTP7Payload(const uint32_t *data, const uint32_t *end)
Definition: Block.cc:55
std::vector< Block > Blocks
Definition: Block.h:64
virtual unsigned getHeaderSize() const =0
BlockHeader header_
Definition: Block.h:56
BlockHeader(unsigned int id, unsigned int size, block_t type=MP7)
Definition: Block.h:14
The Signals That Services Can Subscribe To This is based on ActivityRegistry h
Helper function to determine trigger accepts.
Definition: Activities.doc:4
static const unsigned int size_mask
Definition: Block.h:34
#define end
Definition: vmac.h:37
unsigned int size_
Definition: Block.h:37
const uint32_t * data_
Definition: Block.h:78
amc::Header amc_
Definition: Block.h:60
virtual BlockHeader getHeader() override
Definition: Block.cc:49
static const unsigned int size_mask
Definition: Block.h:98
static const unsigned int CTP7_shift
Definition: Block.h:29
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:82
unsigned int id_
Definition: Block.h:36
virtual unsigned getHeaderSize() const override
Definition: Block.h:94
unsigned getFirmwareId() const
Definition: Block.h:70
bool operator<(const BlockHeader &o) const
Definition: Block.h:20
unsigned int getSize() const
Definition: Block.h:23
BlockHeader(const uint32_t *data, unsigned int size)
Definition: Block.h:18
static const unsigned int size_shift
Definition: Block.h:33
Block(unsigned int id, const std::vector< uint32_t > &payload, block_t type=MP7)
Definition: Block.h:45
void amc(const amc::Header &h)
Definition: Block.h:55
unsigned int getSize() const
Definition: Block.h:50
tuple size
Write out results.
Payload(const uint32_t *data, const uint32_t *end)
Definition: Block.h:68
MP7Payload(const uint32_t *data, const uint32_t *end)
Definition: Block.cc:40
bool operator<(const Block &o) const
Definition: Block.h:48