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 
43  typedef std::vector<bool> data_payload;
44  typedef uint32_t key_type;
45 
46  HGCFETriggerDigi() : codec_((unsigned char)0xffff) {}
48 
49  //detector id information
50  uint32_t id() const { return detid_; } // for edm::SortedCollection
51  template<typename IDTYPE>
52  IDTYPE getDetId() const { return IDTYPE(detid_); }
53  template<typename IDTYPE>
54  void setDetId(const IDTYPE& id) { detid_ = id.rawId(); }
55 
56  // encoding and decoding
57  unsigned char getWhichCodec() const { return codec_; }
58 
59  template<typename CODEC,typename DATA>
60  void encode(const CODEC& codec, const DATA& data) {
61  if( codec_ != hgcal_bad_codec ) {
62  throw cms::Exception("HGCTriggerAlreadyEncoded")
63  << "HGC Codec and data already set with codec: "
64  << std::hex << codec_ << std::dec;
65  }
66  codec_ = codec.getCodecType();
67  data_ = codec.encode(data);
68  }
69 
70  template<typename CODEC, typename DATA>
71  void decode(const CODEC& codec, DATA& data) const {
72  if( codec_ != codec.getCodecType() ){
73  throw cms::Exception("HGCTriggerWrongCodec")
74  << "Wrong HGC codec: " << std::hex << codec.getCodecType()
75  << " given to data encoded with HGC codec type: "
76  << codec_ << std::dec;
77  }
78  data = codec.decode(data_, detid_);
79  }
80 
81  void print(std::ostream& out) const;
82  template<typename CODEC>
83  void print(const CODEC& codec, std::ostream& out) const;
84 
85  private:
86  uint32_t detid_; // save in the abstract form
87  unsigned char codec_; // 0xff is special and means no encoder
88  data_payload data_;
89  };
90 
91  template<typename CODEC>
92  void HGCFETriggerDigi::print(const CODEC& codec, std::ostream& out) const {
93  if( codec_ != codec.getCodecType() ){
94  throw cms::Exception("HGCTriggerWrongCodec")
95  << "Wrong HGC codec: " << codec.getCodecType()
96  << " given to data encoded with HGC codec type: "
97  << codec_;
98  }
99  out << codec.decode(data_, detid_);
100  out << std::endl << " decoded from: " << std::endl;
101  this->print(out);
102  }
103 }
104 
105 #endif
void decode(const CODEC &codec, DATA &data) const
unsigned char getWhichCodec() const
delete x;
Definition: CaloConfig.h:22
#define constexpr
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