File indexing completed on 2024-04-06 12:04:33
0001 #ifndef __DataFormats_L1THGCal_HGCFETriggerDigi_h__
0002 #define __DataFormats_L1THGCal_HGCFETriggerDigi_h__
0003
0004 #include "FWCore/Utilities/interface/Exception.h"
0005 #include <iostream>
0006 #include <vector>
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036 #include "DataFormats/DetId/interface/DetId.h"
0037
0038 namespace l1t {
0039 constexpr unsigned char hgcal_bad_codec(0xff);
0040 class HGCFETriggerDigi {
0041 public:
0042 typedef std::vector<bool> data_payload;
0043 typedef uint32_t key_type;
0044
0045 HGCFETriggerDigi() : codec_((unsigned char)0xffff) { detid_ = 0; }
0046 ~HGCFETriggerDigi() {}
0047
0048
0049 uint32_t id() const { return detid_; }
0050 template <typename IDTYPE>
0051 IDTYPE getDetId() const {
0052 return IDTYPE(detid_);
0053 }
0054 template <typename IDTYPE>
0055 void setDetId(const IDTYPE& id) {
0056 detid_ = id.rawId();
0057 }
0058
0059
0060 unsigned char getWhichCodec() const { return codec_; }
0061
0062 template <typename CODEC, typename DATA>
0063 void encode(const CODEC& codec, const DATA& data) {
0064 if (codec_ != hgcal_bad_codec) {
0065 throw cms::Exception("HGCTriggerAlreadyEncoded")
0066 << "HGC Codec and data already set with codec: " << std::hex << codec_ << std::dec;
0067 }
0068 codec_ = codec.getCodecType();
0069 data_ = codec.encode(data);
0070 }
0071
0072 template <typename CODEC, typename DATA>
0073 void decode(const CODEC& codec, DATA& data) const {
0074 if (codec_ != codec.getCodecType()) {
0075 throw cms::Exception("HGCTriggerWrongCodec")
0076 << "Wrong HGC codec: " << std::hex << codec.getCodecType()
0077 << " given to data encoded with HGC codec type: " << codec_ << std::dec;
0078 }
0079 data = codec.decode(data_, detid_);
0080 }
0081
0082 void print(std::ostream& out) const;
0083 template <typename CODEC>
0084 void print(const CODEC& codec, std::ostream& out) const;
0085
0086 private:
0087 uint32_t detid_;
0088 unsigned char codec_;
0089 data_payload data_;
0090 };
0091
0092 template <typename CODEC>
0093 void HGCFETriggerDigi::print(const CODEC& codec, std::ostream& out) const {
0094 if (codec_ != codec.getCodecType()) {
0095 throw cms::Exception("HGCTriggerWrongCodec")
0096 << "Wrong HGC codec: " << codec.getCodecType() << " given to data encoded with HGC codec type: " << codec_;
0097 }
0098 out << codec.decode(data_, detid_);
0099 out << std::endl << " decoded from: " << std::endl;
0100 this->print(out);
0101 }
0102 }
0103
0104 #endif