CMS 3D CMS Logo

HcalIndexLookup.h
Go to the documentation of this file.
1 #ifndef CondFormats_HcalObjects_HcalIndexLookup_h
2 #define CondFormats_HcalObjects_HcalIndexLookup_h
3 
5 
6 #include "boost/serialization/access.hpp"
7 #include "boost/serialization/version.hpp"
8 #include "boost/serialization/vector.hpp"
9 #include "boost/serialization/utility.hpp"
10 
11 #include <cstdint>
12 #include <climits>
13 #include <vector>
14 
15 //
16 // Storable lookup of unsigned index values by unsigned key
17 // (raw detId, ieta, etc)
18 //
20 public:
21  static const unsigned InvalidIndex = UINT_MAX;
22 
23  inline HcalIndexLookup() : sorted_(true) {}
24 
25  // Add an index for lookup. All "transformedId" numbers should be
26  // unique and "index" argument must not be equal InvalidIndex.
27  void add(unsigned transformedId, unsigned index);
28 
29  void sort();
30  void clear();
31  inline void reserve(const unsigned n) { data_.reserve(n); }
32 
33  // After filling up the table, it is recommended to verify that
34  // there are no duplicate ids. The collection will also become
35  // sorted as a side effect of the following function call.
36  bool hasDuplicateIds();
37 
38  // Some trivial inspectors
39  inline std::size_t size() const { return data_.size(); }
40  inline bool empty() const { return data_.empty(); }
41 
42  // Largest index number. Returns InvalidIndex for empty collection.
43  unsigned largestIndex() const;
44 
45  // "find" returns InvalidIndex in case argument detId
46  // is not in the collection. Note that the object should be
47  // sorted (or even better, checked for duplicate ids) before
48  // performing index lookups.
49  unsigned find(unsigned detId) const;
50 
51  // Comparison is only really useful for testing sorted lookups
52  // (serialized lookups will be sorted)
53  inline bool operator==(const HcalIndexLookup& r) const { return data_ == r.data_ && sorted_ == r.sorted_; }
54 
55  inline bool operator!=(const HcalIndexLookup& r) const { return !(*this == r); }
56 
57 private:
58  std::vector<std::pair<uint32_t, uint32_t> > data_;
59  bool sorted_;
60 
62 
63  template <class Archive>
64  inline void save(Archive& ar, const unsigned /* version */) const {
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  }
70 
71  template <class Archive>
72  inline void load(Archive& ar, const unsigned /* version */) {
73  ar& data_& sorted_;
74  if (hasDuplicateIds())
75  throw cms::Exception("In HcalIndexLookup::load: invalid data");
76  }
77 
78  BOOST_SERIALIZATION_SPLIT_MEMBER()
79 };
80 
81 BOOST_CLASS_VERSION(HcalIndexLookup, 1)
82 
83 #endif // CondFormats_HcalObjects_HcalIndexLookup_h
dqmiodumpmetadata.n
n
Definition: dqmiodumpmetadata.py:28
HcalIndexLookup::operator==
bool operator==(const HcalIndexLookup &r) const
Definition: HcalIndexLookup.h:53
HcalIndexLookup::clear
void clear()
Definition: HcalIndexLookup.cc:5
HcalIndexLookup::sorted_
bool sorted_
Definition: HcalIndexLookup.h:59
HcalIndexLookup::operator!=
bool operator!=(const HcalIndexLookup &r) const
Definition: HcalIndexLookup.h:55
HcalIndexLookup::HcalIndexLookup
HcalIndexLookup()
Definition: HcalIndexLookup.h:23
funct::true
true
Definition: Factorize.h:173
HcalIndexLookup::reserve
void reserve(const unsigned n)
Definition: HcalIndexLookup.h:31
HcalIndexLookup::largestIndex
unsigned largestIndex() const
Definition: HcalIndexLookup.cc:54
HcalIndexLookup::InvalidIndex
static const unsigned InvalidIndex
Definition: HcalIndexLookup.h:21
HcalIndexLookup::access
friend class boost::serialization::access
Definition: HcalIndexLookup.h:61
HcalIndexLookup::sort
void sort()
Definition: HcalIndexLookup.cc:10
HcalIndexLookup::add
void add(unsigned transformedId, unsigned index)
Definition: HcalIndexLookup.cc:29
alignCSCRings.r
r
Definition: alignCSCRings.py:93
HcalIndexLookup::hasDuplicateIds
bool hasDuplicateIds()
Definition: HcalIndexLookup.cc:17
HcalIndexLookup::load
void load(Archive &ar, const unsigned)
Definition: HcalIndexLookup.h:72
Exception
Definition: hltDiff.cc:246
HcalIndexLookup::find
unsigned find(unsigned detId) const
Definition: HcalIndexLookup.cc:36
Exception.h
HcalIndexLookup::data_
std::vector< std::pair< uint32_t, uint32_t > > data_
Definition: HcalIndexLookup.h:58
AlignmentPI::index
index
Definition: AlignmentPayloadInspectorHelper.h:46
HcalIndexLookup::size
std::size_t size() const
Definition: HcalIndexLookup.h:39
HcalIndexLookup::empty
bool empty() const
Definition: HcalIndexLookup.h:40
HcalIndexLookup
Definition: HcalIndexLookup.h:19
HcalIndexLookup::save
void save(Archive &ar, const unsigned) const
Definition: HcalIndexLookup.h:64