CMS 3D CMS Logo

HcalItemCollById.h
Go to the documentation of this file.
1 #ifndef CondFormats_HcalObjects_HcalItemCollById_h
2 #define CondFormats_HcalObjects_HcalItemCollById_h
3 
4 #include <cstdint>
5 
7 
13 
14 //
15 // This collection allows lookup of items by HcalDetId.
16 // If the given HcalDetId is not explicitly listed in the
17 // lookup table, default item is returned.
18 //
19 // Just like HcalItemColl, this collection works with pointers
20 // and references only, so it can be used with the inheritance
21 // scenarios. Note that the ownership of objects is shared with
22 // the collection provided in the constructor. The default item
23 // is owned by this collection. Its ownership will also become
24 // shared if a copy of this collection is made.
25 //
26 template <typename Item>
28 public:
29  typedef Item value_type;
30 
31  // Dummy default constructor. To be used only for deserialization.
33 
34  // Normal constructor
36  const HcalIndexLookup& indexLookupTable,
37  const unsigned detIdTransformCode,
38  std::unique_ptr<Item> defaultItem)
39  : coll_(coll), lookup_(indexLookupTable), default_(defaultItem.release()), transformCode_(detIdTransformCode) {
40  // Check that the lookup table is valid for this application
42  throw cms::Exception(
43  "In HcalItemCollById constructor:"
44  " invalid lookup table");
45 
46  // Check that the lookup table is consistent with the size
47  // of the collection
48  const unsigned maxIndex = lookup_.largestIndex();
50  throw cms::Exception(
51  "In HcalItemCollById constructor:"
52  " collection and lookup table are inconsistent");
53 
55  }
56 
57  inline ~HcalItemCollById() override {}
58 
59  // Modifier for the default item
60  inline void setDefault(std::unique_ptr<Item> f) { default_ = std::shared_ptr<Item>(f.release()); }
61 
62  // Size of the internal collection, not counting the default
63  inline std::size_t size() const { return coll_.size(); }
64 
65  // The following method will return nullptr if there is no default
66  inline const Item* getDefault() const { return default_.get(); }
67 
68  // Look up the index into the collection by detector id
69  inline unsigned getIndex(const HcalDetId& id) const {
71  }
72 
73  // Get an item by its index in the collection. If the index
74  // is out of range, the default item is returned. If the
75  // index is out of range and there is no default, nullptr
76  // is returned.
77  inline const Item* getByIndex(const unsigned index) const {
78  if (index < coll_.size())
79  return coll_.get(index);
80  else
81  return default_.get();
82  }
83 
84  // Convenience function for getting what we need by id.
85  // This method can return nullptr.
86  inline const Item* get(const HcalDetId& id) const { return getByIndex(getIndex(id)); }
87 
88  // The following method will throw an exception if the id is not
89  // in the lookup table and, in addition, there is no default
90  inline const Item& at(const HcalDetId& id) const {
91  const Item* ptr = getByIndex(getIndex(id));
92  if (ptr == nullptr)
93  throw cms::Exception("In HcalItemCollById::at: invalid detector id");
94  return *ptr;
95  }
96 
97 protected:
98  bool isEqual(const AbsHcalAlgoData& other) const override {
99  const HcalItemCollById& r = static_cast<const HcalItemCollById&>(other);
100  if (coll_ != r.coll_)
101  return false;
102  if (lookup_ != r.lookup_)
103  return false;
104  if (transformCode_ != r.transformCode_)
105  return false;
106  // The default may or may not be there
107  const bool ld = default_.get();
108  const bool rd = r.default_.get();
109  if (ld != rd)
110  return false;
111  if (ld)
112  if (!(*default_ == *r.default_))
113  return false;
114  return true;
115  }
116 
117 private:
120  std::shared_ptr<Item> default_;
121  uint32_t transformCode_;
122 
123  friend class boost::serialization::access;
124 
125  template <class Archive>
126  inline void serialize(Archive& ar, unsigned /* version */) {
128  }
129 };
130 
131 // boost serialization version number for this template
132 namespace boost {
133  namespace serialization {
134  template <typename Item>
135  struct version<HcalItemCollById<Item> > {
136  BOOST_STATIC_CONSTANT(int, value = 1);
137  };
138  } // namespace serialization
139 } // namespace boost
140 
141 #endif // CondFormats_HcalObjects_HcalItemCollById_h
HcalDetIdTransform.h
HcalItemCollById::HcalItemCollById
HcalItemCollById()
Definition: HcalItemCollById.h:32
HcalItemColl
Definition: HcalItemColl.h:21
AbsHcalAlgoData
Definition: AbsHcalAlgoData.h:10
HcalItemCollById::isEqual
bool isEqual(const AbsHcalAlgoData &other) const override
Definition: HcalItemCollById.h:98
HcalItemColl.h
f
double f[11][100]
Definition: MuScleFitUtils.cc:78
HcalItemCollById::lookup_
HcalIndexLookup lookup_
Definition: HcalItemCollById.h:119
HcalIndexLookup.h
HcalItemCollById::serialize
void serialize(Archive &ar, unsigned)
Definition: HcalItemCollById.h:126
HcalItemCollById::coll_
HcalItemColl< Item > coll_
Definition: HcalItemCollById.h:118
HcalItemCollById::getDefault
const Item * getDefault() const
Definition: HcalItemCollById.h:66
ApeEstimator_cff.maxIndex
maxIndex
Definition: ApeEstimator_cff.py:25
boost
Definition: CLHEP.h:16
HcalItemCollById::size
std::size_t size() const
Definition: HcalItemCollById.h:63
HcalDetIdTransform::N_TRANSFORMS
Definition: HcalDetIdTransform.h:17
HcalItemCollById::HcalItemCollById
HcalItemCollById(const HcalItemColl< Item > &coll, const HcalIndexLookup &indexLookupTable, const unsigned detIdTransformCode, std::unique_ptr< Item > defaultItem)
Definition: HcalItemCollById.h:35
HcalItemCollById
Definition: HcalItemCollById.h:27
HcalItemCollById::getIndex
unsigned getIndex(const HcalDetId &id) const
Definition: HcalItemCollById.h:69
HcalItemCollById::transformCode_
uint32_t transformCode_
Definition: HcalItemCollById.h:121
trackingPlots.other
other
Definition: trackingPlots.py:1460
HcalDetIdTransform::transform
unsigned transform(const HcalDetId &id, unsigned transformCode)
Definition: HcalDetIdTransform.cc:7
fetchall_from_DQM_v2.release
release
Definition: fetchall_from_DQM_v2.py:92
HcalIndexLookup::largestIndex
unsigned largestIndex() const
Definition: HcalIndexLookup.cc:54
HcalDetId.h
HcalDetId
Definition: HcalDetId.h:12
HcalIndexLookup::InvalidIndex
static const unsigned InvalidIndex
Definition: HcalIndexLookup.h:21
value
Definition: value.py:1
HcalDetIdTransform
Definition: HcalDetIdTransform.h:6
HcalItemCollById::value_type
Item value_type
Definition: HcalItemCollById.h:29
HcalItemCollById::setDefault
void setDefault(std::unique_ptr< Item > f)
Definition: HcalItemCollById.h:60
alignCSCRings.r
r
Definition: alignCSCRings.py:93
HcalItemCollById::getByIndex
const Item * getByIndex(const unsigned index) const
Definition: HcalItemCollById.h:77
HcalIndexLookup::hasDuplicateIds
bool hasDuplicateIds()
Definition: HcalIndexLookup.cc:17
HcalItemCollById::get
const Item * get(const HcalDetId &id) const
Definition: HcalItemCollById.h:86
HcalItemCollById::default_
std::shared_ptr< Item > default_
Definition: HcalItemCollById.h:120
Exception
Definition: hltDiff.cc:245
HcalItemCollById::at
const Item & at(const HcalDetId &id) const
Definition: HcalItemCollById.h:90
HcalIndexLookup::find
unsigned find(unsigned detId) const
Definition: HcalIndexLookup.cc:36
Exception.h
AlignmentPI::index
index
Definition: AlignmentPayloadInspectorHelper.h:46
cms::Exception
Definition: Exception.h:70
HcalIndexLookup
Definition: HcalIndexLookup.h:19
BeamSplash_cfg.version
version
Definition: BeamSplash_cfg.py:45
HcalItemCollById::~HcalItemCollById
~HcalItemCollById() override
Definition: HcalItemCollById.h:57
HcalDetIdTransform::validateCode
void validateCode(unsigned transformCode)
Definition: HcalDetIdTransform.cc:50
AbsHcalAlgoData.h