Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 #ifndef CondFormats_RPCObjects_RPCFebConnector_icc
0002 #define CondFormats_RPCObjects_RPCFebConnector_icc
0003 
0004 #include "CondFormats/RPCObjects/interface/RPCFebConnector.h"
0005 
0006 #include "FWCore/Utilities/interface/Exception.h"
0007 
0008 inline unsigned int RPCFebConnector::bit_count(std::uint16_t value) {
0009   // sum per nibble
0010   value -= (((value >> 1) & 0x7777) + ((value >> 2) & 0x3333) + ((value >> 3) & 0x1111));
0011   value = (value + (value >> 4)) & 0x0f0f;
0012   return ((value + (value >> 8)) & 0x1f);
0013 }
0014 
0015 inline void RPCFebConnector::reset() {
0016   first_strip_ = 1;
0017   slope_ = 1;
0018   channels_ = 0x0;
0019   rpc_det_id_ = RPCDetId(0, 0, 1, 1, 1, 1, 0).rawId();
0020 }
0021 
0022 inline RPCDetId RPCFebConnector::getRPCDetId() const { return RPCDetId(rpc_det_id_); }
0023 
0024 inline unsigned int RPCFebConnector::getFirstStrip() const { return first_strip_; }
0025 
0026 inline int RPCFebConnector::getSlope() const { return slope_; }
0027 
0028 inline std::uint16_t RPCFebConnector::getChannels() const { return channels_; }
0029 
0030 inline RPCFebConnector& RPCFebConnector::setRPCDetId(RPCDetId const& rpc_det_id) {
0031   rpc_det_id_ = rpc_det_id.rawId();
0032   return *this;
0033 }
0034 
0035 inline RPCFebConnector& RPCFebConnector::setFirstStrip(unsigned int first_strip) {
0036   if (first_strip >= min_first_strip_ && first_strip <= max_first_strip_)
0037     first_strip_ = first_strip;
0038   else
0039     throw cms::Exception("OutOfRange") << "Out-of-range input for RPCFebConnector first strip: " << first_strip;
0040   return *this;
0041 }
0042 
0043 inline RPCFebConnector& RPCFebConnector::setSlope(int slope) {
0044   slope_ = (slope < 0 ? -1 : 1);
0045   return *this;
0046 }
0047 
0048 inline RPCFebConnector& RPCFebConnector::setChannels(std::uint16_t channels) {
0049   channels_ = channels;
0050   return *this;
0051 }
0052 
0053 inline bool RPCFebConnector::isActive(unsigned int channel) const {
0054   if (channel > 0 && channel <= nchannels_)
0055     return (channels_ & (0x1 << (channel - 1)));
0056   return false;
0057 }
0058 
0059 inline unsigned int RPCFebConnector::getNChannels() const { return bit_count(channels_); }
0060 
0061 inline unsigned int RPCFebConnector::getStrip(unsigned int channel) const {
0062   if (!isActive(channel))
0063     return 0;
0064   int active_channels = bit_count(std::uint16_t(channels_ & ((0x1 << (channel - 1)) - 1)));
0065   return (int)first_strip_ + slope_ * active_channels;
0066 }
0067 
0068 inline bool RPCFebConnector::hasStrip(unsigned int strip) const {
0069   int offset = slope_ * (strip - first_strip_);
0070   return (offset >= 0 && offset < (int)getNChannels());
0071 }
0072 
0073 inline unsigned int RPCFebConnector::getChannel(unsigned int strip) const {
0074   int offset = slope_ * (strip - first_strip_);
0075   if (offset < 0 || offset >= (int)getNChannels())
0076     return 0;
0077   std::uint16_t channels(channels_);
0078   for (unsigned int channel = 1; channels; channels >>= 1, ++channel)
0079     if (channels & 0x1) {
0080       if (!offset)
0081         return channel;
0082       --offset;
0083     }
0084   return 0;
0085 }
0086 
0087 #endif  // CondFormats_RPCObjects_RPCFebConnector_icc