CMS 3D CMS Logo

HGCFETriggerDigi.h
Go to the documentation of this file.
1 #ifndef __DataFormats_L1THGCal_HGCFETriggerDigi_h__
2 #define __DataFormats_L1THGCal_HGCFETriggerDigi_h__
3 
5 #include <iostream>
6 #include <vector>
7 
8 /*******
9  *
10  * Class: l1t::HGCFETriggerDigi
11  * Author: L. Gray (FNAL)
12  * Date: 26 July, 2015
13  *
14  * An abstract representation of an HGC Front-End Trigger data payload.
15  * The user of the class (some trigger algorithm) provides a codec in
16  * order to interpret the data payload held within class. This implementation
17  * is chosen since final form of the HGC trigger primitives was not known
18  * in July 2015.
19  *
20  * The CODEC class used below *must* implement the following interfaces:
21  *
22  * CODEC::getCodecType() const -- returns an unsigned char indexing the codec
23  *
24  * CODEC::encode(const DATA&) const
25  * -- encodes the data payload described by DATA into std::vector<bool>
26  *
27  * DATA CODEC::decode(const std::vector<bool>& data) const
28  * -- decodes a std::vector<bool> into DATA
29  *
30  * DATA must implement the following interfaces:
31  * DATA::operator<<(std::ostream& out) const
32  * -- prints the contents of the formatted data
33  *
34  *******/
35 
37 
38 namespace l1t {
39  constexpr unsigned char hgcal_bad_codec(0xff);
41  public:
42  typedef std::vector<bool> data_payload;
43  typedef uint32_t key_type;
44 
45  HGCFETriggerDigi() : codec_((unsigned char)0xffff) { detid_ = 0; }
47 
48  //detector id information
49  uint32_t id() const { return detid_; } // for edm::SortedCollection
50  template <typename IDTYPE>
51  IDTYPE getDetId() const {
52  return IDTYPE(detid_);
53  }
54  template <typename IDTYPE>
55  void setDetId(const IDTYPE& id) {
56  detid_ = id.rawId();
57  }
58 
59  // encoding and decoding
60  unsigned char getWhichCodec() const { return codec_; }
61 
62  template <typename CODEC, typename DATA>
63  void encode(const CODEC& codec, const DATA& data) {
64  if (codec_ != hgcal_bad_codec) {
65  throw cms::Exception("HGCTriggerAlreadyEncoded")
66  << "HGC Codec and data already set with codec: " << std::hex << codec_ << std::dec;
67  }
68  codec_ = codec.getCodecType();
69  data_ = codec.encode(data);
70  }
71 
72  template <typename CODEC, typename DATA>
73  void decode(const CODEC& codec, DATA& data) const {
74  if (codec_ != codec.getCodecType()) {
75  throw cms::Exception("HGCTriggerWrongCodec")
76  << "Wrong HGC codec: " << std::hex << codec.getCodecType()
77  << " given to data encoded with HGC codec type: " << codec_ << std::dec;
78  }
79  data = codec.decode(data_, detid_);
80  }
81 
82  void print(std::ostream& out) const;
83  template <typename CODEC>
84  void print(const CODEC& codec, std::ostream& out) const;
85 
86  private:
87  uint32_t detid_; // save in the abstract form
88  unsigned char codec_; // 0xff is special and means no encoder
89  data_payload data_;
90  };
91 
92  template <typename CODEC>
93  void HGCFETriggerDigi::print(const CODEC& codec, std::ostream& out) const {
94  if (codec_ != codec.getCodecType()) {
95  throw cms::Exception("HGCTriggerWrongCodec")
96  << "Wrong HGC codec: " << codec.getCodecType() << " given to data encoded with HGC codec type: " << codec_;
97  }
98  out << codec.decode(data_, detid_);
99  out << std::endl << " decoded from: " << std::endl;
100  this->print(out);
101  }
102 } // namespace l1t
103 
104 #endif
void decode(const CODEC &codec, DATA &data) const
unsigned char getWhichCodec() const
delete x;
Definition: CaloConfig.h:22
std::vector< bool > data_payload
uint32_t id() const
void encode(const CODEC &codec, const DATA &data)
void setDetId(const IDTYPE &id)
unsigned char hgcal_bad_codec(0xff)
void print(std::ostream &out) const
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:82
IDTYPE getDetId() const
#define constexpr