test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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/cstdint.hpp"
7 #include "boost/serialization/access.hpp"
8 #include "boost/serialization/vector.hpp"
9 
11 
13 {
14 public:
15  inline HBHEChannelGroups() : group_(HBHELinearMap::ChannelCount, 0U) {}
16 
17  //
18  // Main constructor. It is expected that "len" equals
19  // HBHELinearMap::ChannelCount and that every element of "data"
20  // indicates to which group that particular channel should belong.
21  //
22  inline HBHEChannelGroups(const unsigned* data, const unsigned len)
23  : group_(data, data+len)
24  {
25  if (!validate()) throw cms::Exception(
26  "In HBHEChannelGroups constructor: invalid input data");
27  }
28 
29  //
30  // Set the group number for the given HBHE linear channel number.
31  // Linear channel numbers are calculated by HBHELinearMap.
32  //
33  inline void setGroup(const unsigned linearChannel, const unsigned groupNum)
34  {group_.at(linearChannel) = groupNum;}
35 
36  // Inspectors
37  inline unsigned size() const {return group_.size();}
38 
39  inline const uint32_t* groupData() const
40  {return group_.empty() ? 0 : &group_[0];}
41 
42  inline unsigned getGroup(const unsigned linearChannel) const
43  {return group_.at(linearChannel);}
44 
45  inline unsigned largestGroupNumber() const
46  {
47  unsigned lg = 0;
48  const unsigned sz = group_.size();
49  const uint32_t* dat = sz ? &group_[0] : 0;
50  for (unsigned i=0; i<sz; ++i)
51  if (dat[i] > lg)
52  lg = dat[i];
53  return lg;
54  }
55 
56  // Comparators
57  inline bool operator==(const HBHEChannelGroups& r) const
58  {return group_ == r.group_;}
59 
60  inline bool operator!=(const HBHEChannelGroups& r) const
61  {return !(*this == r);}
62 
63 private:
64  std::vector<uint32_t> group_;
65 
66  inline bool validate() const
67  {
68  return group_.size() == HBHELinearMap::ChannelCount;
69  }
70 
72 
73  template<class Archive>
74  inline void save(Archive & ar, const unsigned /* version */) const
75  {
76  if (!validate()) throw cms::Exception(
77  "In HBHEChannelGroups::save: invalid data");
78  ar & group_;
79  }
80 
81  template<class Archive>
82  inline void load(Archive & ar, const unsigned /* version */)
83  {
84  ar & group_;
85  if (!validate()) throw cms::Exception(
86  "In HBHEChannelGroups::load: invalid data");
87  }
88 
89  BOOST_SERIALIZATION_SPLIT_MEMBER()
90 };
91 
92 BOOST_CLASS_VERSION(HBHEChannelGroups, 1)
93 
94 #endif // CondFormats_HcalObjects_HBHEChannelGroups_h_
int i
Definition: DBlmapReader.cc:9
unsigned getGroup(const unsigned linearChannel) const
std::vector< uint32_t > group_
bool operator!=(const HBHEChannelGroups &r) const
void load(Archive &ar, const unsigned)
unsigned largestGroupNumber() const
void save(Archive &ar, const unsigned) const
bool operator==(const HBHEChannelGroups &r) const
const uint32_t * groupData() const
unsigned size() const
friend class boost::serialization::access
HBHEChannelGroups(const unsigned *data, const unsigned len)
bool validate() const
void setGroup(const unsigned linearChannel, const unsigned groupNum)