CMS 3D CMS Logo

HcalItemArrayCollById.h
Go to the documentation of this file.
1 #ifndef CondFormats_HcalObjects_HcalItemArrayCollById_h
2 #define CondFormats_HcalObjects_HcalItemArrayCollById_h
3 
4 #include <cstdint>
5 
7 
13 
14 //
15 // This collection allows lookup of arrays 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 HcalItemArrayColl, 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 array
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, unsigned N>
28 public:
29  typedef Item value_type;
31  static constexpr unsigned arraySize() { return N; }
32 
33  // Dummy constructor. To be used for deserialization only.
35 
36  // Normal constructor
38  const HcalIndexLookup& indexLookupTable,
39  const unsigned detIdTransformCode,
40  InputArray& defaultFunctors)
41  : coll_(coll), lookup_(indexLookupTable), transformCode_(detIdTransformCode) {
42  // Check that the lookup table is valid for this application
44  throw cms::Exception(
45  "In HcalItemArrayCollById constructor:"
46  " invalid lookup table");
47 
48  // Check that the lookup table is consistent with the size
49  // of the collection
50  const unsigned maxIndex = lookup_.largestIndex();
52  throw cms::Exception(
53  "In HcalItemArrayCollById constructor:"
54  " collection and lookup table are inconsistent");
55 
57 
58  // Take care of the default array
59  setDefault(defaultFunctors);
60  }
61 
62  inline virtual ~HcalItemArrayCollById() {}
63 
64  // Modifier for the default array of items
65  inline void setDefault(InputArray& arr) {
66  for (unsigned i = 0; i < N; ++i)
67  default_[i] = std::shared_ptr<Item>(arr[i].release());
68  }
69 
70  // Size of the internal collection, not counting the default
71  inline std::size_t size() const { return coll_.size(); }
72 
73  // Look up the index into the collection by detector id
74  inline unsigned getIndex(const HcalDetId& id) const {
76  }
77 
78  // Item lookup by its index and array index. If item lookup
79  // by index fails and the array index is not out of bounds,
80  // default item is returned.
81  inline const Item* getByIndex(const unsigned itemIndex, const unsigned arrayIndex) const {
82  const Item* f = coll_.get(itemIndex, arrayIndex);
83  if (f == nullptr && arrayIndex < N)
84  f = default_[arrayIndex].get();
85  return f;
86  }
87 
88  // The following method will return nullptr if
89  // there is no corresponding default
90  inline const Item* getDefault(const unsigned arrayIndex) const {
91  if (arrayIndex < N)
92  return default_[arrayIndex].get();
93  else
94  return nullptr;
95  }
96 
97  // Convenience function for getting what we need by id.
98  // Note that, if you are simply cycling over array indices,
99  // it will be more efficient to retrieve the item index
100  // first and then use "getByIndex" method.
101  inline const Item* get(const HcalDetId& id, const unsigned arrayIndex) const {
102  return getByIndex(getIndex(id), arrayIndex);
103  }
104 
105  // Similar comment applies here if you are just cycling over array indices
106  inline const Item& at(const HcalDetId& id, const unsigned arrayIndex) const {
107  const Item* f = getByIndex(getIndex(id), arrayIndex);
108  if (f == nullptr)
109  throw cms::Exception("In HcalItemArrayCollById::at: invalid detector id");
110  return *f;
111  }
112 
113 protected:
114  virtual bool isEqual(const AbsHcalAlgoData& other) const override {
115  const HcalItemArrayCollById& r = static_cast<const HcalItemArrayCollById&>(other);
116  if (coll_ != r.coll_)
117  return false;
118  if (lookup_ != r.lookup_)
119  return false;
120  if (transformCode_ != r.transformCode_)
121  return false;
122  for (unsigned j = 0; j < N; ++j) {
123  // The default may or may not be there
124  const bool ld = default_[j].get();
125  const bool rd = r.default_[j].get();
126  if (ld != rd)
127  return false;
128  if (ld)
129  if (!(*default_[j] == *r.default_[j]))
130  return false;
131  }
132  return true;
133  }
134 
135 private:
136  typedef boost::array<std::shared_ptr<Item>, N> StoredArray;
137 
141  uint32_t transformCode_;
142 
144 
145  template <class Archive>
146  inline void serialize(Archive& ar, unsigned /* version */) {
148  }
149 };
150 
151 // boost serialization version number for this template
152 namespace boost {
153  namespace serialization {
154  template <typename Item, unsigned N>
155  struct version<HcalItemArrayCollById<Item, N> > {
156  BOOST_STATIC_CONSTANT(int, value = 1);
157  };
158  } // namespace serialization
159 } // namespace boost
160 
161 #endif // CondFormats_HcalObjects_HcalItemArrayCollById_h
HcalDetIdTransform.h
mps_fire.i
i
Definition: mps_fire.py:428
AbsHcalAlgoData
Definition: AbsHcalAlgoData.h:10
f
double f[11][100]
Definition: MuScleFitUtils.cc:78
HcalIndexLookup.h
HcalItemArrayCollById::HcalItemArrayCollById
HcalItemArrayCollById(const HcalItemArrayColl< Item, N > &coll, const HcalIndexLookup &indexLookupTable, const unsigned detIdTransformCode, InputArray &defaultFunctors)
Definition: HcalItemArrayCollById.h:37
HcalItemArrayCollById::setDefault
void setDefault(InputArray &arr)
Definition: HcalItemArrayCollById.h:65
ApeEstimator_cff.maxIndex
maxIndex
Definition: ApeEstimator_cff.py:25
boost
Definition: CLHEP.h:16
HcalDetIdTransform::N_TRANSFORMS
Definition: HcalDetIdTransform.h:17
HcalItemArrayCollById::at
const Item & at(const HcalDetId &id, const unsigned arrayIndex) const
Definition: HcalItemArrayCollById.h:106
HcalItemArrayCollById::isEqual
virtual bool isEqual(const AbsHcalAlgoData &other) const override
Definition: HcalItemArrayCollById.h:114
HcalItemArrayCollById::getByIndex
const Item * getByIndex(const unsigned itemIndex, const unsigned arrayIndex) const
Definition: HcalItemArrayCollById.h:81
HcalItemArrayCollById::getDefault
const Item * getDefault(const unsigned arrayIndex) const
Definition: HcalItemArrayCollById.h:90
HcalItemArrayCollById::transformCode_
uint32_t transformCode_
Definition: HcalItemArrayCollById.h:141
N
#define N
Definition: blowfish.cc:9
HcalItemArrayCollById::StoredArray
boost::array< std::shared_ptr< Item >, N > StoredArray
Definition: HcalItemArrayCollById.h:136
trackingPlots.other
other
Definition: trackingPlots.py:1460
HcalDetIdTransform::transform
unsigned transform(const HcalDetId &id, unsigned transformCode)
Definition: HcalDetIdTransform.cc:7
HcalItemArrayColl.h
HcalItemArrayCollById::~HcalItemArrayCollById
virtual ~HcalItemArrayCollById()
Definition: HcalItemArrayCollById.h:62
HcalItemArrayCollById::HcalItemArrayCollById
HcalItemArrayCollById()
Definition: HcalItemArrayCollById.h:34
fetchall_from_DQM_v2.release
release
Definition: fetchall_from_DQM_v2.py:92
HcalItemArrayCollById::lookup_
HcalIndexLookup lookup_
Definition: HcalItemArrayCollById.h:139
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
HcalItemArrayColl
Definition: HcalItemArrayColl.h:27
HcalItemArrayCollById::getIndex
unsigned getIndex(const HcalDetId &id) const
Definition: HcalItemArrayCollById.h:74
alignCSCRings.r
r
Definition: alignCSCRings.py:93
HcalItemArrayCollById::size
std::size_t size() const
Definition: HcalItemArrayCollById.h:71
HcalIndexLookup::hasDuplicateIds
bool hasDuplicateIds()
Definition: HcalIndexLookup.cc:17
Exception
Definition: hltDiff.cc:245
HcalItemArrayCollById::arraySize
static constexpr unsigned arraySize()
Definition: HcalItemArrayCollById.h:31
HcalIndexLookup::find
unsigned find(unsigned detId) const
Definition: HcalIndexLookup.cc:36
HcalItemArrayCollById::InputArray
HcalItemArrayColl< Item, N >::InputArray InputArray
Definition: HcalItemArrayCollById.h:30
Exception.h
HcalItemArrayCollById::coll_
HcalItemArrayColl< Item, N > coll_
Definition: HcalItemArrayCollById.h:138
HcalItemArrayCollById::access
friend class boost::serialization::access
Definition: HcalItemArrayCollById.h:143
HcalItemArrayColl::InputArray
std::array< std::unique_ptr< Item >, N > InputArray
Definition: HcalItemArrayColl.h:30
cms::Exception
Definition: Exception.h:70
dqmiolumiharvest.j
j
Definition: dqmiolumiharvest.py:66
HcalIndexLookup
Definition: HcalIndexLookup.h:19
HcalItemArrayCollById::serialize
void serialize(Archive &ar, unsigned)
Definition: HcalItemArrayCollById.h:146
BeamSplash_cfg.version
version
Definition: BeamSplash_cfg.py:45
HcalItemArrayCollById::value_type
Item value_type
Definition: HcalItemArrayCollById.h:29
HcalItemArrayCollById::default_
StoredArray default_
Definition: HcalItemArrayCollById.h:140
HcalDetIdTransform::validateCode
void validateCode(unsigned transformCode)
Definition: HcalDetIdTransform.cc:50
HcalItemArrayCollById::get
const Item * get(const HcalDetId &id, const unsigned arrayIndex) const
Definition: HcalItemArrayCollById.h:101
HcalItemArrayCollById
Definition: HcalItemArrayCollById.h:27
AbsHcalAlgoData.h