Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:10:25

0001 ///this file contains additional dynamic_bitset methods
0002 
0003 #include "EventFilter/CSCRawToDigi/interface/bitset_append.h"
0004 #include <iostream>
0005 #include <cstdio>
0006 
0007 namespace bitset_utilities {
0008 
0009   ///this method takes two bitsets bs1 and bs2 and returns result of bs2 appended to the end of bs1
0010   boost::dynamic_bitset<> append(const boost::dynamic_bitset<> &bs1, const boost::dynamic_bitset<> &bs2) {
0011     boost::dynamic_bitset<> result(bs1.size() + bs2.size());
0012     unsigned size1 = bs1.size();
0013     for (unsigned i = 0; i < size1; ++i) {
0014       result[i] = bs1[i];
0015     }
0016     for (unsigned i = 0; i < bs2.size(); ++i) {
0017       result[size1 + i] = bs2[i];
0018     }
0019     return result;
0020   }
0021 
0022   ///this method takes numberOfBits bits from unsigned short * array and returns them in the bitset obj.
0023   boost::dynamic_bitset<> ushortToBitset(const unsigned int numberOfBits, unsigned short *buf) {
0024     boost::dynamic_bitset<> result(numberOfBits);
0025     for (unsigned i = 0; i < result.size(); ++i) {
0026       result[i] = (buf[i / 16] >> (i % 16)) & 0x1;
0027     }
0028     return result;
0029   }
0030 
0031   ///this method takes bitset obj and returns char * array
0032   void bitsetToChar(const boost::dynamic_bitset<> &bs, unsigned char *result) {
0033     for (unsigned i = 0; i < bs.size(); ++i) {
0034       result[i / 8] = (bs[i + 7] << 7) + (bs[i + 6] << 6) + (bs[i + 5] << 5) + (bs[i + 4] << 4) + (bs[i + 3] << 3) +
0035                       (bs[i + 2] << 2) + (bs[i + 1] << 1) + bs[i];
0036       i += 7;
0037     }
0038   }
0039 
0040   void printWords(const boost::dynamic_bitset<> &bs) {
0041     constexpr unsigned int nShorts = 30000;
0042     unsigned char words[nShorts * 2];
0043     bitsetToChar(bs, words);
0044     unsigned short *buf = (unsigned short *)words;
0045     for (int unsigned i = 0; i < bs.size() / 16 && i + 3 < nShorts; ++i) {
0046       printf("%04x %04x %04x %04x\n", buf[i + 3], buf[i + 2], buf[i + 1], buf[i]);
0047       i += 3;
0048     }
0049   }
0050 }  // namespace bitset_utilities