CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
HcalDcsMap.cc
Go to the documentation of this file.
1 
11 #include <iostream>
12 #include <set>
13 
17 
18 HcalDcsMap::HcalDcsMap(const HcalDcsMapAddons::Helper& helper) : mItems(helper.mItems.begin(), helper.mItems.end()) {
19  initialize();
20 }
21 
23 // copy-ctor
25  : mItems(src.mItems), mItemsById(src.mItemsById), mItemsByDcsId(src.mItemsByDcsId) {}
26 // copy assignment operator
28  HcalDcsMap temp(rhs);
29  temp.swap(*this);
30  return *this;
31 }
32 // public swap function
34  std::swap(mItems, other.mItems);
37 }
38 // move constructor
39 HcalDcsMap::HcalDcsMap(HcalDcsMap&& other) : HcalDcsMap() { other.swap(*this); }
40 
42  const_iterator _iter;
43  _iter.fIter = mItemsById.begin();
44  return _iter;
45 }
46 
48  const_iterator _iter;
49  _iter.fIter = mItemsByDcsId.begin();
50  return _iter;
51 }
52 
54  const_iterator _iter;
55  _iter.fIter = mItemsById.end();
56  return _iter;
57 }
58 
60  const_iterator _iter;
61  _iter.fIter = mItemsByDcsId.end();
62  return _iter;
63 }
64 
65 // iterator methods
67  if (fIter != other.fIter)
68  return true;
69  else
70  return false;
71 }
72 
74  ++fIter;
75  return *this;
76 }
77 
79  const_iterator i = *this;
80  ++fIter;
81  return i;
82 }
83 
84 void HcalDcsMap::const_iterator::next(void) { ++fIter; }
85 
87 
88 HcalDetId HcalDcsMap::const_iterator::getHcalDetId(void) { return (*fIter)->mId; }
89 
90 const HcalDcsMap::Item* HcalDcsMap::findById(unsigned long fId) const {
91  Item target(fId, 0);
92  return HcalObjectAddons::findByT<Item, HcalDcsMapAddons::LessById>(&target, mItemsById);
93 }
94 
95 const HcalDcsMap::Item* HcalDcsMap::findByDcsId(unsigned long fDcsId) const {
96  Item target(0, fDcsId);
97  return HcalObjectAddons::findByT<Item, HcalDcsMapAddons::LessByDcsId>(&target, mItemsByDcsId);
98 }
99 
101  // DCS type is a part of DcsDetId but it does not make sense to keep
102  // duplicate records in the map for DCS channels where only type is different.
103  // Hence, the type in HcalDcsDetId is always forced to DCSUNKNOWN
104  HcalDcsDetId fDcsId_notype(fId.subdet(),
105  fId.ring(), // side is already included
106  fId.slice(),
108  fId.subchannel());
109  auto item = HcalDcsMap::findByDcsId(fDcsId_notype.rawId());
110  return item ? item->mId : 0;
111 }
112 
114  auto item = HcalDcsMap::findById(fId.rawId());
115  HcalDcsDetId _id(item ? item->mId : 0);
116  return HcalDcsDetId(_id.subdet(), _id.zside() * _id.ring(), _id.slice(), type, _id.subchannel());
117 }
118 
119 //FIXME: remove duplicates
120 std::vector<HcalDcsDetId> HcalDcsMap::allHcalDcsDetId() const {
121  std::vector<HcalDcsDetId> result;
122  for (std::vector<Item>::const_iterator item = mItems.begin(); item != mItems.end(); item++)
123  if (item->mDcsId)
124  result.push_back(HcalDcsDetId(item->mDcsId));
125  return result;
126 }
127 
128 // FIXME: remove duplicates
129 std::vector<HcalGenericDetId> HcalDcsMap::allHcalDetId() const {
130  std::vector<HcalGenericDetId> result;
131  std::set<unsigned long> allIds;
132  for (std::vector<Item>::const_iterator item = mItems.begin(); item != mItems.end(); item++)
133  if (item->mId)
134  allIds.insert(item->mId);
135  for (std::set<unsigned long>::const_iterator channel = allIds.begin(); channel != allIds.end(); channel++) {
136  result.push_back(HcalGenericDetId(*channel));
137  }
138  return result;
139 }
140 
142 
144  // DCS type is a part of DcsDetId but it does not make sense to keep
145  // duplicate records in the map for DCS channels where only type is different.
146  // Hence, the type in HcalDcsDetId is always forced to DCSUNKNOWN
147  HcalDcsDetId fDcsId_notype(fDcsId.subdet(),
148  fDcsId.ring(), // side is included
149  fDcsId.slice(),
151  fDcsId.subchannel());
152  HcalDcsMap::Item target(fId, fDcsId_notype);
153  auto iter = mItems.find(target);
154  if (iter != mItems.end() and iter->mId == fId) {
155  edm::LogWarning("HCAL") << "HcalDcsMap::mapGeomId2DcsId-> Geom channel " << fId << " already mapped to DCS channel "
156  << fDcsId_notype;
157  return false; // element already exists
158  }
159  mItems.insert(target);
160 
161  return true;
162 }
163 
164 void HcalDcsMap::sortById() { HcalObjectAddons::sortByT<Item, HcalDcsMapAddons::LessById>(mItems, mItemsById); }
166  HcalObjectAddons::sortByT<Item, HcalDcsMapAddons::LessByDcsId>(mItems, mItemsByDcsId);
167 }
168 
170  sortById();
171  sortByDcsId();
172 }
int subchannel() const
Definition: HcalDcsDetId.h:58
std::vector< HcalDcsDetId > allHcalDcsDetId() const
Definition: HcalDcsMap.cc:120
void initialize()
Definition: HcalDcsMap.cc:169
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:57
const_iterator operator++()
Definition: HcalDcsMap.cc:73
uint32_t mId
Definition: HcalDcsMap.h:40
const Item * findById(unsigned long fId) const
Definition: HcalDcsMap.cc:90
void swap(HcalDcsMap &other)
Definition: HcalDcsMap.cc:33
HcalDetId lookup(HcalDcsDetId fId) const
Definition: HcalDcsMap.cc:100
tuple result
Definition: mps_fire.py:311
const_iterator endById(void) const
Definition: HcalDcsMap.cc:53
const_iterator beginById(void) const
Definition: HcalDcsMap.cc:41
void swap(edm::DataFrameContainer &lhs, edm::DataFrameContainer &rhs)
HcalDetId getHcalDetId(void)
Definition: HcalDcsMap.cc:88
HcalDcsMap & operator=(const HcalDcsMap &rhs)
Definition: HcalDcsMap.cc:27
HcalDcsDetId getHcalDcsDetId(void)
Definition: HcalDcsMap.cc:86
void sortById()
Definition: HcalDcsMap.cc:164
bool mapGeomId2DcsId(HcalDetId fId, HcalDcsDetId fDcsId)
Definition: HcalDcsMap.cc:143
HcalOtherSubdetector subdet() const
get the category
std::vector< HcalGenericDetId > allHcalDetId() const
Definition: HcalDcsMap.cc:129
int slice() const
Definition: HcalDcsDetId.h:56
std::vector< const Item * >::const_iterator fIter
Definition: HcalDcsMap.h:98
bool operator!=(const const_iterator &other)
Definition: HcalDcsMap.cc:66
const Item * findByDcsId(unsigned long fDcsId) const
Definition: HcalDcsMap.cc:95
std::vector< const Item * > mItemsByDcsId
Definition: HcalDcsMap.h:124
const_iterator endByDcsId(void) const
Definition: HcalDcsMap.cc:59
std::vector< Item > mItems
Definition: HcalDcsMap.h:122
string end
Definition: dataset.py:937
Log< level::Warning, false > LogWarning
void sortByDcsId()
Definition: HcalDcsMap.cc:165
int ring() const
Definition: HcalDcsDetId.h:55
const_iterator beginByDcsId(void) const
Definition: HcalDcsMap.cc:47
std::vector< const Item * > mItemsById
Definition: HcalDcsMap.h:123