CMS 3D CMS Logo

HBHEChannelGroups.h
Go to the documentation of this file.
1 #ifndef CondFormats_HcalObjects_HBHEChannelGroups_h_
2 #define CondFormats_HcalObjects_HBHEChannelGroups_h_
3 
5 
6 #include "boost/serialization/access.hpp"
7 #include "boost/serialization/vector.hpp"
8 
10 #include <cstdint>
11 
13 public:
14  inline HBHEChannelGroups() : group_(HBHELinearMap::ChannelCount, 0U) {}
15 
16  //
17  // Main constructor. It is expected that "len" equals
18  // HBHELinearMap::ChannelCount and that every element of "data"
19  // indicates to which group that particular channel should belong.
20  //
21  inline HBHEChannelGroups(const unsigned* data, const unsigned len) : group_(data, data + len) {
22  if (!validate())
23  throw cms::Exception("In HBHEChannelGroups constructor: invalid input data");
24  }
25 
26  //
27  // Set the group number for the given HBHE linear channel number.
28  // Linear channel numbers are calculated by HBHELinearMap.
29  //
30  inline void setGroup(const unsigned linearChannel, const unsigned groupNum) { group_.at(linearChannel) = groupNum; }
31 
32  // Inspectors
33  inline unsigned size() const { return group_.size(); }
34 
35  inline const uint32_t* groupData() const { return group_.empty() ? nullptr : &group_[0]; }
36 
37  inline unsigned getGroup(const unsigned linearChannel) const { return group_.at(linearChannel); }
38 
39  inline unsigned largestGroupNumber() const {
40  unsigned lg = 0;
41  const unsigned sz = group_.size();
42  const uint32_t* dat = sz ? &group_[0] : nullptr;
43  for (unsigned i = 0; i < sz; ++i)
44  if (dat[i] > lg)
45  lg = dat[i];
46  return lg;
47  }
48 
49  // Comparators
50  inline bool operator==(const HBHEChannelGroups& r) const { return group_ == r.group_; }
51 
52  inline bool operator!=(const HBHEChannelGroups& r) const { return !(*this == r); }
53 
54 private:
55  std::vector<uint32_t> group_;
56 
57  inline bool validate() const { return group_.size() == HBHELinearMap::ChannelCount; }
58 
60 
61  template <class Archive>
62  inline void save(Archive& ar, const unsigned /* version */) const {
63  if (!validate())
64  throw cms::Exception("In HBHEChannelGroups::save: invalid data");
65  ar& group_;
66  }
67 
68  template <class Archive>
69  inline void load(Archive& ar, const unsigned /* version */) {
70  ar& group_;
71  if (!validate())
72  throw cms::Exception("In HBHEChannelGroups::load: invalid data");
73  }
74 
75  BOOST_SERIALIZATION_SPLIT_MEMBER()
76 };
77 
78 BOOST_CLASS_VERSION(HBHEChannelGroups, 1)
79 
80 #endif // CondFormats_HcalObjects_HBHEChannelGroups_h_
std::vector< uint32_t > group_
void load(Archive &ar, const unsigned)
bool operator!=(const HBHEChannelGroups &r) const
void save(Archive &ar, const unsigned) const
unsigned getGroup(const unsigned linearChannel) const
unsigned size() const
bool operator==(const HBHEChannelGroups &r) const
friend class boost::serialization::access
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:80
const uint32_t * groupData() const
HBHEChannelGroups(const unsigned *data, const unsigned len)
unsigned largestGroupNumber() const
bool validate() const
void setGroup(const unsigned linearChannel, const unsigned groupNum)