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