Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:02:12

0001 #ifndef CondFormats_HcalObjects_HBHEChannelGroups_h_
0002 #define CondFormats_HcalObjects_HBHEChannelGroups_h_
0003 
0004 #include "FWCore/Utilities/interface/Exception.h"
0005 
0006 #include "boost/serialization/access.hpp"
0007 #include "boost/serialization/vector.hpp"
0008 
0009 #include "CondFormats/HcalObjects/interface/HBHELinearMap.h"
0010 #include <cstdint>
0011 
0012 class HBHEChannelGroups {
0013 public:
0014   inline HBHEChannelGroups() : group_(HBHELinearMap::ChannelCount, 0U) {}
0015 
0016   //
0017   // Main constructor. It is expected that "len" equals
0018   // HBHELinearMap::ChannelCount and that every element of "data"
0019   // indicates to which group that particular channel should belong.
0020   //
0021   inline HBHEChannelGroups(const unsigned* data, const unsigned len) : group_(data, data + len) {
0022     if (!validate())
0023       throw cms::Exception("In HBHEChannelGroups constructor: invalid input data");
0024   }
0025 
0026   //
0027   // Set the group number for the given HBHE linear channel number.
0028   // Linear channel numbers are calculated by HBHELinearMap.
0029   //
0030   inline void setGroup(const unsigned linearChannel, const unsigned groupNum) { group_.at(linearChannel) = groupNum; }
0031 
0032   // Inspectors
0033   inline unsigned size() const { return group_.size(); }
0034 
0035   inline const uint32_t* groupData() const { return group_.empty() ? nullptr : &group_[0]; }
0036 
0037   inline unsigned getGroup(const unsigned linearChannel) const { return group_.at(linearChannel); }
0038 
0039   inline unsigned largestGroupNumber() const {
0040     unsigned lg = 0;
0041     const unsigned sz = group_.size();
0042     const uint32_t* dat = sz ? &group_[0] : nullptr;
0043     for (unsigned i = 0; i < sz; ++i)
0044       if (dat[i] > lg)
0045         lg = dat[i];
0046     return lg;
0047   }
0048 
0049   // Comparators
0050   inline bool operator==(const HBHEChannelGroups& r) const { return group_ == r.group_; }
0051 
0052   inline bool operator!=(const HBHEChannelGroups& r) const { return !(*this == r); }
0053 
0054 private:
0055   std::vector<uint32_t> group_;
0056 
0057   inline bool validate() const { return group_.size() == HBHELinearMap::ChannelCount; }
0058 
0059   friend class boost::serialization::access;
0060 
0061   template <class Archive>
0062   inline void save(Archive& ar, const unsigned /* version */) const {
0063     if (!validate())
0064       throw cms::Exception("In HBHEChannelGroups::save: invalid data");
0065     ar& group_;
0066   }
0067 
0068   template <class Archive>
0069   inline void load(Archive& ar, const unsigned /* version */) {
0070     ar& group_;
0071     if (!validate())
0072       throw cms::Exception("In HBHEChannelGroups::load: invalid data");
0073   }
0074 
0075   BOOST_SERIALIZATION_SPLIT_MEMBER()
0076 };
0077 
0078 BOOST_CLASS_VERSION(HBHEChannelGroups, 1)
0079 
0080 #endif  // CondFormats_HcalObjects_HBHEChannelGroups_h_