CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Classes | Public Member Functions | Protected Member Functions | Protected Attributes
HcalDcsMap Class Reference

#include <HcalDcsMap.h>

Classes

class  const_iterator
 
class  Item
 

Public Member Functions

const_iterator beginByDcsId (void) const
 
const_iterator beginById (void) const
 
const_iterator endByDcsId (void) const
 
const_iterator endById (void) const
 
 HcalDcsMap ()
 
 HcalDcsMap (const HcalDcsMap &src)
 
 HcalDcsMap (HcalDcsMap &&other)
 
const std::vector< HcalDetIdlookup (HcalDcsDetId fId) const
 
const std::vector< HcalDcsDetIdlookup (HcalDetId fId, HcalDcsDetId::DcsType type) const
 
bool mapGeomId2DcsId (HcalDetId fId, HcalDcsDetId fDcsId)
 
HcalDcsMapoperator= (const HcalDcsMap &rhs)
 
void sort ()
 
void sortByDcsId () const
 
void sortById () const
 
void swap (HcalDcsMap &other)
 
 ~HcalDcsMap ()
 

Protected Member Functions

std::vector< HcalDcsDetIdallHcalDcsDetId () const
 
std::vector< HcalGenericDetIdallHcalDetId () const
 
const std::vector< const Item * > findByDcsId (unsigned long fDcsId) const
 
const std::vector< const Item * > findById (unsigned long fId) const
 
const std::vector< const Item * > * getItemsByDcsId (void)
 
const std::vector< const Item * > * getItemsById (void)
 

Protected Attributes

std::vector< ItemmItems
 
std::atomic< std::vector
< const Item * > * > 
mItemsByDcsId
 
std::atomic< std::vector
< const Item * > * > 
mItemsById
 

Detailed Description

Author
Gena Kukartsev POOL object to store map between detector ID and DCS ID Inspired by HcalElectronicsMap $Author: kukartse
Date:
2007/12/14 13:31:21
Revision:
1.1
Author
Gena Kukartsev POOL object to store map between detector ID and DCS ID Inspired by HcalElectronicsMap $Author: kukartse
Date:
2010/02/22 21:08:07
Revision:
1.1

Definition at line 26 of file HcalDcsMap.h.

Constructor & Destructor Documentation

HcalDcsMap::HcalDcsMap ( )

Definition at line 17 of file HcalDcsMap.cc.

20  : mItemsById(nullptr), mItemsByDcsId(nullptr)
21 {
22 }
std::atomic< std::vector< const Item * > * > mItemsById
Definition: HcalDcsMap.h:119
std::atomic< std::vector< const Item * > * > mItemsByDcsId
Definition: HcalDcsMap.h:120
HcalDcsMap::~HcalDcsMap ( )

Definition at line 24 of file HcalDcsMap.cc.

References mItemsByDcsId, and mItemsById.

24  {
25  delete mItemsById;
26  mItemsById = nullptr;
27  delete mItemsByDcsId;
28  mItemsByDcsId = nullptr;
29 }
std::atomic< std::vector< const Item * > * > mItemsById
Definition: HcalDcsMap.h:119
std::atomic< std::vector< const Item * > * > mItemsByDcsId
Definition: HcalDcsMap.h:120
HcalDcsMap::HcalDcsMap ( const HcalDcsMap src)

Definition at line 31 of file HcalDcsMap.cc.

32  : mItems(src.mItems),
33  mItemsById(nullptr), mItemsByDcsId(nullptr) {}
std::atomic< std::vector< const Item * > * > mItemsById
Definition: HcalDcsMap.h:119
std::atomic< std::vector< const Item * > * > mItemsByDcsId
Definition: HcalDcsMap.h:120
std::vector< Item > mItems
Definition: HcalDcsMap.h:117
HcalDcsMap::HcalDcsMap ( HcalDcsMap &&  other)

Definition at line 52 of file HcalDcsMap.cc.

References swap().

53  : HcalDcsMap() {
54  other.swap(*this);
55 }
void swap(HcalDcsMap &other)
Definition: HcalDcsMap.cc:42

Member Function Documentation

std::vector< HcalDcsDetId > HcalDcsMap::allHcalDcsDetId ( ) const
protected

Definition at line 217 of file HcalDcsMap.cc.

References mItems, and query::result.

217  {
218  std::vector <HcalDcsDetId> result;
219  for (std::vector<Item>::const_iterator item = mItems.begin (); item != mItems.end (); item++)
220  if (item->mDcsId) result.push_back(HcalDcsDetId(item->mDcsId));
221  return result;
222 }
tuple result
Definition: query.py:137
std::vector< Item > mItems
Definition: HcalDcsMap.h:117
std::vector< HcalGenericDetId > HcalDcsMap::allHcalDetId ( ) const
protected

Definition at line 225 of file HcalDcsMap.cc.

References mItems, and query::result.

225  {
226  std::vector <HcalGenericDetId> result;
227  std::set <unsigned long> allIds;
228  for (std::vector<Item>::const_iterator item = mItems.begin (); item != mItems.end (); item++)
229  if (item->mId) allIds.insert (item->mId);
230  for (std::set <unsigned long>::const_iterator channel = allIds.begin (); channel != allIds.end (); channel++) {
231  result.push_back (HcalGenericDetId (*channel));
232  }
233  return result;
234 }
tuple result
Definition: query.py:137
std::vector< Item > mItems
Definition: HcalDcsMap.h:117
HcalDcsMap::const_iterator HcalDcsMap::beginByDcsId ( void  ) const

Definition at line 82 of file HcalDcsMap.cc.

References begin, HcalDcsMap::const_iterator::fIter, mItemsByDcsId, and sortByDcsId().

82  {
83  const_iterator _iter;
84  sortByDcsId();
85  _iter.fIter = (*mItemsByDcsId.load(std::memory_order_acquire)).begin();
86  return _iter;
87 }
void sortByDcsId() const
Definition: HcalDcsMap.cc:283
std::atomic< std::vector< const Item * > * > mItemsByDcsId
Definition: HcalDcsMap.h:120
#define begin
Definition: vmac.h:30
HcalDcsMap::const_iterator HcalDcsMap::beginById ( void  ) const

Definition at line 75 of file HcalDcsMap.cc.

References begin, HcalDcsMap::const_iterator::fIter, mItemsById, and sortById().

75  {
76  const_iterator _iter;
77  sortById();
78  _iter.fIter = (*mItemsById.load(std::memory_order_acquire)).begin();
79  return _iter;
80 }
std::atomic< std::vector< const Item * > * > mItemsById
Definition: HcalDcsMap.h:119
#define begin
Definition: vmac.h:30
void sortById() const
Definition: HcalDcsMap.cc:266
HcalDcsMap::const_iterator HcalDcsMap::endByDcsId ( void  ) const

Definition at line 96 of file HcalDcsMap.cc.

References end, HcalDcsMap::const_iterator::fIter, mItemsByDcsId, and sortByDcsId().

96  {
97  const_iterator _iter;
98  sortByDcsId();
99  _iter.fIter = (*mItemsByDcsId.load(std::memory_order_acquire)).end();
100  return _iter;
101 }
void sortByDcsId() const
Definition: HcalDcsMap.cc:283
#define end
Definition: vmac.h:37
std::atomic< std::vector< const Item * > * > mItemsByDcsId
Definition: HcalDcsMap.h:120
HcalDcsMap::const_iterator HcalDcsMap::endById ( void  ) const

Definition at line 89 of file HcalDcsMap.cc.

References end, HcalDcsMap::const_iterator::fIter, mItemsById, and sortById().

89  {
90  const_iterator _iter;
91  sortById();
92  _iter.fIter = (*mItemsById.load(std::memory_order_acquire)).end();
93  return _iter;
94 }
std::atomic< std::vector< const Item * > * > mItemsById
Definition: HcalDcsMap.h:119
#define end
Definition: vmac.h:37
void sortById() const
Definition: HcalDcsMap.cc:266
const std::vector< const HcalDcsMap::Item * > HcalDcsMap::findByDcsId ( unsigned long  fDcsId) const
protected

Definition at line 156 of file HcalDcsMap.cc.

References mItemsByDcsId, query::result, sortByDcsId(), and filterCSVwithJSON::target.

Referenced by lookup(), and mapGeomId2DcsId().

156  {
157  Item target (0, fDcsId);
158  std::vector<const HcalDcsMap::Item*>::const_iterator item;
159  std::vector<const HcalDcsMap::Item *> result;
160 
161  sortByDcsId();
162 
163  hcal_impl::LessByDcsId lessByDcsId;
164  auto ptr = (*mItemsByDcsId.load(std::memory_order_acquire));
165  item = std::lower_bound (ptr.begin(), ptr.end(), &target, lessByDcsId);
166  if (item == ptr.end() || (*item)->mDcsId != fDcsId) {
167  // throw cms::Exception ("Conditions not found") << "Unavailable Dcs map for cell " << fDcsId;
168  return result;
169  }
170  else{
171  if(item != ptr.end() && !lessByDcsId(&target, *item)){
172  result.push_back( *item );
173  ++item;
174  }
175  }
176  return result;
177 }
void sortByDcsId() const
Definition: HcalDcsMap.cc:283
tuple result
Definition: query.py:137
std::atomic< std::vector< const Item * > * > mItemsByDcsId
Definition: HcalDcsMap.h:120
const std::vector< const HcalDcsMap::Item * > HcalDcsMap::findById ( unsigned long  fId) const
protected

Definition at line 133 of file HcalDcsMap.cc.

References mItemsById, query::result, sortById(), and filterCSVwithJSON::target.

Referenced by lookup().

133  {
134  Item target (fId, 0);
135  std::vector<const HcalDcsMap::Item*>::const_iterator item;
136  std::vector<const HcalDcsMap::Item *> result;
137 
138  sortById();
139 
140  hcal_impl::LessById lessById;
141  auto ptr = (*mItemsById.load(std::memory_order_acquire));
142  item = std::lower_bound (ptr.begin(), ptr.end(), &target, lessById);
143  if (item == ptr.end() || (*item)->mId != fId){
144  // throw cms::Exception ("Conditions not found") << "Unavailable Dcs map for cell " << fId;
145  return result;
146  }
147  else{
148  if(item != ptr.end() && !lessById(&target, *item)){
149  result.push_back( *item );
150  ++item;
151  }
152  }
153  return result;
154 }
std::atomic< std::vector< const Item * > * > mItemsById
Definition: HcalDcsMap.h:119
tuple result
Definition: query.py:137
void sortById() const
Definition: HcalDcsMap.cc:266
const std::vector<const Item*>* HcalDcsMap::getItemsByDcsId ( void  )
inlineprotected

Definition at line 122 of file HcalDcsMap.h.

References mItemsByDcsId.

122 {return mItemsByDcsId.load(std::memory_order_acquire);}
std::atomic< std::vector< const Item * > * > mItemsByDcsId
Definition: HcalDcsMap.h:120
const std::vector<const Item*>* HcalDcsMap::getItemsById ( void  )
inlineprotected

Definition at line 121 of file HcalDcsMap.h.

References mItemsById.

121 {return mItemsById.load(std::memory_order_acquire);}
std::atomic< std::vector< const Item * > * > mItemsById
Definition: HcalDcsMap.h:119
const std::vector< HcalDetId > HcalDcsMap::lookup ( HcalDcsDetId  fId) const

Definition at line 179 of file HcalDcsMap.cc.

References HcalDcsDetId::DCSUNKNOWN, findByDcsId(), HcalDcsDetId::ring(), HcalDcsDetId::slice(), HcalDcsDetId::subchannel(), and HcalOtherDetId::subdet().

179  {
180  // DCS type is a part of DcsDetId but it does not make sense to keep
181  // duplicate records in the map for DCS channels where only type is different.
182  // Hence, the type in HcalDcsDetId is always forced to DCSUNKNOWN
183  HcalDcsDetId fDcsId_notype(fId.subdet(),
184  fId.ring(), // side is already included
185  fId.slice(),
187  fId.subchannel());
188  const std::vector<const Item *> items = findByDcsId (fDcsId_notype.rawId ());
189  std::vector<HcalDetId> _ids;
190  for (std::vector<const Item *>::const_iterator item = items.begin();
191  item != items.end();
192  ++item){
193  _ids.push_back( DetId(*item ? (*item)->mId : 0) );
194  }
195  return _ids;
196 }
int subchannel() const
Definition: HcalDcsDetId.h:49
const std::vector< const Item * > findByDcsId(unsigned long fDcsId) const
Definition: HcalDcsMap.cc:156
Definition: DetId.h:18
HcalOtherSubdetector subdet() const
get the category
int slice() const
Definition: HcalDcsDetId.h:47
int ring() const
Definition: HcalDcsDetId.h:46
const std::vector< HcalDcsDetId > HcalDcsMap::lookup ( HcalDetId  fId,
HcalDcsDetId::DcsType  type 
) const

Definition at line 198 of file HcalDcsMap.cc.

References findById(), DetId::rawId(), HcalDcsDetId::ring(), HcalDcsDetId::slice(), HcalDcsDetId::subchannel(), HcalOtherDetId::subdet(), and HcalDcsDetId::zside().

198  {
199  const std::vector<const Item *> items = findById (fId.rawId ());
200  std::vector<HcalDcsDetId> _ids;
201  for (std::vector<const Item *>::const_iterator item = items.begin();
202  item != items.end();
203  ++item){
204  HcalDcsDetId _id(*item ? (*item)->mId : 0);
205  _ids.push_back( HcalDcsDetId(_id.subdet(),
206  _id.zside()*_id.ring(),
207  _id.slice(),
208  type,
209  _id.subchannel()
210  )
211  );
212  }
213  return _ids;
214 }
type
Definition: HCALResponse.h:21
uint32_t rawId() const
get the raw id
Definition: DetId.h:43
const std::vector< const Item * > findById(unsigned long fId) const
Definition: HcalDcsMap.cc:133
bool HcalDcsMap::mapGeomId2DcsId ( HcalDetId  fId,
HcalDcsDetId  fDcsId 
)

Definition at line 237 of file HcalDcsMap.cc.

References HcalDcsDetId::DCSUNKNOWN, findByDcsId(), mItems, mItemsByDcsId, mItemsById, HcalDcsDetId::ring(), HcalDcsDetId::slice(), HcalDcsDetId::subchannel(), and HcalOtherDetId::subdet().

237  {
238  // DCS type is a part of DcsDetId but it does not make sense to keep
239  // duplicate records in the map for DCS channels where only type is different.
240  // Hence, the type in HcalDcsDetId is always forced to DCSUNKNOWN
241  HcalDcsDetId fDcsId_notype(fDcsId.subdet(),
242  fDcsId.ring(), // side is included
243  fDcsId.slice(),
245  fDcsId.subchannel());
246  const std::vector<const Item *> items = findByDcsId(fDcsId_notype);
247  for (std::vector<const Item *>::const_iterator item = items.begin();
248  item != items.end();
249  ++item){
250  if ((*item)->mId == fId){
251  edm::LogWarning("HCAL") << "HcalDcsMap::mapGeomId2DcsId-> Geom channel " << fId
252  << " already mapped to DCS channel " << fDcsId_notype;
253  return false; // element already exists
254  }
255  }
256  Item _item(fId, fDcsId_notype);
257  mItems.push_back(_item);
258  delete mItemsById;
259  mItemsById = nullptr;
260  delete mItemsByDcsId;
261  mItemsByDcsId = nullptr;
262  return true;
263 }
int subchannel() const
Definition: HcalDcsDetId.h:49
std::atomic< std::vector< const Item * > * > mItemsById
Definition: HcalDcsMap.h:119
const std::vector< const Item * > findByDcsId(unsigned long fDcsId) const
Definition: HcalDcsMap.cc:156
std::atomic< std::vector< const Item * > * > mItemsByDcsId
Definition: HcalDcsMap.h:120
HcalOtherSubdetector subdet() const
get the category
int slice() const
Definition: HcalDcsDetId.h:47
std::vector< Item > mItems
Definition: HcalDcsMap.h:117
int ring() const
Definition: HcalDcsDetId.h:46
HcalDcsMap & HcalDcsMap::operator= ( const HcalDcsMap rhs)

Definition at line 36 of file HcalDcsMap.cc.

References swap(), and groupFilesInBlocks::temp.

36  {
37  HcalDcsMap temp(rhs);
38  temp.swap(*this);
39  return *this;
40 }
void HcalDcsMap::sort ( )
inline

Definition at line 76 of file HcalDcsMap.h.

76 {}
void HcalDcsMap::sortByDcsId ( ) const

Definition at line 283 of file HcalDcsMap.cc.

References i, mItems, mItemsByDcsId, and python.multivaluedict::sort().

Referenced by beginByDcsId(), endByDcsId(), and findByDcsId().

283  {
284  if (!mItemsByDcsId.load(std::memory_order_acquire)) {
285  auto ptr = new std::vector<const Item*>;
286  for (auto i=mItems.begin(); i!=mItems.end(); ++i) {
287  if (i->mDcsId) ptr->push_back(&(*i));
288  }
289 
290  std::sort (ptr->begin(), ptr->end(), hcal_impl::LessByDcsId ());
291  //atomically try to swap this to become mItemsByDcsId
292  std::vector<const Item*>* expect = nullptr;
293  bool exchanged = mItemsByDcsId.compare_exchange_strong(expect, ptr, std::memory_order_acq_rel);
294  if(!exchanged) {
295  delete ptr;
296  }
297  }
298 }
int i
Definition: DBlmapReader.cc:9
std::atomic< std::vector< const Item * > * > mItemsByDcsId
Definition: HcalDcsMap.h:120
std::vector< Item > mItems
Definition: HcalDcsMap.h:117
void HcalDcsMap::sortById ( ) const

Definition at line 266 of file HcalDcsMap.cc.

References i, mItems, mItemsById, and python.multivaluedict::sort().

Referenced by beginById(), endById(), and findById().

266  {
267  if (!mItemsById.load(std::memory_order_acquire)) {
268  auto ptr = new std::vector<const Item*>;
269  for (auto i=mItems.begin(); i!=mItems.end(); ++i) {
270  if (i->mDcsId) ptr->push_back(&(*i));
271  }
272 
273  std::sort (ptr->begin(), ptr->end(), hcal_impl::LessById ());
274  //atomically try to swap this to become mItemsById
275  std::vector<const Item*>* expect = nullptr;
276  bool exchanged = mItemsById.compare_exchange_strong(expect, ptr, std::memory_order_acq_rel);
277  if(!exchanged) {
278  delete ptr;
279  }
280  }
281 }
int i
Definition: DBlmapReader.cc:9
std::atomic< std::vector< const Item * > * > mItemsById
Definition: HcalDcsMap.h:119
std::vector< Item > mItems
Definition: HcalDcsMap.h:117
void HcalDcsMap::swap ( HcalDcsMap other)

Definition at line 42 of file HcalDcsMap.cc.

References mItems, mItemsByDcsId, mItemsById, and std::swap().

Referenced by HcalDcsMap(), and operator=().

42  {
43  std::swap(mItems, other.mItems);
44  other.mItemsByDcsId.exchange(
45  mItemsByDcsId.exchange(other.mItemsByDcsId.load(std::memory_order_acquire), std::memory_order_acq_rel),
46  std::memory_order_acq_rel);
47  other.mItemsById.exchange(
48  mItemsById.exchange(other.mItemsById.load(std::memory_order_acquire), std::memory_order_acq_rel),
49  std::memory_order_acq_rel);
50 }
void swap(edm::DataFrameContainer &lhs, edm::DataFrameContainer &rhs)
std::atomic< std::vector< const Item * > * > mItemsById
Definition: HcalDcsMap.h:119
std::atomic< std::vector< const Item * > * > mItemsByDcsId
Definition: HcalDcsMap.h:120
std::vector< Item > mItems
Definition: HcalDcsMap.h:117

Member Data Documentation

std::vector<Item> HcalDcsMap::mItems
protected
std::atomic<std::vector<const Item*>*> HcalDcsMap::mItemsByDcsId
mutableprotected
std::atomic<std::vector<const Item*>*> HcalDcsMap::mItemsById
mutableprotected