CMS 3D CMS Logo

HGCalTriggerFECodecBase.h
Go to the documentation of this file.
1 #ifndef __L1Trigger_L1THGCal_HGCalTriggerFECodecBase_h__
2 #define __L1Trigger_L1THGCal_HGCalTriggerFECodecBase_h__
3 
5 
7 
9 
11 
12 /*******
13  *
14  * class: HGCalTriggerCodecBase
15  * author: L.Gray (FNAL)
16  * date: 27 July, 2015
17  *
18  * Base classes for defining HGCal FE codec classes.
19  * The base class defines an abstract interface, which is then specialized
20  * by the "Codec<>" class to handle a specific data format.
21  * To keep the implementation properly factorized, an implementation class
22  * is used to provide the appropriate coding and decoding.
23  *
24  *******/
25 
27 public:
29  : geometry_(nullptr),
30  name_(conf.getParameter<std::string>("CodecName")),
31  codec_idx_(static_cast<unsigned char>(conf.getParameter<uint32_t>("CodecIndex"))) {}
33 
34  const std::string& name() const { return name_; }
35 
36  const unsigned char getCodecType() const { return codec_idx_; }
38 
39  // give the FECodec the input digis and it sets itself
40  // with the approprate data
41  virtual void setDataPayload(const HGCalDigiCollection&, const HGCalDigiCollection&, const HGCalDigiCollection&) = 0;
42  virtual void setDataPayload(const l1t::HGCFETriggerDigi&) = 0;
43  virtual void unSetDataPayload() = 0;
44  // get the set data out for your own enjoyment
45  virtual std::vector<bool> getDataPayload() const = 0;
46 
47  // abstract interface to manipulating l1t::HGCFETriggerDigis
48  // these will yell at you if you haven't set the data in the Codec class
49  virtual void encode(l1t::HGCFETriggerDigi&) = 0;
50  virtual void decode(const l1t::HGCFETriggerDigi&) = 0;
51  virtual void print(const l1t::HGCFETriggerDigi& digi, std::ostream& out = std::cout) const = 0;
52 
53 protected:
55 
56 private:
58  unsigned char codec_idx_; // I hope we never come to having 256 FE codecs :-)
59 };
60 
61 // ----> all codec classes derive from this <----
62 // inheritance looks like class MyCodec : public HGCalTriggerFE::Codec<MyCodec,MyData>
63 namespace HGCalTriggerFE {
64  template <typename Impl, typename DATA>
65  class Codec : public HGCalTriggerFECodecBase {
66  public:
67  Codec(const edm::ParameterSet& conf) : HGCalTriggerFECodecBase(conf), dataIsSet_(false) {}
68 
69  // mark these as final since at this level we know
70  // the implementation of the codec
71  void encode(l1t::HGCFETriggerDigi& digi) final {
72  if (!dataIsSet_) {
73  edm::LogWarning("HGCalTriggerFECodec|NoDataPayload")
74  << "No data payload was set for HGCTriggerFECodec: " << this->name();
75  }
76  digi.encode(static_cast<const Impl&>(*this), data_);
77  }
78  void decode(const l1t::HGCFETriggerDigi& digi) final {
79  if (dataIsSet_) {
80  edm::LogWarning("HGCalTriggerFECodec|OverwritePayload")
81  << "Data payload was already set for HGCTriggerFECodec: " << this->name() << " overwriting current data!";
82  }
83  digi.decode(static_cast<const Impl&>(*this), data_);
84  dataIsSet_ = true;
85  }
86 
88  const HGCalDigiCollection& fh,
89  const HGCalDigiCollection& bh) final {
90  if (dataIsSet_) {
91  edm::LogWarning("HGCalTriggerFECodec|OverwritePayload")
92  << "Data payload was already set for HGCTriggerFECodec: " << this->name() << " overwriting current data!";
93  }
94  if (geometry_ == nullptr) {
95  throw cms::Exception("HGCTriggerBadInitialization")
96  << "The HGC trigger geometry has not been passed to the front-end codec\n";
97  }
98  static_cast<Impl&>(*this).setDataPayloadImpl(ee, fh, bh);
99  dataIsSet_ = true;
100  }
101 
102  void setDataPayload(const l1t::HGCFETriggerDigi& digi) final {
103  if (dataIsSet_) {
104  edm::LogWarning("HGCalTriggerFECodec|OverwritePayload")
105  << "Data payload was already set for HGCTriggerFECodec: " << this->name() << " overwriting current data!";
106  }
107  if (geometry_ == nullptr) {
108  throw cms::Exception("HGCTriggerBadInitialization")
109  << "The HGC trigger geometry has not been passed to the front-end codec\n";
110  }
111  static_cast<Impl&>(*this).setDataPayloadImpl(digi);
112  dataIsSet_ = true;
113  }
114 
115  void unSetDataPayload() final {
116  data_.reset();
117  dataIsSet_ = false;
118  }
119  std::vector<bool> getDataPayload() const final { return this->encode(data_); }
120 
121  void print(const l1t::HGCFETriggerDigi& digi, std::ostream& out = std::cout) const final {
122  digi.print(static_cast<const Impl&>(*this), out);
123  }
124 
125  std::vector<bool> encode(const DATA& data) const {
126  if (geometry_ == nullptr) {
127  throw cms::Exception("HGCTriggerBadInitialization")
128  << "The HGC trigger geometry has not been passed to the front-end codec\n";
129  }
130  return static_cast<const Impl&>(*this).encodeImpl(data);
131  }
132 
133  DATA decode(const std::vector<bool>& data, const uint32_t module = 0) const {
134  if (geometry_ == nullptr) {
135  throw cms::Exception("HGCTriggerBadInitialization")
136  << "The HGC trigger geometry has not been passed to the front-end codec\n";
137  }
138  return static_cast<const Impl&>(*this).decodeImpl(data, module);
139  }
140 
141  protected:
143 
144  private:
146  };
147 } // namespace HGCalTriggerFE
148 
151 
152 #endif
void setDataPayload(const l1t::HGCFETriggerDigi &digi) final
void decode(const l1t::HGCFETriggerDigi &digi) final
DATA decode(const std::vector< bool > &data, const uint32_t module=0) const
void setDataPayload(const HGCalDigiCollection &ee, const HGCalDigiCollection &fh, const HGCalDigiCollection &bh) final
virtual std::vector< bool > getDataPayload() const =0
#define nullptr
edmplugin::PluginFactory< HGCalTriggerFECodecBase *(const edm::ParameterSet &)> HGCalTriggerFECodecFactory
Codec(const edm::ParameterSet &conf)
std::vector< bool > getDataPayload() const final
std::vector< bool > encode(const DATA &data) const
Definition: __init__.py:1
virtual void unSetDataPayload()=0
virtual void setDataPayload(const HGCalDigiCollection &, const HGCalDigiCollection &, const HGCalDigiCollection &)=0
void print(const l1t::HGCFETriggerDigi &digi, std::ostream &out=std::cout) const final
HGCalTriggerFECodecBase(const edm::ParameterSet &conf)
const unsigned char getCodecType() const
virtual void decode(const l1t::HGCFETriggerDigi &)=0
void setGeometry(const HGCalTriggerGeometryBase *const geom)
const HGCalTriggerGeometryBase * geometry_
void print(std::ostream &out) const
virtual void print(const l1t::HGCFETriggerDigi &digi, std::ostream &out=std::cout) const =0
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:79
const std::string & name() const
Definition: vlib.h:198
void encode(l1t::HGCFETriggerDigi &digi) final
virtual void encode(l1t::HGCFETriggerDigi &)=0