CMS 3D CMS Logo

HcalDcsMap.h
Go to the documentation of this file.
1 #ifndef HcalDcsMap_h
2 #define HcalDcsMap_h
3 
15 
16 #include <set>
17 #include <vector>
18 #include <algorithm>
19 #if !defined(__CINT__) && !defined(__MAKECINT__) && !defined(__REFLEX__)
20 #include <atomic>
21 #endif
22 
27 #include <cstdint>
28 
29 //forward declaration
30 namespace HcalDcsMapAddons {
31  class Helper;
32 }
33 
34 class HcalDcsMap {
35 public:
36  class Item {
37  public:
38  Item() { mId = mDcsId = 0; }
39  Item(uint32_t fId, uint32_t fDcsId) : mId(fId), mDcsId(fDcsId) {}
40  uint32_t mId;
41  uint32_t mDcsId;
42 
44  };
45 
48  ~HcalDcsMap();
49 
50  // swap function
51  void swap(HcalDcsMap& other);
52  // copy-ctor
53  HcalDcsMap(const HcalDcsMap& src);
54  // copy assignment operator
55  HcalDcsMap& operator=(const HcalDcsMap& rhs);
56  // move constructor
57 #if !defined(__CINT__) && !defined(__MAKECINT__) && !defined(__REFLEX__)
59 #endif
60 
61  // lookup the logical detid associated with the given DCS id
62  // return Null item if no such mapping.
63  //
64  // Note that type (HV, BV etc.) is a part of HcalDcsDetId but
65  // it is not preserved in the map in order to reduce data volume.
66  // This is possible because the same HCAL channels will correspond
67  // to the DCS channels where only the type is different.
68  //
69  // For the aforementioned reason, you might use any DCS type
70  // when constructing the DetId for this lookup
71  HcalDetId lookup(HcalDcsDetId fId) const;
72 
73  // brief lookup the DCS detid associated with the given logical id
74  //return Null item if no such mapping
75  //
76  // Note that type (HV, BV etc.) is a part of HcalDcsDetId but
77  // it is not preserved in the map in order to reduce data volume.
78  // This is possible because the same HCAL channels will correspond
79  // to the DCS channels where only the type is different.
80  //
81  // For this reason, you need to specify the DCS type in order
82  // to extract proper HcalDcsDetId from the map
84 
86  public:
87  friend class HcalDcsMap;
90  bool operator!=(const const_iterator& other);
93  void next(void);
95  HcalDetId getHcalDetId(void);
96 
97  private:
98  std::vector<const Item*>::const_iterator fIter;
99  };
100 
101  // iterators
102  const_iterator beginById(void) const;
103  const_iterator beginByDcsId(void) const;
104  const_iterator endById(void) const;
105  const_iterator endByDcsId(void) const;
106 
107  void initialize();
108 
109  const Item* findById(unsigned long fId) const;
110  const Item* findByDcsId(unsigned long fDcsId) const;
111 
112  //sorting
113  void sortById();
114  void sortByDcsId();
115 
116 protected:
117  // these are inspired by the emap. Not clear if they are needed
118  // for this DCS map at all since it's many-to-many map
119  std::vector<HcalDcsDetId> allHcalDcsDetId() const;
120  std::vector<HcalGenericDetId> allHcalDetId() const;
121 
122  std::vector<Item> mItems;
123  std::vector<const Item*> mItemsById COND_TRANSIENT;
124  std::vector<const Item*> mItemsByDcsId COND_TRANSIENT;
125 
127 };
128 
129 namespace HcalDcsMapAddons {
130  class LessById {
131  public:
132  bool operator()(const HcalDcsMap::Item* a, const HcalDcsMap::Item* b) const { return a->mId < b->mId; }
133  bool operator()(const HcalDcsMap::Item& a, const HcalDcsMap::Item& b) const { return a.mId < b.mId; }
134  bool equal(const HcalDcsMap::Item* a, const HcalDcsMap::Item* b) const { return a->mId == b->mId; }
135  bool good(const HcalDcsMap::Item& a) const { return a.mDcsId; }
136  };
137  class LessByDcsId {
138  public:
139  bool operator()(const HcalDcsMap::Item* a, const HcalDcsMap::Item* b) const { return a->mDcsId < b->mDcsId; }
140  bool operator()(const HcalDcsMap::Item& a, const HcalDcsMap::Item& b) const { return a.mDcsId < b.mDcsId; }
141  bool equal(const HcalDcsMap::Item* a, const HcalDcsMap::Item* b) const { return a->mDcsId == b->mDcsId; }
142  bool good(const HcalDcsMap::Item& a) const { return a.mDcsId; }
143  };
144  class Helper {
145  public:
146  Helper();
147  // map channels
148  // DCS type is a part of DcsDetId but it does not make sense to keep
149  // duplicate records in the map for DCS channels where only type is different.
150  // Hence, the type in HcalDcsDetId is always forced to DCSUNKNOWN
151  // inside this method
152  bool mapGeomId2DcsId(HcalDetId fId, HcalDcsDetId fDcsId);
153 
154  std::set<HcalDcsMap::Item, LessByDcsId> mItems;
155  };
156 } // namespace HcalDcsMapAddons
157 
158 #endif
bool operator()(const HcalDcsMap::Item &a, const HcalDcsMap::Item &b) const
Definition: HcalDcsMap.h:140
const_iterator endByDcsId(void) const
Definition: HcalDcsMap.cc:59
std::set< HcalDcsMap::Item, LessByDcsId > mItems
Definition: HcalDcsMap.h:154
uint32_t mDcsId
Definition: HcalDcsMap.h:41
Definition: helper.py:1
void initialize()
Definition: HcalDcsMap.cc:169
bool operator()(const HcalDcsMap::Item *a, const HcalDcsMap::Item *b) const
Definition: HcalDcsMap.h:139
const Item * findByDcsId(unsigned long fDcsId) const
Definition: HcalDcsMap.cc:95
const_iterator operator++()
Definition: HcalDcsMap.cc:73
uint32_t mId
Definition: HcalDcsMap.h:40
std::vector< HcalGenericDetId > allHcalDetId() const
Definition: HcalDcsMap.cc:129
void swap(HcalDcsMap &other)
Definition: HcalDcsMap.cc:33
const_iterator beginById(void) const
Definition: HcalDcsMap.cc:41
const_iterator beginByDcsId(void) const
Definition: HcalDcsMap.cc:47
bool good(const HcalDcsMap::Item &a) const
Definition: HcalDcsMap.h:142
bool operator()(const HcalDcsMap::Item *a, const HcalDcsMap::Item *b) const
Definition: HcalDcsMap.h:132
bool equal(const HcalDcsMap::Item *a, const HcalDcsMap::Item *b) const
Definition: HcalDcsMap.h:134
Item(uint32_t fId, uint32_t fDcsId)
Definition: HcalDcsMap.h:39
bool operator()(const HcalDcsMap::Item &a, const HcalDcsMap::Item &b) const
Definition: HcalDcsMap.h:133
HcalDetId getHcalDetId(void)
Definition: HcalDcsMap.cc:88
HcalDcsMap & operator=(const HcalDcsMap &rhs)
Definition: HcalDcsMap.cc:27
HcalDcsDetId getHcalDcsDetId(void)
Definition: HcalDcsMap.cc:86
bool equal(const HcalDcsMap::Item *a, const HcalDcsMap::Item *b) const
Definition: HcalDcsMap.h:141
void sortById()
Definition: HcalDcsMap.cc:164
bool mapGeomId2DcsId(HcalDetId fId, HcalDcsDetId fDcsId)
Definition: HcalDcsMap.cc:143
const Item * findById(unsigned long fId) const
Definition: HcalDcsMap.cc:90
#define COND_TRANSIENT
Definition: Serializable.h:63
HcalDetId lookup(HcalDcsDetId fId) const
Definition: HcalDcsMap.cc:100
double b
Definition: hdecay.h:120
#define COND_SERIALIZABLE
Definition: Serializable.h:39
std::vector< const Item * >::const_iterator fIter
Definition: HcalDcsMap.h:98
bool operator!=(const const_iterator &other)
Definition: HcalDcsMap.cc:66
std::vector< const Item * > mItemsByDcsId
Definition: HcalDcsMap.h:124
double a
Definition: hdecay.h:121
std::vector< Item > mItems
Definition: HcalDcsMap.h:122
bool good(const HcalDcsMap::Item &a) const
Definition: HcalDcsMap.h:135
const_iterator endById(void) const
Definition: HcalDcsMap.cc:53
void sortByDcsId()
Definition: HcalDcsMap.cc:165
std::vector< HcalDcsDetId > allHcalDcsDetId() const
Definition: HcalDcsMap.cc:120
std::vector< const Item * > mItemsById
Definition: HcalDcsMap.h:123