CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_9_patch3/src/DataFormats/HLTReco/interface/HLTResult.h

Go to the documentation of this file.
00001 #ifndef HLTReco_HLTResult_h
00002 #define HLTReco_HLTResult_h
00003 #include <boost/static_assert.hpp>
00004 #include <algorithm>
00005 
00006 namespace reco {
00007 
00008   namespace hlt {
00009 
00010     template<unsigned int numberOfBits, typename word = unsigned short>
00011     struct wordConstants {
00012       enum {
00013         bytesInAWord = sizeof( word ),
00014         numberOfWords = 1 + ( numberOfBits - 1 ) / bytesInAWord
00015       };
00016     };
00017 
00018     template<unsigned short i, typename W>
00019     struct mask { 
00020       enum { 
00021         wordOffset = i / W::numberOfWords,
00022         bitOffset = i % W::numberOfWords,
00023         value = mask<bitOffset - 1, W>::value << 1 
00024       }; 
00025     };
00026 
00027     template<typename W>
00028     struct mask<0, W> { 
00029       enum {
00030         wordOffset = 0,
00031         bitOffset = 0,
00032         value = 1
00033       }; 
00034     };
00035 
00036   }
00037 
00038   template<unsigned int numberOfBits, typename word = unsigned short>
00039   class HLTResult {
00040     BOOST_STATIC_ASSERT( numberOfBits > 0 );
00041   public:
00042     HLTResult() { std::fill( words_, words_ + size, 0 ); }
00043     HLTResult( word w[] ) { std::copy( w, w + size, words_ ); }
00044   public:
00045     template<unsigned short i>
00046     bool match() const {
00047       typedef hlt::mask<i, wordConstants> mask;
00048       return words_[ mask::wordOffset ] & mask::value;
00049     }
00050     template<unsigned short i>
00051     void set() {
00052       typedef hlt::mask<i, wordConstants> mask;
00053       words_[ mask::wordOffset ] |= mask::value;
00054     }
00055     template<unsigned short i>
00056     void unSet() {
00057       typedef hlt::mask<i, wordConstants> mask;
00058       words_[ mask::wordOffset ] &= ! mask::value;
00059     }
00060     
00061   private:
00062     typedef hlt::wordConstants<numberOfBits, word> wordConstants;
00063     enum { wordSize = sizeof( word ), size = 1 + ( numberOfBits - 1 ) / wordSize };
00064     word words_[ size ];
00065   };
00066 
00067 }
00068 
00069 #endif