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 18 of file HcalIndexLookup.h.

Constructor & Destructor Documentation

HcalIndexLookup::HcalIndexLookup ( )
inline

Definition at line 23 of file HcalIndexLookup.h.

References add(), clear(), and sort().

23 : sorted_(true) {}

Member Function Documentation

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

Definition at line 34 of file HcalIndexLookup.cc.

References data_, Exception, InvalidIndex, and sorted_.

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

35 {
36  if (index == InvalidIndex)
37  throw cms::Exception("In HcalIndexLookup::add: invalid index");
38  data_.push_back(std::pair<uint32_t,uint32_t>(detId, index));
39  sorted_ = false;
40 }
std::vector< std::pair< uint32_t, uint32_t > > data_
static const unsigned InvalidIndex
void HcalIndexLookup::clear ( void  )
bool HcalIndexLookup::empty ( ) const
inline

Definition at line 40 of file HcalIndexLookup.h.

References data_, find(), and largestIndex().

Referenced by Vispa.Gui.VispaWidget.TextField::setAutosizeFont(), and Vispa.Gui.VispaWidget.TextField::setAutotruncate().

40 {return data_.empty();}
std::vector< std::pair< uint32_t, uint32_t > > data_
unsigned HcalIndexLookup::find ( unsigned  detId) const

Definition at line 42 of file HcalIndexLookup.cc.

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

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

43 {
44  if (data_.empty())
45  return InvalidIndex;
46  if (!sorted_)
47  throw cms::Exception("In HcalIndexLookup::lookup:"
48  " collection is not sorted");
49  std::pair<uint32_t,uint32_t> search(detId, 0U);
50  auto end = data_.end();
51  auto it = std::lower_bound(data_.begin(), end, search);
52  if (it == end)
53  return InvalidIndex;
54  if (it->first == detId)
55  return it->second;
56  else
57  return InvalidIndex;
58 }
std::vector< T >::const_iterator search(const cond::Time_t &val, const std::vector< T > &container)
Definition: IOVProxy.cc:314
#define end
Definition: vmac.h:39
std::vector< std::pair< uint32_t, uint32_t > > data_
static const unsigned InvalidIndex
bool HcalIndexLookup::hasDuplicateIds ( )

Definition at line 20 of file HcalIndexLookup.cc.

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

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

21 {
22  const std::size_t sz = data_.size();
23  if (sz)
24  {
25  sort();
26  const std::size_t szm1 = sz - 1;
27  for (std::size_t i=0; i<szm1; ++i)
28  if (data_[i].first == data_[i+1].first)
29  return true;
30  }
31  return false;
32 }
std::vector< std::pair< uint32_t, uint32_t > > data_
unsigned HcalIndexLookup::largestIndex ( ) const

Definition at line 60 of file HcalIndexLookup.cc.

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

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

61 {
62  const std::size_t sz = data_.size();
63  if (sz)
64  {
65  uint32_t largest = 0;
66  for (std::size_t i=0; i<sz; ++i)
67  if (data_[i].second > largest)
68  largest = data_[i].second;
69  return largest;
70  }
71  else
72  return InvalidIndex;
73 }
U second(std::pair< T, U > const &p)
std::vector< std::pair< uint32_t, uint32_t > > data_
static const unsigned InvalidIndex
template<class Archive >
void HcalIndexLookup::load ( Archive &  ar,
const unsigned   
)
inlineprivate

Definition at line 75 of file HcalIndexLookup.h.

References Exception, hasDuplicateIds(), and sorted_.

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

76  {
77  ar & data_ & sorted_;
78  if (hasDuplicateIds()) throw cms::Exception(
79  "In HcalIndexLookup::load: invalid data");
80  }
std::vector< std::pair< uint32_t, uint32_t > > data_
bool HcalIndexLookup::operator!= ( const HcalIndexLookup r) const
inline

Definition at line 56 of file HcalIndexLookup.h.

References alignCSCRings::r.

57  {return !(*this == r);}
bool HcalIndexLookup::operator== ( const HcalIndexLookup r) const
inline

Definition at line 53 of file HcalIndexLookup.h.

References data_, and sorted_.

54  {return data_ == r.data_ && sorted_ == r.sorted_;}
std::vector< std::pair< uint32_t, uint32_t > > data_
void HcalIndexLookup::reserve ( const unsigned  n)
inline

Definition at line 31 of file HcalIndexLookup.h.

References data_, and hasDuplicateIds().

31 {data_.reserve(n);}
std::vector< std::pair< uint32_t, uint32_t > > data_
template<class Archive >
void HcalIndexLookup::save ( Archive &  ar,
const unsigned   
) const
inlineprivate

Definition at line 66 of file HcalIndexLookup.h.

References Exception, hasDuplicateIds(), and sorted_.

Referenced by Vispa.Main.TabController.TabController::allowClose(), Vispa.Main.TabController.TabController::checkModificationTimestamp(), and SpecificationBuilder_cfi.Specification::saveAll().

67  {
68  // Make sure that there are no duplicate ids
69  if ((const_cast<HcalIndexLookup*>(this))->hasDuplicateIds())
70  throw cms::Exception("In HcalIndexLookup::save: invalid data");
71  ar & data_ & sorted_;
72  }
std::vector< std::pair< uint32_t, uint32_t > > data_
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_
void HcalIndexLookup::sort ( )

Definition at line 11 of file HcalIndexLookup.cc.

References data_, and sorted_.

Referenced by hasDuplicateIds(), and HcalIndexLookup().

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

Friends And Related Function Documentation

friend class boost::serialization::access
friend

Definition at line 63 of file HcalIndexLookup.h.

Member Data Documentation

std::vector<std::pair<uint32_t,uint32_t> > HcalIndexLookup::data_
private
const unsigned HcalIndexLookup::InvalidIndex = UINT_MAX
static
bool HcalIndexLookup::sorted_
private

Definition at line 61 of file HcalIndexLookup.h.

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