Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:23:38

0001 #include "PhysicsTools/MVAComputer/interface/BitSet.h"
0002 #include "PhysicsTools/MVAComputer/interface/Calibration.h"
0003 
0004 namespace PhysicsTools {
0005 
0006   BitSet::size_t BitSet::bits() const {
0007     static constexpr unsigned char byteBits[256] = {
0008         0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4, 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, 1, 2, 2, 3, 2,
0009         3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, 1, 2, 2, 3, 2, 3, 3, 4, 2, 3,
0010         3, 4, 3, 4, 4, 5, 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5,
0011         6, 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7, 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, 2, 3, 3, 4,
0012         3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, 3, 4, 4, 5, 4, 5, 5, 6, 4,
0013         5, 5, 6, 5, 6, 6, 7, 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6,
0014         6, 7, 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7, 4, 5, 5, 6, 5, 6, 6, 7, 5, 6, 6, 7, 6, 7, 7, 8};
0015     const unsigned char *begin = reinterpret_cast<const unsigned char *>(store);
0016     const unsigned char *end = reinterpret_cast<const unsigned char *>(store + bitsToWords(bits_));
0017 
0018     size_t bits = 0;
0019     for (const unsigned char *p = begin; p < end; p++)
0020       bits += byteBits[*p];
0021 
0022     return bits;
0023   }
0024 
0025   BitSet Calibration::convert(const Calibration::BitSet &bitSet) {
0026     PhysicsTools::BitSet::size_t size = bitSet.store.size();
0027     size = (size - 1) * 8 + (bitSet.bitsInLast + 7) % 8 + 1;
0028 
0029     PhysicsTools::BitSet result(size);
0030     for (PhysicsTools::BitSet::size_t i = 0; i < size; i++)
0031       result[i] = bitSet.store[i / 8] & (1 << (i % 8));
0032 
0033     return result;
0034   }
0035 
0036   Calibration::BitSet Calibration::convert(const PhysicsTools::BitSet &bitSet) {
0037     PhysicsTools::BitSet::size_t size = bitSet.size();
0038     PhysicsTools::BitSet::size_t bytes = (size + 7) / 8;
0039 
0040     Calibration::BitSet result;
0041     result.store.resize(bytes);
0042     result.bitsInLast = (size + 7) % 8 + 1;
0043 
0044     for (PhysicsTools::BitSet::size_t i = 0; i < size; i++)
0045       result.store[i / 8] |= bitSet[i] ? (1 << (i % 8)) : 0;
0046 
0047     return result;
0048   }
0049 
0050 }  // namespace PhysicsTools