Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-07-09 23:01:15

0001 #ifndef HashMapper_h
0002 #define HashMapper_h
0003 
0004 /**
0005  *  file:           HashMapper.h
0006  *  Author:         Viktor Khristenko
0007  *
0008  *  Description:
0009  *
0010  */
0011 
0012 #include "DQM/HcalCommon/interface/HashFunctions.h"
0013 #include "DQM/HcalCommon/interface/Mapper.h"
0014 
0015 namespace hcaldqm {
0016   namespace mapper {
0017     class HashMapper : public Mapper {
0018     public:
0019       //    constructors/destructors
0020       HashMapper() {}
0021       HashMapper(hashfunctions::HashType htype) : Mapper(), _htype(htype) {}
0022       ~HashMapper() override {}
0023 
0024       //    initialize
0025       virtual void initialize(hashfunctions::HashType htype) { _htype = htype; }
0026 
0027       //    get hash
0028       using Mapper::getHash;
0029       uint32_t getHash(HcalDetId const &did) const override { return hashfunctions::hash_did[_htype](did); }
0030       uint32_t getHash(HcalElectronicsId const &eid) const override {
0031         return hashfunctions::hash_eid[_htype - hashfunctions::nHashType_did - 1](eid);
0032       }
0033       uint32_t getHash(HcalTrigTowerDetId const &tid) const override {
0034         return hashfunctions::hash_tid[_htype - hashfunctions::nHashType_eid - 1](tid);
0035       }
0036       uint32_t getHash(HcalTrigTowerDetId const &tid, HcalElectronicsId const &eid) const override {
0037         return hashfunctions::hash_mixid[_htype - hashfunctions::nHashType_tid - 1](tid, eid);
0038       }
0039 
0040       //    get name of the hashed element
0041       using Mapper::getName;
0042       std::string getName(HcalDetId const &did) const override { return hashfunctions::name_did[_htype](did); }
0043       std::string getName(HcalElectronicsId const &eid) const override {
0044         return hashfunctions::name_eid[_htype - hashfunctions::nHashType_did - 1](eid);
0045       }
0046       std::string getName(HcalTrigTowerDetId const &tid) const override {
0047         return hashfunctions::name_tid[_htype - hashfunctions::nHashType_eid - 1](tid);
0048       }
0049       std::string getName(HcalTrigTowerDetId const &tid, HcalElectronicsId const &eid) const override {
0050         return hashfunctions::name_mixid[_htype - hashfunctions::nHashType_tid - 1](tid, eid);
0051       }
0052 
0053       //    get the Hash Type Name
0054       virtual std::string getHashTypeName() const { return hashfunctions::hash_names[this->getLinearHashType(_htype)]; }
0055       virtual hashfunctions::HashType getHashType() const { return _htype; }
0056 
0057       //    determine the type of the hash
0058       virtual bool isDHash() const { return _htype < hashfunctions::nHashType_did ? true : false; }
0059       virtual bool isEHash() const {
0060         return (_htype > hashfunctions::nHashType_did && _htype < hashfunctions::nHashType_eid) ? true : false;
0061       }
0062       virtual bool isTHash() const {
0063         return (_htype > hashfunctions::nHashType_eid && _htype < hashfunctions::nHashType_tid) ? true : false;
0064       }
0065       virtual bool isMixHash() const {
0066         return (_htype > hashfunctions::nHashType_tid && _htype < hashfunctions::nHashType_mixid) ? true : false;
0067       }
0068 
0069       //    get the Linear Hash Type
0070       virtual int getLinearHashType(hashfunctions::HashType htype) const {
0071         int l = 0;
0072         if (htype < hashfunctions::nHashType_did)
0073           l = htype;
0074         else if (htype < hashfunctions::nHashType_eid)
0075           l = htype - 1;
0076         else if (htype < hashfunctions::nHashType_tid)
0077           l = htype - 2;
0078         else
0079           l = htype - 3;
0080         return l;
0081       }
0082 
0083     protected:
0084       hashfunctions::HashType _htype;
0085     };
0086   }  // namespace mapper
0087 }  // namespace hcaldqm
0088 
0089 #endif