CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
HLTResult.h
Go to the documentation of this file.
1 #ifndef HLTReco_HLTResult_h
2 #define HLTReco_HLTResult_h
3 #include <boost/static_assert.hpp>
4 #include <algorithm>
5 
6 namespace reco {
7 
8  namespace hlt {
9 
10  template<unsigned int numberOfBits, typename word = unsigned short>
11  struct wordConstants {
12  enum {
13  bytesInAWord = sizeof( word ),
14  numberOfWords = 1 + ( numberOfBits - 1 ) / bytesInAWord
15  };
16  };
17 
18  template<unsigned short i, typename W>
19  struct mask {
20  enum {
21  wordOffset = i / W::numberOfWords,
22  bitOffset = i % W::numberOfWords,
23  value = mask<bitOffset - 1, W>::value << 1
24  };
25  };
26 
27  template<typename W>
28  struct mask<0, W> {
29  enum {
31  bitOffset = 0,
32  value = 1
33  };
34  };
35 
36  }
37 
38  template<unsigned int numberOfBits, typename word = unsigned short>
39  class HLTResult {
40  BOOST_STATIC_ASSERT( numberOfBits > 0 );
41  public:
43  HLTResult( word w[] ) { std::copy( w, w + size, words_ ); }
44  public:
45  template<unsigned short i>
46  bool match() const {
47  typedef hlt::mask<i, wordConstants> mask;
48  return words_[ mask::wordOffset ] & mask::value;
49  }
50  template<unsigned short i>
51  void set() {
52  typedef hlt::mask<i, wordConstants> mask;
53  words_[ mask::wordOffset ] |= mask::value;
54  }
55  template<unsigned short i>
56  void unSet() {
57  typedef hlt::mask<i, wordConstants> mask;
58  words_[ mask::wordOffset ] &= ! mask::value;
59  }
60 
61  private:
63  enum { wordSize = sizeof( word ), size = 1 + ( numberOfBits - 1 ) / wordSize };
64  word words_[ size ];
65  };
66 
67 }
68 
69 #endif
int i
Definition: DBlmapReader.cc:9
string fill
Definition: lumiContext.py:319
bool match() const
Definition: HLTResult.h:46
void unSet()
Definition: HLTResult.h:56
hlt::wordConstants< numberOfBits, word > wordConstants
Definition: HLTResult.h:62
word words_[size]
Definition: HLTResult.h:64
BOOST_STATIC_ASSERT(numberOfBits > 0)
HLTResult(word w[])
Definition: HLTResult.h:43
T w() const