CMS 3D CMS Logo

/data/git/CMSSW_5_3_11_patch5/src/PhysicsTools/MVAComputer/src/BitSet.cc

Go to the documentation of this file.
00001 #include "PhysicsTools/MVAComputer/interface/BitSet.h"
00002 #include "PhysicsTools/MVAComputer/interface/Calibration.h"
00003 
00004 namespace PhysicsTools {
00005 
00006 BitSet::size_t BitSet::bits() const
00007 {
00008         static unsigned char byteBits[256] = {
00009                 0,  1,  1,  2,  1,  2,  2,  3,  1,  2,  2,  3,  2,  3,  3,    
00010                 4,  1,  2,  2,  3,  2,  3,  3,  4,  2,  3,  3,  4,  3,  4,
00011                 4,  5,  1,  2,  2,  3,  2,  3,  3,  4,  2,  3,  3,  4,  3,    
00012                 4,  4,  5,  2,  3,  3,  4,  3,  4,  4,  5,  3,  4,  4,  5,    
00013                 4,  5,  5,  6,  1,  2,  2,  3,  2,  3,  3,  4,  2,  3,  3,    
00014                 4,  3,  4,  4,  5,  2,  3,  3,  4,  3,  4,  4,  5,  3,  4,
00015                 4,  5,  4,  5,  5,  6,  2,  3,  3,  4,  3,  4,  4,  5,  3,
00016                 4,  4,  5,  4,  5,  5,  6,  3,  4,  4,  5,  4,  5,  5,  6,
00017                 4,  5,  5,  6,  5,  6,  6,  7,  1,  2,  2,  3,  2,  3,  3,    
00018                 4,  2,  3,  3,  4,  3,  4,  4,  5,  2,  3,  3,  4,  3,  4,    
00019                 4,  5,  3,  4,  4,  5,  4,  5,  5,  6,  2,  3,  3,  4,  3,    
00020                 4,  4,  5,  3,  4,  4,  5,  4,  5,  5,  6,  3,  4,  4,  5,    
00021                 4,  5,  5,  6,  4,  5,  5,  6,  5,  6,  6,  7,  2,  3,  3,
00022                 4,  3,  4,  4,  5,  3,  4,  4,  5,  4,  5,  5,  6,  3,  4,    
00023                 4,  5,  4,  5,  5,  6,  4,  5,  5,  6,  5,  6,  6,  7,  3,    
00024                 4,  4,  5,  4,  5,  5,  6,  4,  5,  5,  6,  5,  6,  6,  7,
00025                 4,  5,  5,  6,  5,  6,  6,  7,  5,  6,  6,  7,  6,  7,  7,    
00026                 8
00027         };
00028         unsigned char *begin = (unsigned char*)store;
00029         unsigned char *end   = (unsigned char*)(store + bitsToWords(bits_));
00030 
00031         size_t bits = 0;
00032         for(unsigned char *p = begin; p < end; p++)
00033                 bits += byteBits[*p];
00034 
00035         return bits;
00036 }
00037 
00038 BitSet Calibration::convert(const Calibration::BitSet &bitSet)
00039 {
00040         PhysicsTools::BitSet::size_t size = bitSet.store.size();
00041         size = (size - 1) * 8 + (bitSet.bitsInLast + 7) % 8 + 1;
00042 
00043         PhysicsTools::BitSet result(size);
00044         for(PhysicsTools::BitSet::size_t i = 0; i < size; i++)
00045                 result[i] = bitSet.store[i / 8] & (1 << (i % 8));
00046 
00047         return result;
00048 }
00049 
00050 Calibration::BitSet Calibration::convert(const PhysicsTools::BitSet &bitSet)
00051 {
00052         PhysicsTools::BitSet::size_t size = bitSet.size();
00053         PhysicsTools::BitSet::size_t bytes = (size + 7) / 8;
00054 
00055         Calibration::BitSet result;
00056         result.store.resize(bytes);
00057         result.bitsInLast = (size + 7) % 8 + 1;
00058 
00059         for(PhysicsTools::BitSet::size_t i = 0; i < size; i++)
00060                 result.store[i / 8] |= bitSet[i] ? (1 << (i % 8)) : 0;
00061 
00062         return result;
00063 }
00064 
00065 } // namespace PhysicsTools