CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
HcalDcsMap.h
Go to the documentation of this file.
1 #ifndef HcalDcsMap_h
2 #define HcalDcsMap_h
3 
14 #include <vector>
15 #include <algorithm>
16 #include <boost/cstdint.hpp>
17 #if !defined(__CINT__) && !defined(__MAKECINT__) && !defined(__REFLEX__)
18 #include <atomic>
19 #endif
20 
25 //
26 class HcalDcsMap {
27  public:
28  HcalDcsMap();
29  ~HcalDcsMap();
30 
31  // swap function
32  void swap(HcalDcsMap& other);
33  // copy-ctor
34  HcalDcsMap(const HcalDcsMap& src);
35  // copy assignment operator
36  HcalDcsMap& operator=(const HcalDcsMap& rhs);
37  // move constructor
38 #if !defined(__CINT__) && !defined(__MAKECINT__) && !defined(__REFLEX__)
39  HcalDcsMap(HcalDcsMap&& other);
40 #endif
41 
42  // lookup the logical detid associated with the given DCS id
43  // return Null item if no such mapping.
44  //
45  // Note that type (HV, BV etc.) is a part of HcalDcsDetId but
46  // it is not preserved in the map in order to reduce data volume.
47  // This is possible because the same HCAL channels will correspond
48  // to the DCS channels where only the type is different.
49  //
50  // For the aforementioned reason, you might use any DCS type
51  // when constructing the DetId for this lookup
52  const std::vector<HcalDetId> lookup(HcalDcsDetId fId) const;
53 
54  // brief lookup the DCS detid associated with the given logical id
55  //return Null item if no such mapping
56  //
57  // Note that type (HV, BV etc.) is a part of HcalDcsDetId but
58  // it is not preserved in the map in order to reduce data volume.
59  // This is possible because the same HCAL channels will correspond
60  // to the DCS channels where only the type is different.
61  //
62  // For this reason, you need to specify the DCS type in order
63  // to extract proper HcalDcsDetId from the map
64  const std::vector<HcalDcsDetId> lookup(HcalDetId fId, HcalDcsDetId::DcsType type) const;
65 
66  // map channels
67  // DCS type is a part of DcsDetId but it does not make sense to keep
68  // duplicate records in the map for DCS channels where only type is different.
69  // Hence, the type in HcalDcsDetId is always forced to DCSUNKNOWN
70  // inside this method
71  bool mapGeomId2DcsId (HcalDetId fId, HcalDcsDetId fDcsId);
72 
73  // sorting
74  void sortById () const;
75  void sortByDcsId () const;
76  void sort() {}
77 
78  class Item {
79  public:
80  Item () {mId = mDcsId = 0;}
81  Item (uint32_t fId, uint32_t fDcsId)
82  : mId (fId), mDcsId (fDcsId) {}
83  uint32_t mId;
84  uint32_t mDcsId;
85  };
86 
88  public:
89  friend class HcalDcsMap;
92  bool operator!=(const const_iterator & other);
95  void next(void);
97  HcalDetId getHcalDetId(void);
98  private:
99  std::vector<const Item *>::const_iterator fIter;
100  };
101 
102  // iterators
103  const_iterator beginById(void) const;
104  const_iterator beginByDcsId(void) const;
105  const_iterator endById(void) const;
106  const_iterator endByDcsId(void) const;
107 
108  protected:
109  const std::vector<const Item *> findById (unsigned long fId) const;
110  const std::vector<const Item *> findByDcsId (unsigned long fDcsId) const;
111 
112  // these are inspired by the emap. Not clear if they are needed
113  // for this DCS map at all since it's many-to-many map
114  std::vector <HcalDcsDetId> allHcalDcsDetId () const;
115  std::vector <HcalGenericDetId> allHcalDetId () const;
116 
117  std::vector<Item> mItems;
118 #if !defined(__CINT__) && !defined(__MAKECINT__) && !defined(__REFLEX__)
119  mutable std::atomic<std::vector<const Item*>*> mItemsById;
120  mutable std::atomic<std::vector<const Item*>*> mItemsByDcsId;
121  const std::vector<const Item*>* getItemsById(void){return mItemsById.load(std::memory_order_acquire);}
122  const std::vector<const Item*>* getItemsByDcsId(void){return mItemsByDcsId.load(std::memory_order_acquire);}
123 #else
124  mutable std::vector<const Item*> mItemsById;
125  mutable std::vector<const Item*> mItemsByDcsId;
126  const std::vector<const Item*>* getItemsById(void){return &mItemsById;}
127  const std::vector<const Item*>* getItemsByDcsId(void){return &mItemsByDcsId;}
128 #endif
129 };
130 
131 #endif
std::vector< const Item * >::const_iterator fIter
Definition: HcalDcsMap.h:99
type
Definition: HCALResponse.h:21
void sortByDcsId() const
Definition: HcalDcsMap.cc:283
uint32_t mDcsId
Definition: HcalDcsMap.h:84
bool mapGeomId2DcsId(HcalDetId fId, HcalDcsDetId fDcsId)
Definition: HcalDcsMap.cc:237
std::vector< HcalDcsDetId > allHcalDcsDetId() const
Definition: HcalDcsMap.cc:217
const_iterator operator++()
Definition: HcalDcsMap.cc:109
uint32_t mId
Definition: HcalDcsMap.h:83
void swap(HcalDcsMap &other)
Definition: HcalDcsMap.cc:42
const_iterator endById(void) const
Definition: HcalDcsMap.cc:89
Item(uint32_t fId, uint32_t fDcsId)
Definition: HcalDcsMap.h:81
const_iterator beginById(void) const
Definition: HcalDcsMap.cc:75
std::atomic< std::vector< const Item * > * > mItemsById
Definition: HcalDcsMap.h:119
const std::vector< HcalDetId > lookup(HcalDcsDetId fId) const
Definition: HcalDcsMap.cc:179
HcalDetId getHcalDetId(void)
Definition: HcalDcsMap.cc:128
const std::vector< const Item * > findByDcsId(unsigned long fDcsId) const
Definition: HcalDcsMap.cc:156
HcalDcsMap & operator=(const HcalDcsMap &rhs)
Definition: HcalDcsMap.cc:36
HcalDcsDetId getHcalDcsDetId(void)
Definition: HcalDcsMap.cc:124
std::atomic< std::vector< const Item * > * > mItemsByDcsId
Definition: HcalDcsMap.h:120
const std::vector< const Item * > findById(unsigned long fId) const
Definition: HcalDcsMap.cc:133
std::vector< HcalGenericDetId > allHcalDetId() const
Definition: HcalDcsMap.cc:225
const std::vector< const Item * > * getItemsByDcsId(void)
Definition: HcalDcsMap.h:122
void sort()
Definition: HcalDcsMap.h:76
bool operator!=(const const_iterator &other)
Definition: HcalDcsMap.cc:104
const_iterator endByDcsId(void) const
Definition: HcalDcsMap.cc:96
std::vector< Item > mItems
Definition: HcalDcsMap.h:117
const std::vector< const Item * > * getItemsById(void)
Definition: HcalDcsMap.h:121
void sortById() const
Definition: HcalDcsMap.cc:266
const_iterator beginByDcsId(void) const
Definition: HcalDcsMap.cc:82