CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_2_9/src/EventFilter/CSCRawToDigi/src/bitset_append.cc

Go to the documentation of this file.
00001 
00002 
00003 #include "EventFilter/CSCRawToDigi/src/bitset_append.h" 
00004 #include <iostream>
00005 #include <cstdio>
00006 
00007 namespace bitset_utilities {
00008 
00010   boost::dynamic_bitset<> append(const boost::dynamic_bitset<> & bs1, 
00011                                  const boost::dynamic_bitset<> & bs2)
00012   {
00013     boost::dynamic_bitset<> result(bs1.size()+bs2.size());
00014     unsigned size1 = bs1.size();
00015     for(unsigned i = 0; i < size1; ++i)
00016       {
00017         result[i] = bs1[i];
00018       }
00019     for(unsigned i = 0; i < bs2.size(); ++i)
00020       {
00021         result[size1+i] = bs2[i];
00022       }
00023     return result;
00024   }
00025 
00027   boost::dynamic_bitset<> ushortToBitset(const unsigned int numberOfBits,
00028                                          unsigned short * buf)
00029   {
00030     boost::dynamic_bitset<> result(numberOfBits);
00031     for(unsigned i = 0; i < result.size(); ++i)
00032       {
00033         result[i] = (buf[i/16]>>(i%16)) & 0x1;
00034       }
00035     return result;
00036   }
00037 
00038 
00040   void bitsetToChar(const boost::dynamic_bitset<> & bs, unsigned char * result)
00041   {
00042     for(unsigned i = 0; i < bs.size(); ++i)
00043       {
00044         result[i/8] =  (bs[i+7]<<7)+
00045           (bs[i+6]<<6)+
00046           (bs[i+5]<<5)+
00047           (bs[i+4]<<4)+ 
00048           (bs[i+3]<<3)+
00049           (bs[i+2]<<2)+
00050           (bs[i+1]<<1)+
00051           bs[i];
00052         i+=7;
00053       }
00054   }
00055 
00056   void printWords(const boost::dynamic_bitset<> & bs) 
00057   {
00058     unsigned char words[60000];
00059     bitsetToChar(bs, words);
00060     unsigned short * buf= (unsigned short *) words;
00061     for (int unsigned i=0;i<bs.size()/16;++i) {
00062       printf("%04x %04x %04x %04x\n",buf[i+3],buf[i+2],buf[i+1],buf[i]);
00063       i+=3;
00064     }
00065   }
00066 }