CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
HcalDcsMap.cc
Go to the documentation of this file.
1 
11 #include <iostream>
12 #include <set>
13 
16 
18  //FIXME mItems(HcalDcsDetId::maxLinearIndex+1),
19  //mItems(0x7FFF),
20  sortedById(false),
21  sortedByDcsId(false){
22 }
23 
25 }
26 
27 namespace hcal_impl {
28  class LessById {
29  public:
31  const HcalDcsMap::Item* b) {
32  return a->mId < b->mId;
33  }
34  };
35 
36  class LessByDcsId {
37  public:
39  const HcalDcsMap::Item* b) {
40  return a->mDcsId < b->mDcsId;
41  }
42  };
43 }
44 
46  const_iterator _iter;
47  if (!sortedById) sortById();
48  _iter.fIter = mItemsById.begin();
49  return _iter;
50 }
51 
53  const_iterator _iter;
54  if (!sortedByDcsId) sortByDcsId();
55  _iter.fIter = mItemsByDcsId.begin();
56  return _iter;
57 }
58 
60  const_iterator _iter;
61  if (!sortedById) sortById();
62  _iter.fIter = mItemsById.end();
63  return _iter;
64 }
65 
67  const_iterator _iter;
68  if (!sortedByDcsId) sortByDcsId();
69  _iter.fIter = mItemsByDcsId.end();
70  return _iter;
71 }
72 
73 // iterator methods
75  if (fIter != other.fIter) return true;
76  else return false;
77 }
78 
80  ++fIter;
81  return *this;
82 }
83 
85  const_iterator i = *this;
86  ++fIter;
87  return i;
88 }
89 
91  ++fIter;
92 }
93 
95  return (*fIter)->mDcsId;
96 }
97 
99  return (*fIter)->mId;
100 }
101 
102 
103 const std::vector<const HcalDcsMap::Item *> HcalDcsMap::findById (unsigned long fId) const {
104  Item target (fId, 0);
105  std::vector<const HcalDcsMap::Item*>::const_iterator item;
106  std::vector<const HcalDcsMap::Item *> result;
107 
108  if (!sortedById) sortById();
109 
110  hcal_impl::LessById lessById;
111  item = std::lower_bound (mItemsById.begin(), mItemsById.end(), &target, lessById);
112  if (item == mItemsById.end() || (*item)->mId != fId){
113  // throw cms::Exception ("Conditions not found") << "Unavailable Dcs map for cell " << fId;
114  return result;
115  }
116  else{
117  if(item != mItemsById.end() && !lessById(&target, *item)){
118  result.push_back( *item );
119  ++item;
120  }
121  }
122  return result;
123 }
124 
125 const std::vector<const HcalDcsMap::Item *> HcalDcsMap::findByDcsId (unsigned long fDcsId) const {
126  Item target (0, fDcsId);
127  std::vector<const HcalDcsMap::Item*>::const_iterator item;
128  std::vector<const HcalDcsMap::Item *> result;
129 
130  if (!sortedByDcsId) sortByDcsId();
131 
132  hcal_impl::LessByDcsId lessByDcsId;
133  item = std::lower_bound (mItemsByDcsId.begin(), mItemsByDcsId.end(), &target, lessByDcsId);
134  if (item == mItemsByDcsId.end() || (*item)->mDcsId != fDcsId) {
135  // throw cms::Exception ("Conditions not found") << "Unavailable Dcs map for cell " << fDcsId;
136  return result;
137  }
138  else{
139  if(item != mItemsByDcsId.end() && !lessByDcsId(&target, *item)){
140  result.push_back( *item );
141  ++item;
142  }
143  }
144  return result;
145 }
146 
147 const std::vector<HcalDetId> HcalDcsMap::lookup(HcalDcsDetId fId ) const{
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  HcalDcsDetId fDcsId_notype(fId.subdet(),
152  fId.ring(), // side is already included
153  fId.slice(),
155  fId.subchannel());
156  const std::vector<const Item *> items = findByDcsId (fDcsId_notype.rawId ());
157  std::vector<HcalDetId> _ids;
158  for (std::vector<const Item *>::const_iterator item = items.begin();
159  item != items.end();
160  ++item){
161  _ids.push_back( DetId(*item ? (*item)->mId : 0) );
162  }
163  return _ids;
164 }
165 
166 const std::vector<HcalDcsDetId> HcalDcsMap::lookup(HcalDetId fId, HcalDcsDetId::DcsType type) const {
167  const std::vector<const Item *> items = findById (fId.rawId ());
168  std::vector<HcalDcsDetId> _ids;
169  for (std::vector<const Item *>::const_iterator item = items.begin();
170  item != items.end();
171  ++item){
172  HcalDcsDetId _id(*item ? (*item)->mId : 0);
173  _ids.push_back( HcalDcsDetId(_id.subdet(),
174  _id.zside()*_id.ring(),
175  _id.slice(),
176  type,
177  _id.subchannel()
178  )
179  );
180  }
181  return _ids;
182 }
183 
184 //FIXME: remove duplicates
185 std::vector <HcalDcsDetId> HcalDcsMap::allHcalDcsDetId () const {
186  std::vector <HcalDcsDetId> result;
187  for (std::vector<Item>::const_iterator item = mItems.begin (); item != mItems.end (); item++)
188  if (item->mDcsId) result.push_back(HcalDcsDetId(item->mDcsId));
189  return result;
190 }
191 
192 // FIXME: remove duplicates
193 std::vector <HcalGenericDetId> HcalDcsMap::allHcalDetId () const {
194  std::vector <HcalGenericDetId> result;
195  std::set <unsigned long> allIds;
196  for (std::vector<Item>::const_iterator item = mItems.begin (); item != mItems.end (); item++)
197  if (item->mId) allIds.insert (item->mId);
198  for (std::set <unsigned long>::const_iterator channel = allIds.begin (); channel != allIds.end (); channel++) {
199  result.push_back (HcalGenericDetId (*channel));
200  }
201  return result;
202 }
203 
204 
206  // DCS type is a part of DcsDetId but it does not make sense to keep
207  // duplicate records in the map for DCS channels where only type is different.
208  // Hence, the type in HcalDcsDetId is always forced to DCSUNKNOWN
209  HcalDcsDetId fDcsId_notype(fDcsId.subdet(),
210  fDcsId.ring(), // side is included
211  fDcsId.slice(),
213  fDcsId.subchannel());
214  const std::vector<const Item *> items = findByDcsId(fDcsId_notype);
215  for (std::vector<const Item *>::const_iterator item = items.begin();
216  item != items.end();
217  ++item){
218  if ((*item)->mId == fId){
219  edm::LogWarning("HCAL") << "HcalDcsMap::mapGeomId2DcsId-> Geom channel " << fId
220  << " already mapped to DCS channel " << fDcsId_notype;
221  return false; // element already exists
222  }
223  }
224  Item _item(fId, fDcsId_notype);
225  mItems.push_back(_item);
226  sortedById=false;
227  sortedByDcsId=false;
228  return true;
229 }
230 
231 
232 void HcalDcsMap::sortById () const {
233  if (!sortedById) {
234  mItemsById.clear();
235  for (std::vector<Item>::const_iterator i=mItems.begin(); i!=mItems.end(); ++i) {
236  if (i->mDcsId) mItemsById.push_back(&(*i));
237  }
238  std::sort (mItemsById.begin(), mItemsById.end(), hcal_impl::LessById ());
239  sortedById=true;
240  }
241 }
242 
243 void HcalDcsMap::sortByDcsId () const {
244  if (!sortedByDcsId) {
245  mItemsByDcsId.clear();
246  for (std::vector<Item>::const_iterator i=mItems.begin(); i!=mItems.end(); ++i) {
247  if (i->mDcsId) mItemsByDcsId.push_back(&(*i));
248  }
249 
251  sortedByDcsId=true;
252  }
253 }
std::vector< const Item * >::const_iterator fIter
Definition: HcalDcsMap.h:85
type
Definition: HCALResponse.h:22
int i
Definition: DBlmapReader.cc:9
void sortByDcsId() const
Definition: HcalDcsMap.cc:243
bool sortedById
Definition: HcalDcsMap.h:105
uint32_t mDcsId
Definition: HcalDcsMap.h:70
int subchannel() const
Definition: HcalDcsDetId.h:49
bool mapGeomId2DcsId(HcalDetId fId, HcalDcsDetId fDcsId)
Definition: HcalDcsMap.cc:205
std::vector< HcalDcsDetId > allHcalDcsDetId() const
Definition: HcalDcsMap.cc:185
const_iterator operator++()
Definition: HcalDcsMap.cc:79
uint32_t mId
Definition: HcalDcsMap.h:69
bool sortedByDcsId
Definition: HcalDcsMap.h:108
uint32_t rawId() const
get the raw id
Definition: DetId.h:45
const_iterator endById(void) const
Definition: HcalDcsMap.cc:59
const_iterator beginById(void) const
Definition: HcalDcsMap.cc:45
bool operator()(const HcalDcsMap::Item *a, const HcalDcsMap::Item *b)
Definition: HcalDcsMap.cc:38
const std::vector< HcalDetId > lookup(HcalDcsDetId fId) const
Definition: HcalDcsMap.cc:147
HcalDetId getHcalDetId(void)
Definition: HcalDcsMap.cc:98
tuple result
Definition: query.py:137
const std::vector< const Item * > findByDcsId(unsigned long fDcsId) const
Definition: HcalDcsMap.cc:125
HcalDcsDetId getHcalDcsDetId(void)
Definition: HcalDcsMap.cc:94
int zside() const
Definition: HcalDcsDetId.h:45
Definition: DetId.h:20
const std::vector< const Item * > findById(unsigned long fId) const
Definition: HcalDcsMap.cc:103
HcalOtherSubdetector subdet() const
get the category
std::vector< HcalGenericDetId > allHcalDetId() const
Definition: HcalDcsMap.cc:193
double b
Definition: hdecay.h:120
int slice() const
Definition: HcalDcsDetId.h:47
bool operator()(const HcalDcsMap::Item *a, const HcalDcsMap::Item *b)
Definition: HcalDcsMap.cc:30
bool operator!=(const const_iterator &other)
Definition: HcalDcsMap.cc:74
std::vector< const Item * > mItemsByDcsId
Definition: HcalDcsMap.h:107
const_iterator endByDcsId(void) const
Definition: HcalDcsMap.cc:66
double a
Definition: hdecay.h:121
std::vector< Item > mItems
Definition: HcalDcsMap.h:103
void sortById() const
Definition: HcalDcsMap.cc:232
int ring() const
Definition: HcalDcsDetId.h:46
const_iterator beginByDcsId(void) const
Definition: HcalDcsMap.cc:52
std::vector< const Item * > mItemsById
Definition: HcalDcsMap.h:104