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 | Private Member Functions | Friends
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
 

Private Member Functions

template<class Archive >
void serialize (Archive &ar, const unsigned int version)
 

Friends

class boost::serialization::access
 
template<typename CondSerializationT , typename Enabled >
struct cond::serialization::access
 

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 28 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:123
std::atomic< std::vector< const Item * > * > mItemsByDcsId
Definition: HcalDcsMap.h:124
HcalDcsMap::~HcalDcsMap ( )

Definition at line 24 of file HcalDcsMap.cc.

References mItemsByDcsId, and mItemsById.

24  {
25  delete mItemsById.load();
26  delete mItemsByDcsId.load();
27 }
std::atomic< std::vector< const Item * > * > mItemsById
Definition: HcalDcsMap.h:123
std::atomic< std::vector< const Item * > * > mItemsByDcsId
Definition: HcalDcsMap.h:124
HcalDcsMap::HcalDcsMap ( const HcalDcsMap src)

Definition at line 29 of file HcalDcsMap.cc.

30  : mItems(src.mItems),
31  mItemsById(nullptr), mItemsByDcsId(nullptr) {}
std::atomic< std::vector< const Item * > * > mItemsById
Definition: HcalDcsMap.h:123
std::atomic< std::vector< const Item * > * > mItemsByDcsId
Definition: HcalDcsMap.h:124
std::vector< Item > mItems
Definition: HcalDcsMap.h:121
HcalDcsMap::HcalDcsMap ( HcalDcsMap &&  other)

Definition at line 50 of file HcalDcsMap.cc.

References swap().

51  : HcalDcsMap() {
52  other.swap(*this);
53 }
void swap(HcalDcsMap &other)
Definition: HcalDcsMap.cc:40

Member Function Documentation

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

Definition at line 215 of file HcalDcsMap.cc.

References mItems, and mps_fire::result.

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

Definition at line 223 of file HcalDcsMap.cc.

References mItems, and mps_fire::result.

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

Definition at line 80 of file HcalDcsMap.cc.

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

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

Definition at line 73 of file HcalDcsMap.cc.

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

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

Definition at line 94 of file HcalDcsMap.cc.

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

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

Definition at line 87 of file HcalDcsMap.cc.

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

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

Definition at line 154 of file HcalDcsMap.cc.

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

Referenced by lookup(), and mapGeomId2DcsId().

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

Definition at line 131 of file HcalDcsMap.cc.

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

Referenced by lookup().

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

Definition at line 126 of file HcalDcsMap.h.

References mItemsByDcsId.

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

Definition at line 125 of file HcalDcsMap.h.

References mItemsById.

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

Definition at line 177 of file HcalDcsMap.cc.

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

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

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

196  {
197  const std::vector<const Item *> items = findById (fId.rawId ());
198  std::vector<HcalDcsDetId> _ids;
199  for (std::vector<const Item *>::const_iterator item = items.begin();
200  item != items.end();
201  ++item){
202  HcalDcsDetId _id(*item ? (*item)->mId : 0);
203  _ids.push_back( HcalDcsDetId(_id.subdet(),
204  _id.zside()*_id.ring(),
205  _id.slice(),
206  type,
207  _id.subchannel()
208  )
209  );
210  }
211  return _ids;
212 }
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:131
bool HcalDcsMap::mapGeomId2DcsId ( HcalDetId  fId,
HcalDcsDetId  fDcsId 
)

Definition at line 235 of file HcalDcsMap.cc.

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

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

Definition at line 34 of file HcalDcsMap.cc.

References swap(), and groupFilesInBlocks::temp.

34  {
35  HcalDcsMap temp(rhs);
36  temp.swap(*this);
37  return *this;
38 }
template<class Archive >
void HcalDcsMap::serialize ( Archive &  ar,
const unsigned int  version 
)
private
void HcalDcsMap::sort ( )
inline

Definition at line 78 of file HcalDcsMap.h.

78 {}
void HcalDcsMap::sortByDcsId ( ) const

Definition at line 281 of file HcalDcsMap.cc.

References i, mItems, and mItemsByDcsId.

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

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

Definition at line 264 of file HcalDcsMap.cc.

References i, mItems, and mItemsById.

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

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

Definition at line 40 of file HcalDcsMap.cc.

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

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

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

Friends And Related Function Documentation

friend class boost::serialization::access
friend

Definition at line 134 of file HcalDcsMap.h.

template<typename CondSerializationT , typename Enabled >
friend struct cond::serialization::access
friend

Definition at line 134 of file HcalDcsMap.h.

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