File indexing completed on 2024-09-07 04:35:38
0001 #ifndef CondFormats_HcalObjects_HcalIndexLookup_h
0002 #define CondFormats_HcalObjects_HcalIndexLookup_h
0003
0004 #include "FWCore/Utilities/interface/Exception.h"
0005
0006 #include "boost/serialization/access.hpp"
0007 #include "boost/serialization/version.hpp"
0008 #include "boost/serialization/vector.hpp"
0009 #include "boost/serialization/utility.hpp"
0010
0011 #include <cstdint>
0012 #include <climits>
0013 #include <vector>
0014
0015
0016
0017
0018
0019 class HcalIndexLookup {
0020 public:
0021 static const unsigned InvalidIndex = UINT_MAX;
0022
0023 inline HcalIndexLookup() : sorted_(true) {}
0024
0025
0026
0027 void add(unsigned transformedId, unsigned index);
0028
0029 void sort();
0030 void clear();
0031 inline void reserve(const unsigned n) { data_.reserve(n); }
0032
0033
0034
0035
0036 bool hasDuplicateIds();
0037
0038
0039 inline std::size_t size() const { return data_.size(); }
0040 inline bool empty() const { return data_.empty(); }
0041
0042
0043 unsigned largestIndex() const;
0044
0045
0046
0047
0048
0049 unsigned find(unsigned detId) const;
0050
0051
0052
0053 inline bool operator==(const HcalIndexLookup& r) const { return data_ == r.data_ && sorted_ == r.sorted_; }
0054
0055 inline bool operator!=(const HcalIndexLookup& r) const { return !(*this == r); }
0056
0057 private:
0058 std::vector<std::pair<uint32_t, uint32_t> > data_;
0059 bool sorted_;
0060
0061 friend class boost::serialization::access;
0062
0063 template <class Archive>
0064 inline void save(Archive& ar, const unsigned ) const {
0065
0066 if ((const_cast<HcalIndexLookup*>(this))->hasDuplicateIds())
0067 throw cms::Exception("In HcalIndexLookup::save: invalid data");
0068 ar & data_ & sorted_;
0069 }
0070
0071 template <class Archive>
0072 inline void load(Archive& ar, const unsigned ) {
0073 ar & data_ & sorted_;
0074 if (hasDuplicateIds())
0075 throw cms::Exception("In HcalIndexLookup::load: invalid data");
0076 }
0077
0078 BOOST_SERIALIZATION_SPLIT_MEMBER()
0079 };
0080
0081 BOOST_CLASS_VERSION(HcalIndexLookup, 1)
0082
0083 #endif