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"))) {}
32  virtual ~HGCalTriggerFECodecBase() {}
33 
34  const std::string& name() const { return name_; }
35 
36  const unsigned char getCodecType() const { return codec_idx_; }
37  void setGeometry(const HGCalTriggerGeometryBase* const geom) { geometry_ = geom; }
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:
57  const std::string name_;
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:
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 
87  void setDataPayload(const HGCalDigiCollection& ee,
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:
142  DATA data_;
143 
144  private:
145  bool dataIsSet_;
146  };
147 } // namespace HGCalTriggerFE
148 
151 
152 #endif
HGCalTriggerFECodecBase::name_
const std::string name_
Definition: HGCalTriggerFECodecBase.h:67
HGCalTriggerGeometryBase
Definition: HGCalTriggerGeometryBase.h:19
PluginFactory.h
l1t::HGCFETriggerDigi
Definition: HGCFETriggerDigi.h:64
funct::false
false
Definition: Factorize.h:34
HGCalTriggerFE::Codec::Codec
Codec(const edm::ParameterSet &conf)
Definition: HGCalTriggerFECodecBase.h:66
HGCalTriggerFECodecBase::print
virtual void print(const l1t::HGCFETriggerDigi &digi, std::ostream &out=std::cout) const =0
HGCalTriggerFE::Codec::encode
void encode(l1t::HGCFETriggerDigi &digi) final
Definition: HGCalTriggerFECodecBase.h:70
HGCalTriggerFECodecBase::getDataPayload
virtual std::vector< bool > getDataPayload() const =0
HGCalTriggerFECodecBase::~HGCalTriggerFECodecBase
virtual ~HGCalTriggerFECodecBase()
Definition: HGCalTriggerFECodecBase.h:42
gather_cfg.cout
cout
Definition: gather_cfg.py:144
HGCalTriggerFE::Codec::setDataPayload
void setDataPayload(const HGCalDigiCollection &ee, const HGCalDigiCollection &fh, const HGCalDigiCollection &bh) final
Definition: HGCalTriggerFECodecBase.h:86
edm::SortedCollection
Definition: SortedCollection.h:49
watchdog.const
const
Definition: watchdog.py:83
HGCalTriggerFE::Codec::data_
DATA data_
Definition: HGCalTriggerFECodecBase.h:141
HGCalTriggerFECodecBase::name
const std::string & name() const
Definition: HGCalTriggerFECodecBase.h:44
HGCalTriggerGeometryBase.h
HGCFETriggerDigi.h
HGCalTriggerFECodecBase::decode
virtual void decode(const l1t::HGCFETriggerDigi &)=0
HGCalTriggerFECodecBase::HGCalTriggerFECodecBase
HGCalTriggerFECodecBase(const edm::ParameterSet &conf)
Definition: HGCalTriggerFECodecBase.h:38
relativeConstraints.geom
geom
Definition: relativeConstraints.py:72
HGCalTriggerFE::Codec::getDataPayload
std::vector< bool > getDataPayload() const final
Definition: HGCalTriggerFECodecBase.h:118
HGCalTriggerFECodecBase
Definition: HGCalTriggerFECodecBase.h:25
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
edm::LogWarning
Definition: MessageLogger.h:141
cscdqm::DATA
Definition: CSCDQM_Summary.h:47
edm::ParameterSet
Definition: ParameterSet.h:36
HGCalTriggerFECodecBase::unSetDataPayload
virtual void unSetDataPayload()=0
HGCalTriggerFECodecBase::geometry_
const HGCalTriggerGeometryBase * geometry_
Definition: HGCalTriggerFECodecBase.h:64
edmplugin::PluginFactory
Definition: PluginFactory.h:34
HGCalTriggerFECodecBase::setDataPayload
virtual void setDataPayload(const HGCalDigiCollection &, const HGCalDigiCollection &, const HGCalDigiCollection &)=0
HGCDigiCollections.h
HGCalTriggerFECodecBase::setGeometry
void setGeometry(const HGCalTriggerGeometryBase *const geom)
Definition: HGCalTriggerFECodecBase.h:47
module
Definition: vlib.h:198
HGCalTriggerFE::Codec::print
void print(const l1t::HGCFETriggerDigi &digi, std::ostream &out=std::cout) const final
Definition: HGCalTriggerFECodecBase.h:120
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
HGCalTriggerFE
Definition: HGCalTriggerFECodecBase.h:62
HGCalTriggerFE::Codec::unSetDataPayload
void unSetDataPayload() final
Definition: HGCalTriggerFECodecBase.h:114
HGCalTriggerFECodecBase::getCodecType
const unsigned char getCodecType() const
Definition: HGCalTriggerFECodecBase.h:46
Exception
Definition: hltDiff.cc:246
HGCalTriggerFECodecBase::encode
virtual void encode(l1t::HGCFETriggerDigi &)=0
HGCalTriggerFECodecBase::codec_idx_
unsigned char codec_idx_
Definition: HGCalTriggerFECodecBase.h:68
data
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:79
MillePedeFileConverter_cfg.out
out
Definition: MillePedeFileConverter_cfg.py:31
ParameterSet.h
HGCalTriggerFE::Codec::decode
void decode(const l1t::HGCFETriggerDigi &digi) final
Definition: HGCalTriggerFECodecBase.h:77
HGCalTriggerFE::Codec::dataIsSet_
bool dataIsSet_
Definition: HGCalTriggerFECodecBase.h:144