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:
30  name_(conf.getParameter<std::string>("CodecName")),
31  codec_idx_(static_cast<unsigned char>(conf.getParameter<uint32_t>("CodecIndex")))
32  {}
34 
35  const std::string& name() const { return name_; }
36 
37  const unsigned char getCodecType() const { return codec_idx_; }
39 
40  // give the FECodec the input digis and it sets itself
41  // with the approprate data
42  virtual void setDataPayload(const HGCEEDigiCollection&,
43  const HGCHEDigiCollection&,
44  const HGCHEDigiCollection& ) = 0;
45  virtual void setDataPayload(const l1t::HGCFETriggerDigi&) = 0;
46  virtual void unSetDataPayload() = 0;
47  // get the set data out for your own enjoyment
48  virtual std::vector<bool> getDataPayload() const = 0;
49 
50  // abstract interface to manipulating l1t::HGCFETriggerDigis
51  // these will yell at you if you haven't set the data in the Codec class
52  virtual void encode(l1t::HGCFETriggerDigi&) = 0;
53  virtual void decode(const l1t::HGCFETriggerDigi&) = 0;
54  virtual void print(const l1t::HGCFETriggerDigi& digi,
55  std::ostream& out = std::cout) const = 0;
56 
57  protected:
59 
60  private:
62  unsigned char codec_idx_; // I hope we never come to having 256 FE codecs :-)
63 };
64 
65 // ----> all codec classes derive from this <----
66 // inheritance looks like class MyCodec : public HGCalTriggerFE::Codec<MyCodec,MyData>
67 namespace HGCalTriggerFE {
68  template<typename Impl,typename DATA>
69  class Codec : public HGCalTriggerFECodecBase {
70  public:
71  Codec(const edm::ParameterSet& conf) :
73  dataIsSet_(false) {
74  }
75 
76  // mark these as final since at this level we know
77  // the implementation of the codec
78  virtual void encode(l1t::HGCFETriggerDigi& digi) override final {
79  if( !dataIsSet_ ) {
80  edm::LogWarning("HGCalTriggerFECodec|NoDataPayload")
81  << "No data payload was set for HGCTriggerFECodec: "
82  << this->name();
83  }
84  digi.encode(static_cast<const Impl&>(*this),data_);
85  }
86  virtual void decode(const l1t::HGCFETriggerDigi& digi) override final {
87  if( dataIsSet_ ) {
88  edm::LogWarning("HGCalTriggerFECodec|OverwritePayload")
89  << "Data payload was already set for HGCTriggerFECodec: "
90  << this->name() << " overwriting current data!";
91  }
92  digi.decode(static_cast<const Impl&>(*this),data_);
93  dataIsSet_ = true;
94  }
95 
96  virtual void setDataPayload(const HGCEEDigiCollection& ee,
97  const HGCHEDigiCollection& fh,
98  const HGCHEDigiCollection& bh ) override final {
99  if( dataIsSet_ ) {
100  edm::LogWarning("HGCalTriggerFECodec|OverwritePayload")
101  << "Data payload was already set for HGCTriggerFECodec: "
102  << this->name() << " overwriting current data!";
103  }
104  if(geometry_==nullptr) {
105  throw cms::Exception("HGCTriggerBadInitialization")
106  << "The HGC trigger geometry has not been passed to the front-end codec\n";
107  }
108  static_cast<Impl&>(*this).setDataPayloadImpl(ee,fh,bh);
109  dataIsSet_ = true;
110  }
111 
112  virtual void setDataPayload(const l1t::HGCFETriggerDigi& digi) override final {
113  if( dataIsSet_ ) {
114  edm::LogWarning("HGCalTriggerFECodec|OverwritePayload")
115  << "Data payload was already set for HGCTriggerFECodec: "
116  << this->name() << " overwriting current data!";
117  }
118  if(geometry_==nullptr) {
119  throw cms::Exception("HGCTriggerBadInitialization")
120  << "The HGC trigger geometry has not been passed to the front-end codec\n";
121  }
122  static_cast<Impl&>(*this).setDataPayloadImpl(digi);
123  dataIsSet_ = true;
124  }
125 
126  virtual void unSetDataPayload() override final {
127  data_.reset();
128  dataIsSet_ = false;
129  }
130  std::vector<bool> getDataPayload() const override final {
131  return this->encode(data_);
132  }
133 
134  virtual void print(const l1t::HGCFETriggerDigi& digi,
135  std::ostream& out = std::cout) const override final {
136  digi.print(static_cast<const Impl&>(*this),out);
137  }
138 
139  std::vector<bool> encode(const DATA& data) const {
140  if(geometry_==nullptr) {
141  throw cms::Exception("HGCTriggerBadInitialization")
142  << "The HGC trigger geometry has not been passed to the front-end codec\n";
143  }
144  return static_cast<const Impl&>(*this).encodeImpl(data);
145  }
146 
147  DATA decode(const std::vector<bool>& data, const uint32_t module=0) const {
148  if(geometry_==nullptr) {
149  throw cms::Exception("HGCTriggerBadInitialization")
150  << "The HGC trigger geometry has not been passed to the front-end codec\n";
151  }
152  return static_cast<const Impl&>(*this).decodeImpl(data, module);
153  }
154 
155  protected:
157  private:
159  };
160 }
161 
164 
165 #endif
virtual void print(const l1t::HGCFETriggerDigi &digi, std::ostream &out=std::cout) const override final
DATA decode(const std::vector< bool > &data, const uint32_t module=0) const
virtual void unSetDataPayload() override final
virtual std::vector< bool > getDataPayload() const =0
Codec(const edm::ParameterSet &conf)
#define nullptr
std::vector< bool > encode(const DATA &data) const
virtual void decode(const l1t::HGCFETriggerDigi &digi) override final
Definition: __init__.py:1
virtual void unSetDataPayload()=0
edmplugin::PluginFactory< HGCalTriggerFECodecBase *(const edm::ParameterSet &) > HGCalTriggerFECodecFactory
HGCalTriggerFECodecBase(const edm::ParameterSet &conf)
virtual void setDataPayload(const HGCEEDigiCollection &, const HGCHEDigiCollection &, const HGCHEDigiCollection &)=0
virtual void encode(l1t::HGCFETriggerDigi &digi) override final
const unsigned char getCodecType() const
virtual void setDataPayload(const l1t::HGCFETriggerDigi &digi) override final
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
std::vector< bool > getDataPayload() const override final
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:82
const std::string & name() const
virtual void setDataPayload(const HGCEEDigiCollection &ee, const HGCHEDigiCollection &fh, const HGCHEDigiCollection &bh) override final
Definition: vlib.h:208
virtual void encode(l1t::HGCFETriggerDigi &)=0