CMS 3D CMS Logo

List of all members | Public Member Functions | Static Public Attributes | Private Member Functions | Private Attributes | Friends
HcalIndexLookup Class Reference

#include <HcalIndexLookup.h>

Public Member Functions

void add (unsigned transformedId, unsigned index)
 
void clear ()
 
bool empty () const
 
unsigned find (unsigned detId) const
 
bool hasDuplicateIds ()
 
 HcalIndexLookup ()
 
unsigned largestIndex () const
 
bool operator!= (const HcalIndexLookup &r) const
 
bool operator== (const HcalIndexLookup &r) const
 
void reserve (const unsigned n)
 
std::size_t size () const
 
void sort ()
 

Static Public Attributes

static const unsigned InvalidIndex = UINT_MAX
 

Private Member Functions

template<class Archive >
void load (Archive &ar, const unsigned)
 
template<class Archive >
void save (Archive &ar, const unsigned) const
 

Private Attributes

std::vector< std::pair< uint32_t, uint32_t > > data_
 
bool sorted_
 

Friends

class boost::serialization::access
 

Detailed Description

Definition at line 19 of file HcalIndexLookup.h.

Constructor & Destructor Documentation

◆ HcalIndexLookup()

HcalIndexLookup::HcalIndexLookup ( )
inline

Definition at line 23 of file HcalIndexLookup.h.

23 : sorted_(true) {}

Member Function Documentation

◆ add()

void HcalIndexLookup::add ( unsigned  transformedId,
unsigned  index 
)

Definition at line 29 of file HcalIndexLookup.cc.

References data_, Exception, InvalidIndex, and sorted_.

Referenced by counter.Counter::register(), SequenceTypes._TaskBase::remove(), and SequenceTypes._TaskBase::replace().

29  {
30  if (index == InvalidIndex)
31  throw cms::Exception("In HcalIndexLookup::add: invalid index");
32  data_.push_back(std::pair<uint32_t, uint32_t>(detId, index));
33  sorted_ = false;
34 }
std::vector< std::pair< uint32_t, uint32_t > > data_
static const unsigned InvalidIndex

◆ clear()

void HcalIndexLookup::clear ( void  )

Definition at line 5 of file HcalIndexLookup.cc.

References data_, and sorted_.

5  {
6  data_.clear();
7  sorted_ = true;
8 }
std::vector< std::pair< uint32_t, uint32_t > > data_

◆ empty()

bool HcalIndexLookup::empty ( ) const
inline

Definition at line 40 of file HcalIndexLookup.h.

References data_.

40 { return data_.empty(); }
std::vector< std::pair< uint32_t, uint32_t > > data_

◆ find()

unsigned HcalIndexLookup::find ( unsigned  detId) const

Definition at line 36 of file HcalIndexLookup.cc.

References data_, mps_fire::end, Exception, InvalidIndex, pfDeepBoostedJetPreprocessParams_cfi::lower_bound, cond::persistency::search(), sorted_, and mitigatedMETSequence_cff::U.

Referenced by HcalItemCollById< HFPhase1PMTData >::getIndex().

36  {
37  if (data_.empty())
38  return InvalidIndex;
39  if (!sorted_)
40  throw cms::Exception(
41  "In HcalIndexLookup::lookup:"
42  " collection is not sorted");
43  std::pair<uint32_t, uint32_t> search(detId, 0U);
44  auto end = data_.end();
45  auto it = std::lower_bound(data_.begin(), end, search);
46  if (it == end)
47  return InvalidIndex;
48  if (it->first == detId)
49  return it->second;
50  else
51  return InvalidIndex;
52 }
std::vector< T >::const_iterator search(const cond::Time_t &val, const std::vector< T > &container)
Definition: IOVProxy.cc:21
std::vector< std::pair< uint32_t, uint32_t > > data_
static const unsigned InvalidIndex

◆ hasDuplicateIds()

bool HcalIndexLookup::hasDuplicateIds ( )

Definition at line 17 of file HcalIndexLookup.cc.

References data_, first, mps_fire::i, and sort().

Referenced by HcalItemCollById< HFPhase1PMTData >::HcalItemCollById(), load(), and save().

17  {
18  const std::size_t sz = data_.size();
19  if (sz) {
20  sort();
21  const std::size_t szm1 = sz - 1;
22  for (std::size_t i = 0; i < szm1; ++i)
23  if (data_[i].first == data_[i + 1].first)
24  return true;
25  }
26  return false;
27 }
std::vector< std::pair< uint32_t, uint32_t > > data_

◆ largestIndex()

unsigned HcalIndexLookup::largestIndex ( ) const

Definition at line 54 of file HcalIndexLookup.cc.

References data_, mps_fire::i, InvalidIndex, and edm::second().

Referenced by HcalItemCollById< HFPhase1PMTData >::HcalItemCollById().

54  {
55  const std::size_t sz = data_.size();
56  if (sz) {
57  uint32_t largest = 0;
58  for (std::size_t i = 0; i < sz; ++i)
59  if (data_[i].second > largest)
60  largest = data_[i].second;
61  return largest;
62  } else
63  return InvalidIndex;
64 }
std::vector< std::pair< uint32_t, uint32_t > > data_
U second(std::pair< T, U > const &p)
static const unsigned InvalidIndex

◆ load()

template<class Archive >
void HcalIndexLookup::load ( Archive &  ar,
const unsigned   
)
inlineprivate

Definition at line 72 of file HcalIndexLookup.h.

References data_, Exception, hasDuplicateIds(), and sorted_.

Referenced by MatrixToProcess.MatrixToProcess::getProcess(), MatrixToProcess.MatrixToProcess::listAll(), and ConfigBuilder.ConfigBuilder::prepare_FILTER().

72  {
73  ar& data_& sorted_;
74  if (hasDuplicateIds())
75  throw cms::Exception("In HcalIndexLookup::load: invalid data");
76  }
std::vector< std::pair< uint32_t, uint32_t > > data_

◆ operator!=()

bool HcalIndexLookup::operator!= ( const HcalIndexLookup r) const
inline

Definition at line 55 of file HcalIndexLookup.h.

References alignCSCRings::r.

55 { return !(*this == r); }

◆ operator==()

bool HcalIndexLookup::operator== ( const HcalIndexLookup r) const
inline

Definition at line 53 of file HcalIndexLookup.h.

References data_, alignCSCRings::r, and sorted_.

53 { return data_ == r.data_ && sorted_ == r.sorted_; }
std::vector< std::pair< uint32_t, uint32_t > > data_

◆ reserve()

void HcalIndexLookup::reserve ( const unsigned  n)
inline

Definition at line 31 of file HcalIndexLookup.h.

References data_, and dqmiodumpmetadata::n.

31 { data_.reserve(n); }
std::vector< std::pair< uint32_t, uint32_t > > data_

◆ save()

template<class Archive >
void HcalIndexLookup::save ( Archive &  ar,
const unsigned   
) const
inlineprivate

Definition at line 64 of file HcalIndexLookup.h.

References data_, Exception, hasDuplicateIds(), and sorted_.

Referenced by SpecificationBuilder_cfi.Specification::saveAll().

64  {
65  // Make sure that there are no duplicate ids
66  if ((const_cast<HcalIndexLookup*>(this))->hasDuplicateIds())
67  throw cms::Exception("In HcalIndexLookup::save: invalid data");
68  ar& data_& sorted_;
69  }
std::vector< std::pair< uint32_t, uint32_t > > data_

◆ size()

std::size_t HcalIndexLookup::size ( void  ) const
inline

Definition at line 39 of file HcalIndexLookup.h.

References data_.

Referenced by ntupleDataFormat._Collection::__iter__(), and ntupleDataFormat._Collection::__len__().

39 { return data_.size(); }
std::vector< std::pair< uint32_t, uint32_t > > data_

◆ sort()

void HcalIndexLookup::sort ( )

Definition at line 10 of file HcalIndexLookup.cc.

References data_, jetUpdater_cfi::sort, and sorted_.

Referenced by hasDuplicateIds().

10  {
11  if (!sorted_) {
12  std::sort(data_.begin(), data_.end());
13  sorted_ = true;
14  }
15 }
std::vector< std::pair< uint32_t, uint32_t > > data_

Friends And Related Function Documentation

◆ boost::serialization::access

friend class boost::serialization::access
friend

Definition at line 61 of file HcalIndexLookup.h.

Member Data Documentation

◆ data_

std::vector<std::pair<uint32_t, uint32_t> > HcalIndexLookup::data_
private

◆ InvalidIndex

const unsigned HcalIndexLookup::InvalidIndex = UINT_MAX
static

◆ sorted_

bool HcalIndexLookup::sorted_
private

Definition at line 59 of file HcalIndexLookup.h.

Referenced by add(), clear(), find(), load(), operator==(), save(), and sort().