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);
40  class HGCFETriggerDigi {
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) {
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
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
l1t::HGCFETriggerDigi::HGCFETriggerDigi
HGCFETriggerDigi()
Definition: HGCFETriggerDigi.h:69
l1t::HGCFETriggerDigi::detid_
uint32_t detid_
Definition: HGCFETriggerDigi.h:111
l1t::HGCFETriggerDigi::encode
void encode(const CODEC &codec, const DATA &data)
Definition: HGCFETriggerDigi.h:87
l1t::HGCFETriggerDigi::getDetId
IDTYPE getDetId() const
Definition: HGCFETriggerDigi.h:75
l1t::hgcal_bad_codec
constexpr unsigned char hgcal_bad_codec(0xff)
l1t::HGCFETriggerDigi::setDetId
void setDetId(const IDTYPE &id)
Definition: HGCFETriggerDigi.h:79
cscdqm::DATA
Definition: CSCDQM_Summary.h:47
l1t::HGCFETriggerDigi::data_payload
std::vector< bool > data_payload
Definition: HGCFETriggerDigi.h:66
l1t
delete x;
Definition: CaloConfig.h:22
l1t::HGCFETriggerDigi::id
uint32_t id() const
Definition: HGCFETriggerDigi.h:73
l1t::HGCFETriggerDigi::key_type
uint32_t key_type
Definition: HGCFETriggerDigi.h:67
l1t::HGCFETriggerDigi::getWhichCodec
unsigned char getWhichCodec() const
Definition: HGCFETriggerDigi.h:84
l1t::HGCFETriggerDigi::codec_
unsigned char codec_
Definition: HGCFETriggerDigi.h:112
l1t::HGCFETriggerDigi::data_
data_payload data_
Definition: HGCFETriggerDigi.h:113
DetId.h
Exception
Definition: hltDiff.cc:245
Exception.h
data
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:79
MillePedeFileConverter_cfg.out
out
Definition: MillePedeFileConverter_cfg.py:31
l1t::HGCFETriggerDigi::print
void print(std::ostream &out) const
Definition: HGCFETriggerDigi.cc:5
l1t::HGCFETriggerDigi::~HGCFETriggerDigi
~HGCFETriggerDigi()
Definition: HGCFETriggerDigi.h:70
TauDecayModes.dec
dec
Definition: TauDecayModes.py:142
l1t::HGCFETriggerDigi::decode
void decode(const CODEC &codec, DATA &data) const
Definition: HGCFETriggerDigi.h:97