CMS 3D CMS Logo

HcalItemArrayColl.h
Go to the documentation of this file.
1 #ifndef CondFormats_HcalObjects_HcalItemArrayColl_h
2 #define CondFormats_HcalObjects_HcalItemArrayColl_h
3 
4 #include "boost/array.hpp"
5 #include "boost/serialization/access.hpp"
6 #include "boost/serialization/version.hpp"
7 #include "boost/serialization/shared_ptr.hpp"
8 #include "boost/serialization/vector.hpp"
9 #include "boost/version.hpp"
10 #if BOOST_VERSION < 106400
11 #include "boost/serialization/array.hpp"
12 #else
13 #include "boost/serialization/boost_array.hpp"
14 #endif
15 
16 #include <memory>
17 #include <array>
18 #include <vector>
19 
20 //
21 // This collection manages arrays of pointers and references.
22 // In particular, it can be used for storing objects in
23 // an inheritance hierarchy by their base pointers.
24 // The pointee objects are owned by this collection.
25 //
26 template <typename Item, unsigned N>
28 public:
29  typedef Item value_type;
30  typedef std::array<std::unique_ptr<Item>, N> InputArray;
31  static constexpr unsigned arraySize() { return N; }
32 
33  // The following method adds a new array of pointers to the collection.
34  // This class will take ownership of the pointee objects.
35  void push_back(InputArray& arr) {
36  StoredArray st;
37  for (unsigned i = 0; i < N; ++i)
38  st[i] = std::shared_ptr<Item>(arr[i].release());
39  data_.push_back(st);
40  }
41 
42  // Other modifiers
43  inline void clear() { data_.clear(); }
44  inline void reserve(const unsigned n) { data_.reserve(n); }
45 
46  // Some inspectors
47  inline std::size_t size() const { return data_.size(); }
48  inline bool empty() const { return data_.empty(); }
49 
50  // The following function returns nullptr if
51  // one of the argument indices is out of range
52  inline const Item* get(const unsigned itemIndex, const unsigned arrayIndex) const {
53  if (itemIndex < data_.size() && arrayIndex < N)
54  return data_[itemIndex][arrayIndex].get();
55  else
56  return nullptr;
57  }
58 
59  // The following function throws an exception if
60  // one of the argument indices is out of range
61  inline Item& at(const unsigned itemIndex, const unsigned arrayIndex) const {
62  return *data_.at(itemIndex).at(arrayIndex);
63  }
64 
65  // Deep comparison for equality is useful for testing serialization
66  bool operator==(const HcalItemArrayColl& r) const {
67  const std::size_t sz = data_.size();
68  if (sz != r.data_.size())
69  return false;
70  for (std::size_t i = 0; i < sz; ++i)
71  for (unsigned j = 0; j < N; ++j)
72  if (!(*data_[i][j] == *r.data_[i][j]))
73  return false;
74  return true;
75  }
76 
77  inline bool operator!=(const HcalItemArrayColl& r) const { return !(*this == r); }
78 
79 private:
80  typedef boost::array<std::shared_ptr<Item>, N> StoredArray;
81  std::vector<StoredArray> data_;
82 
84 
85  template <class Archive>
86  inline void serialize(Archive& ar, unsigned /* version */) {
87  ar& data_;
88  }
89 };
90 
91 // boost serialization version number for this template
92 namespace boost {
93  namespace serialization {
94  template <typename Item, unsigned N>
95  struct version<HcalItemArrayColl<Item, N> > {
96  BOOST_STATIC_CONSTANT(int, value = 1);
97  };
98  } // namespace serialization
99 } // namespace boost
100 
101 #endif // CondFormats_HcalObjects_HcalItemArrayColl_h
HcalItemArrayColl::reserve
void reserve(const unsigned n)
Definition: HcalItemArrayColl.h:44
mps_fire.i
i
Definition: mps_fire.py:428
dqmiodumpmetadata.n
n
Definition: dqmiodumpmetadata.py:28
HcalItemArrayColl::access
friend class boost::serialization::access
Definition: HcalItemArrayColl.h:83
HcalItemArrayColl::empty
bool empty() const
Definition: HcalItemArrayColl.h:48
HcalItemArrayColl::get
const Item * get(const unsigned itemIndex, const unsigned arrayIndex) const
Definition: HcalItemArrayColl.h:52
boost
Definition: CLHEP.h:16
HcalItemArrayColl::StoredArray
boost::array< std::shared_ptr< Item >, N > StoredArray
Definition: HcalItemArrayColl.h:80
HcalItemArrayColl::operator==
bool operator==(const HcalItemArrayColl &r) const
Definition: HcalItemArrayColl.h:66
N
#define N
Definition: blowfish.cc:9
HcalItemArrayColl::operator!=
bool operator!=(const HcalItemArrayColl &r) const
Definition: HcalItemArrayColl.h:77
HcalItemArrayColl::arraySize
static constexpr unsigned arraySize()
Definition: HcalItemArrayColl.h:31
fetchall_from_DQM_v2.release
release
Definition: fetchall_from_DQM_v2.py:92
value
Definition: value.py:1
HcalItemArrayColl::push_back
void push_back(InputArray &arr)
Definition: HcalItemArrayColl.h:35
HcalItemArrayColl
Definition: HcalItemArrayColl.h:27
HcalItemArrayColl::data_
std::vector< StoredArray > data_
Definition: HcalItemArrayColl.h:81
alignCSCRings.r
r
Definition: alignCSCRings.py:93
HcalItemArrayColl::at
Item & at(const unsigned itemIndex, const unsigned arrayIndex) const
Definition: HcalItemArrayColl.h:61
HcalItemArrayColl::serialize
void serialize(Archive &ar, unsigned)
Definition: HcalItemArrayColl.h:86
HcalItemArrayColl::InputArray
std::array< std::unique_ptr< Item >, N > InputArray
Definition: HcalItemArrayColl.h:30
HcalItemArrayColl::size
std::size_t size() const
Definition: HcalItemArrayColl.h:47
dqmiolumiharvest.j
j
Definition: dqmiolumiharvest.py:66
HcalItemArrayColl::clear
void clear()
Definition: HcalItemArrayColl.h:43
BeamSplash_cfg.version
version
Definition: BeamSplash_cfg.py:45
HcalItemArrayColl::value_type
Item value_type
Definition: HcalItemArrayColl.h:29