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.

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 }

References data_, Exception, InvalidIndex, and sorted_.

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

◆ clear()

void HcalIndexLookup::clear ( void  )

Definition at line 5 of file HcalIndexLookup.cc.

5  {
6  data_.clear();
7  sorted_ = true;
8 }

References data_, and sorted_.

Referenced by BeautifulSoup.Tag::setString().

◆ empty()

bool HcalIndexLookup::empty ( ) const
inline

Definition at line 40 of file HcalIndexLookup.h.

40 { return data_.empty(); }

References data_.

◆ find()

unsigned HcalIndexLookup::find ( unsigned  detId) const

Definition at line 36 of file HcalIndexLookup.cc.

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 }

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

Referenced by BeautifulSoup.Tag::__getattr__(), BeautifulSoup.Tag::firstText(), HcalItemCollById< HFPhase1PMTData >::getIndex(), and HcalItemArrayCollById< Item, N >::getIndex().

◆ hasDuplicateIds()

bool HcalIndexLookup::hasDuplicateIds ( )

Definition at line 17 of file HcalIndexLookup.cc.

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 }

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

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

◆ largestIndex()

unsigned HcalIndexLookup::largestIndex ( ) const

Definition at line 54 of file HcalIndexLookup.cc.

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 }

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

Referenced by HcalItemArrayCollById< Item, N >::HcalItemArrayCollById(), and HcalItemCollById< HFPhase1PMTData >::HcalItemCollById().

◆ load()

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

Definition at line 72 of file HcalIndexLookup.h.

72  {
73  ar& data_& sorted_;
74  if (hasDuplicateIds())
75  throw cms::Exception("In HcalIndexLookup::load: invalid data");
76  }

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

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

◆ operator!=()

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

Definition at line 55 of file HcalIndexLookup.h.

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

References alignCSCRings::r.

◆ operator==()

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

Definition at line 53 of file HcalIndexLookup.h.

53 { return data_ == r.data_ && sorted_ == r.sorted_; }

References data_, alignCSCRings::r, and sorted_.

◆ reserve()

void HcalIndexLookup::reserve ( const unsigned  n)
inline

Definition at line 31 of file HcalIndexLookup.h.

31 { data_.reserve(n); }

References data_, and dqmiodumpmetadata::n.

◆ save()

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

Definition at line 64 of file HcalIndexLookup.h.

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  }

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

Referenced by SpecificationBuilder_cfi.Specification::saveAll().

◆ size()

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

Definition at line 39 of file HcalIndexLookup.h.

39 { return data_.size(); }

References data_.

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

◆ sort()

void HcalIndexLookup::sort ( )

Definition at line 10 of file HcalIndexLookup.cc.

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

References data_, jetUpdater_cfi::sort, and sorted_.

Referenced by hasDuplicateIds().

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().

mps_fire.i
i
Definition: mps_fire.py:428
dqmiodumpmetadata.n
n
Definition: dqmiodumpmetadata.py:28
edm::second
U second(std::pair< T, U > const &p)
Definition: ParameterSet.cc:222
HcalIndexLookup::sorted_
bool sorted_
Definition: HcalIndexLookup.h:59
mps_fire.end
end
Definition: mps_fire.py:242
cond::persistency::search
std::vector< T >::const_iterator search(const cond::Time_t &val, const std::vector< T > &container)
Definition: IOVProxy.cc:21
first
auto first
Definition: CAHitNtupletGeneratorKernelsImpl.h:112
mitigatedMETSequence_cff.U
U
Definition: mitigatedMETSequence_cff.py:36
pfDeepBoostedJetPreprocessParams_cfi.lower_bound
lower_bound
Definition: pfDeepBoostedJetPreprocessParams_cfi.py:15
jetUpdater_cfi.sort
sort
Definition: jetUpdater_cfi.py:29
HcalIndexLookup::InvalidIndex
static const unsigned InvalidIndex
Definition: HcalIndexLookup.h:21
HcalIndexLookup::sort
void sort()
Definition: HcalIndexLookup.cc:10
alignCSCRings.r
r
Definition: alignCSCRings.py:93
HcalIndexLookup::hasDuplicateIds
bool hasDuplicateIds()
Definition: HcalIndexLookup.cc:17
Exception
Definition: hltDiff.cc:245
HcalIndexLookup::data_
std::vector< std::pair< uint32_t, uint32_t > > data_
Definition: HcalIndexLookup.h:58
AlignmentPI::index
index
Definition: AlignmentPayloadInspectorHelper.h:46