Back to home page

Project CMSSW displayed by LXR

 
 

    


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  * Class: l1t::HGCFETriggerDigi
0011  * Author: L. Gray (FNAL)
0012  * Date: 26 July, 2015
0013  *
0014  * An abstract representation of an HGC Front-End Trigger data payload.
0015  * The user of the class (some trigger algorithm) provides a codec in 
0016  * order to interpret the data payload held within class. This implementation
0017  * is chosen since final form of the HGC trigger primitives was not known
0018  * in July 2015.
0019  *
0020  * The CODEC class used below *must* implement the following interfaces:
0021  * 
0022  * CODEC::getCodecType() const -- returns an unsigned char indexing the codec
0023  *
0024  * CODEC::encode(const DATA&) const 
0025  *     -- encodes the data payload described by DATA into std::vector<bool>
0026  *
0027  * DATA CODEC::decode(const std::vector<bool>& data) const 
0028  *     -- decodes a std::vector<bool> into DATA
0029  * 
0030  * DATA must implement the following interfaces:
0031  * DATA::operator<<(std::ostream& out) const 
0032  *     -- prints the contents of the formatted data
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     //detector id information
0049     uint32_t id() const { return detid_; }  // for edm::SortedCollection
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     // encoding and decoding
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_;       // save in the abstract form
0088     unsigned char codec_;  // 0xff is special and means no encoder
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 }  // namespace l1t
0103 
0104 #endif