Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 12:51:08

0001 #ifndef HcalElectronicsMap_h
0002 #define HcalElectronicsMap_h
0003 
0004 /** 
0005 \class HcalElectronicsMap
0006 \author Fedor Ratnikov (UMd)
0007 POOL object to store map between detector ID, electronics ID and trigger ID
0008 $Author: ratnikov
0009 $Date: 2007/12/10 18:36:43 $
0010 $Revision: 1.16 $
0011 */
0012 
0013 #include "CondFormats/Serialization/interface/Serializable.h"
0014 
0015 #include <vector>
0016 #include <algorithm>
0017 
0018 #include "DataFormats/DetId/interface/DetId.h"
0019 #include "DataFormats/HcalDetId/interface/HcalDetId.h"
0020 #include "DataFormats/HcalDetId/interface/HcalCalibDetId.h"
0021 #include "DataFormats/HcalDetId/interface/HcalTrigTowerDetId.h"
0022 #include "DataFormats/HcalDetId/interface/HcalElectronicsId.h"
0023 #include "DataFormats/HcalDetId/interface/HcalGenericDetId.h"
0024 #include <cstdint>
0025 
0026 //forward declaration
0027 namespace HcalElectronicsMapAddons {
0028   class Helper;
0029 }
0030 
0031 class HcalElectronicsMap {
0032 public:
0033   class PrecisionItem {
0034   public:
0035     PrecisionItem() { mId = mElId = 0; }
0036     PrecisionItem(uint32_t fId, uint32_t fElId) : mId(fId), mElId(fElId) {}
0037     uint32_t mId;
0038     uint32_t mElId;
0039 
0040     COND_SERIALIZABLE;
0041   };
0042 
0043   class TriggerItem {
0044   public:
0045     TriggerItem() { mElId = mTrigId = 0; }
0046     TriggerItem(uint32_t fTrigId, uint32_t fElId) : mTrigId(fTrigId), mElId(fElId) {}
0047     uint32_t mTrigId;
0048     uint32_t mElId;
0049 
0050     COND_SERIALIZABLE;
0051   };
0052 
0053   HcalElectronicsMap() {}
0054   HcalElectronicsMap(const HcalElectronicsMapAddons::Helper& helper);
0055   ~HcalElectronicsMap();
0056 
0057   // swap function
0058   void swap(HcalElectronicsMap& other);
0059   // copy-ctor
0060   HcalElectronicsMap(const HcalElectronicsMap& src);
0061   // copy assignment operator
0062   HcalElectronicsMap& operator=(const HcalElectronicsMap& rhs);
0063   // move constructor
0064 #if !defined(__CINT__) && !defined(__MAKECINT__) && !defined(__REFLEX__)
0065   HcalElectronicsMap(HcalElectronicsMap&& other);
0066 #endif
0067 
0068   /// lookup the logical detid associated with the given electronics id
0069   //return Null item if no such mapping
0070   const DetId lookup(HcalElectronicsId fId) const;
0071 
0072   /// brief lookup the electronics detid associated with the given logical id
0073   //return Null item if no such mapping
0074   const HcalElectronicsId lookup(DetId fId) const;
0075 
0076   /// brief lookup the trigger logical detid associated with the given electronics id
0077   //return Null item if no such mapping
0078   const DetId lookupTrigger(HcalElectronicsId fId) const;
0079 
0080   /// brief lookup the electronics detid associated with the given trigger logical id
0081   //return Null item if no such mapping
0082   const HcalElectronicsId lookupTrigger(DetId fId) const;
0083 
0084   /// brief lookup the DetId and full electronics id associated with this partial (dcc/spigot/fiber/fiberchan) id
0085   bool lookup(const HcalElectronicsId pId, HcalElectronicsId& eid, HcalGenericDetId& did) const;
0086   /// brief lookup the DetId and full electronics id associated with this partial (dcc/spigot/slb/slbchan) id
0087   bool lookup(const HcalElectronicsId pId, HcalElectronicsId& eid, HcalTrigTowerDetId& did) const;
0088 
0089   std::vector<HcalElectronicsId> allElectronicsId() const;
0090   std::vector<HcalElectronicsId> allElectronicsIdPrecision() const;
0091   std::vector<HcalElectronicsId> allElectronicsIdTrigger() const;
0092   std::vector<HcalGenericDetId> allPrecisionId() const;
0093   std::vector<HcalTrigTowerDetId> allTriggerId() const;
0094 
0095   void initialize();
0096 
0097 protected:
0098   const PrecisionItem* findById(unsigned long fId) const;
0099   const PrecisionItem* findPByElId(unsigned long fElId) const;
0100   const TriggerItem* findTByElId(unsigned long fElId) const;
0101   const TriggerItem* findByTrigId(unsigned long fTrigId) const;
0102 
0103   std::vector<PrecisionItem> mPItems;
0104   std::vector<TriggerItem> mTItems;
0105   std::vector<const PrecisionItem*> mPItemsById COND_TRANSIENT;
0106   std::vector<const TriggerItem*> mTItemsByTrigId COND_TRANSIENT;
0107 
0108 private:
0109   // sorting
0110   void sortById();
0111   void sortByTriggerId();
0112 
0113   COND_SERIALIZABLE;
0114 };
0115 
0116 namespace HcalElectronicsMapAddons {
0117   class LessById {
0118   public:
0119     bool operator()(const HcalElectronicsMap::PrecisionItem* a, const HcalElectronicsMap::PrecisionItem* b) {
0120       return a->mId < b->mId;
0121     }
0122     bool equal(const HcalElectronicsMap::PrecisionItem* a, const HcalElectronicsMap::PrecisionItem* b) {
0123       return a->mId == b->mId;
0124     }
0125     bool good(const HcalElectronicsMap::PrecisionItem& a) { return a.mId; }
0126   };
0127   class LessByTrigId {
0128   public:
0129     bool operator()(const HcalElectronicsMap::TriggerItem* a, const HcalElectronicsMap::TriggerItem* b) {
0130       return a->mTrigId < b->mTrigId;
0131     }
0132     bool equal(const HcalElectronicsMap::TriggerItem* a, const HcalElectronicsMap::TriggerItem* b) {
0133       return a->mTrigId == b->mTrigId;
0134     }
0135     bool good(const HcalElectronicsMap::TriggerItem& a) { return a.mTrigId; }
0136   };
0137   class Helper {
0138   public:
0139     Helper();
0140     // map channels
0141     bool mapEId2tId(HcalElectronicsId fElectronicsId, HcalTrigTowerDetId fTriggerId);
0142     bool mapEId2chId(HcalElectronicsId fElectronicsId, DetId fId);
0143 
0144     std::vector<HcalElectronicsMap::PrecisionItem> mPItems;
0145     std::vector<HcalElectronicsMap::TriggerItem> mTItems;
0146   };
0147 }  // namespace HcalElectronicsMapAddons
0148 
0149 #endif