Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:02:13

0001 #ifndef HcalDcsMap_h
0002 #define HcalDcsMap_h
0003 
0004 /** 
0005 \class HcalDcsMap
0006 \author Gena Kukartsev
0007 POOL object to store map between detector ID and DCS ID
0008 Inspired by HcalElectronicsMap
0009 $Author: kukartse
0010 $Date: 2007/12/14 13:31:21 $
0011 $Revision: 1.1 $
0012 */
0013 
0014 #include "CondFormats/Serialization/interface/Serializable.h"
0015 
0016 #include <set>
0017 #include <vector>
0018 #include <algorithm>
0019 #if !defined(__CINT__) && !defined(__MAKECINT__) && !defined(__REFLEX__)
0020 #include <atomic>
0021 #endif
0022 
0023 #include "DataFormats/DetId/interface/DetId.h"
0024 #include "DataFormats/HcalDetId/interface/HcalDetId.h"
0025 #include "DataFormats/HcalDetId/interface/HcalDcsDetId.h"
0026 #include "DataFormats/HcalDetId/interface/HcalGenericDetId.h"
0027 #include <cstdint>
0028 
0029 //forward declaration
0030 namespace HcalDcsMapAddons {
0031   class Helper;
0032 }
0033 
0034 class HcalDcsMap {
0035 public:
0036   class Item {
0037   public:
0038     Item() { mId = mDcsId = 0; }
0039     Item(uint32_t fId, uint32_t fDcsId) : mId(fId), mDcsId(fDcsId) {}
0040     uint32_t mId;
0041     uint32_t mDcsId;
0042 
0043     COND_SERIALIZABLE;
0044   };
0045 
0046   HcalDcsMap() {}
0047   HcalDcsMap(const HcalDcsMapAddons::Helper& helper);
0048   ~HcalDcsMap();
0049 
0050   // swap function
0051   void swap(HcalDcsMap& other);
0052   // copy-ctor
0053   HcalDcsMap(const HcalDcsMap& src);
0054   // copy assignment operator
0055   HcalDcsMap& operator=(const HcalDcsMap& rhs);
0056   // move constructor
0057 #if !defined(__CINT__) && !defined(__MAKECINT__) && !defined(__REFLEX__)
0058   HcalDcsMap(HcalDcsMap&& other);
0059 #endif
0060 
0061   // lookup the logical detid associated with the given DCS id
0062   // return Null item if no such mapping.
0063   //
0064   // Note that type (HV, BV etc.) is a part of HcalDcsDetId but
0065   // it is not preserved in the map in order to reduce data volume.
0066   // This is possible because the same HCAL channels will correspond
0067   // to the DCS channels where only the type is different.
0068   //
0069   // For the aforementioned reason, you might use any DCS type
0070   // when constructing the DetId for this lookup
0071   HcalDetId lookup(HcalDcsDetId fId) const;
0072 
0073   // brief lookup the DCS detid associated with the given logical id
0074   //return Null item if no such mapping
0075   //
0076   // Note that type (HV, BV etc.) is a part of HcalDcsDetId but
0077   // it is not preserved in the map in order to reduce data volume.
0078   // This is possible because the same HCAL channels will correspond
0079   // to the DCS channels where only the type is different.
0080   //
0081   // For this reason, you need to specify  the DCS type in order
0082   // to extract proper HcalDcsDetId from the map
0083   HcalDcsDetId lookup(HcalDetId fId, HcalDcsDetId::DcsType type) const;
0084 
0085   class const_iterator {
0086   public:
0087     friend class HcalDcsMap;
0088     const_iterator() {}
0089     ~const_iterator() {}
0090     bool operator!=(const const_iterator& other);
0091     const_iterator operator++();
0092     const_iterator operator++(int);
0093     void next(void);
0094     HcalDcsDetId getHcalDcsDetId(void);
0095     HcalDetId getHcalDetId(void);
0096 
0097   private:
0098     std::vector<const Item*>::const_iterator fIter;
0099   };
0100 
0101   // iterators
0102   const_iterator beginById(void) const;
0103   const_iterator beginByDcsId(void) const;
0104   const_iterator endById(void) const;
0105   const_iterator endByDcsId(void) const;
0106 
0107   void initialize();
0108 
0109   const Item* findById(unsigned long fId) const;
0110   const Item* findByDcsId(unsigned long fDcsId) const;
0111 
0112   //sorting
0113   void sortById();
0114   void sortByDcsId();
0115 
0116 protected:
0117   // these are inspired by the emap. Not clear if they are needed
0118   // for this DCS map at all since it's many-to-many map
0119   std::vector<HcalDcsDetId> allHcalDcsDetId() const;
0120   std::vector<HcalGenericDetId> allHcalDetId() const;
0121 
0122   std::vector<Item> mItems;
0123   std::vector<const Item*> mItemsById COND_TRANSIENT;
0124   std::vector<const Item*> mItemsByDcsId COND_TRANSIENT;
0125 
0126   COND_SERIALIZABLE;
0127 };
0128 
0129 namespace HcalDcsMapAddons {
0130   class LessById {
0131   public:
0132     bool operator()(const HcalDcsMap::Item* a, const HcalDcsMap::Item* b) const { return a->mId < b->mId; }
0133     bool operator()(const HcalDcsMap::Item& a, const HcalDcsMap::Item& b) const { return a.mId < b.mId; }
0134     bool equal(const HcalDcsMap::Item* a, const HcalDcsMap::Item* b) const { return a->mId == b->mId; }
0135     bool good(const HcalDcsMap::Item& a) const { return a.mDcsId; }
0136   };
0137   class LessByDcsId {
0138   public:
0139     bool operator()(const HcalDcsMap::Item* a, const HcalDcsMap::Item* b) const { return a->mDcsId < b->mDcsId; }
0140     bool operator()(const HcalDcsMap::Item& a, const HcalDcsMap::Item& b) const { return a.mDcsId < b.mDcsId; }
0141     bool equal(const HcalDcsMap::Item* a, const HcalDcsMap::Item* b) const { return a->mDcsId == b->mDcsId; }
0142     bool good(const HcalDcsMap::Item& a) const { return a.mDcsId; }
0143   };
0144   class Helper {
0145   public:
0146     Helper();
0147     // map channels
0148     // DCS type is a part of DcsDetId but it does not make sense to keep
0149     // duplicate records in the map for DCS channels where only type is different.
0150     // Hence, the type in HcalDcsDetId is always forced to DCSUNKNOWN
0151     // inside this method
0152     bool mapGeomId2DcsId(HcalDetId fId, HcalDcsDetId fDcsId);
0153 
0154     std::set<HcalDcsMap::Item, LessByDcsId> mItems;
0155   };
0156 }  // namespace HcalDcsMapAddons
0157 
0158 #endif